void BodyMemberToogle(string bodyPart, ref BodyMember 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;

            foreach (HitBox hitBox in bodyMember.attackObject.hitBoxes)
            {
                if (hitBox != null)
                {
                    hitBox.gameObject.tag   = "Ignore Ragdoll";
                    hitBox.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
                }//add layer e tag for each hitbox
            }
        }
    }
    void CheckSingleHitBox(Transform transform, HumanBones bodyPart, bool debug = false)
    {
        if (transform)
        {
            MeleeAttackObject attackObject = transform.GetComponent <MeleeAttackObject>();
            if (attackObject == null)
            {
                attackObject = transform.gameObject.AddComponent <MeleeAttackObject>();
            }

            var _hitBoxes     = transform.GetComponentsInChildren <HitBox>();
            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
                {
                    BodyMember bodyMember = new BodyMember();
                    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();
    }
 void AddExtraBodyPart()
 {
     GUILayout.BeginVertical(inAddBodyMember ? "highlightBox" : "box");
     if (!inAddBodyMember && GUILayout.Button("Add Extra Body Member", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
     {
         extraBodyMember = new BodyMember();
         inAddBodyMember = true;
         isHuman         = true;
     }
     if (inAddBodyMember)
     {
         DrawAddExtraBodyMember();
     }
     GUILayout.EndVertical();
 }
 void DrawBodyMember(ref BodyMember 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(MeleeAttackObject), true) as MeleeAttackObject;
     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();
 }
    void CheckHitBoxes(BodyMember bodyMember, bool isDefault = false)
    {
        if (AssetDatabase.Contains(manager.gameObject))
        {
            return;
        }
        var hitBoxes = bodyMember.transform.GetComponentsInChildren <HitBox>();
        var _result  = hitBoxes.vToList().FindAll(hitBox => hitBox.transform.parent == bodyMember.transform);

        if (_result.Count > 0)
        {
            bodyMember.attackObject.hitBoxes = _result;
        }
        else
        {
            var hitBox = new GameObject("hitBox", typeof(HitBox), typeof(BoxCollider));
            var scale  = Vector3.one * .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 * .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;
            }
        }
    }
Пример #6
0
 public static BodyMember NewBodyMemberFollowing(BodyMember b)
 {
     return(new(Position.Behind(b.Position, b.Size, b.Direction), b.Direction));
 }
    void DrawAddExtraBodyMember()
    {
        if (extraBodyMember != null)
        {
            isHuman = Convert.ToBoolean(EditorGUILayout.Popup("Member Type", Convert.ToInt32(isHuman), new string[] { "Generic", "Human" }));
            extraBodyMember.isHuman = isHuman;
            if (isHuman)
            {
                HumanBones humanBone = 0;
                try
                {
                    humanBone = (HumanBones)Enum.Parse(typeof(HumanBones), extraBodyMember.bodyPart);
                }
                catch { }
                humanBone = (HumanBones)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)))
                {
                    BodyMember member = new BodyMember();
                    member.attackObject = extraBodyMember.transform.gameObject.AddComponent <MeleeAttackObject>();
                    member.transform    = extraBodyMember.transform;
                    member.bodyPart     = extraBodyMember.bodyPart;
                    var type      = typeof(BoxCollider);
                    var hitObject = new GameObject("hitBox", typeof(HitBox), 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 <HitBox>();
                    hitBox.damagePercentage      = 100;
                    hitBox.triggerType           = HitBoxType.Damage | HitBoxType.Recoil;
                    member.attackObject.hitBoxes = new List <HitBox>();
                    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();
        }
    }