Example #1
0
        /// <summary>
        /// Get a scene object from the scene object field.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldIDA">ID assigned to action field A.</param>
        /// <param name="actionFieldIDB">ID assigned to action field B.</param>
        /// <param name="includeInactive">Include inactive scene objects?</param>
        /// <returns>The scene object.</returns>
        public static SceneObjectValueData GetValue(HeroKitObject heroKitObject, int actionFieldIDA, int actionFieldIDB, bool includeInactive)
        {
            SceneObjectValueData objectData = new SceneObjectValueData();
            int dataType = DropDownListValue.GetValue(heroKitObject, actionFieldIDA);

            // object is hero object
            if (dataType == 1)
            {
                objectData.heroKitObject = HeroObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB);
            }

            // object is game object
            else if (dataType == 2)
            {
                GameObject gameObject = GameObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB, includeInactive);
                objectData.gameObject = new GameObject[] { gameObject };
            }

            return(objectData);
        }
Example #2
0
        /// <summary>
        /// Get a camera.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the camera field.</param>
        /// <param name="actionFieldIDA">ID assigned to action field A.</param>
        /// <param name="actionFieldIDB">ID assigned to action field B.</param>
        /// <returns></returns>
        public static Camera GetValue(HeroKitObject heroKitObject, int actionFieldIDA, int actionFieldIDB)
        {
            Camera camera = null;

            // get the camera
            bool customCamera = BoolValue.GetValue(heroKitObject, actionFieldIDA);

            if (customCamera)
            {
                HeroKitObject cameraObject = HeroObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB)[0];
                if (cameraObject != null)
                {
                    camera = cameraObject.GetHeroComponent <Camera>("Camera", true);
                }
            }
            else
            {
                camera = Camera.main;
            }

            return(camera);
        }
Example #3
0
        /// <summary>
        /// Get a field from a script and set this value in a hero object list.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldIDB">ID assigned to action field B.</param>
        /// <param name="field">The field in the script.</param>
        /// <param name="component">The script component on the hero kit object.</param>
        private static void SetFieldOnHero(HeroKitObject heroKitObject, int actionFieldIDB, FieldInfo field, MonoBehaviour component)
        {
            // Get value type on the target instance.
            object valueType = field.FieldType;

            // Test value type.
            if (valueType == typeof(int))
            {
                int value = (int)field.GetValue(component);
                IntegerFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(float))
            {
                float value = (float)field.GetValue(component);;
                FloatFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(string))
            {
                string value = (string)field.GetValue(component);;
                StringFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(bool))
            {
                bool value = (bool)field.GetValue(component);;
                BoolFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(HeroKitObject))
            {
                HeroKitObject        value = (HeroKitObject)field.GetValue(component);;
                List <HeroKitObject> hko   = new List <HeroKitObject>();
                hko.Add((HeroKitObject)value);
                HeroObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, hko);
            }
            else if (valueType == typeof(GameObject))
            {
                GameObject value = (GameObject)field.GetValue(component);;
                GameObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
        }
Example #4
0
        /// <summary>
        /// Get a property from a script and set this value in a hero object list.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldIDB">ID assigned to action field B.</param>
        /// <param name="property">The property in the script.</param>
        /// <param name="component">The script component on the hero kit object.</param>
        public static void SetPropertyOnHero(HeroKitObject heroKitObject, int actionFieldIDB, PropertyInfo property, MonoBehaviour component)
        {
            // Get value type on the target instance.
            object valueType = property.PropertyType;

            // Test value type.
            if (valueType == typeof(int))
            {
                int value = (int)property.GetValue(component, null);
                IntegerFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(float))
            {
                float value = (float)property.GetValue(component, null);;
                FloatFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(string))
            {
                string value = (string)property.GetValue(component, null);;
                StringFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(bool))
            {
                bool value = (bool)property.GetValue(component, null);;
                BoolFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
            else if (valueType == typeof(HeroKitObject))
            {
                HeroKitObject        value = (HeroKitObject)property.GetValue(component, null);;
                List <HeroKitObject> hko   = new List <HeroKitObject>();
                hko.Add((HeroKitObject)value);
                HeroObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, hko);
            }
            else if (valueType == typeof(GameObject))
            {
                GameObject value = (GameObject)property.GetValue(component, null);;
                GameObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, value);
            }
        }
Example #5
0
        // --------------------------------------------------------------
        // Helpers
        // --------------------------------------------------------------

        /// <summary>
        /// Get a value from a hero object list and set this value for a field in a script.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldIDB">ID assigned to action field B.</param>
        /// <param name="field">The field in the script.</param>
        /// <param name="component">The script component on the hero kit object.</param>
        private static void SetFieldOnScript(HeroKitObject heroKitObject, int actionFieldIDB, FieldInfo field, MonoBehaviour component)
        {
            // Get value on the target instance.
            object value = field.FieldType;

            // Test value type.
            if (value == typeof(int))
            {
                int newValue = IntegerFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                field.SetValue(component, newValue);
            }
            else if (value == typeof(float))
            {
                float newValue = FloatFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                field.SetValue(component, newValue);
            }
            else if (value == typeof(string))
            {
                string newValue = StringFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                field.SetValue(component, newValue);
            }
            else if (value == typeof(bool))
            {
                bool newValue = BoolFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                field.SetValue(component, newValue);
            }
            else if (value == typeof(HeroKitObject))
            {
                HeroKitObject newValue = HeroObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB)[0];
                field.SetValue(component, newValue);
            }
            else if (value == typeof(GameObject))
            {
                GameObject newValue = GameObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                field.SetValue(component, newValue);
            }
        }
Example #6
0
        /// <summary>
        /// Get a value from a hero object list and set this value for a property in a script.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldIDB">ID assigned to action field B.</param>
        /// <param name="property">The property in the script.</param>
        /// <param name="component">The script component on the hero kit object.</param>
        public static void SetPropertyOnScript(HeroKitObject heroKitObject, int actionFieldIDB, PropertyInfo property, MonoBehaviour component)
        {
            // Get value on the target instance.
            object value = property.PropertyType;

            // Test value type.
            if (value == typeof(int))
            {
                int newValue = IntegerFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                property.SetValue(component, newValue, null);
            }
            else if (value == typeof(float))
            {
                float newValue = FloatFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                property.SetValue(component, newValue, null);
            }
            else if (value == typeof(string))
            {
                string newValue = StringFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                property.SetValue(component, newValue, null);
            }
            else if (value == typeof(bool))
            {
                bool newValue = BoolFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                property.SetValue(component, newValue, null);
            }
            else if (value == typeof(HeroKitObject))
            {
                HeroKitObject newValue = HeroObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB)[0];
                property.SetValue(component, newValue, null);
            }
            else if (value == typeof(GameObject))
            {
                GameObject newValue = GameObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB);
                property.SetValue(component, newValue, null);
            }
        }
Example #7
0
        /// <summary>
        /// Checks to see if a string list field has the Use Variables flag enabled.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to the action field.</param>
        /// <returns>Is the Use Variables flag enabled in a string list field.</returns>
        private static bool UseVariables(HeroKitObject heroKitObject, int actionFieldID)
        {
            bool useVariables = false;

            // Get the data type
            HeroAction action   = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];
            int        itemType = action.actionFields[actionFieldID].ints[3];

            if (itemType == 0)
            {
                Debug.LogError("String type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return(false);
            }

            if (itemType == 2 || itemType == 3)
            {
                // Get the hero kit object
                HeroKitObject targetHKO = HeroObjectFieldValue.GetTargetHeroObject(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return(false);
                }

                // Get the slot in the list that contains the string
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // check strings for variables if data type is variable
                if (itemType == 2)
                {
                    if (targetHKO.heroList.strings.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "String", slotID, 0, heroKitObject));
                        return(false);
                    }

                    useVariables = targetHKO.heroList.strings.items[slotID].useVariables;
                }
                // check strings for variables if data type is property
                if (itemType == 3)
                {
                    int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                    if (targetHKO.heroProperties == null || targetHKO.heroProperties.Length == 0 ||
                        targetHKO.heroProperties.Length <= propertyID || propertyID < 0 ||
                        targetHKO.heroProperties[propertyID].itemProperties.strings.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Properties", "String", slotID, 0, heroKitObject));
                        return(false);
                    }

                    useVariables = targetHKO.heroProperties[propertyID].itemProperties.strings.items[slotID].useVariables;
                }
            }
            else if (itemType == 4)
            {
                // Get the slot in the list that contains the string
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;
                // Check if there are variables to parse
                useVariables = HeroKitDatabase.GetGlobals().strings.items[slotID].useVariables;
            }

            return(useVariables);
        }
Example #8
0
        /// <summary>
        /// Set the value for a string in a string field.
        /// This is for a field that contains Variable, Property, Global.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to the action field.</param>
        /// <param name="newValue">The new value for a string field.</param>
        /// <param name="convertVariablesToText">Convert variables to text?</param>
        public static void SetValueB(HeroKitObject heroKitObject, int actionFieldID, string newValue, bool convertVariablesToText = false)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the string type
            int itemType = action.actionFields[actionFieldID].ints[3];

            // convert variables to text
            if (convertVariablesToText)
            {
                bool useVariables = UseVariables(heroKitObject, actionFieldID);
                if (useVariables)
                {
                    newValue = InsertVariablesInString(heroKitObject, newValue);
                }
            }

            // No type specified
            if (itemType == 0)
            {
                Debug.LogError("String type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return;
            }
            // set item in variable or property list
            else if (itemType == 1 || itemType == 2)
            {
                // Get the hero kit object
                HeroKitObject[] targetHKO = HeroObjectFieldValue.GetTargetHeroObjects(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return;
                }

                // Get the slot in the list that contains the integer
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the string from the string list
                if (itemType == 1)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        if (targetHKO[i].heroList.strings.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Variables", "String", slotID, 0, heroKitObject));
                            return;
                        }

                        // Set the string
                        targetHKO[i].heroList.strings.items[slotID].value = newValue;
                    }
                }

                // Get the string from the property list
                if (itemType == 2)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                        if (targetHKO[i].heroProperties == null || targetHKO[i].heroProperties.Length == 0 ||
                            targetHKO[i].heroProperties.Length <= propertyID || propertyID < 0 ||
                            targetHKO[i].heroProperties[propertyID].itemProperties.strings.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Properties", "String", slotID, 0, heroKitObject));
                            return;
                        }

                        targetHKO[i].heroProperties[propertyID].itemProperties.strings.items[slotID].value = newValue;
                    }
                }
            }
            // set item in global list
            if (itemType == 3)
            {
                // Get the slot in the list that contains the bool
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().strings.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "String", slotID, 0, heroKitObject));
                    return;
                }
                HeroKitDatabase.GetGlobals().strings.items[slotID].value = newValue;
            }
        }
Example #9
0
        /// <summary>
        /// Get a value from a string field.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </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="convertVariablesToText">Convert variables to text?</param>
        /// <returns>The value from a string field.</returns>
        public static string GetValueA(HeroKitObject heroKitObject, int actionFieldID, bool convertVariablesToText = false)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the data type
            int           itemType  = action.actionFields[actionFieldID].ints[3];
            string        itemValue = "";
            HeroKitObject targetHKO = null;

            if (itemType == 0)
            {
                Debug.LogError("String type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return("");
            }
            // get string from field
            else if (itemType == 1)
            {
                itemValue = action.actionFields[actionFieldID].strings[1];
                targetHKO = heroKitObject;
            }
            // get string from variable field or property field
            else if (itemType == 2 || itemType == 3)
            {
                // Get the hero kit object
                targetHKO = HeroObjectFieldValue.GetTargetHeroObject(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return("");
                }

                // Get the slot in the list that contains the string
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the string from variable list
                if (itemType == 2)
                {
                    if (targetHKO.heroList.strings.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "String", slotID, 0, heroKitObject));
                        return("");
                    }
                    itemValue = targetHKO.heroList.strings.items[slotID].value;
                }

                // Get the string from property list
                if (itemType == 3)
                {
                    int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                    if (targetHKO.heroProperties == null || targetHKO.heroProperties.Length == 0 ||
                        targetHKO.heroProperties.Length <= propertyID || propertyID < 0 ||
                        targetHKO.heroProperties[propertyID].itemProperties.strings.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Properties", "String", slotID, 0, heroKitObject));
                        return("");
                    }

                    itemValue = targetHKO.heroProperties[propertyID].itemProperties.strings.items[slotID].value;
                }
            }
            // get string from global field
            else if (itemType == 4)
            {
                // Get the slot in the list that contains the string
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().strings.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "String", slotID, 0, heroKitObject));
                    return("");
                }
                itemValue = HeroKitDatabase.GetGlobals().strings.items[slotID].value;
            }

            // localize the text
            itemValue = HeroKitDatabase.GetLocalization(itemValue);

            // convert variables into text
            if (convertVariablesToText)
            {
                bool useVariables = (itemType > 1) ? UseVariables(heroKitObject, actionFieldID) : true;
                if (useVariables)
                {
                    itemValue = InsertVariablesInString(targetHKO, itemValue);
                }
            }

            // Return the string
            return(itemValue);
        }
Example #10
0
        /// <summary>
        /// Set the value for a game object in a game object field.
        /// This is for a field that contains Variable, Property, Global.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to the action field.</param>
        /// <param name="newValue">The new value for a game object field.</param>
        public static void SetValueB(HeroKitObject heroKitObject, int actionFieldID, GameObject newValue)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the data type
            int itemType = action.actionFields[actionFieldID].ints[0];

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Game Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return;
            }
            // set item in variable or property list
            else if (itemType == 1 || itemType == 2)
            {
                // Get the hero kit object
                HeroKitObject[] targetHKO = HeroObjectFieldValue.GetTargetHeroObjects(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return;
                }

                // Get the slot in the list that contains the integer
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the integer from the integer list
                if (itemType == 1)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        if (targetHKO[i].heroList.gameObjects.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Variables", "Game Object", slotID, 0, heroKitObject));
                            return;
                        }

                        // Set the integer
                        targetHKO[i].heroList.gameObjects.items[slotID].value = newValue;
                    }
                }

                // Get the integer from the property list
                if (itemType == 2)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                        if (targetHKO[i].heroProperties == null || targetHKO[i].heroProperties.Length == 0 ||
                            targetHKO[i].heroProperties.Length <= propertyID || propertyID < 0 ||
                            targetHKO[i].heroProperties[propertyID].itemProperties.bools.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Properties", "Game Object", slotID, 0, heroKitObject));
                            return;
                        }

                        // Set the integer
                        targetHKO[i].heroProperties[propertyID].itemProperties.gameObjects.items[slotID].value = newValue;
                    }
                }
            }
            // set item in global list
            if (itemType == 3)
            {
                // Get the slot in the list that contains the bool
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().gameObjects.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Game Object", slotID, 0, heroKitObject));
                    return;
                }
                HeroKitDatabase.GetGlobals().gameObjects.items[slotID].value = newValue;
            }
        }
Example #11
0
        /// <summary>
        /// Get a value from a game object field.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </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>
        /// <returns>The value from a game object field.</returns>
        public static GameObject GetValueA(HeroKitObject heroKitObject, int actionFieldID, bool includeInactive = false)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the data type
            int        itemType  = action.actionFields[actionFieldID].ints[3];
            GameObject itemValue = null;

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Game Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return(null);
            }
            // get value from Value
            else if (itemType == 1)
            {
                string name = action.actionFields[actionFieldID].strings[0];

                // get gameobjects
                // WARNING: If you use Resources.Find... this will return hidden scene objects, including prefabs that you don't want
                // to work with. Only use this option if you absolutely must. If you have any prefabs with the same name as objects
                // in your scene, the prefabs might be referenced instead of the object you want
                Transform[] transforms = (includeInactive) ? Resources.FindObjectsOfTypeAll <Transform>() : Object.FindObjectsOfType <Transform>();
                for (int i = 0; i < transforms.Length; i++)
                {
                    if (transforms[i].gameObject.name == name)
                    {
                        itemValue = transforms[i].gameObject;
                        break;
                    }
                }
            }
            // Get the item from the value list (2=variables, 3=properties, 4=this)
            else if (itemType == 2 || itemType == 3 || itemType == 4)
            {
                HeroKitObject targetHKO = HeroObjectFieldValue.GetTargetHeroObject(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return(null);
                }

                // Get the slot in the list that contains the game object
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the item from the variable list
                if (itemType == 2)
                {
                    if (targetHKO.heroList.gameObjects.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "Game Object", slotID, 0, heroKitObject));
                        return(null);
                    }

                    itemValue = targetHKO.heroList.gameObjects.items[slotID].value;
                }

                // Get the item from the property list
                if (itemType == 3)
                {
                    int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                    if (targetHKO.heroProperties == null || targetHKO.heroProperties.Length == 0 ||
                        targetHKO.heroProperties.Length <= propertyID || propertyID < 0 ||
                        targetHKO.heroProperties[propertyID].itemProperties.bools.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Properties", "Game Object", slotID, 0, heroKitObject));
                        return(null);
                    }

                    itemValue = targetHKO.heroProperties[propertyID].itemProperties.gameObjects.items[slotID].value;
                }

                // Get the item from target hero kit object
                if (itemType == 4)
                {
                    itemValue = targetHKO.gameObject;
                }
            }
            // get item from global field
            else if (itemType == 5)
            {
                // Get the slot in the list that contains the item
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().gameObjects.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Game Objects", slotID, 0, heroKitObject));
                    return(null);
                }
                itemValue = HeroKitDatabase.GetGlobals().gameObjects.items[slotID].value;
            }

            return(itemValue);
        }
Example #12
0
        /// <summary>
        /// Get a value from a game object field.
        /// This is for a field that contains Variable, Property, Global.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to the action field.</param>
        /// <returns>The value from a game object field.</returns>
        public static GameObject GetValueB(HeroKitObject heroKitObject, int actionFieldID, bool includeInactive = false)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the data type
            int        itemType  = action.actionFields[actionFieldID].ints[3];
            GameObject itemValue = null;

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Game Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return(null);
            }
            // get item from variable or property list
            else if (itemType == 1 || itemType == 2)
            {
                HeroKitObject targetHKO = HeroObjectFieldValue.GetTargetHeroObject(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return(null);
                }

                // Get the slot in the list that contains the game object
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the item from the variable list
                if (itemType == 1)
                {
                    if (targetHKO.heroList.gameObjects.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "Game Object", slotID, 0, heroKitObject));
                        return(null);
                    }

                    itemValue = targetHKO.heroList.gameObjects.items[slotID].value;
                }

                // Get the item from the property list
                if (itemType == 2)
                {
                    int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                    if (targetHKO.heroProperties == null || targetHKO.heroProperties.Length == 0 ||
                        targetHKO.heroProperties.Length <= propertyID || propertyID < 0 ||
                        targetHKO.heroProperties[propertyID].itemProperties.bools.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Properties", "Game Object", slotID, 0, heroKitObject));
                        return(null);
                    }

                    itemValue = targetHKO.heroProperties[propertyID].itemProperties.gameObjects.items[slotID].value;
                }
            }
            // get item from globals
            else if (itemType == 3)
            {
                // Get the slot in the list that contains the item
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().gameObjects.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Game Object", slotID, 0, heroKitObject));
                    return(null);
                }
                itemValue = HeroKitDatabase.GetGlobals().gameObjects.items[slotID].value;
            }

            return(itemValue);
        }
Example #13
0
        /// <summary>
        /// Get a value from a float field.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </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>
        /// <returns>The value from a float field.</returns>
        public static float GetValueA(HeroKitObject heroKitObject, int actionFieldID)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the Float type
            int   itemType  = action.actionFields[actionFieldID].ints[3];
            float itemValue = 0;

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Float type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return(0f);
            }
            // get Float from field
            else if (itemType == 1)
            {
                itemValue = action.actionFields[actionFieldID].floats[0];
            }
            // get Float from Float field or property field
            else if (itemType == 2 || itemType == 3)
            {
                // Get the hero kit object
                HeroKitObject targetHKO = HeroObjectFieldValue.GetTargetHeroObject(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return(0f);
                }

                // Get the slot in the list that contains the Float
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the Float from Float list
                if (itemType == 2)
                {
                    if (targetHKO.heroList.floats.items.Count <= slotID)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "Float", slotID, 0, heroKitObject));
                        return(0);
                    }
                    itemValue = targetHKO.heroList.floats.items[slotID].value;
                }

                // Get the Float from property list
                if (itemType == 3)
                {
                    int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                    if (targetHKO.heroProperties == null || targetHKO.heroProperties.Length == 0 ||
                        targetHKO.heroProperties.Length <= propertyID || propertyID < 0 ||
                        targetHKO.heroProperties[propertyID].itemProperties.bools.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Properties", "Float", slotID, 0, heroKitObject));
                        return(0);
                    }

                    itemValue = targetHKO.heroProperties[propertyID].itemProperties.floats.items[slotID].value;
                }
            }
            // get Float from global field
            else if (itemType == 4)
            {
                // Get the slot in the list that contains the float
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().floats.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Float", slotID, 0, heroKitObject));
                    return(0);
                }
                itemValue = HeroKitDatabase.GetGlobals().floats.items[slotID].value;
            }

            // Return the Float
            return(itemValue);
        }
Example #14
0
        /// <summary>
        /// Get a value from a unity object field.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </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>
        /// <returns>The value from a unity object field.</returns>
        public static UnityObjectField GetValueA(HeroKitObject heroKitObject, int actionFieldID, bool requiredField = true)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the object type
            int itemType = action.actionFields[actionFieldID].ints[3];
            UnityObjectField itemValue = new UnityObjectField();

            itemValue.sceneID = -1;

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                if (requiredField)
                {
                    Debug.LogError("Unity Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                }
                return(itemValue);
            }
            // get object from field
            else if (itemType == 1)
            {
                itemValue.value     = action.actionFields[actionFieldID].unityObjects[0];
                itemValue.sceneID   = action.actionFields[actionFieldID].ints[5];
                itemValue.sceneName = action.actionFields[actionFieldID].strings[1];
            }
            // get object from variable field or property field
            else if (itemType == 2 || itemType == 3)
            {
                // Get the hero kit object
                HeroKitObject targetHKO = HeroObjectFieldValue.GetTargetHeroObject(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    if (requiredField)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    }
                    return(itemValue);
                }

                // Get the slot in the list that contains the object
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the object from variable list
                if (itemType == 2)
                {
                    if (targetHKO.heroList.unityObjects.items.Count <= slotID || slotID < 0)
                    {
                        if (requiredField)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "Hero Object", slotID, 0, heroKitObject));
                        }
                        return(itemValue);
                    }

                    itemValue = itemValue.Clone(targetHKO.heroList.unityObjects.items[slotID]);
                }

                // Get the object from property list
                if (itemType == 3)
                {
                    int propertyID = action.actionFields[actionFieldID].ints[6] - 1;

                    if (targetHKO.heroProperties == null || targetHKO.heroProperties.Length == 0 ||
                        targetHKO.heroProperties.Length <= propertyID || propertyID < 0 ||
                        targetHKO.heroProperties[propertyID].itemProperties.bools.items.Count <= slotID || slotID < 0)
                    {
                        if (requiredField)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Properties", "Hero Object", slotID, 0, heroKitObject));
                        }
                        return(itemValue);
                    }

                    itemValue = itemValue.Clone(targetHKO.heroProperties[propertyID].itemProperties.unityObjects.items[slotID]);
                }
            }
            // get object from global field
            else if (itemType == 4)
            {
                // Get the slot in the list that contains the value
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().unityObjects.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Unity Object", slotID, 0, heroKitObject));
                    return(itemValue);
                }
                itemValue = itemValue.Clone(HeroKitDatabase.GetGlobals().unityObjects.items[slotID]);
            }

            // Return the object
            return(itemValue);
        }
Example #15
0
        /// <summary>
        /// Get a value from a bool field on an event.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to the action field.</param>
        /// <returns>The value from a bool field.</returns>
        public static bool GetValueEvent(HeroKitObject heroKitObject, ConditionBoolField eventField)
        {
            // Get the bool type
            int  itemType  = eventField.fieldType;
            bool itemValue = false;

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Bool type was never specified for " + "event" + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return(false);
            }
            // get bool from field
            else if (itemType == 1)
            {
                itemValue = eventField.fieldValue;
            }
            // get bool from variable field or property field
            else if (itemType == 2 || itemType == 3)
            {
                // Get the hero kit object
                HeroKitObject targetHKO = HeroObjectFieldValue.GetValueEvent(heroKitObject, eventField);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo("event", 0, heroKitObject));
                    return(false);
                }

                // Get the slot in the list that contains the bool
                int slotID = eventField.fieldID - 1;

                // Get the bool from bool list
                if (itemType == 2)
                {
                    if (targetHKO.heroList.bools.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo("event", targetHKO.heroObject.name, "Variables", "Bool", slotID, 0, heroKitObject));
                        return(false);
                    }
                    itemValue = targetHKO.heroList.bools.items[slotID].value;
                }

                // Get the bool from property list
                if (itemType == 3)
                {
                    int propertyID = eventField.propertyID - 1;

                    if (targetHKO.heroProperties == null || targetHKO.heroProperties.Length == 0 ||
                        targetHKO.heroProperties.Length <= propertyID || propertyID < 0 ||
                        targetHKO.heroProperties[propertyID].itemProperties.bools.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo("event", targetHKO.heroObject.name, "Properties", "Bool", slotID, 0, heroKitObject));
                        return(false);
                    }

                    itemValue = targetHKO.heroProperties[propertyID].itemProperties.bools.items[slotID].value;
                }
            }
            // get bool from global
            else if (itemType == 4)
            {
                // Get the slot in the list that contains the bool
                int slotID = eventField.fieldID - 1;

                if (HeroKitDatabase.GetGlobals().bools.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo("event", "n/a", "Globals", "Bool", slotID, 0, heroKitObject));
                    return(false);
                }
                itemValue = HeroKitDatabase.GetGlobals().bools.items[slotID].value;
            }

            // Return the bool
            return(itemValue);
        }