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; }
void DrawRagdolled() { if (subStep == 0) { HideNextButton = true; DrawText("Alright, with the model ready it's time to start set up it, the first thing that you need to do is make a ragdoll of your new player model," + " So normally you make a ragdoll manually with GameObject -> " + "3D Object -> Ragdoll -> and then assign every player bone in the wizard window manually, but this tool will make this automatically, you simple need drag the player model."); DownArrow(); DrawText("Drag here your player model from the <b>Project View</b>"); PlayerModel = EditorGUILayout.ObjectField("Player Model", PlayerModel, typeof(GameObject), false) as GameObject; GUI.enabled = PlayerModel != null; if (DrawButton("Continue")) { AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(PlayerModel)); if (importer != null) { ModelInfo = importer as ModelImporter; if (ModelInfo != null) { if (ModelInfo.animationType == ModelImporterAnimationType.Human) { PlayerInstantiated = PrefabUtility.InstantiatePrefab(PlayerModel) as GameObject; #if UNITY_2018_3_OR_NEWER PrefabUtility.UnpackPrefabInstance(PlayerInstantiated, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); #endif PlayerAnimator = PlayerInstantiated.GetComponent <Animator>(); PlayerModelAvatar = PlayerAnimator.avatar; var view = (SceneView)SceneView.sceneViews[0]; view.LookAt(PlayerInstantiated.transform.position); EditorGUIUtility.PingObject(PlayerInstantiated); Selection.activeTransform = PlayerInstantiated.transform; subStep++; } else { LogLine = "Your model is not set to Humanoid Rig!"; } } else { LogLine = "Please Select Imported Model in Project View not prefab or other."; } } else { LogLine = "Please Select Imported Model in Project View not prefab"; } } GUI.enabled = true; if (!string.IsNullOrEmpty(LogLine)) { GUILayout.Label(LogLine); } } else if (subStep == 1) { HideNextButton = false; GUI.enabled = false; GUILayout.BeginVertical("box"); PlayerInstantiated = EditorGUILayout.ObjectField("Player Prefab", PlayerInstantiated, typeof(GameObject), false) as GameObject; PlayerModelAvatar = EditorGUILayout.ObjectField("Avatar", PlayerModelAvatar, typeof(Avatar), true) as Avatar; SkinnedMeshRenderer smr = null; if (PlayerInstantiated != null) { smr = PlayerInstantiated.GetComponentInChildren <SkinnedMeshRenderer>(); GUILayout.Label(string.Format("Model Height: <b>{0}</b> | Expected Height: <b>2</b>", smr.bounds.size.y)); if (ModelInfo != null) { GUILayout.Label(string.Format("Model Rig: {0}", ModelInfo.animationType.ToString())); } GUI.enabled = true; if (smr.bounds.size.y < 1.9f) { GUILayout.Label("<color=yellow>the size of the model is very small</color>, you want resize it automatically?", EditorStyles.label); if (DrawButton("Yes, Resize automatically")) { Vector3 v = PlayerInstantiated.transform.localScale; float dif = 2f / smr.bounds.size.y; v = v * dif; PlayerInstantiated.transform.localScale = v; } } else if (smr.bounds.size.y > 2.25f) { GUILayout.Label("<color=yellow>the size of the model is very large</color>, you want resize it automatically?", EditorStyles.label); if (DrawButton("Yes, Resize automatically")) { Vector3 v = PlayerInstantiated.transform.localScale; float dif = smr.bounds.size.y / 2; v = v / dif; PlayerInstantiated.transform.localScale = v; } } } GUILayout.EndVertical(); GUI.enabled = true; if (PlayerModelAvatar != null && PlayerAnimator != null) { DownArrow(); DrawText("All ready to create the ragdoll, Click in the button below to build it."); if (DrawButton("Build Ragdoll")) { if (AutoRagdoller.Build(PlayerAnimator)) { var view = (SceneView)SceneView.sceneViews[0]; view.ShowNotification(new GUIContent("Ragdoll Created!")); NextStep(); } } } else { GUILayout.Label("<color=yellow>Hmm... something is happening here, can't get the model avatar.</color>", EditorStyles.label); } } else if (subStep == 2) { DrawText("Right now your player model (in the scene) should look like this:"); DrawImage(GetServerImage(2)); DownArrow(); DrawText("Now the ragdoll is ready, what you need to do now is create a prefab of this ragdoll (don't delete the one in the scene yet), simple drag the player model from the hirarchy window " + "into a folder in the Project Window, just remember in which folder cuz you will need that prefab later.\n\nYou are ready for the next step."); } }