This commit is contained in:
2026-05-30 09:16:35 +07:00
parent 2f87ce19a7
commit 1c0ee6efb7
4001 changed files with 3363438 additions and 1738 deletions

View File

@@ -0,0 +1,298 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Invector.vMelee
{
using Invector.vCamera;
using Invector.vItemManager;
using vCharacterController;
public class vCreateMeleeCharacterEditor : EditorWindow
{
GUISkin skin;
public GameObject template;
public bool useGameController = true;
public bool useInventory = true;
public GameObject inventory;
public vItemListData itemListData;
public GameObject charObj;
Animator charAnimator;
Vector2 rect = new Vector2(500, 660);
UnityEditor.Editor humanoidpreview;
Texture2D m_Logo;
/// <summary>
/// 3rdPersonController Menu
/// </summary>
[MenuItem("Invector/Melee Combat/Create Melee Controller", false, 1)]
public static void CreateNewCharacter()
{
GetWindow<vCreateMeleeCharacterEditor>();
}
bool isHuman, isValidAvatar, charExist;
public virtual void OnEnable()
{
m_Logo = Resources.Load("icon_v2") as Texture2D;
if (Selection.activeObject)
{
charObj = Selection.activeGameObject;
}
if (charObj)
{
charAnimator = charObj.GetComponent<Animator>();
humanoidpreview = Editor.CreateEditor(charObj);
}
charExist = charAnimator != null;
isHuman = charExist ? charAnimator.isHuman : false;
isValidAvatar = charExist ? charAnimator.avatar.isValid : false;
}
public virtual void OnGUI()
{
if (!skin)
{
skin = Resources.Load("vSkin") as GUISkin;
}
GUI.skin = skin;
this.minSize = rect;
this.titleContent = new GUIContent("Character", null, "Third Person Character Creator");
GUILayout.BeginVertical("Character Creator Window", "window");
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
GUILayout.Space(5);
GUILayout.BeginVertical("box");
if (!charObj)
{
EditorGUILayout.HelpBox("Make sure your FBX model is set as Humanoid!", MessageType.Info);
}
else if (!charExist)
{
EditorGUILayout.HelpBox("Missing a Animator Component", MessageType.Error);
}
else if (!isHuman)
{
EditorGUILayout.HelpBox("This is not a Humanoid", MessageType.Error);
}
else if (!isValidAvatar)
{
EditorGUILayout.HelpBox(charObj.name + " is a invalid Humanoid", MessageType.Info);
}
template = EditorGUILayout.ObjectField("Template", template, typeof(GameObject), true, GUILayout.ExpandWidth(true)) as GameObject;
charObj = EditorGUILayout.ObjectField("FBX Model", charObj, typeof(GameObject), true, GUILayout.ExpandWidth(true)) as GameObject;
EditorGUILayout.Space();
EditorGUILayout.LabelField("--- Optional---");
useGameController = EditorGUILayout.Toggle("Add GameController", useGameController);
useInventory = EditorGUILayout.Toggle("Add Inventory", useInventory);
if (useInventory)
{
inventory = EditorGUILayout.ObjectField("Inventory Prefab", inventory, typeof(GameObject), true, GUILayout.ExpandWidth(true)) as GameObject;
itemListData = EditorGUILayout.ObjectField("ItemListData", itemListData, typeof(vItemListData), true, GUILayout.ExpandWidth(true)) as vItemListData;
}
if (GUI.changed && charObj != null && charObj.GetComponent<vThirdPersonController>() == null)
{
humanoidpreview = Editor.CreateEditor(charObj);
}
if (charObj != null && charObj.GetComponent<vThirdPersonController>() != null)
{
EditorGUILayout.HelpBox("This gameObject already contains the component vThirdPersonController", MessageType.Warning);
}
GUILayout.EndVertical();
//GUILayout.BeginHorizontal("box");
//EditorGUILayout.LabelField("Need to know how it works?");
//if (GUILayout.Button("Video Tutorial"))
//{
// Application.OpenURL("https://www.youtube.com/watch?v=KQ5xha36tfE&index=1&list=PLvgXGzhT_qehtuCYl2oyL-LrWoT7fhg9d");
//}
//GUILayout.EndHorizontal();
if (charObj)
{
charAnimator = charObj.GetComponent<Animator>();
}
charExist = charAnimator != null;
isHuman = charExist ? charAnimator.isHuman : false;
isValidAvatar = charExist ? charAnimator.avatar.isValid : false;
if (CanCreate())
{
DrawHumanoidPreview();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Create"))
{
Create();
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
public virtual bool CanCreate()
{
return isValidAvatar && isHuman && charObj != null && charObj.GetComponent<vThirdPersonController>() == null;
}
/// <summary>
/// Draw the Preview window
/// </summary>
public virtual void DrawHumanoidPreview()
{
GUILayout.FlexibleSpace();
if (humanoidpreview != null)
{
humanoidpreview.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(100, 400), "window");
}
}
private GameObject InstantiateNewCharacter(GameObject selected)
{
if (selected == null)
{
return selected;
}
if (selected.scene.IsValid())
{
return selected;
}
return PrefabUtility.InstantiatePrefab(selected) as GameObject;
}
/// <summary>
/// Created the Third Person Controller
/// </summary>
public virtual void Create()
{
// base for the character
GameObject newCharacter = InstantiateNewCharacter(charObj);
if (!newCharacter)
{
return;
}
GameObject _template = Instantiate(template, newCharacter.transform.position, newCharacter.transform.rotation);
// finds the '3D Model' gameobject or crate one if it doesn't exist
Transform modelParent = _template.transform.Find("3D Model");
if (modelParent == null)
{
modelParent = new GameObject("3D Model").transform;
modelParent.parent = _template.transform;
}
// finds the 'Invector Components' gameobject or crate one if it doesn't exist
Transform componentsParent = _template.transform.Find("Invector Components");
if (componentsParent == null)
{
componentsParent = new GameObject("Invector Components").transform;
componentsParent.parent = _template.transform;
}
newCharacter.transform.parent = modelParent;
newCharacter.transform.localPosition = Vector3.zero;
newCharacter.transform.localEulerAngles = Vector3.zero;
_template.name = "vMeleeController_" + charObj.gameObject.name;
Animator animatorController = newCharacter.GetComponent<Animator>();
Animator animatorTemplate = _template.GetComponent<Animator>();
animatorTemplate.avatar = animatorController.avatar;
animatorTemplate.Rebind();
DestroyImmediate(animatorController);
newCharacter.tag = "Player";
var p_layer = LayerMask.NameToLayer("Player");
newCharacter.layer = p_layer;
foreach (Transform t in newCharacter.transform.GetComponentsInChildren<Transform>())
{
t.gameObject.layer = p_layer;
}
Selection.activeGameObject = _template;
// search for a MainCamera and attach to the tpCamera
var mainCamera = Camera.main;
var tpCamera = _template.GetComponentInChildren<vThirdPersonCamera>();
if (mainCamera == null)
{
mainCamera = new GameObject("MainCamera", typeof(Camera), typeof(AudioListener)).GetComponent<Camera>();
mainCamera.tag = "MainCamera";
}
if (mainCamera.transform.parent != tpCamera.transform)
{
mainCamera.transform.parent = tpCamera.transform;
mainCamera.transform.localPosition = Vector3.zero;
mainCamera.transform.localEulerAngles = Vector3.zero;
}
// add the gameController example
if (useGameController)
{
GameObject gC = null;
var gameController = FindObjectOfType<vGameController>();
if (gameController == null)
{
gC = new GameObject("vGameController_Example");
gC.AddComponent<vGameController>();
}
}
if (useInventory)
{
// add prefab inventory to the 'Invector Components' gameObject inside the Controller
inventory = Instantiate(inventory, componentsParent.transform.position, componentsParent.transform.rotation);
inventory.gameObject.transform.parent = componentsParent.transform;
inventory.transform.localPosition = Vector3.zero;
inventory.transform.localEulerAngles = Vector3.zero;
// add shooter melee item list data
var _itemManager = _template.GetComponent<vItemManager>();
_itemManager.itemListData = itemListData;
}
else
{
// remove ItemManager from the character
var _inventory = _template.GetComponent<vItemManager>();
DestroyImmediate(_inventory as vItemManager, true);
}
// load bones for the BodySnapControl
var _bodySnap = _template.GetComponentInChildren<vBodySnappingControl>();
_bodySnap.LoadBones();
UnityEditor.SceneView.lastActiveSceneView.FrameSelected();
this.Close();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 02a4e7a48de713e4c9a33da11544a1c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_PersistentViewDataDictionary: {instanceID: 0}
- template: {fileID: 123100320241753025, guid: d9a4707ba2be96f49b3704765aafa732,
type: 3}
- inventory: {fileID: 3444320678111530354, guid: 3ae53b796aaabf94ba9bd40ed132f17d,
type: 3}
- itemListData: {fileID: 11400000, guid: 96e918a0f3173b14dbbbe08b7523b670, type: 2}
- charObj: {fileID: 199726, guid: 5563b2c1cf35cae4f8490dfea2d2aa41, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
using UnityEngine;
using UnityEditor;
namespace Invector
{
// MELEE COMBAT FEATURES
public partial class vMenuComponent
{
public const string path = "Invector/Melee Combat/Components/";
[MenuItem(path + "Melee Manager")]
static void MeleeManagerMenu()
{
if (Selection.activeGameObject)
Selection.activeGameObject.AddComponent<vMelee.vMeleeManager>();
else
Debug.Log("Please select a vCharacter to add the component.");
}
[MenuItem(path + "WeaponHolderManager (Player Only)")]
static void WeaponHolderMenu()
{
if (Selection.activeGameObject && Selection.activeGameObject.GetComponent<Invector.vCharacterController.vThirdPersonInput>() != null)
Selection.activeGameObject.AddComponent<Invector.vItemManager.vWeaponHolderManager>();
else
Debug.Log("Please select the Player to add the component.");
}
[MenuItem(path + "LockOn (Player Only)")]
static void LockOnMenu()
{
if (Selection.activeGameObject && Selection.activeGameObject.GetComponent<Invector.vCharacterController.vThirdPersonInput>() != null)
Selection.activeGameObject.AddComponent<vCharacterController.vLockOn>();
else
Debug.Log("Please select a Player to add the component.");
}
[MenuItem(path + "DrawHide MeleeWeapons")]
static void DrawMeleeWeaponMenu()
{
if (Selection.activeGameObject && Selection.activeGameObject.GetComponent<Invector.vCharacterController.vMeleeCombatInput>() != null)
Selection.activeGameObject.AddComponent<vDrawHideMeleeWeapons>();
else
Debug.Log("Please select a Player to add the component.");
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ff99e6ba5dc57ab43b12c4177a80f216
timeCreated: 1495232492
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: