Beispiel #1
0
        /// <summary>
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        protected virtual void Update()
        {
            // Check if we should cast a spell
            if (_ActionAlias.Length > 0 && _InputSource != null && _DefaultSpellIndex > 0 && _DefaultSpellIndex < _Spells.Count)
            {
                if (_InputSource.IsJustPressed(_ActionAlias))
                {
                    bool lCast = false;

                    // Activate the spell through the motion
                    MotionController lMotionController = gameObject.GetComponent <MotionController>();
                    if (lMotionController != null)
                    {
                        PMP_BasicSpellCastings lCastMotion = lMotionController.GetMotion <PMP_BasicSpellCastings>();
                        if (lCastMotion != null)
                        {
                            lCast = true;
                            lMotionController.ActivateMotion(lCastMotion, _DefaultSpellIndex);
                        }
                    }

                    // If we couldn't activate the motion, activate the spell directly
                    if (!lCast)
                    {
                        InstantiateSpell(_DefaultSpellIndex);
                    }
                }
            }

            // Update each active spell
            for (int i = 0; i < _ActiveSpells.Count; i++)
            {
                _ActiveSpells[i].Update();
            }

            // Release the completed spells
            for (int i = _ActiveSpells.Count - 1; i >= 0; i--)
            {
                Spell lSpell = _ActiveSpells[i];
                if (lSpell.State == EnumSpellState.COMPLETED)
                {
                    lSpell.Release();
                    _ActiveSpells.RemoveAt(i);
                }
            }
        }
Beispiel #2
0
        void SpellCast()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                return;
            }

            mMotionController = go.GetComponent <MotionController>();
            mSpellInventory   = go.GetComponent <SpellInventory>();

            if (mMotionController != null && mSpellInventory != null)
            {
                PMP_BasicSpellCastings lCastMotion = mMotionController.GetMotion <PMP_BasicSpellCastings>();
                if (!lCastMotion.IsActive && (!lCastMotion.RequiresStance || mMotionController.ActorController.State.Stance == EnumControllerStance.SPELL_CASTING))
                {
                    mMotionController.ActivateMotion(lCastMotion, spellIndex.Value);
                }
                Debug.Log("Cast Spell " + GetSpellName());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draws the inspector for the pack
        /// </summary>
        /// <returns></returns>
        public static bool OnPackInspector(MotionController rMotionController)
        {
            EditorHelper.DrawSmallTitle(GroupName());
            EditorHelper.DrawLink("Mixamo Pro Magic Pack Animations", "http://www.ootii.com/Unity/MotionPacks/SpellCasting/SpellCastingUsersGuide.pdf");

            GUILayout.Space(5f);

            EditorGUILayout.LabelField("See included documentation:", EditorHelper.SmallBoldLabel);
            EditorGUILayout.LabelField("1. Download and import animations.", EditorHelper.SmallLabel);
            EditorGUILayout.LabelField("2. Unzip and replace animation meta files.", EditorHelper.SmallLabel);
            EditorGUILayout.LabelField("3. Select options and create motions.", EditorHelper.SmallLabel);

            EditorHelper.DrawLine();

            EditorHelper.BoolField("Create Mecanim States", "Determines if we create/override the existing sub-state machine", sCreateSubStateMachines);
            sCreateSubStateMachines = EditorHelper.FieldBoolValue;

            EditorHelper.BoolField("Create Input Aliases", "Determines if we create input aliases", sCreateInputAliases);
            sCreateInputAliases = EditorHelper.FieldBoolValue;

            EditorHelper.BoolField("Create Inventory", "Determines if we create/override the existing inventory", sCreateInventory);
            sCreateInventory = EditorHelper.FieldBoolValue;

            EditorHelper.BoolField("Create Attributes", "Determines if we create/override the existing attributes", sCreateAttributes);
            sCreateAttributes = EditorHelper.FieldBoolValue;

            EditorHelper.BoolField("Create Spell Inventory", "Create the spell inventory for the caster", sCreateSpellInventory);
            sCreateSpellInventory = EditorHelper.FieldBoolValue;

            EditorHelper.BoolField("Create Combatant", "Determines if we create/override the existing core", sCreateCore);
            sCreateCore = EditorHelper.FieldBoolValue;

            EditorHelper.BoolField("Create Motions", "Determines if we create the archery motions", sCreateMotions);
            sCreateMotions = EditorHelper.FieldBoolValue;

            GUILayout.Space(5f);

            if (GUILayout.Button(new GUIContent("Setup Pack", "Create and setup the motion pack."), EditorStyles.miniButton))
            {
                if (sCreateInventory)
                {
                    BasicInventory lInventory = rMotionController.gameObject.GetComponent <BasicInventory>();
                    if (lInventory == null)
                    {
                        lInventory = rMotionController.gameObject.AddComponent <BasicInventory>();
                    }

                    BasicInventoryItem lItem = lInventory.GetInventoryItem("Spell_01");
                    if (lItem != null)
                    {
                        lInventory.Items.Remove(lItem);
                    }

                    lInventory.Items.Add(new BasicInventoryItem());
                    lInventory.Items[lInventory.Items.Count - 1].ID          = "Spell_01";
                    lInventory.Items[lInventory.Items.Count - 1].EquipMotion = "PMP_EquipSpell";
                    lInventory.Items[lInventory.Items.Count - 1].StoreMotion = "PMP_StoreSpell";

                    BasicInventorySlot lSlot = lInventory.GetInventorySlot("RIGHT_HAND");
                    if (lSlot == null)
                    {
                        lInventory.Slots.Add(new BasicInventorySlot());
                        lInventory.Slots[lInventory.Slots.Count - 1].ID     = "RIGHT_HAND";
                        lInventory.Slots[lInventory.Slots.Count - 1].ItemID = "";
                    }

                    if (lInventory.GetInventorySlot("LEFT_HAND") == null)
                    {
                        lInventory.Slots.Add(new BasicInventorySlot());
                        lInventory.Slots[lInventory.Slots.Count - 1].ID     = "LEFT_HAND";
                        lInventory.Slots[lInventory.Slots.Count - 1].ItemID = "";
                    }

                    lSlot = lInventory.GetInventorySlot("LEFT_LOWER_ARM");
                    if (lSlot == null)
                    {
                        lInventory.Slots.Add(new BasicInventorySlot());
                        lInventory.Slots[lInventory.Slots.Count - 1].ID     = "LEFT_LOWER_ARM";
                        lInventory.Slots[lInventory.Slots.Count - 1].ItemID = "";
                    }

                    if (lInventory.GetInventorySlot("READY_PROJECTILE") == null)
                    {
                        lInventory.Slots.Add(new BasicInventorySlot());
                        lInventory.Slots[lInventory.Slots.Count - 1].ID     = "READY_PROJECTILE";
                        lInventory.Slots[lInventory.Slots.Count - 1].ItemID = "";
                    }

                    BasicInventorySet lWeaponSet = lInventory.GetWeaponSet("Spell Casting");
                    if (lWeaponSet != null)
                    {
                        lInventory.WeaponSets.Remove(lWeaponSet);
                    }

                    lWeaponSet    = new BasicInventorySet();
                    lWeaponSet.ID = "Spell Casting";

                    BasicInventorySetItem lWeaponSetItem = new BasicInventorySetItem();
                    lWeaponSetItem.ItemID      = "";
                    lWeaponSetItem.SlotID      = "LEFT_HAND";
                    lWeaponSetItem.Instantiate = true;
                    lWeaponSet.Items.Add(lWeaponSetItem);

                    lWeaponSetItem             = new BasicInventorySetItem();
                    lWeaponSetItem.ItemID      = "";
                    lWeaponSetItem.SlotID      = "READY_PROJECTILE";
                    lWeaponSetItem.Instantiate = false;
                    lWeaponSet.Items.Add(lWeaponSetItem);

                    lWeaponSetItem             = new BasicInventorySetItem();
                    lWeaponSetItem.ItemID      = "Spell_01";
                    lWeaponSetItem.SlotID      = "RIGHT_HAND";
                    lWeaponSetItem.Instantiate = false;
                    lWeaponSet.Items.Add(lWeaponSetItem);

                    lWeaponSetItem             = new BasicInventorySetItem();
                    lWeaponSetItem.ItemID      = "";
                    lWeaponSetItem.SlotID      = "LEFT_LOWER_ARM";
                    lWeaponSetItem.Instantiate = false;
                    lWeaponSet.Items.Add(lWeaponSetItem);

                    if (lInventory.WeaponSets.Count == 0)
                    {
                        BasicInventorySet lFirstWeaponSet = new BasicInventorySet();
                        lFirstWeaponSet.ID = "Sword and Shield";

                        lInventory.WeaponSets.Add(lFirstWeaponSet);
                    }

                    if (lInventory.WeaponSets.Count == 1)
                    {
                        BasicInventorySet lSecondWeaponSet = new BasicInventorySet();
                        lSecondWeaponSet.ID = "Longbow";

                        lInventory.WeaponSets.Add(lSecondWeaponSet);
                    }

                    lInventory.WeaponSets.Insert(2, lWeaponSet);
                }

                if (sCreateAttributes)
                {
                    BasicAttributes lAttributes = rMotionController.gameObject.GetComponent <BasicAttributes>();
                    if (lAttributes == null)
                    {
                        lAttributes = rMotionController.gameObject.AddComponent <BasicAttributes>();
                    }

                    BasicAttribute lAttribute = lAttributes.GetAttribute("Health");
                    if (lAttribute != null)
                    {
                        lAttributes.Items.Remove(lAttribute);
                    }

                    lAttributes.Items.Add(new BasicAttribute());
                    lAttributes.Items[lAttributes.Items.Count - 1].ID = "Health";
                    lAttributes.Items[lAttributes.Items.Count - 1].SetValue <float>(100f);
                }

                if (sCreateSpellInventory)
                {
                    SpellInventory lAttributes = rMotionController.gameObject.GetComponent <SpellInventory>();
                    if (lAttributes == null)
                    {
                        lAttributes = rMotionController.gameObject.AddComponent <SpellInventory>();
                    }
                }

                if (sCreateCore)
                {
                    Combatant lCombatant = rMotionController.gameObject.GetComponent <Combatant>();
                    if (lCombatant == null)
                    {
                        lCombatant = rMotionController.gameObject.AddComponent <Combatant>();
                    }

                    if (rMotionController._ActorController == null || !rMotionController._ActorController.UseTransformPosition)
                    {
                        lCombatant.IsLockingEnabled = true;
                        lCombatant.TargetLockedIcon = AssetDatabase.LoadAssetAtPath <Texture>("Assets/ootii/Framework_v1/Content/Textures/UI/TargetIcon_2.png");
                    }

                    ActorCore lCore = rMotionController.gameObject.GetComponent <ActorCore>();
                    if (lCore == null)
                    {
                        lCore = rMotionController.gameObject.AddComponent <ActorCore>();
                    }

                    lCore.IsAlive = true;
                }

                if (sCreateInputAliases)
                {
                    // Sheathe
                    if (!InputManagerHelper.IsDefined("Spell Casting Equip"))
                    {
                        InputManagerEntry lEntry = new InputManagerEntry();
                        lEntry.Name           = "Spell Casting Equip";
                        lEntry.PositiveButton = "3"; // "3" key
                        lEntry.Gravity        = 1000;
                        lEntry.Dead           = 0.001f;
                        lEntry.Sensitivity    = 1000;
                        lEntry.Type           = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis           = 0;
                        lEntry.JoyNum         = 0;
                        InputManagerHelper.AddEntry(lEntry, true);

                        lEntry             = new InputManagerEntry();
                        lEntry.Name        = "Spell Casting Equip";
                        lEntry.Gravity     = 1000;
                        lEntry.Dead        = 0.001f;
                        lEntry.Sensitivity = 1000;
                        lEntry.JoyNum      = 0;

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
                        lEntry.PositiveButton = "joystick button 8";
                        lEntry.Type           = InputManagerEntryType.KEY_MOUSE_BUTTON; // D-pad Y
                        lEntry.Axis           = 0;
#else
                        lEntry.PositiveButton = "";
                        lEntry.Type           = InputManagerEntryType.JOYSTICK_AXIS; // D-pad Y
                        lEntry.Axis           = 7;
#endif

                        InputManagerHelper.AddEntry(lEntry, true);
                    }

                    // Fire
                    if (!InputManagerHelper.IsDefined("Spell Casting Cast"))
                    {
                        InputManagerEntry lEntry = new InputManagerEntry();
                        lEntry.Name              = "Spell Casting Cast";
                        lEntry.PositiveButton    = "left ctrl";
                        lEntry.AltPositiveButton = "mouse 0"; // Left mouse button
                        lEntry.Gravity           = 1000;
                        lEntry.Dead              = 0.001f;
                        lEntry.Sensitivity       = 1000;
                        lEntry.Type              = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis              = 0;
                        lEntry.JoyNum            = 0;
                        InputManagerHelper.AddEntry(lEntry, true);

                        lEntry      = new InputManagerEntry();
                        lEntry.Name = "Spell Casting Cast";

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
                        lEntry.PositiveButton = "joystick button 16"; // Green A
#else
                        lEntry.PositiveButton = "joystick button 0";  // Green A
#endif

                        lEntry.Gravity     = 1000;
                        lEntry.Dead        = 0.001f;
                        lEntry.Sensitivity = 1000;
                        lEntry.Type        = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis        = 0;
                        lEntry.JoyNum      = 0;
                        InputManagerHelper.AddEntry(lEntry, true);
                    }

                    // Continue
                    if (!InputManagerHelper.IsDefined("Spell Casting Continue"))
                    {
                        InputManagerEntry lEntry = new InputManagerEntry();
                        lEntry.Name              = "Spell Casting Continue";
                        lEntry.PositiveButton    = "left ctrl";
                        lEntry.AltPositiveButton = "mouse 0"; // Left mouse button
                        lEntry.Gravity           = 1000;
                        lEntry.Dead              = 0.001f;
                        lEntry.Sensitivity       = 1000;
                        lEntry.Type              = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis              = 0;
                        lEntry.JoyNum            = 0;
                        InputManagerHelper.AddEntry(lEntry, true);

                        lEntry      = new InputManagerEntry();
                        lEntry.Name = "Spell Casting Continue";

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
                        lEntry.PositiveButton = "joystick button 16"; // Green A
#else
                        lEntry.PositiveButton = "joystick button 0";  // Green A
#endif

                        lEntry.Gravity     = 1000;
                        lEntry.Dead        = 0.001f;
                        lEntry.Sensitivity = 1000;
                        lEntry.Type        = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis        = 0;
                        lEntry.JoyNum      = 0;
                        InputManagerHelper.AddEntry(lEntry, true);
                    }

                    // Cancel
                    if (!InputManagerHelper.IsDefined("Spell Casting Cancel"))
                    {
                        InputManagerEntry lEntry = new InputManagerEntry();
                        lEntry.Name           = "Spell Casting Cancel";
                        lEntry.PositiveButton = "escape";
                        lEntry.Gravity        = 1000;
                        lEntry.Dead           = 0.001f;
                        lEntry.Sensitivity    = 1000;
                        lEntry.Type           = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis           = 0;
                        lEntry.JoyNum         = 0;
                        InputManagerHelper.AddEntry(lEntry, true);

                        lEntry      = new InputManagerEntry();
                        lEntry.Name = "Spell Casting Cancel";

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
                        lEntry.PositiveButton = "joystick button 19"; // Yellow Y
#else
                        lEntry.PositiveButton = "joystick button 3";  // Yellow Y
#endif

                        lEntry.Gravity     = 1000;
                        lEntry.Dead        = 0.001f;
                        lEntry.Sensitivity = 1000;
                        lEntry.Type        = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis        = 0;
                        lEntry.JoyNum      = 0;
                        InputManagerHelper.AddEntry(lEntry, true);
                    }

                    // Move Up
                    if (!InputManagerHelper.IsDefined("Move Up"))
                    {
                        InputManagerEntry lEntry = new InputManagerEntry();
                        lEntry.Name           = "Move Up";
                        lEntry.PositiveButton = "e";
                        lEntry.Gravity        = 1000;
                        lEntry.Dead           = 0.001f;
                        lEntry.Sensitivity    = 1000;
                        lEntry.Type           = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis           = 0;
                        lEntry.JoyNum         = 0;

                        InputManagerHelper.AddEntry(lEntry, true);
                    }

                    // Move down
                    if (!InputManagerHelper.IsDefined("Move Down"))
                    {
                        InputManagerEntry lEntry = new InputManagerEntry();
                        lEntry.Name           = "Move Down";
                        lEntry.PositiveButton = "q";
                        lEntry.Gravity        = 1000;
                        lEntry.Dead           = 0.001f;
                        lEntry.Sensitivity    = 1000;
                        lEntry.Type           = InputManagerEntryType.KEY_MOUSE_BUTTON;
                        lEntry.Axis           = 0;
                        lEntry.JoyNum         = 0;

                        InputManagerHelper.AddEntry(lEntry, true);
                    }
                }

                if (sCreateMotions || sCreateSubStateMachines)
                {
                    IBaseCameraRig lCameraRig = rMotionController.CameraRig;
                    if (lCameraRig == null)
                    {
                        lCameraRig = rMotionController.ExtractCameraRig(rMotionController.CameraTransform);
                    }

                    if (rMotionController.MotionLayers.Count == 0)
                    {
                        MotionControllerLayer lMotionLayer = new MotionControllerLayer();
                        rMotionController.MotionLayers.Add(lMotionLayer);
                    }

                    PMP_Idle lIdle = rMotionController.GetMotion <PMP_Idle>();
                    if (lIdle == null)
                    {
                        lIdle = rMotionController.CreateMotion <PMP_Idle>(0);
                    }

                    PMP_EquipSpell lEquip = rMotionController.GetMotion <PMP_EquipSpell>(0);
                    if (lEquip == null)
                    {
                        lEquip = rMotionController.CreateMotion <PMP_EquipSpell>(0);
                    }

                    PMP_StoreSpell lStore = rMotionController.GetMotion <PMP_StoreSpell>(0);
                    if (lStore == null)
                    {
                        lStore = rMotionController.CreateMotion <PMP_StoreSpell>(0);
                    }

                    PMP_WalkRunPivot lPivot = rMotionController.GetMotion <PMP_WalkRunPivot>(0);
                    if (lPivot == null)
                    {
                        lPivot = rMotionController.CreateMotion <PMP_WalkRunPivot>(0);
                    }

                    PMP_WalkRunStrafe lStrafe = rMotionController.GetMotion <PMP_WalkRunStrafe>(0);
                    if (lStrafe == null)
                    {
                        lStrafe = rMotionController.CreateMotion <PMP_WalkRunStrafe>(0);
                    }

                    PMP_BasicSpellCastings lCast = rMotionController.GetMotion <PMP_BasicSpellCastings>(0);
                    if (lCast == null)
                    {
                        lCast = rMotionController.CreateMotion <PMP_BasicSpellCastings>(0);
                    }

                    Cower lCower = rMotionController.GetMotion <Cower>(0);
                    if (lCower == null)
                    {
                        lCower = rMotionController.CreateMotion <Cower>(0);
                    }

                    Death lDeath = rMotionController.GetMotion <Death>(0);
                    if (lDeath == null)
                    {
                        lDeath = rMotionController.CreateMotion <Death>(0);
                    }

                    Damaged lDamaged = rMotionController.GetMotion <Damaged>(0);
                    if (lDamaged == null)
                    {
                        lDamaged = rMotionController.CreateMotion <Damaged>(0);
                    }

                    Frozen lFrozen = rMotionController.GetMotion <Frozen>(0);
                    if (lFrozen == null)
                    {
                        lFrozen = rMotionController.CreateMotion <Frozen>(0);
                    }

                    KnockedDown lKnockedDown = rMotionController.GetMotion <KnockedDown>(0);
                    if (lKnockedDown == null)
                    {
                        lKnockedDown = rMotionController.CreateMotion <KnockedDown>(0);
                    }

                    Levitate lLevitate = rMotionController.GetMotion <Levitate>(0);
                    if (lLevitate == null)
                    {
                        lLevitate = rMotionController.CreateMotion <Levitate>(0);
                    }

                    PushedBack lPushedBack = rMotionController.GetMotion <PushedBack>(0);
                    if (lPushedBack == null)
                    {
                        lPushedBack = rMotionController.CreateMotion <PushedBack>(0);
                    }

                    Sleep lSleep = rMotionController.GetMotion <Sleep>(0);
                    if (lSleep == null)
                    {
                        lSleep = rMotionController.CreateMotion <Sleep>(0);
                    }

                    Stunned lStunned = rMotionController.GetMotion <Stunned>(0);
                    if (lStunned == null)
                    {
                        lStunned = rMotionController.CreateMotion <Stunned>(0);
                    }

                    if (sCreateSubStateMachines)
                    {
                        Animator lAnimator = rMotionController.Animator;
                        if (lAnimator == null)
                        {
                            lAnimator = rMotionController.gameObject.GetComponent <Animator>();
                        }

                        if (lAnimator != null)
                        {
                            UnityEditor.Animations.AnimatorController lAnimatorController = lAnimator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;

                            lIdle.CreateStateMachine(lAnimatorController);
                            lEquip.CreateStateMachine(lAnimatorController);
                            lPivot.CreateStateMachine(lAnimatorController);
                            lStrafe.CreateStateMachine(lAnimatorController);
                            lCast.CreateStateMachine(lAnimatorController);
                            lDeath.CreateStateMachine(lAnimatorController);
                            lLevitate.CreateStateMachine(lAnimatorController);
                        }
                    }
                }

                EditorUtility.DisplayDialog("Motion Pack: " + GroupName(), "Motion pack imported.", "ok");

                return(true);
            }

            return(false);
        }