/// <summary> /// Get a hero kit object from a conditional bool 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 bool field on an event.</returns> public static HeroKitObject GetValueEvent(HeroKitObject heroKitObject, ConditionBoolField itemField) { // Get the game object HeroObjectFieldData goData = new HeroObjectFieldData(); goData.heroKitObject = heroKitObject; goData.heroList = goData.heroKitObject.heroList; goData.objectType = itemField.objectType; 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); }
/// <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); }
/// <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="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, ConditionBoolField boolData, HeroObject heroObject) { BoolFieldData data = new BoolFieldData(); data.heroObject = heroObject; data.targetHeroObject = boolData.targetHeroObject; data.objectType = boolData.objectType; data.objectID = boolData.objectID; data.fieldID = boolData.fieldID; data.fieldType = boolData.fieldType; data.heroGUID = boolData.heroGUID; data.propertyID = boolData.propertyID; data.objectName = boolData.objectName; data.fieldValue = boolData.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) //----------------------------------------- if (data.fieldType == 2 || data.fieldType == 3) { data = ActionCommon.GetTargetHeroObject(data); } //----------------------------------------- // Get the list you want to work with. // The list is in hero object editor > Variables //----------------------------------------- // if this is a field, draw field (1=value) if (data.fieldType == 1) { data.fieldValue = SimpleLayout.BoolField(data.fieldValue); } // if this is a list, draw ints (2=variables, 3=properties) if (data.fieldType != 1) { data = SetPropertyID(data, -1); List <BoolField> items = GetItemsFromList(data, -1); data = BuildItemFieldList(data, items); } //----------------------------------------- // assign values back to hero object fields //----------------------------------------- boolData.objectType = data.objectType; boolData.objectID = data.objectID; boolData.fieldID = data.fieldID; boolData.fieldType = data.fieldType; boolData.heroGUID = data.heroGUID; boolData.propertyID = data.propertyID; boolData.targetHeroObject = data.targetHeroObject; boolData.objectName = data.objectName; boolData.fieldValue = data.fieldValue; }