コード例 #1
0
        // Execute the action
        public int Execute(HeroKitObject hko)
        {
            heroKitObject = hko;

            // add menu to scene if it doesn't exist
            HeroKitObject targetObject = HeroKitCommonRuntime.GetPrefabFromAssets(HeroKitCommonRuntime.settingsInfo.inventoryMenu, true);
            HeroObject    item         = null;
            int           count        = 0;
            bool          runThis      = (targetObject != null);

            if (runThis)
            {
                targetObject.gameObject.name = HeroKitCommonRuntime.settingsInfo.inventoryMenu.name;
                targetObject.gameObject.SetActive(true);

                // get the container for the inventory slots
                GameObject parent = HeroKitCommonRuntime.GetChildGameObject(targetObject.gameObject, "Inventory Menu Content");
                if (parent != null)
                {
                    // get the item we want to remove
                    item = HeroObjectFieldValue.GetValueC(heroKitObject, 0);
                    if (item != null)
                    {
                        // get the number of items to remove
                        bool addMultiple = BoolValue.GetValue(heroKitObject, 1);
                        count = (addMultiple) ? IntegerFieldValue.GetValueA(heroKitObject, 2) : 1;

                        // check to see if the inventory slot already exists in the menu
                        GameObject    gameObject = HeroKitCommonRuntime.GetChildGameObject(parent, item.name, false);
                        HeroKitObject heroObject = null;

                        // if the item exists, remove it
                        if (gameObject != null)
                        {
                            // get hero kit object
                            if (heroObject == null)
                            {
                                heroObject = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, gameObject);
                            }

                            // add the # of items to add to integer variable list, slot 1
                            heroObject.heroList.ints.items[1].value = count;

                            // play event 2 in the hero kit object attached to this prefab
                            heroObject.PlayEvent(2);
                        }
                    }
                }
            }

            // debug message
            if (heroKitObject.debugHeroObject)
            {
                string debugMessage = "Item: " + item + "\n" +
                                      "Count: " + count;
                Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage));
            }

            return(-99);
        }
コード例 #2
0
ファイル: EventValue.cs プロジェクト: antfitch/HeroKit
        /// <summary>
        /// Play an event.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to action field A.</param>
        /// <param name="targetObject">The heor kit object where the event should play.</param>
        public static void PlayEvent(HeroKitObject heroKitObject, int actionFieldID, HeroKitObject targetObject)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the hero kit object
            if (targetObject == null)
            {
                Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                return;
            }

            // Get the state ID
            int stateID = action.actionFields[actionFieldID].ints[3] - 1;

            // Get the event ID
            int eventID = action.actionFields[actionFieldID].ints[2] - 1;

            // Play the event if possible
            if (targetObject.heroStateData.state == stateID)
            {
                targetObject.PlayEvent(eventID, heroKitObject.gameObject);
            }
            else
            {
                Debug.LogWarning("Can't play event because its state is not active.");
            }
        }
コード例 #3
0
ファイル: ShowEndGameMenu.cs プロジェクト: antfitch/HeroKit
        // Execute the action
        public int Execute(HeroKitObject hko)
        {
            heroKitObject = hko;

            // add menu to scene if it doesn't exist
            HeroKitObject targetObject = HeroKitCommonRuntime.GetPrefabFromAssets(HeroKitCommonRuntime.settingsInfo.gameoverMenu, true);
            bool          runThis      = (targetObject != null);

            if (runThis)
            {
                targetObject.gameObject.SetActive(true);

                // save the scene to load
                UnityObjectField objectData = UnityObjectFieldValue.GetValueA(heroKitObject, 0);
                targetObject.heroList.unityObjects.items[0] = objectData;

                // enable the canvas
                Canvas canvas = targetObject.GetHeroComponent <Canvas>("Canvas");
                canvas.enabled = true;

                // play event 0
                targetObject.PlayEvent(0);
            }

            if (heroKitObject.debugHeroObject)
            {
                Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject));
            }

            return(-99);
        }
コード例 #4
0
 /// <summary>
 /// Call an event in the active state on a hero kit object.
 /// </summary>
 /// <param name="eventID">ID assigned to the event in the hero kit object.</param>
 private void CallHeroEvent(int eventID)
 {
     if (heroKitObject != null)
     {
         if (eventID > 0)
         {
             heroKitObject.PlayEvent(eventID);
         }
     }
 }
コード例 #5
0
        // Execute the action
        public int Execute(HeroKitObject hko)
        {
            heroKitObject = hko;

            // add menu to scene if it doesn't exist
            HeroKitObject targetObject = HeroKitCommonRuntime.GetPrefabFromAssets(HeroKitCommonRuntime.settingsInfo.journalMenu, true);
            HeroObject    item         = null;
            bool          runThis      = (targetObject != null);

            if (runThis)
            {
                targetObject.gameObject.name = HeroKitCommonRuntime.settingsInfo.journalMenu.name;
                targetObject.gameObject.SetActive(true);

                // get the container for the inventory slots
                GameObject parent = HeroKitCommonRuntime.GetChildGameObject(targetObject.gameObject, "Journal Menu Content");
                if (parent != null)
                {
                    // get the item we want to remove
                    item = HeroObjectFieldValue.GetValueC(heroKitObject, 0);
                    if (item != null)
                    {
                        // check to see if the inventory slot already exists in the menu
                        GameObject gameObject = HeroKitCommonRuntime.GetChildGameObject(parent, item.name, false);

                        // if the item exists, remove it
                        if (gameObject != null)
                        {
                            HeroKitObject heroObject = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, gameObject);

                            // play event 2 in the hero kit object attached to this prefab
                            if (heroObject != null)
                            {
                                heroObject.PlayEvent(2);
                            }
                        }
                    }
                }
            }

            // debug message
            if (heroKitObject.debugHeroObject)
            {
                string debugMessage = "Journal Entry: " + item;
                Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage));
            }

            return(-99);
        }
コード例 #6
0
 /// <summary>
 /// Call an event in a state on a hero kit object.
 /// </summary>
 /// <param name="heroKitObject">The hero kit object.</param>
 /// <param name="stateID">ID assigned to the state on the hero kit object.</param>
 /// <param name="eventID">ID assigned to the event in the hero kit object.</param>
 private void callEvent(HeroKitObject heroKitObject, int stateID, int eventID)
 {
     if (heroKitObject != null)
     {
         if (stateID > 0 && eventID > 0)
         {
             if (heroKitObject.heroStateData.state == stateID - 1)
             {
                 heroKitObject.heroListenerData.active = true;
                 heroKitObject.heroListenerData.itemID = itemID;
                 heroKitObject.heroListenerData.item   = item;
                 heroKitObject.PlayEvent(eventID - 1, gameObject);
             }
         }
     }
 }
コード例 #7
0
ファイル: AddInventoryItem.cs プロジェクト: antfitch/HeroKit
        // Execute the action
        public int Execute(HeroKitObject hko)
        {
            heroKitObject = hko;

            // add menu to scene if it doesn't exist
            HeroKitObject targetObject = HeroKitCommonRuntime.GetPrefabFromAssets(HeroKitCommonRuntime.settingsInfo.inventoryMenu, true);
            HeroObject    item         = null;
            int           count        = 0;
            bool          runThis      = (targetObject != null);

            if (runThis)
            {
                targetObject.gameObject.SetActive(true);

                // get the container for the inventory slots
                GameObject parent = HeroKitCommonRuntime.GetChildGameObject(targetObject.gameObject, "Inventory Menu Content");
                if (parent != null)
                {
                    // get the item we want to add
                    item = HeroObjectFieldValue.GetValueC(heroKitObject, 0);
                    if (item != null)
                    {
                        // get the number of items to add
                        bool addMultiple = BoolValue.GetValue(heroKitObject, 1);
                        count = (addMultiple) ? IntegerFieldValue.GetValueA(heroKitObject, 2) : 1;

                        // check to see if the inventory slot already exists in the menu
                        GameObject    gameObject = HeroKitCommonRuntime.GetChildGameObject(parent, item.name, true);
                        HeroKitObject heroObject = null;

                        // add item if it doesn't exist
                        if (gameObject == null)
                        {
                            // get the inventory slot
                            GameObject prefab = HeroKitCommonRuntime.settingsInfo.inventorySlot;
                            if (prefab == null)
                            {
                                Debug.LogError("Can't add prefab because it can't be found. (Inventory Slot)");
                            }

                            // add prefab to parent
                            if (parent != null && prefab != null)
                            {
                                // create the game object
                                gameObject = UnityEngine.Object.Instantiate(prefab, parent.transform);

                                // get the hero kit listener component
                                HeroKitListenerUI heroListener = heroKitObject.GetGameObjectComponent <HeroKitListenerUI>("HeroKitListenerUI", false, gameObject);
                                if (heroListener != null)
                                {
                                    // add item
                                    heroListener.item = item;

                                    // setup notifications
                                    HeroKitObject notifications = HeroObjectFieldValue.GetValueA(heroKitObject, 3)[0];
                                    if (notifications != null)
                                    {
                                        heroListener.sendNotificationsHere = notifications;
                                        heroListener.actionType            = 1;
                                        heroListener.stateID = EventValue.GetStateID(heroKitObject, 4);
                                        heroListener.eventID = EventValue.GetEventID(heroKitObject, 4);
                                    }

                                    // rename the object
                                    gameObject.name = heroListener.item.name;
                                }

                                // get the hero object component
                                heroObject = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, gameObject);
                                if (heroObject != null)
                                {
                                    heroObject.doNotSave = true;
                                    heroObject.heroGUID  = HeroKitCommonRuntime.GetHeroGUID();
                                }

                                // enable the game object
                                gameObject.SetActive(true);
                            }
                        }

                        // if prefab is not active, make it active
                        if (!gameObject.activeSelf)
                        {
                            gameObject.SetActive(true);
                        }

                        // get hero kit object
                        if (heroObject == null)
                        {
                            heroObject = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, gameObject);
                        }

                        // add the # of items to add to integer variable list, slot 1
                        heroObject.heroList.ints.items[1].value = count;

                        // play event 1 in the hero kit object attached to this prefab
                        heroObject.PlayEvent(1);
                    }
                }
            }

            // debug message
            if (heroKitObject.debugHeroObject)
            {
                string debugMessage = "Item: " + item + "\n" +
                                      "Count: " + count;
                Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage));
            }

            return(-99);
        }
コード例 #8
0
        // Execute the action
        public int Execute(HeroKitObject hko)
        {
            heroKitObject = hko;

            // add menu to scene if it doesn't exist
            HeroKitObject targetObject = HeroKitCommonRuntime.GetPrefabFromAssets(HeroKitCommonRuntime.settingsInfo.journalMenu, true);
            HeroObject    item         = null;
            bool          runThis      = (targetObject != null);

            if (runThis)
            {
                targetObject.gameObject.SetActive(true);

                // get the container for the inventory slots
                GameObject parent = HeroKitCommonRuntime.GetChildGameObject(targetObject.gameObject, "Journal Menu Content");
                if (parent != null)
                {
                    // get the item we want to add
                    item = HeroObjectFieldValue.GetValueC(heroKitObject, 0);
                    if (item != null)
                    {
                        // check to see if the inventory slot already exists in the menu
                        GameObject    gameObject = HeroKitCommonRuntime.GetChildGameObject(parent, item.name, true);
                        HeroKitObject heroObject = null;

                        // add item if it doesn't exist
                        if (gameObject == null)
                        {
                            // get the inventory slot
                            GameObject prefab = HeroKitCommonRuntime.settingsInfo.journalSlot;
                            if (prefab == null)
                            {
                                Debug.LogError("Prefab for journal slot is missing. (Journal Slot)");
                            }

                            // add prefab to parent
                            if (parent != null && prefab != null)
                            {
                                // create the game object
                                gameObject = UnityEngine.Object.Instantiate(prefab, parent.transform);

                                // get the hero kit listener component
                                HeroKitListenerUI heroListener = heroKitObject.GetGameObjectComponent <HeroKitListenerUI>("HeroKitListenerUI", false, gameObject);
                                if (heroListener != null)
                                {
                                    // add item
                                    heroListener.item = item;

                                    // rename the object
                                    gameObject.name = heroListener.item.name;
                                }

                                // get the hero object component
                                heroObject = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, gameObject);
                                if (heroObject != null)
                                {
                                    heroObject.doNotSave = true;
                                    heroObject.heroGUID  = HeroKitCommonRuntime.GetHeroGUID();
                                }

                                // enable the game object
                                gameObject.SetActive(true);
                            }

                            // if prefab is not active, make it active
                            if (!gameObject.activeSelf)
                            {
                                gameObject.SetActive(true);
                            }

                            // get hero kit object
                            if (heroObject == null)
                            {
                                heroObject = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, gameObject);
                            }

                            // play event 1 in the hero kit object attached to this prefab
                            heroObject.PlayEvent(1);
                        }
                        else
                        {
                            gameObject.SetActive(true);
                        }
                    }
                }
            }

            // debug message
            if (heroKitObject.debugHeroObject)
            {
                string debugMessage = "Journal Entry: " + item;
                Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage));
            }

            return(-99);
        }