Example #1
0
    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();
    }
Example #2
0
    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();
        }
    }