Exemplo n.º 1
0
        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();
            }
        }