void OnWizardCreate() { if (!character) { UnityEditor.EditorUtility.DisplayDialog("Error", "Character not assiged.", "OK"); return; } if (!character.activeSelf) { character.SetActive(true); } PrefabType ptype = PrefabUtility.GetPrefabType(character); bool needs2create = ptype == PrefabType.ModelPrefab; if (needs2create) { character = Instantiate(character); Undo.RegisterCreatedObjectUndo(character, "Create Player"); } Animator anim = _createAnimator(); if (!anim) { Debug.LogError("Error creating character. Could not add animator component." + " < " + this.ToString() + ">"); return; } EditorUtils.CreateGameControllerObject(CharacterType != CharacterTypes.Default); _createCapsule(); _createRigidbody(); _createAudiosource(); _createTPCharacter(); _createRagdollManager(); UnityEngine.UI.Text triggerUI = _createUI(); _createTriggerManager(triggerUI); _createIKHelper(); BaseCamera camera = null; camera = _createCamera(); _createPlayerScript(camera); _createLegsIK(); if (CharacterType != CharacterTypes.TopDown) { _createSlopeScript(); // dont need for top down system because its traversing on navmesh } _createAudio(); _createPlayerControl(); _createStats(); _createEquipmentScript(); _createItemPicker(); character.tag = "Player"; character.name = characterName; character.layer = LayerMask.NameToLayer("PlayerLayer"); Undo.SetCurrentGroupName("Create Player"); if (!camera) { Debug.Log("camera is null."); } else { Debug.Log("camera " + camera.name + " parent: " + (camera.transform.parent == null ? "NULL" : camera.transform.parent.name)); } if (OnCreate != null) { OnCreate(); } }
bool _createPlayerScript(BaseCamera camera) { switch (CharacterType) { case CharacterTypes.Default: { PlayerThirdPerson playerScript = character.GetComponent <PlayerThirdPerson>(); if (!playerScript) { playerScript = Undo.AddComponent <PlayerThirdPerson>(character); } playerScript.m_Camera = camera; // Create crouch camera target Transform camCrouchTargetXform = Utils.FindChildTransformByName(character.transform, "CameraCrouchTarget"); if (!camCrouchTargetXform) { GameObject cameraCrouchTarget = new GameObject("CameraCrouchTarget"); cameraCrouchTarget.transform.SetParent(character.transform); cameraCrouchTarget.transform.localPosition = new Vector3(0.276f, 0.961f, 0.0f); camCrouchTargetXform = cameraCrouchTarget.transform; } playerScript.crouchCameraTarget = camCrouchTargetXform; playerScript.standCameraTarget = camera.Target; } break; case CharacterTypes.ThirdPerson: { PlayerThirdPerson playerScript = character.GetComponent <PlayerThirdPerson>(); if (!playerScript) { playerScript = Undo.AddComponent <PlayerThirdPerson>(character); } playerScript.m_Camera = camera; // Create crouch camera target Transform camCrouchTargetXform = Utils.FindChildTransformByName(character.transform, "CameraCrouchTarget"); if (!camCrouchTargetXform) { GameObject cameraCrouchTarget = new GameObject("CameraCrouchTarget"); cameraCrouchTarget.transform.SetParent(character.transform); cameraCrouchTarget.transform.localPosition = new Vector3(0.276f, 0.961f, 0.0f); camCrouchTargetXform = cameraCrouchTarget.transform; } playerScript.crouchCameraTarget = camCrouchTargetXform; playerScript.standCameraTarget = camera.Target; } break; case CharacterTypes.TopDown: { PlayerTopDown playerScript = character.GetComponent <PlayerTopDown>(); if (!playerScript) { playerScript = Undo.AddComponent <PlayerTopDown>(character); } playerScript.m_Camera = camera; playerScript.walkableTarrainMask = LayerMask.GetMask("Walkable"); } break; } return(true); }