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,120 @@
using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
namespace Invector.vMelee
{
public class vCreateMeleeWeaponEditor : EditorWindow
{
GUISkin skin;
GameObject obj;
Vector2 rect = new Vector2(480, 210);
Vector2 scrool;
[MenuItem("Invector/Melee Combat/Create Melee Weapon")]
public static void CreateNewWeapon()
{
GetWindow<vCreateMeleeWeaponEditor>();
}
void OnGUI()
{
if (!skin) skin = Resources.Load("vSkin") as GUISkin;
GUI.skin = skin;
this.minSize = rect;
this.titleContent = new GUIContent("Melee Weapon", null, "Melee Weapon Creator Window");
GUILayout.BeginVertical("Melee Weapon Creator Window", "window");
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
GUILayout.BeginVertical("box");
EditorGUILayout.HelpBox("Make sure that your object doens't have any colliders or scripts, just the mesh", MessageType.Info);
obj = EditorGUILayout.ObjectField("FBX Model", obj, typeof(GameObject), true, GUILayout.ExpandWidth(true)) as GameObject;
if (obj != null && obj.GetComponent<vMeleeWeapon>() != null)
{
EditorGUILayout.HelpBox("This gameObject already contains the component vMeleeWeapon", 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=1aA_PU9-G-0&index=3&list=PLvgXGzhT_qehtuCYl2oyL-LrWoT7fhg9d");
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (obj != null)
{
if (GUILayout.Button("Create"))
Create();
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
private GameObject InstantiateNewWeapon(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 newWeapon = InstantiateNewWeapon(obj);
if (!newWeapon)
return;
newWeapon.gameObject.name = obj.name;
var weaponObj = new GameObject(newWeapon.name);
weaponObj.transform.position = newWeapon.transform.position;
weaponObj.transform.rotation = newWeapon.transform.rotation;
weaponObj.gameObject.tag = "Weapon";
var components = new GameObject("Components");
components.transform.position = newWeapon.transform.position;
components.transform.rotation = newWeapon.transform.rotation;
components.gameObject.tag = "Weapon";
var hitBox = new GameObject("hitBox", typeof(BoxCollider), typeof(vHitBox));
hitBox.transform.position = newWeapon.transform.position;
hitBox.transform.rotation = newWeapon.transform.rotation;
hitBox.gameObject.tag = "Weapon";
var layer = LayerMask.NameToLayer("Ignore Raycast");
hitBox.gameObject.layer = layer;
components.transform.SetParent(weaponObj.transform);
hitBox.transform.SetParent(components.transform);
var weapon = weaponObj.AddComponent<vMeleeWeapon>();
weapon.hitBoxes = new System.Collections.Generic.List<vHitBox>();
weapon.hitBoxes.Add(hitBox.GetComponent<vHitBox>());
newWeapon.transform.SetParent(components.transform);
newWeapon.transform.localPosition = Vector3.zero;
newWeapon.transform.localEulerAngles = Vector3.zero;
newWeapon.gameObject.tag = "Weapon";
this.Close();
}
}
}

View File

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

View File

@@ -0,0 +1,117 @@
using System;
using System.Collections;
using UnityEditor;
using UnityEngine;
namespace Invector.vMelee
{
[CustomPropertyDrawer(typeof(vDamage))]
public class vDamageDrawer : PropertyDrawer
{
public bool isOpen;
public bool valid;
GUISkin skin;
float helpBoxHeight;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var oldSkin = GUI.skin;
if (!skin) skin = Resources.Load("vSkin") as GUISkin;
if (skin) GUI.skin = skin;
position = EditorGUI.IndentedRect(position);
GUI.Box(position, "");
position.width -= 10;
position.height = 15;
position.y += 5f;
position.x += 5;
isOpen = GUI.Toggle(position, isOpen, "Damage Options", EditorStyles.miniButton);
if (isOpen)
{
var attackName = property.FindPropertyRelative("damageType");
var value = property.FindPropertyRelative("damageValue");
var staminaBlockCost = property.FindPropertyRelative("staminaBlockCost");
var staminaRecoveryDelay = property.FindPropertyRelative("staminaRecoveryDelay");
var ignoreDefense = property.FindPropertyRelative("ignoreDefense");
var activeRagdoll = property.FindPropertyRelative("activeRagdoll");
var hitreactionID = property.FindPropertyRelative("reaction_id");
var hitrecoilID = property.FindPropertyRelative("recoil_id");
var senselessTime = property.FindPropertyRelative("senselessTime");
var obj = (property.serializedObject.targetObject as MonoBehaviour);
valid = true;
if (obj != null)
{
var parent = obj.transform.parent;
if (parent != null)
{
var manager = parent.GetComponentInParent<vMeleeManager>();
valid = !(obj.GetType() == typeof(vMeleeWeapon) || obj.GetType().IsSubclassOf(typeof(vMeleeWeapon))) || manager == null;
}
}
if (!valid)
{
position.y += 20;
var style = new GUIStyle(EditorStyles.helpBox);
var content = new GUIContent("Damage type and other options can be overridden by the Animator Attack State\nIf the weapon is used by a character with an ItemManager, the damage value can be overridden by the item attribute");
helpBoxHeight = style.CalcHeight(content, position.width);
position.height = helpBoxHeight;
GUI.Box(position, content.text, style);
position.y += helpBoxHeight - 20;
}
position.height = EditorGUIUtility.singleLineHeight;
if (attackName != null)
{
position.y += 20;
EditorGUI.PropertyField(position, attackName);
}
if (value != null)
{
position.y += 20;
EditorGUI.PropertyField(position, value);
}
if (staminaBlockCost != null)
{
position.y += 20;
EditorGUI.PropertyField(position, staminaBlockCost);
}
if (staminaRecoveryDelay != null)
{
position.y += 20;
EditorGUI.PropertyField(position, staminaRecoveryDelay);
}
if (ignoreDefense != null && valid)
{
position.y += 20;
EditorGUI.PropertyField(position, ignoreDefense);
}
if (activeRagdoll != null && valid)
{
position.y += 20;
EditorGUI.PropertyField(position, activeRagdoll);
position.y += 20;
EditorGUI.PropertyField(position, senselessTime);
}
if (hitreactionID != null && valid)
{
position.y += 20;
EditorGUI.PropertyField(position, hitreactionID);
}
if (hitrecoilID != null && valid)
{
position.y += 20;
EditorGUI.PropertyField(position, hitrecoilID);
}
}
GUI.skin = oldSkin;
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return !isOpen ? 25 : (valid ? 210 : 130 + helpBoxHeight);
}
}
}

View File

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

View File

@@ -0,0 +1,30 @@
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Invector
{
[CustomPropertyDrawer(typeof(vEnumFlagAttribute))]
public class vEnumFlagDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
vEnumFlagAttribute flagSettings = (vEnumFlagAttribute)attribute;
string propName = flagSettings.enumName;
if (string.IsNullOrEmpty(propName))
propName = property.displayName;
if (property.propertyType == SerializedPropertyType.Enum)
{
EditorGUI.BeginProperty(position, label, property);
property.intValue = EditorGUI.MaskField(position, propName, property.intValue, Enum.GetNames(fieldInfo.FieldType));
EditorGUI.EndProperty();
}
else EditorGUI.PropertyField(position, property,property.hasChildren);
}
}
}

View File

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

View File

@@ -0,0 +1,226 @@
using System;
using UnityEditor;
using UnityEngine;
namespace Invector.vMelee
{
[CustomEditor(typeof(vMeleeAttackControl))]
public class vMeleeAttackControlEditor : UnityEditor.Editor
{
vMeleeAttackControl attackControl;
string currentBodyPart;
string oldBodyPart;
bool inAddBodyPart;
bool inEditBodyPart;
bool isHuman;
vAttackType currentAttackType;
GUISkin skin;
GUISkin defaultSkin;
int indexSelected;
public Texture2D m_Logo;
enum WeponSide
{
LeftLowerArm, RightLowerArm
}
void OnEnable()
{
try
{
attackControl = (vMeleeAttackControl)target;
currentAttackType = attackControl.meleeAttackType;
skin = Resources.Load("vSkin") as GUISkin;
}
catch { }
indexSelected = -1;
isHuman = true;
m_Logo = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D));
}
public override void OnInspectorGUI()
{
defaultSkin = GUI.skin;
if (skin) GUI.skin = skin;
GUILayout.BeginVertical("Melee Attack Control", "window");
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
EditorGUILayout.HelpBox("Make sure that the <b>Exit Time</b> of this state to the next one in your Combo is <b>lower</b> then the Exit Time to the Exit state, otherwise it will always exit first and never play the next animation.\n\n" +
"For Example if your Exit Time to the Exit State is 0.7 then your transition to the next state must be 0.6 or lower.\n\n" +
"The same applies to the <b>End Damage</b>", MessageType.Info);
base.OnInspectorGUI();
GUILayout.BeginVertical();
GUILayout.BeginVertical("box");
GUILayout.BeginHorizontal();
GUILayout.Box("nº", GUILayout.Width(40));
GUILayout.Box("BodyPart", GUILayout.ExpandWidth(true));
GUILayout.Box("", GUILayout.Width(20));
GUILayout.EndHorizontal();
for (int i = 0; i < attackControl.bodyParts.Count; i++)
{
GUILayout.BeginHorizontal();
GUIStyle labelCenter = EditorStyles.miniLabel;
labelCenter.alignment = TextAnchor.MiddleCenter;
GUILayout.Box(i.ToString("00"), labelCenter, GUILayout.Width(40));
Color color = GUI.color;
GUI.color = indexSelected == i ? new Color(1, 1, 0, 1) : color;
if (GUILayout.Button(attackControl.bodyParts[i], EditorStyles.miniButton))
{
if (indexSelected == i)
{
inEditBodyPart = false;
indexSelected = -1;
oldBodyPart = "";
}
else
{
indexSelected = i;
inEditBodyPart = true;
oldBodyPart = attackControl.bodyParts[indexSelected];
try
{
oldBodyPart = Enum.Parse(typeof(vHumanBones), oldBodyPart).ToString();
isHuman = true;
}
catch { isHuman = false; }
}
}
GUI.color = color;
if (attackControl.bodyParts.Count > 1 && !inEditBodyPart && GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
{
attackControl.bodyParts.RemoveAt(i);
GUILayout.EndHorizontal();
break;
}
else if (attackControl.bodyParts.Count == 1 || inEditBodyPart)
{
GUILayout.Label("", GUILayout.Width(20));
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
GUILayout.EndVertical();
if (inEditBodyPart)
{
EditBodyPart();
}
GUILayout.Space(20);
if (GUILayout.Button("Add New Body Part", EditorStyles.miniButton))
{
inAddBodyPart = true;
isHuman = true;
currentBodyPart = "RightLowerArm";
}
if (currentAttackType != attackControl.meleeAttackType)
{
currentAttackType = attackControl.meleeAttackType;
if (currentAttackType == vAttackType.MeleeWeapon)
{
var noMeleeWeapon = attackControl.bodyParts.FindAll(bodyPart => bodyPart != "LeftLowerArm" || bodyPart != "RightLowerArm");
if (noMeleeWeapon.Count > 0)
{
attackControl.bodyParts.RemoveAll(bodyPart => !(bodyPart == "LeftLowerArm" || bodyPart == "RightLowerArm"));
}
}
}
if (inAddBodyPart) AddBodyPart();
GUILayout.EndVertical();
GUI.skin = defaultSkin;
}
void AddBodyPart()
{
GUILayout.BeginVertical("box");
if (attackControl.meleeAttackType == vAttackType.Unarmed)
{
isHuman = Convert.ToBoolean(EditorGUILayout.Popup("Member Type", Convert.ToInt32(isHuman), new string[] { "Generic", "Human" }));
if (isHuman)
{
try
{
currentBodyPart = EditorGUILayout.EnumPopup("Body Part", (vHumanBones)Enum.Parse(typeof(vHumanBones), currentBodyPart)).ToString();
}
catch { currentBodyPart = "RightLowerArm"; }
}
else
{
currentBodyPart = EditorGUILayout.TextField("BodyPart Name", currentBodyPart);
}
}
else
{
currentBodyPart = EditorGUILayout.EnumPopup("Body Part", (WeponSide)Enum.Parse(typeof(WeponSide), currentBodyPart)).ToString();
}
bool isValid = true;
if (attackControl.bodyParts.Contains(currentBodyPart))
{
EditorGUILayout.HelpBox("This Body Part already exist,select another name", MessageType.Error);
isValid = false;
}
GUILayout.BeginHorizontal();
if (isValid && GUILayout.Button("Add", EditorStyles.miniButton))
{
attackControl.bodyParts.Add(currentBodyPart);
inAddBodyPart = false;
}
if (GUILayout.Button("Cancel", EditorStyles.miniButton))
{
inAddBodyPart = false;
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
void EditBodyPart()
{
GUILayout.BeginVertical("box");
GUILayout.Box("Editing BodyParty " + indexSelected.ToString("00"), GUILayout.ExpandWidth(true));
if (attackControl.meleeAttackType == vAttackType.Unarmed)
{
isHuman = Convert.ToBoolean(EditorGUILayout.Popup("Member Type", Convert.ToInt32(isHuman), new string[] { "Generic", "Human" }));
if (isHuman)
{
try
{
oldBodyPart = EditorGUILayout.EnumPopup("Body Part", (vHumanBones)Enum.Parse(typeof(vHumanBones), oldBodyPart)).ToString();
}
catch { oldBodyPart = currentBodyPart = "RightLowerArm"; }
}
else
{
oldBodyPart = EditorGUILayout.TextField("BodyPart Name", oldBodyPart);
}
}
else
{
oldBodyPart = EditorGUILayout.EnumPopup("Body Part", (WeponSide)Enum.Parse(typeof(WeponSide), oldBodyPart)).ToString();
}
bool isValid = true;
if (attackControl.bodyParts.Contains(oldBodyPart) && oldBodyPart != attackControl.bodyParts[indexSelected])
{
EditorGUILayout.HelpBox("This Body Part already exist,select another name", MessageType.Error);
isValid = false;
}
GUILayout.BeginHorizontal();
if (isValid && GUILayout.Button("Ok", EditorStyles.miniButton))
{
attackControl.bodyParts[indexSelected] = oldBodyPart;
inEditBodyPart = false;
indexSelected = -1;
}
if (GUILayout.Button("Cancel", EditorStyles.miniButton))
{
indexSelected = -1;
inEditBodyPart = false;
oldBodyPart = "";
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
}

View File

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

View File

@@ -0,0 +1,641 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Invector.vMelee
{
[CanEditMultipleObjects]
[CustomEditor(typeof(vMeleeManager), true)]
public class vMeleeManagerEditor : vEditorBase
{
#region variables
protected vMeleeManager manager;
protected Animator animator;
protected int selectedID;
protected int seletedHitboxIndex;
protected int toolBarBodyMembers;
protected int damagePercentage;
protected bool selLeftArm, selRightArm, selLeftLeg, selRightLeg, selHead, selTorso;
protected bool showEvents;
protected bool showDefaultInfo;
protected bool inAddBodyMember;
protected bool isHuman;
protected bool inCreateHitBox;
protected bool inChangeHitBoxCollider;
protected Transform leftLowerArm, rightLowerArm, leftLowerLeg, rightLowerLeg;
protected vBodyMember currentBodyMember;
protected vBodyMember extraBodyMember;
protected Component hitCollider;
protected vHitBoxType triggerType;
protected string seletedBone;
protected virtual string[] ignoreProperties => new string[] { "m_Script", "Members", "defaultDamage", "hitProperties", "leftWeapon", "rightWeapon", "onDamageHit", "onRecoilHit", "openCloseWindow", "openCloseEvents", "selectedToolbar", "onEquipWeapon" };
#endregion
protected virtual void OnSceneGUI()
{
var renderers = manager.GetComponentsInChildren<SkinnedMeshRenderer>();
foreach (SkinnedMeshRenderer renderer in renderers)
{
EditorUtility.SetSelectedRenderState(renderer, EditorSelectedRenderState.Hidden);
}
DrawRecoilRange();
}
protected override void OnEnable()
{
manager = (vMeleeManager)target;
base.OnEnable();
m_Logo = Resources.Load("meleeIcon") as Texture2D;
if (!manager.gameObject.scene.IsValid())
{
return;
}
CreateDefaultBodyMembers();
CheckMembersName(manager.Members);
}
protected virtual void CreateDefaultBodyMembers()
{
animator = manager.GetComponent<Animator>();
if (animator && animator.isHuman)
{
leftLowerArm = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
CheckSingleHitBox(leftLowerArm, vHumanBones.LeftLowerArm);
rightLowerArm = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
CheckSingleHitBox(rightLowerArm, vHumanBones.RightLowerArm);
leftLowerLeg = animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
CheckSingleHitBox(leftLowerLeg, vHumanBones.LeftLowerLeg);
rightLowerLeg = animator.GetBoneTransform(HumanBodyBones.RightLowerLeg);
CheckSingleHitBox(rightLowerLeg, vHumanBones.RightLowerLeg);
}
}
protected virtual void CheckMembersName(List<vBodyMember> Members)
{
foreach (var member in Members)
{
if (member.attackObject)
{
member.attackObject.attackObjectName = member.bodyPart;
}
}
}
protected virtual void CheckSingleHitBox(Transform transform, vHumanBones bodyPart, bool debug = false)
{
if (transform)
{
vMeleeAttackObject attackObject = transform.GetComponent<vMeleeAttackObject>();
if (attackObject == null)
{
attackObject = transform.gameObject.AddComponent<vMeleeAttackObject>();
}
var _hitBoxes = transform.GetComponentsInChildren<vHitBox>();
var validHitBoxes = _hitBoxes.vToList().FindAll(hitBox => hitBox.transform.parent == attackObject.transform);
attackObject.hitBoxes = validHitBoxes;
if (manager && manager.Members != null)
{
var bodyMembers = manager.Members.FindAll(member => member.bodyPart == bodyPart.ToString());
if (bodyMembers.Count > 0)
{
bodyMembers[0].isHuman = true;
bodyMembers[0].attackObject = attackObject;
bodyMembers[0].bodyPart = bodyPart.ToString();
bodyMembers[0].transform = transform;
if (bodyMembers.Count > 1)
{
for (int i = 1; i < bodyMembers.Count; i++)
{
manager.Members.Remove(bodyMembers[i]);
}
}
CheckHitBoxes(bodyMembers[0], true);
EditorUtility.SetDirty(manager);
}
else
{
vBodyMember bodyMember = new vBodyMember();
bodyMember.isHuman = true;
bodyMember.attackObject = attackObject;
bodyMember.bodyPart = bodyPart.ToString();
bodyMember.transform = transform;
manager.Members.Add(bodyMember);
CheckHitBoxes(bodyMember, true);
EditorUtility.SetDirty(manager);
}
}
}
serializedObject.ApplyModifiedProperties();
}
public override void OnInspectorGUI()
{
var oldSkin = GUI.skin;
GUI.skin = skin;
var script = serializedObject.FindProperty("m_Script");
GUILayout.BeginVertical("MELEE MANAGER", "window");
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
openCloseWindow = GUILayout.Toggle(openCloseWindow, openCloseWindow ? "Close" : "Open", EditorStyles.toolbarButton);
if (openCloseWindow)
{
if (script != null)
{
EditorGUILayout.PropertyField(script);
}
GUI.enabled = !AssetDatabase.Contains(manager.gameObject);
if (manager.Members == null || manager.Members.Count == 0)
{
if (GUILayout.Button("Create Default Body Members", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
CreateDefaultBodyMembers();
}
}
GUILayout.BeginVertical("box");
OpenCloseDefaultInfo();
OpenCloseEvents(oldSkin);
AddExtraBodyPart();
//GUI.enabled = true;
GUILayout.EndVertical();
var seletedBodyMember = manager.Members.Find(member => member.bodyPart == seletedBone);
GUILayout.BeginVertical(seletedBodyMember != null ? "highlightBox" : "box");
DrawBodyMemberToogles();
if (seletedBodyMember != null)
{
bool canRemove = seletedBodyMember.bodyPart != vHumanBones.LeftLowerArm.ToString() && seletedBodyMember.bodyPart != vHumanBones.RightLowerArm.ToString() &&
seletedBodyMember.bodyPart != vHumanBones.LeftLowerLeg.ToString() && seletedBodyMember.bodyPart != vHumanBones.RightLowerLeg.ToString();
DrawBodyMember(ref seletedBodyMember, seletedBodyMember.bodyPart.ToString(), canRemove);
}
GUILayout.EndVertical();
GUILayout.BeginVertical("box");
GUILayout.Label("Who you can Hit?", GUILayout.ExpandWidth(true));
EditorGUILayout.PropertyField(serializedObject.FindProperty("hitProperties"), true);
GUILayout.EndVertical();
GUILayout.BeginVertical("box");
GUILayout.Label("Weapons");
GUILayout.BeginHorizontal();
GUILayout.BeginVertical("box");
GUILayout.Label("LeftWeapon", EditorStyles.miniLabel);
manager.leftWeapon = EditorGUILayout.ObjectField(manager.leftWeapon, typeof(vMeleeWeapon), true) as vMeleeWeapon;
GUILayout.EndVertical();
GUILayout.BeginVertical("box");
GUILayout.Label("RightWeapon", EditorStyles.miniLabel);
manager.rightWeapon = EditorGUILayout.ObjectField(manager.rightWeapon, typeof(vMeleeWeapon), true) as vMeleeWeapon;
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
GUILayout.EndVertical();
serializedObject.ApplyModifiedProperties();
if (GUI.changed)
{
EditorUtility.SetDirty(target);
}
}
protected virtual void OpenCloseEvents(GUISkin oldSkin)
{
var onDamageHit = serializedObject.FindProperty("onDamageHit");
var onRecoilHit = serializedObject.FindProperty("onRecoilHit");
var onEquipWeapon = serializedObject.FindProperty("onEquipWeapon");
GUILayout.BeginVertical(showEvents ? "highlightBox" : "box");
showEvents = GUILayout.Toggle(showEvents, showEvents ? "Close Events" : "Open Events", EditorStyles.miniButton);
GUI.skin = oldSkin;
if (showEvents)
{
if (onDamageHit != null)
{
EditorGUILayout.PropertyField(onDamageHit);
}
if (onRecoilHit != null)
{
EditorGUILayout.PropertyField(onRecoilHit);
}
if (onEquipWeapon != null)
{
EditorGUILayout.PropertyField(onEquipWeapon);
}
}
GUI.skin = skin;
GUILayout.EndVertical();
}
protected virtual void OpenCloseDefaultInfo()
{
GUILayout.BeginVertical(showDefaultInfo ? "highlightBox" : "box");
showDefaultInfo = GUILayout.Toggle(showDefaultInfo, showDefaultInfo ? "Close Default Info" : "Open Default Info", EditorStyles.miniButton);
var oldSkin = GUI.skin;
GUI.skin = oldSkin;
if (showDefaultInfo)
{
manager.defaultDamage.damageValue = EditorGUILayout.FloatField("DefaultDamage", manager.defaultDamage.damageValue);
DrawPropertiesExcluding(serializedObject, ignoreProperties);
}
GUI.skin = skin;
GUILayout.EndVertical();
}
protected virtual void AddExtraBodyPart()
{
GUILayout.BeginVertical(inAddBodyMember ? "highlightBox" : "box");
if (!inAddBodyMember && GUILayout.Button("Add Extra Body Member", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
extraBodyMember = new vBodyMember();
inAddBodyMember = true;
isHuman = true;
}
if (inAddBodyMember)
{
DrawAddExtraBodyMember();
}
GUILayout.EndVertical();
}
protected virtual void DrawRecoilRange()
{
var coll = manager.gameObject.GetComponent<Collider>();
if (coll != null && manager != null && manager.hitProperties != null && manager.hitProperties.useRecoil && manager.hitProperties.drawRecoilGizmos)
{
Handles.DrawWireDisc(coll.bounds.center, Vector3.up, 0.5f);
Handles.color = new Color(1, 0, 0, 0.2f);
Handles.DrawSolidArc(coll.bounds.center, Vector3.up, manager.transform.forward, manager.hitProperties.recoilRange, 0.5f);
Handles.DrawSolidArc(coll.bounds.center, Vector3.up, manager.transform.forward, (float)-manager.hitProperties.recoilRange, 0.5f);
}
}
protected virtual void DrawBodyMemberToogles()
{
var bmleftLowerArm = manager.Members.Find(member => member.bodyPart == vHumanBones.LeftLowerArm.ToString());
var bmrightLowerArm = manager.Members.Find(member => member.bodyPart == vHumanBones.RightLowerArm.ToString());
var bmleftLowerLeg = manager.Members.Find(member => member.bodyPart == vHumanBones.LeftLowerLeg.ToString());
var bmrightLowerLeg = manager.Members.Find(member => member.bodyPart == vHumanBones.RightLowerLeg.ToString());
GUILayout.BeginVertical();
GUILayout.Label("Body Members", GUILayout.ExpandWidth(true));
GUILayout.EndVertical();
// GUILayout.Box("Default Human Body Members", GUILayout.ExpandWidth(true));
GUILayout.BeginHorizontal();
if (bmleftLowerArm != null)
{
BodyMemberToogle(bmleftLowerArm.bodyPart, ref bmleftLowerArm, "LeftLowerArm");
}
if (bmrightLowerArm != null)
{
BodyMemberToogle(bmrightLowerArm.bodyPart, ref bmrightLowerArm, "RightLowerArm");
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (bmleftLowerLeg != null)
{
BodyMemberToogle(bmleftLowerLeg.bodyPart, ref bmleftLowerLeg, "LeftLowerLeg");
}
if (bmrightLowerLeg != null)
{
BodyMemberToogle(bmrightLowerLeg.bodyPart, ref bmrightLowerLeg, "RightLowerLeg");
}
GUILayout.EndHorizontal();
//GUILayout.Box("Extra Human BodyMembers", GUILayout.ExpandWidth(true));
for (int i = 0; i < manager.Members.Count; i++)
{
if (manager.Members[i] != bmleftLowerArm && manager.Members[i] != bmrightLowerArm &&
manager.Members[i] != bmleftLowerLeg && manager.Members[i] != bmrightLowerLeg)
{
var bodyMember = manager.Members[i];
BodyMemberToogle(bodyMember.bodyPart, ref bodyMember, bodyMember.bodyPart.ToString());
CheckHitBoxes(manager.Members[i]);
}
else
{
CheckHitBoxes(manager.Members[i], true);
}
}
}
protected virtual void CheckHitBoxes(vBodyMember bodyMember, bool isDefault = false)
{
if (AssetDatabase.Contains(manager.gameObject))
{
return;
}
var hitBoxes = bodyMember.transform.GetComponentsInChildren<vHitBox>();
var _result = hitBoxes.vToList().FindAll(hitBox => hitBox.transform.parent == bodyMember.transform);
if (_result.Count > 0)
{
if (bodyMember.attackObject) bodyMember.attackObject.hitBoxes = _result;
}
else
{
var hitBox = new GameObject("hitBox", typeof(vHitBox), typeof(BoxCollider));
var scale = Vector3.one * 0.15f;
if (isDefault)
{
var lookDir = bodyMember.transform.GetChild(0).position - bodyMember.transform.position;
var rotation = Quaternion.LookRotation(lookDir);
scale.z = Vector3.Distance(bodyMember.transform.position, bodyMember.transform.GetChild(0).position);
var point = bodyMember.transform.position + (lookDir.normalized) * (scale.z * 0.7f);
hitBox.transform.position = point;
hitBox.transform.rotation = rotation;
hitBox.transform.localScale = scale;
hitBox.transform.parent = bodyMember.transform;
}
else
{
hitBox.transform.localScale = scale;
hitBox.transform.parent = bodyMember.transform;
hitBox.transform.localPosition = Vector3.zero;
hitBox.transform.localEulerAngles = Vector3.zero;
}
}
}
protected virtual void DrawAddExtraBodyMember()
{
if (extraBodyMember != null)
{
isHuman = Convert.ToBoolean(EditorGUILayout.Popup("Member Type", Convert.ToInt32(isHuman), new string[] { "Generic", "Human" }));
extraBodyMember.isHuman = isHuman;
if (isHuman)
{
vHumanBones humanBone = 0;
try
{
humanBone = (vHumanBones)Enum.Parse(typeof(vHumanBones), extraBodyMember.bodyPart);
}
catch { }
humanBone = (vHumanBones)EditorGUILayout.EnumPopup("Body Part", humanBone);
extraBodyMember.bodyPart = humanBone.ToString();
var humanBodyBone = (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), extraBodyMember.bodyPart);
extraBodyMember.transform = manager.GetComponent<Animator>().GetBoneTransform(humanBodyBone);
}
else
{
extraBodyMember.bodyPart = EditorGUILayout.TextField("BodyPart Name", extraBodyMember.bodyPart);
}
extraBodyMember.transform = EditorGUILayout.ObjectField("Body Member", extraBodyMember.transform, typeof(Transform), true) as Transform;
var valid = true;
if (extraBodyMember.transform != null && manager.Members.Find(member => member.transform == extraBodyMember.transform) != null)
{
EditorGUILayout.HelpBox("This Body Member already exists, select another", MessageType.Error);
valid = false;
}
if (manager.Members.Find(member => member.bodyPart == extraBodyMember.bodyPart) != null)
{
EditorGUILayout.HelpBox("This Body Part already exists, select another", MessageType.Error);
valid = false;
}
GUILayout.BeginHorizontal();
if (valid)
{
if (GUILayout.Button("Create", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
vBodyMember member = new vBodyMember();
member.attackObject = extraBodyMember.transform.gameObject.AddComponent<vMeleeAttackObject>();
member.transform = extraBodyMember.transform;
member.bodyPart = extraBodyMember.bodyPart;
var type = typeof(BoxCollider);
var hitObject = new GameObject("hitBox", typeof(vHitBox), type);
hitObject.transform.localScale = Vector3.one * 0.2f;
hitObject.transform.parent = member.transform;
hitObject.transform.localPosition = Vector3.zero;
hitObject.transform.localEulerAngles = Vector3.zero;
var hitBox = hitObject.GetComponent<vHitBox>();
hitBox.damagePercentage = 100;
hitBox.triggerType = vHitBoxType.Damage | vHitBoxType.Recoil;
member.attackObject.hitBoxes = new List<vHitBox>();
member.attackObject.hitBoxes.Add(hitBox);
inCreateHitBox = false;
manager.Members.Add(member);
extraBodyMember = null;
inAddBodyMember = false;
}
}
if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
extraBodyMember = null;
inAddBodyMember = false;
}
GUILayout.EndHorizontal();
}
}
protected virtual void DrawBodyMember(ref vBodyMember bodyMember, string name, bool canRemove = false)
{
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
//GUILayout.Box("Selected " + name, GUILayout.ExpandWidth(true));
if (canRemove && GUILayout.Button("X"))
{
var hitColliders = bodyMember.attackObject.hitBoxes;
for (int i = 0; i < hitColliders.Count; i++)
{
DestroyImmediate(hitColliders[i].gameObject);
}
DestroyImmediate(bodyMember.attackObject);
manager.Members.Remove(bodyMember);
}
GUILayout.EndHorizontal();
bodyMember.attackObject = EditorGUILayout.ObjectField("Attack Object", bodyMember.attackObject, typeof(vMeleeAttackObject), true) as vMeleeAttackObject;
if (bodyMember.attackObject) bodyMember.attackObject.damageModifier = EditorGUILayout.IntField(new GUIContent("Damage Modifier +", "Use This to Change the Default damage"), bodyMember.attackObject.damageModifier);
GUILayout.Box("Hit Boxes", GUILayout.ExpandWidth(true));
DrawHitBoxesList(bodyMember.attackObject);
GUILayout.EndVertical();
}
protected virtual void DrawHitBoxesList(vMeleeAttackObject attackObject)
{
if (attackObject != null && attackObject.hitBoxes != null)
{
for (int i = 0; i < attackObject.hitBoxes.Count; i++)
{
try
{
GUILayout.BeginHorizontal();
if (attackObject.hitBoxes[i] != null && attackObject.hitBoxes[i].transform == attackObject.transform ||
(attackObject.GetComponent<vHitBox>() != null))
{
DestroyImmediate(attackObject.GetComponent<vHitBox>());
attackObject.hitBoxes.RemoveAt(i);
GUILayout.EndHorizontal();
break;
}
Color color = GUI.color;
GUI.color = seletedHitboxIndex == i ? new Color(1, 1, 0, 0.6f) : color;
if (GUILayout.Button("Hit Box " + (i + 1), EditorStyles.miniButton))
{
if (seletedHitboxIndex == i)
{
seletedHitboxIndex = -1;
}
else
{
seletedHitboxIndex = i;
}
}
GUI.color = color;
if (attackObject.hitBoxes.Count > 1 && GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
{
if (attackObject.hitBoxes[i] != null && attackObject.hitBoxes[i].transform != attackObject.transform)
{
DestroyImmediate(attackObject.hitBoxes[i].gameObject);
}
attackObject.hitBoxes.RemoveAt(i);
GUILayout.EndHorizontal();
break;
}
GUILayout.EndHorizontal();
}
catch { }
}
}
if (seletedHitboxIndex > -1 && seletedHitboxIndex < attackObject.hitBoxes.Count)
{
GUILayout.BeginVertical("box");
var hitBox = attackObject.hitBoxes[seletedHitboxIndex];
if (hitBox)
{
EditorGUILayout.ObjectField("Selected Hit Box " + (seletedHitboxIndex + 1), hitBox, typeof(vHitBox), true);
//GUILayout.Box("Hit Settings", GUILayout.ExpandWidth(true));
hitBox.damagePercentage = EditorGUILayout.IntSlider("Damage Percentage", hitBox.damagePercentage, 0, 100);
#if UNITY_2017_3_OR_NEWER
hitBox.triggerType = (vHitBoxType)EditorGUILayout.EnumFlagsField("Trigger Type", hitBox.triggerType);
#else
hitBox.triggerType = (vHitBoxType)EditorGUILayout.EnumMaskField("Trigger Type", hitBox.triggerType);
#endif
if (GUI.changed)
{
EditorUtility.SetDirty(hitBox);
}
}
GUILayout.EndVertical();
}
GUILayout.Space(10);
if (!inCreateHitBox && GUILayout.Button("Create New Hit Box", EditorStyles.miniButton))
{
inCreateHitBox = true;
damagePercentage = 100;
triggerType = vHitBoxType.Damage | vHitBoxType.Recoil;
}
if (inCreateHitBox)
{
GUILayout.Box("New Hit Box", GUILayout.ExpandWidth(true));
damagePercentage = EditorGUILayout.IntSlider("Damage Percentage", damagePercentage, 0, 100);
#if UNITY_2017_3_OR_NEWER
triggerType = (vHitBoxType)EditorGUILayout.EnumFlagsField("Trigger Type", triggerType);
#else
triggerType = (vHitBoxType)EditorGUILayout.EnumMaskField("Trigger Type", triggerType);
#endif
GUILayout.BeginHorizontal();
if (GUILayout.Button("Create", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
var type = typeof(BoxCollider);
var hitObject = new GameObject("hitBox", typeof(vHitBox), type);
hitObject.transform.localScale = Vector3.one * 0.2f;
hitObject.transform.parent = attackObject.transform;
hitObject.transform.localPosition = Vector3.zero;
hitObject.transform.localEulerAngles = Vector3.zero;
var hitBox = hitObject.GetComponent<vHitBox>();
hitBox.damagePercentage = damagePercentage;
hitBox.triggerType = triggerType;
attackObject.hitBoxes.Add(hitBox);
inCreateHitBox = false;
}
if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
inCreateHitBox = false;
}
GUILayout.EndHorizontal();
}
GUILayout.Space(10);
}
protected virtual void BodyMemberToogle(string bodyPart, ref vBodyMember bodyMember, string name)
{
if (bodyMember != null)
{
Color color = GUI.color;
GUI.color = seletedBone == bodyPart ? new Color(1, 1, 0, 0.6f) : color;
if (GUILayout.Button(name, EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
if (seletedBone == bodyPart)
{
seletedBone = "null";
}
else
{
seletedBone = bodyPart;
}
seletedHitboxIndex = -1;
Repaint();
}
GUI.color = color;
if (bodyMember.attackObject)
{
foreach (vHitBox hitBox in bodyMember.attackObject.hitBoxes)
{
if (hitBox != null)
{
hitBox.gameObject.tag = "Ignore Ragdoll";
hitBox.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
}
}
}
}
}
}
}

View File

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