Пример #1
0
        /// <summary>
        /// Get a hero kit object from a conditional int field on 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>
        /// <returns>A hero kit object from a conditional int field on an event.</returns>
        public static HeroKitObject GetValueEvent(HeroKitObject heroKitObject, ConditionIntField itemField)
        {
            // Get the game object
            HeroObjectFieldData goData = new HeroObjectFieldData();

            goData.heroKitObject = heroKitObject;
            goData.heroList      = goData.heroKitObject.heroList;
            goData.objectType    = itemField.objectType;
            goData.objectID      = itemField.objectID;
            goData.heroGUID      = itemField.heroGUID;
            goData.propertyID    = itemField.propertyID;

            // Get the hero kit object
            HeroKitObject targetHKO = HeroObjectTargetField.GetValue(goData)[0];

            if (targetHKO == null)
            {
                Debug.LogError("No hero kit object was found for this event." + HeroKitCommonRuntime.GetHeroDebugInfo(goData.heroKitObject));
                return(null);
            }

            // If we are working with a hero object in the scene or a property or variable field, make sure it matches the object we want to work with.
            if (heroKitObject.debugHeroObject && goData.objectType != 1)
            {
                // make sure we're working with the right kind of hero object inside the hero kit object
                HeroObject expectedHeroObject = itemField.heroObject;
                HeroObject thisHeroObject     = targetHKO.heroObject;
                if (expectedHeroObject != null && (expectedHeroObject != thisHeroObject))
                {
                    Debug.LogWarning("Wrong hero object for this event. Expected " + expectedHeroObject.name + " but got " + thisHeroObject.name + ". " + HeroKitCommonRuntime.GetHeroDebugInfo(goData.heroKitObject));
                }
            }

            return(targetHKO);
        }
Пример #2
0
        /// <summary>
        /// Get a value from an integer field on an event.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </summary>
        /// <param name="title">Title for action field.</param>
        /// <param name="boolData">Current data for this action field.</param>
        /// <param name="heroObject">Hero object that is the target of this action.</param>
        public static void BuildEventField(string title, ConditionIntField eventData, HeroObject heroObject) // string title, ref int fieldType, ref int objectType, ref int objectID, ref int fieldID, ref int heroGUID)
        {
            IntegerFieldData data = new IntegerFieldData();

            data.heroObject       = heroObject;
            data.targetHeroObject = eventData.targetHeroObject;
            data.objectType       = eventData.objectType;
            data.objectID         = eventData.objectID;
            data.fieldID          = eventData.fieldID;
            data.fieldType        = eventData.fieldType;
            data.heroGUID         = eventData.heroGUID;
            data.propertyID       = eventData.propertyID;
            data.objectName       = eventData.objectName;
            data.fieldValue       = eventData.fieldValue;

            SimpleLayout.Label(title);

            //-----------------------------------------
            // Get the type of field you want to work with.
            //-----------------------------------------
            data.fieldType = new HeroField.ValueTypeField().SetValues(data.fieldType, 0);

            //-----------------------------------------
            // Get the type of game object we are working with
            // Option 1: This game object (game object that this hero object is attached to)
            // Option 2: Another game object (another game object in the scene that has a hero object attached to it)
            // 2 = Local Variable, 3 = Property
            //-----------------------------------------
            if (data.fieldType == 2 || data.fieldType == 3)
            {
                data = ActionCommon.GetTargetHeroObject(data);
            }

            //-----------------------------------------
            // Get the integer list you want to work with.
            // The integer list is in hero object editor > Variables
            //-----------------------------------------

            // if this is a field, draw field (1=number)
            if (data.fieldType == 1)
            {
                data.fieldValue = SimpleLayout.IntField(data.fieldValue, 149);
            }

            // if this is a list, draw ints (2=integers, 3=properties)
            if (data.fieldType != 1)
            {
                data = SetPropertyID(data, -1);
                List <IntField> items = GetItemsFromList(data, -1);
                data = BuildItemFieldList(data, items);
            }


            //-----------------------------------------
            // assign values back to hero object fields
            //-----------------------------------------
            eventData.objectType       = data.objectType;
            eventData.objectID         = data.objectID;
            eventData.fieldID          = data.fieldID;
            eventData.fieldType        = data.fieldType;
            eventData.heroGUID         = data.heroGUID;
            eventData.propertyID       = data.propertyID;
            eventData.targetHeroObject = data.targetHeroObject;
            eventData.objectName       = data.objectName;
            eventData.fieldValue       = data.fieldValue;
        }
Пример #3
0
        /// <summary>
        /// Get a value from an int 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 an int field.</returns>
        public static int GetValueEvent(HeroKitObject heroKitObject, ConditionIntField eventField)
        {
            // Get the integer type
            int itemType  = eventField.fieldType;
            int itemValue = 0;

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Integer type was never specified for " + "event" + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return(0);
            }
            // get integer from field
            else if (itemType == 1)
            {
                itemValue = eventField.fieldValue;
            }
            // get integer from integer 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(0);
                }

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

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

                // Get the integer 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.ints.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo("event", targetHKO.heroObject.name, "Properties", "Integer", slotID, 0, heroKitObject));
                        return(0);
                    }

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

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

            // Return the integer
            return(itemValue);
        }