public void SetScripts() { for (int i = 0; i < mRigidBody.Count; i++) { mRigidBody[i].gameObject.tag = "AI"; bl_AIHitBox box = null; if (mRigidBody[i].gameObject.GetComponent <bl_AIHitBox>() == null) { box = mRigidBody[i].gameObject.AddComponent <bl_AIHitBox>(); } else { box = mRigidBody[i].gameObject.GetComponent <bl_AIHitBox>(); } box.AI = transform.parent.GetComponent <bl_AIShooterHealth>(); box.m_Collider = mRigidBody[i].gameObject.GetComponent <Collider>(); box.isHead = gameObject.name.ToLower().Contains("head"); HitBoxes.Add(box); } }
void ReplaceBotModel() { if (ModelPrefab == null) { return; } GameObject model = ModelPrefab; if (PrefabUtility.GetPrefabParent(ModelPrefab) == null && PrefabUtility.GetPrefabObject(ModelPrefab) != null) { model = PrefabUtility.InstantiatePrefab(ModelPrefab) as GameObject; #if UNITY_2018_3_OR_NEWER PrefabUtility.UnpackPrefabInstance(model, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); #endif } model.name += " [NEW]"; GameObject botPrefab = PrefabUtility.InstantiatePrefab(bl_GameData.Instance.BotTeam1) as GameObject; #if UNITY_2018_3_OR_NEWER PrefabUtility.UnpackPrefabInstance(botPrefab, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); #endif botPrefab.name = "AISoldier [NEW]"; bl_AIAnimation oldModel = botPrefab.GetComponentInChildren <bl_AIAnimation>(); oldModel.name += " [OLD]"; Animator modelAnimator = model.GetComponent <Animator>(); modelAnimator.applyRootMotion = false; modelAnimator.runtimeAnimatorController = oldModel.GetComponent <Animator>().runtimeAnimatorController; if (!AutoRagdoller.Build(modelAnimator)) { Debug.LogError("Could not build a ragdoll for this model"); return; } botPrefab.GetComponent <bl_AIShooterAgent>().AimTarget = modelAnimator.GetBoneTransform(HumanBodyBones.Spine); model.transform.parent = oldModel.transform.parent; model.transform.localPosition = oldModel.transform.localPosition; model.transform.localRotation = oldModel.transform.localRotation; bl_AIAnimation aia = model.AddComponent <bl_AIAnimation>(); aia.mRigidBody.AddRange(model.transform.GetComponentsInChildren <Rigidbody>()); Collider[] allColliders = model.transform.GetComponentsInChildren <Collider>(); for (int i = 0; i < allColliders.Length; i++) { allColliders[i].gameObject.layer = LayerMask.NameToLayer("Player"); allColliders[i].gameObject.tag = "AI"; bl_AIHitBox hbox = allColliders[i].gameObject.AddComponent <bl_AIHitBox>(); hbox.m_Collider = allColliders[i]; hbox.AI = botPrefab.GetComponent <bl_AIShooterHealth>(); hbox.isHead = allColliders[i].name.ToLower().Contains("head"); aia.HitBoxes.Add(hbox); } Transform weaponRoot = botPrefab.GetComponent <bl_AIShooterWeapon>().m_AIWeapons[0].WeaponObject.transform.parent; Vector3 wrp = weaponRoot.localPosition; Quaternion wrr = weaponRoot.localRotation; weaponRoot.parent = modelAnimator.GetBoneTransform(HumanBodyBones.RightHand); weaponRoot.localRotation = wrr; weaponRoot.localPosition = wrp; DestroyImmediate(oldModel.gameObject); var view = (SceneView)SceneView.sceneViews[0]; view.LookAt(botPrefab.transform.position); EditorGUIUtility.PingObject(botPrefab); Selection.activeTransform = botPrefab.transform; }