/// <summary> /// Builds the Third Person Controller character. /// </summary> public static void BuildCharacter(GameObject character, bool aiAgent, bool isNetworked, RigidbodyCharacterController.MovementType movementType, RuntimeAnimatorController animatorController, PhysicMaterial maxFrictionMaterial, PhysicMaterial frictionlessMaterial, Transform[] itemTransforms, Transform[] feet) { // Set the internal variables. m_Character = character; m_AIAgent = aiAgent; #if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0) m_IsNetworked = isNetworked; #endif m_MovementType = movementType; m_AnimatorController = animatorController; m_MaxFrictionMaterial = maxFrictionMaterial; m_FrictionlessMaterial = frictionlessMaterial; // Build the character. BuildStandardComponents(feet); for (int i = 0; i < itemTransforms.Length; ++i) { BuildItemHands(itemTransforms[i]); } #if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0) if (m_IsNetworked) { BuildNetwork(); } #endif }
/// <summary> /// Shows the Character Builder options. /// </summary> private bool ShowGUI() { var modelType = (ModelType)EditorGUILayout.EnumPopup("Model Type", m_ModelType); if (modelType != m_ModelType) { m_ModelType = modelType; UpdateAnimatorController(); } var canContinue = true; m_Character = EditorGUILayout.ObjectField("Character", m_Character, typeof(GameObject), true) as GameObject; if (m_Character == null) { EditorGUILayout.HelpBox("Select the GameObject which will be used as the character. This object will have the majority of the components added to it.", MessageType.Error); canContinue = false; } else if (PrefabUtility.GetPrefabType(m_Character) == PrefabType.Prefab) { EditorGUILayout.HelpBox("Please drag your character into the scene. The Character Builder cannot add components to prefabs.", MessageType.Error); canContinue = false; } if (m_ModelType == ModelType.Humanoid) { // Ensure the character is a humanoid. if (GUI.changed || m_CharacterUpdate) { if (m_Character != null) { var character = m_Character; var spawnedCharacter = false; // The character has to be spawned in order to be able to detect if it is a Humanoid. if (AssetDatabase.GetAssetPath(m_Character).Length > 0) { character = GameObject.Instantiate(character) as GameObject; spawnedCharacter = true; } var animator = character.GetComponent <Animator>(); var hasAnimator = animator != null; if (!hasAnimator) { animator = character.AddComponent <Animator>(); } // A human will have a head. m_IsHumanoid = animator.GetBoneTransform(HumanBodyBones.Head) != null; // Clean up. if (!hasAnimator) { DestroyImmediate(animator, true); } if (spawnedCharacter) { DestroyImmediate(character, true); } } m_CharacterUpdate = false; } if (m_Character != null && !m_IsHumanoid) { EditorGUILayout.HelpBox(m_Character.name + " is not a humanoid. Please select the Humanoid Animation Type within the Rig Import Settings. " + "In addition, ensure all of the bones are configured correctly.", MessageType.Error); canContinue = false; } } var movementType = (RigidbodyCharacterController.MovementType)EditorGUILayout.EnumPopup("Movement Type", m_MovementType); if (m_MovementType != movementType) { m_MovementType = movementType; UpdateAnimatorController(); } m_AIAgent = EditorGUILayout.Toggle("Is AI Agent", m_AIAgent); EditorGUILayout.HelpBox("Is this character going to be used for AI? Some components (such as PlayerInput) do not need to be added if the character is an AI agent.", MessageType.Info); #if DEATHMATCH_AI_KIT_PRESENT if (m_AIAgent) { m_DeathmatchAgent = EditorGUILayout.Toggle("Is Deathmatch Agent", m_DeathmatchAgent); EditorGUILayout.HelpBox("Is this character going to be used by the Deathmatch AI Kit?", MessageType.Info); } #endif m_IsNetworked = EditorGUILayout.Toggle("Is Networked", m_IsNetworked); EditorGUILayout.HelpBox("Is this character going to be used on the network with Unity 5's multiplayer implementation?", MessageType.Info); if (m_ModelType == ModelType.Humanoid) { m_AddStandardAbilities = EditorGUILayout.Toggle("Add Standard Abilities", m_AddStandardAbilities); m_AddRagdoll = EditorGUILayout.Toggle("Add Ragdoll", m_AddRagdoll); if (m_AddRagdoll) { EditorGUILayout.HelpBox("Unity's Ragdoll Builder will open when this wizard is complete.", MessageType.Info); } } if (m_ModelType == ModelType.Generic || m_AnimatorController == null) { if (m_ModelType == ModelType.Humanoid) { EditorGUILayout.HelpBox("Unable to find the built-in Animator Controller. Please select the controlled that your character should use.", MessageType.Warning); } m_AnimatorController = EditorGUILayout.ObjectField("Animator Controller", m_AnimatorController, typeof(RuntimeAnimatorController), true) as RuntimeAnimatorController; canContinue = canContinue && m_ModelType == ModelType.Generic; } if (m_ModelType == ModelType.Generic) { m_SerializedObject.Update(); EditorGUILayout.PropertyField(m_SerializedObject.FindProperty("m_ItemTransforms"), true); EditorGUILayout.PropertyField(m_SerializedObject.FindProperty("m_FootTransforms"), true); m_SerializedObject.ApplyModifiedProperties(); } return(canContinue); }
public static void BuildHumanoidCharacter(GameObject character, bool aiAgent, bool isNetworked, RigidbodyCharacterController.MovementType movementType, RuntimeAnimatorController animatorController, PhysicMaterial maxFrictionMaterial, PhysicMaterial frictionlessMaterial) { var animator = character.GetComponent <Animator>(); var hands = new Transform[] { animator.GetBoneTransform(HumanBodyBones.LeftHand), animator.GetBoneTransform(HumanBodyBones.RightHand) }; var feet = new Transform[] { animator.GetBoneTransform(HumanBodyBones.LeftFoot), animator.GetBoneTransform(HumanBodyBones.RightFoot) }; BuildCharacter(character, aiAgent, isNetworked, movementType, animatorController, maxFrictionMaterial, frictionlessMaterial, hands, feet); }