Exemplo n.º 1
0
        public IEnumerator CreateCharacter()
        {
            if (IsPlayer)
            {
                // If there are already any objects tagged "Player" in the scene, disable them so that there is no conflict
                // with the newly created character
                var lExistingPlayers = GameObject.FindGameObjectsWithTag("Player");
                if (lExistingPlayers != null)
                {
                    foreach (var lPlayer in lExistingPlayers)
                    {
                        if (lPlayer.GetComponent <MotionController>() == null)
                        {
                            continue;
                        }
                        lPlayer.gameObject.SetActive(false);
                    }
                }
            }

            // Instantiate the character
            if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(Character)))
            {
                // Use the entered Name (if not blank); default to the character model/prefab name
                string lName = string.IsNullOrEmpty(Name) ? Character.name : Name;
                Character      = GameObject.Instantiate(Character) as GameObject;
                Character.name = lName;
                yield return(mShortWait);
            }

            Character.SetActive(true);

            // Add the Motion Controller component
            MotionController lMotionController = CharacterSetupHelper.CreateMotionController(Character, IsPlayer);

            yield return(mShortWait);


            this.StartCoroutine(ActiveProfile.CreateCharacter(lMotionController, AnimatorPath, Name, IsPlayer));

            // Wait for the profile to finish
            while (ActiveProfile.IsWorking)
            {
                yield return(mShortWait);
            }

            yield return(mShortWait);

            EditorUtility.ClearProgressBar();
            Debug.Log("Character Wizard: Completed");

            yield return(mShortWait);

            this.Close();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Step 1: Add and configure the actor components on the character
        /// </summary>
        /// <param name="rMotionController"></param>
        /// <param name="rIsPlayer"></param>
        protected virtual void SetupComponents(MotionController rMotionController, bool rIsPlayer)
        {
            string lComponentsTitle = "Configuring Components (Step 1 of 6)";
            float  lProgressAmount  = 1f / 6f;

            EditorUtility.DisplayProgressBar(lComponentsTitle, "Base components", lProgressAmount);

            // Set the Motion Controller's inspector to Advanced mode, as Basic mode's functionality is superseded by
            // the Character Wizard
            rMotionController.EditorTabIndex = 1;

            // Configure core components (Actor Controller and Actor Core):
            CharacterSetupHelper.ConfigureActorController(rMotionController, rIsPlayer);
            CharacterSetupHelper.CreateActorCore(rMotionController, 0);
            if (!rIsPlayer && UseTransformPosition)
            {
                CharacterSetupHelper.EnableUseTransform(rMotionController);
            }

            // Configure Attributes:
            if (AddBasicAttributes)
            {
                var lAttributes = CharacterSetupHelper.CreateBasicAttributes(rMotionController, HealthValue);
                if (!rIsPlayer)
                {
                    // Add the "NPC" tag attribute to NPCs
                    if (!lAttributes.AttributeExists("NPC"))
                    {
                        lAttributes.AddAttribute("NPC", EnumAttributeTypes.Types[EnumAttributeTypes.TAG]);
                        lAttributes.OnBeforeSerialize();
                    }
                }
            }

            // Configure Inventory:
            if (AddBasicInventory)
            {
                CharacterSetupHelper.CreateBasicInventory(rMotionController, CreateDefaultSlots, rIsPlayer);
            }

            // Configure the Combatant:
            if (AddCombatant)
            {
                CharacterSetupHelper.CreateCombatant(rMotionController, MaxTargetLockDistance, rIsPlayer);
            }

            // Configure additional Unity components:
            if (AddRigidbody)
            {
                CharacterSetupHelper.AddRigidbody(rMotionController, RigidbodyMass);
            }
            if (!rIsPlayer && AddNavMeshAgent)
            {
                CharacterSetupHelper.AddNavMeshAgent(rMotionController, NavMeshAngularSpeed);
            }

            // Configure components in enabled modules:
            if (Modules == null)
            {
                return;
            }

            EditorUtility.DisplayProgressBar(lComponentsTitle, "Setting up module components", lProgressAmount);
            foreach (var lModule in Modules)
            {
                if (lModule.IsValid && lModule is IConfigureComponents)
                {
                    ((IConfigureComponents)lModule).ConfigureComponents();
                }
            }
        }