Esempio n. 1
0
        /// <summary>
        /// Spawn a hero kit object.
        /// </summary>
        /// <param name="usePool">Spawn the hero kit object from a pool?</param>
        /// <param name="poolName">The pool name.</param>
        /// <param name="position">The position in the scene to spawn the hero kit object.</param>
        /// <param name="rotation">The rotation of the hero kit object.</param>
        /// <param name="heroObject">The type of hero kit object to spawn.</param>
        /// <param name="showLog">Enable debugging for the hero kit object?</param>
        /// <param name="dontSave">Don't allow hero kit object to be saved?</param>
        /// <returns>The hero kit object.</returns>
        public static HeroKitObject SpawnHeroKitObject(bool usePool, string poolName, Vector3 position, Quaternion rotation, HeroObject heroObject, bool showLog, bool dontSave)
        {
            HeroKitObject newHKO;

            // spawn directly in scene
            if (usePool)
            {
                newHKO = SpawnFromPool(poolName, position, rotation, true, heroObject);
            }
            else
            {
                GameObject template   = Resources.Load <GameObject>("Hero Templates/Components/HeroKit Default Object");
                GameObject gameObject = UnityEngine.Object.Instantiate(template, position, rotation);
                gameObject.name = heroObject.name;
                newHKO          = gameObject.GetComponent <HeroKitObject>();
                newHKO.heroGUID = HeroKitCommonRuntime.GetHeroGUID();
            }

            newHKO.ChangeHeroObject(heroObject);

            // debug object?
            newHKO.debugHeroObject = showLog;

            // ignore object during save?
            newHKO.doNotSave = dontSave;

            return(newHKO);
        }
Esempio n. 2
0
        /// <summary>
        /// Add a pool to the Pool Dictionary.
        /// </summary>
        /// <param name="key">The key for the pool.</param>
        /// <param name="poolObject">The pool game object.</param>
        /// <param name="objectCount">The number of items in the pool.</param>
        /// <param name="isHeroKitObject">Is the pool for hero kit objects?</param>
        public static void AddPool(string key, GameObject poolObject, int objectCount, bool isHeroKitObject)
        {
            if (!PoolDictionary.ContainsKey(key))
            {
                GameObject parent = new GameObject();
                parent.name = key;

                List <GameObject> poolObjects = new List <GameObject>();

                for (int i = 0; i < objectCount; i++)
                {
                    GameObject gameObject = UnityEngine.Object.Instantiate(poolObject, parent.transform);
                    gameObject.SetActive(false);
                    poolObjects.Add(gameObject);

                    if (isHeroKitObject)
                    {
                        HeroKitObject heroKitObject = poolObjects[i].GetComponent <HeroKitObject>();
                        if (heroKitObject != null)
                        {
                            heroKitObject.heroGUID = HeroKitCommonRuntime.GetHeroGUID();
                        }
                    }
                }

                PoolDictionary.Add(key, poolObjects);
            }
            else
            {
                Debug.LogError("Could not add pool. A pool called " + key + " already exists.");
            }
        }
Esempio n. 3
0
        public void CreateUIObjects(GameObject prefabObject, GameObject contentObject, int objectCount, bool incrementID,
                                    HeroKitObject notificationObject, int stateID, int eventID, bool selfNotify)
        {
            GameObject prefab = prefabObject;
            GameObject parent = contentObject;
            int        count  = objectCount;

            for (int i = 0; i < count; i++)
            {
                // create the game object
                GameObject gameObject = UnityEngine.Object.Instantiate(prefab, parent.transform);
                gameObject.name = prefab.name + " " + (i + 1);
                HeroKitObject hko = gameObject.GetComponent <HeroKitObject>();

                // get the hero kit listener component
                HeroKitListenerUI heroListener = hko.GetGameObjectComponent <HeroKitListenerUI>("HeroKitListenerUI", false, gameObject);
                if (heroListener != null)
                {
                    // increment item id?
                    if (incrementID)
                    {
                        heroListener.itemID = (i + 1);
                    }

                    // setup notifications
                    HeroKitObject notifications = (selfNotify) ? hko : notificationObject;
                    if (notifications != null)
                    {
                        heroListener.sendNotificationsHere = notifications;
                        heroListener.actionType            = 1;
                        heroListener.stateID = stateID;
                        heroListener.eventID = eventID;
                    }
                }

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

                gameObject.SetActive(true);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Spawn a hero kit object or prefab from a pool.
        /// </summary>
        /// <param name="poolName">The name of the pool.</param>
        /// <param name="position">The position in the scene to spawn the object.</param>
        /// <param name="rotation">The rotation of the object.</param>
        /// <param name="useHKO">Are you spawning a hero kit object?</param>
        /// <param name="heroObject">The type of hero kit object to spawn.</param>
        /// <returns>The hero kit object (if you are spawning a hero kit object). Otherwise, this is always null.</returns>
        public static HeroKitObject SpawnFromPool(string poolName, Vector3 position, Quaternion rotation, bool useHKO = false, HeroObject heroObject = null)
        {
            // increase pool size if it's too small
            bool          growPool = false;
            HeroKitObject newHKO   = null;

            List <GameObject> poolObjects = GetPool(poolName);

            if (poolObjects != null)
            {
                for (int i = 0; i < poolObjects.Count; i++)
                {
                    if (!poolObjects[i].activeInHierarchy)
                    {
                        if (useHKO)
                        {
                            newHKO            = poolObjects[i].GetComponent <HeroKitObject>();
                            newHKO.heroObject = heroObject;
                            if (heroObject != null)
                            {
                                poolObjects[i].name = heroObject.name;
                            }
                        }

                        poolObjects[i].transform.position = position;
                        poolObjects[i].transform.rotation = rotation;
                        poolObjects[i].SetActive(true);

                        // if this was the last active item in the list, grow the pool
                        if (i == poolObjects.Count - 1)
                        {
                            growPool = true;
                        }

                        break;
                    }
                }

                // double the size of the pool
                if (growPool)
                {
                    int itemsToAdd = poolObjects.Count;

                    for (int i = 0; i < itemsToAdd; i++)
                    {
                        GameObject gameObject = UnityEngine.Object.Instantiate(poolObjects[itemsToAdd - 1], poolObjects[itemsToAdd - 1].transform.parent);
                        gameObject.SetActive(false);
                        poolObjects.Add(gameObject);

                        if (useHKO)
                        {
                            HeroKitObject heroKitObject = gameObject.GetComponent <HeroKitObject>();
                            if (heroKitObject != null)
                            {
                                heroKitObject.heroGUID = HeroKitCommonRuntime.GetHeroGUID();
                            }
                        }
                    }
                }
            }

            return(newHKO);
        }
Esempio n. 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.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);
        }
Esempio n. 6
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);
        }