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 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(); } }