private GameObject AddImage(string prefabName, int imageID, GameObject group) { GameObject targetObject = null; // get parent container for images. if it doesn't, add it. if (HeroKitDatabase.PersistentObjectDictionary.ContainsKey(prefabName + imageID)) { targetObject = HeroKitDatabase.GetPersistentObject(prefabName + imageID); } else { // add dialog box to scene if it doesn't already exist GameObject template = Resources.Load <GameObject>("Hero Templates/Components/" + prefabName); if (template == null) { Debug.LogError("Can't add dialog box to scene because template for " + prefabName + " does not exist."); } targetObject = UnityEngine.Object.Instantiate(template, new Vector3(), new Quaternion(), group.transform); targetObject.name = prefabName + imageID; // add the object to the game object dictionary HeroKitDatabase.AddPersistentObject(prefabName + imageID, targetObject); } return(targetObject); }
public void ExecuteOnTarget(HeroKitObject targetObject, ParticleSystem particlePrefab, bool changePosition, bool changeRotation) { // create a pool for this particle if it doesn't exist string poolName = particlePrefab.transform.name + " particle effects" + targetObject.transform.GetInstanceID(); if (HeroKitDatabase.GetParticlePool(poolName, false) == null) { HeroKitDatabase.AddParticlePool(poolName, particlePrefab, 1, targetObject); } // change position of particle system Vector3 position = new Vector3(); if (changePosition) { position = CoordinatesValue.GetValue(heroKitObject, 4, 5, 6, 7, 8, 9, new Vector3()); } // change rotation Quaternion rotation = new Quaternion(); if (changeRotation) { Vector3 eulerAngles = CoordinatesValue.GetValue(heroKitObject, 11, 12, 13, 14, 15, 16, new Vector3()); rotation = Quaternion.Euler(eulerAngles); } // spawn the particle effect particleObject = HeroKitDatabase.SpawnParticle(poolName, position, rotation); // play the particle effect particleObject.Stop(); particleObject.Play(); }
private GameObject GetImage(string prefabName, int imageID, GameObject group) { GameObject targetObject = null; // get parent container for images. if it doesn't, add it. if (HeroKitDatabase.PersistentObjectDictionary.ContainsKey(prefabName + imageID)) { targetObject = HeroKitDatabase.GetPersistentObject(prefabName + imageID); } return(targetObject); }
private GameObject GetImageGroup(string prefabName) { GameObject gameObject = null; // get parent container for images. if it doesn't, add it. if (HeroKitDatabase.PersistentObjectDictionary.ContainsKey(prefabName)) { gameObject = HeroKitDatabase.GetPersistentObject(prefabName); } return(gameObject); }
// Save the scene data in a temporary directory. public void SaveSceneData(HeroKitObject hko, bool savePersistentObjects) { // Save all herokit objects in the current scene in the database HeroKitDatabase.AddAllHeroKitObjects(); // get the path where you want to put the save game file on the player's device string sceneName = (savePersistentObjects) ? "PersistentObjects" : UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; string path = Application.temporaryCachePath + "/HeroScenes/" + sceneName + ".json"; // convert game data to json data string jsonText = GetSceneData(hko, savePersistentObjects); // save the json data to player's device File.WriteAllText(path, jsonText); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; string poolName = StringFieldValue.GetValueA(heroKitObject, 0); int itemCount = IntegerFieldValue.GetValueA(heroKitObject, 1); int objectType = DropDownListValue.GetValue(heroKitObject, 2); // ------------------------------------------------ // Get the prefab that will populate the pool // ------------------------------------------------ GameObject prefab = null; bool isHeroKitObject = false; // hero object if (objectType == 1) { prefab = Resources.Load <GameObject>("Hero Templates/Components/HeroKit Default Object"); isHeroKitObject = true; } // prefab else if (objectType == 2) { prefab = PrefabValue.GetValue(heroKitObject, 3); } // ------------------------------------------------ // Create the pool // ------------------------------------------------ HeroKitDatabase.AddPool(poolName, prefab, itemCount, isHeroKitObject); //------------------------------------ // debug message //------------------------------------ if (heroKitObject.debugHeroObject) { string debugMessage = "Pool Name: " + poolName + "\n" + "Items to add: " + itemCount + "\n" + "Item: " + prefab; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } // normal return return(-99); }
/// <summary> /// Get the template assigned to a hero object field. /// </summary> /// <param name="data">Information about hero object field.</param> /// <returns>The hero object in a hero object field.</returns> public static HeroObject GetTemplate(HeroObjectFieldData data) { HeroObject heroObject = null; // return game object attached to this hero object as value (not done here) // return this hero object if (data.objectType == 2) { heroObject = data.heroKitObject.heroObject; } // return a hero object in variables else if (data.objectType == 3) { heroObject = GetHeroTemplate(data.heroKitObject.heroList.heroObjects, data, "Variables"); } // return a hero object in the scene else if (data.objectType == 4) { // get the hero object in the scene using its GUID HeroKitObject hko = HeroKitDatabase.GetHeroKitObject(data.heroGUID); if (hko != null) { heroObject = hko.heroObject; } } // return a hero object in properties else if (data.objectType == 5) { heroObject = GetHeroTemplate(data.heroKitObject.heroProperties[data.propertyID - 1].itemProperties.heroObjects, data, "Properties"); } // return a hero object in globals else if (data.objectType == 6) { heroObject = GetHeroTemplate(data.heroKitObject.heroGlobals.heroObjects, data, "Globals"); } return(heroObject); }
private GameObject AddImageGroup(string prefabName) { GameObject gameObject = null; // get parent container for images. if it doesn't, add it. if (HeroKitDatabase.PersistentObjectDictionary.ContainsKey(prefabName)) { gameObject = HeroKitDatabase.GetPersistentObject(prefabName); } else { // add image to scene if it doesn't already exist GameObject template = Resources.Load <GameObject>("Hero Templates/Components/" + prefabName); if (template == null) { Debug.LogError("Can't add dialog box to scene because template for " + prefabName + " does not exist."); } gameObject = UnityEngine.Object.Instantiate(template, new Vector3(), new Quaternion()); gameObject.name = prefabName; // add the object to the game object dictionary HeroKitDatabase.AddPersistentObject(prefabName, gameObject); // make it persistent HeroKitObject imageHKO = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, gameObject); if (imageHKO == null) { Debug.LogError("Can't make dialog box persistent because hero kit object component is missing."); } else { MakePersistent makePersistent = new MakePersistent(); makePersistent.ExecuteOnTarget(imageHKO); } } return(gameObject); }
/// <summary> /// Get the hero kit objects that are the target of an action. /// </summary> /// <param name="data">Information about hero object field.</param> /// <returns>A list of hero kit objects.</returns> public static HeroKitObject[] GetValue(HeroObjectFieldData data) { HeroKitObject[] heroKitObject = new HeroKitObject[1]; // return game object attached to this hero object if (data.objectType == 1) { heroKitObject[0] = data.heroKitObject; } // return a game object in this hero object's game object list (in variables) else if (data.objectType == 2) { heroKitObject = GetHeroList(data.heroKitObject.heroList.heroObjects, data, "Variables"); } // return a game object in the scene else if (data.objectType == 3) { // get the game object in the scene using its GUID heroKitObject[0] = HeroKitDatabase.GetHeroKitObject(data.heroGUID); } // return a game object in this hero object's game object list (in properties) else if (data.objectType == 4) { heroKitObject = GetHeroList(data.heroKitObject.heroProperties[data.propertyID - 1].itemProperties.heroObjects, data, "Properties"); } // return a game object in this hero object's game object list (in globals) else if (data.objectType == 5) { heroKitObject = GetHeroList(HeroKitDatabase.globals.heroObjects, data, "Globals"); } return(heroKitObject); }
/// <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); }
/// <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); }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; TextAsset csv = ObjectValue.GetValue <TextAsset>(heroKitObject, 0); bool runThis = (csv != null); if (runThis) { string text = csv.text; // save name of the localization file (used to play localized audio for messages) bool localizeAudio = BoolValue.GetValue(heroKitObject, 1); HeroKitCommonRuntime.localizatonDirectory = (localizeAudio) ? StringFieldValue.GetValueA(heroKitObject, 2) : ""; // get each line in the file string[] delimitersA = { "\r\n" }; string[] lines = text.Split(delimitersA, StringSplitOptions.RemoveEmptyEntries); // get key and value from each line List <KeyValuePair <string, string> > localizationList = new List <KeyValuePair <string, string> >(); char[] delimitersB = { ',' }; for (int i = 0; i < lines.Length; i++) { string[] textLine = lines[i].Split(delimitersB, 2); if (textLine.Length >= 2) { string key = textLine[0]; string value = textLine[1]; // if value is more than one word, remove quotes bool removeQuotes = value.Contains(" "); if (removeQuotes) { string trimmedValue = value.Trim('\"'); value = trimmedValue; } // add the key and value to the localization list localizationList.Add(new KeyValuePair <string, string>(key, value)); } } // add the key value pairs to the dictionary if (localizationList.Count > 0) { HeroKitDatabase.LocalizationDictionary = new Dictionary <string, string>(); HeroKitDatabase.AddLocalization(localizationList); } } // show debug message if (heroKitObject.debugHeroObject) { string fileName = (csv != null) ? csv.name : ""; string debugMessage = "CSV File: " + fileName; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get the particle to play UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 0); ParticleSystem particlePrefab = (unityObject.value != null) ? (ParticleSystem)unityObject.value : null; bool runThis = (particlePrefab != null); if (runThis) { // create a pool for this particle if it doesn't exist string poolName = particlePrefab.transform.name + " particle effects"; if (HeroKitDatabase.GetParticlePool(poolName, false) == null) { HeroKitDatabase.AddParticlePool(poolName, particlePrefab); } // get the positon to use for the particle Vector3 position = particlePrefab.transform.localPosition; bool changePosition = BoolValue.GetValue(heroKitObject, 1); if (changePosition) { position = CoordinatesValue.GetValue(heroKitObject, 2, 3, 4, 5, 6, 7, particlePrefab.transform.localPosition); } // get the rotation to use for the particle Quaternion rotation = particlePrefab.transform.localRotation; bool changeRotation = BoolValue.GetValue(heroKitObject, 8); if (changeRotation) { Vector3 eulerAngles = CoordinatesValue.GetValue(heroKitObject, 9, 10, 11, 12, 13, 14, particlePrefab.transform.localEulerAngles); rotation = Quaternion.Euler(eulerAngles); } // spawn the particle effect particleObject = HeroKitDatabase.SpawnParticle(poolName, position, rotation); // should next action wait until this action is complete? wait = BoolValue.GetValue(heroKitObject, 15); // play the particle effect particleObject.Stop(); particleObject.Play(); // set up the long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = wait; updateIsDone = false; heroKitObject.longActions.Add(this); } // show debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Particle System: " + particleObject; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
/// <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> /// 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); }
/// <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); }
/// <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; } }
/// <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); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get the type of object to spawn int spawnType = DropDownListValue.GetValue(heroKitObject, 0); // where are we spawning item? from pool or in scene? bool usePool = BoolValue.GetValue(heroKitObject, 1); string poolName = (usePool) ? StringFieldValue.GetValueA(heroKitObject, 2) : ""; // debug string string debugSpawn = ""; // get the object to spawn (1=hero object, 2=prefab) if (spawnType == 1) { HeroObject heroSpawn = HeroObjectFieldValue.GetValueC(heroKitObject, 3); bool debugHeroSpawn = BoolValue.GetValue(heroKitObject, 4); bool dontSave = BoolValue.GetValue(heroKitObject, 5); Vector3 position = GetPosition(); Quaternion rotation = GetRotation(); HeroKitDatabase.SpawnHeroKitObject(usePool, poolName, position, rotation, heroSpawn, debugHeroSpawn, dontSave); if (heroKitObject.debugHeroObject) { debugSpawn = "Hero Object: " + heroSpawn + "\n" + "Debug: " + debugHeroSpawn + "\n" + "Can Save: " + !dontSave + "\n" + "Position: " + position + "\n" + "Rotation: " + rotation + "\n" + "Use Pool: " + usePool + "\n" + "Pool Name: " + poolName; } } else if (spawnType == 2) { GameObject prefabSpawn = (!usePool) ? PrefabValue.GetValue(heroKitObject, 5) : null; Vector3 position = GetPosition(); Quaternion rotation = GetRotation(); HeroKitDatabase.SpawnPrefab(usePool, poolName, position, rotation, prefabSpawn); if (heroKitObject.debugHeroObject) { debugSpawn = "Game Object: " + prefabSpawn + "\n" + "Position: " + position + "\n" + "Rotation: " + rotation + "\n" + "Use Pool: " + usePool + "\n" + "Pool Name: " + poolName; } } //------------------------------------ // debug message //------------------------------------ if (heroKitObject.debugHeroObject) { string debugMessage = debugSpawn; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
/// <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); }
/// <summary> /// Get a value from a string field in a hero object template. /// 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 string field.</returns> public static string GetValueC(HeroKitObject heroKitObject, int actionFieldID, HeroObject heroObject) { // Get the action HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action]; // exit early if object does not exist if (heroObject == null) { Debug.LogError(HeroKitCommonRuntime.NoHeroObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject)); return(""); } // Get the item type int itemType = action.actionFields[actionFieldID].ints[3]; string itemValue = ""; // Get the slot in the list that contains the item int slotID = action.actionFields[actionFieldID].ints[2] - 1; // Get the lists StringList targetList = null; string itemTypeName = ""; string heroName = ""; if (itemType == 0) { Debug.LogError("String type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject)); return(""); } else if (itemType == 1) { heroName = heroObject.name; itemTypeName = "Variables"; targetList = heroObject.lists.strings; } else if (itemType == 2) { heroName = heroObject.name; itemTypeName = "Properties"; int propertyID = action.actionFields[actionFieldID].ints[5] - 1; if (propertyID < 0) { Debug.LogError("Property slot does not exist!"); } targetList = heroObject.propertiesList.properties[propertyID].itemProperties.strings; } else if (itemType == 3) { heroName = "n/a"; itemTypeName = "Globals"; targetList = HeroKitDatabase.GetGlobals().strings; } // exit early if the slot in the list does not exist if (targetList.items.Count <= slotID || slotID < 0) { Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, heroName, itemTypeName, "String", slotID, 0, heroKitObject)); return(""); } // get the item in the list slot itemValue = targetList.items[slotID].value; // Return the item return(itemValue); }
/// <summary> /// Get a value from a hero 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 hero object field.</returns> public static HeroKitObject[] GetValueA(HeroKitObject heroKitObject, int actionFieldID) { // 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]; HeroKitObject[] itemValue = new HeroKitObject[1]; // don't get item. Item type was never specified if (itemType == 0) { Debug.LogError("Hero Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject)); return(new HeroKitObject[1]); } // Get item from value else if (itemType == 1) { HeroKitObject[] targetHKO = GetTargetHeroObjects(heroKitObject, actionFieldID); itemValue = targetHKO; } // Get the item from variable or property else if (itemType == 2 || itemType == 3) { // Get the game object HeroObjectFieldData goData = new HeroObjectFieldData(); goData.heroKitObject = heroKitObject; goData.heroList = goData.heroKitObject.heroList; goData.objectType = action.actionFields[actionFieldID].ints[0]; goData.objectID = action.actionFields[actionFieldID].ints[1]; goData.heroGUID = action.actionFields[actionFieldID].ints[4]; goData.propertyID = action.actionFields[actionFieldID].ints[5]; // Get the hero kit object HeroKitObject targetHKO = HeroObjectTargetField.GetValue(goData)[0]; if (targetHKO == null) { Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject)); return(new HeroKitObject[1]); } int slotID = action.actionFields[actionFieldID].ints[2] - 1; // Get item from variable if (itemType == 2) { if (targetHKO.heroList.heroObjects.items.Count <= slotID || slotID < 0) { Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "Hero Object", slotID, 0, heroKitObject)); return(new HeroKitObject[1]); } if (targetHKO.heroList.heroObjects.items[slotID].heroKitGameObjects != null) { itemValue = targetHKO.heroList.heroObjects.items[slotID].heroKitGameObjects.ToArray(); } } // Get item from property else 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", "Hero Object", slotID, 0, heroKitObject)); return(new HeroKitObject[1]); } if (targetHKO.heroProperties[propertyID].itemProperties.heroObjects.items[slotID].heroKitGameObjects != null) { itemValue = targetHKO.heroProperties[propertyID].itemProperties.heroObjects.items[slotID].heroKitGameObjects.ToArray(); } } // 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 && itemValue != null) { // make sure we're working with the right kind of hero object inside the hero kit object HeroObject expectedHeroObject = action.actionFields[actionFieldID].heroObjects[0]; HeroObject thisHeroObject = itemValue[0].heroObject; if (expectedHeroObject != null && thisHeroObject != null && (expectedHeroObject != thisHeroObject)) { Debug.LogWarning("Wrong hero object for this action. Expected " + expectedHeroObject.name + " but got " + thisHeroObject.name + ". " + HeroKitCommonRuntime.GetHeroDebugInfo(goData.heroKitObject)); } } } // get from global field else if (itemType == 4) { // Get the slot in the list that contains the bool int slotID = action.actionFields[actionFieldID].ints[2] - 1; if (HeroKitDatabase.GetGlobals().heroObjects.items.Count <= slotID || slotID < 0) { Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Hero Object", slotID, 0, heroKitObject)); return(new HeroKitObject[1]); } if (HeroKitDatabase.GetGlobals().heroObjects.items[slotID].heroKitGameObjects != null) { itemValue = HeroKitDatabase.GetGlobals().heroObjects.items[slotID].heroKitGameObjects.ToArray(); } } if (itemValue == null) { Debug.LogError("No hero kit object was found for " + action.actionTemplate.name + ". " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject)); itemValue = new HeroKitObject[1]; } return(itemValue); }
/// <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; } }
/// <summary> /// Hero Object = A hero object attached to a game object in a scene. /// </summary> /// <typeparam name="T">The type of data for the action field.</typeparam> /// <param name="data">The data for the action field.</param> /// <returns>The data for the action field.</returns> public static T GetHeroObjectInScene <T>(T data) where T : ITargetHeroObject { GameObject go = null; HeroKitObject hkoField = null; // if there is no game object attached to action, do this here... if (data.heroGUID == 0) { hkoField = SimpleLayout.ObjectField <HeroKitObject>(hkoField, 300, true); if (hkoField != null) { go = hkoField.gameObject; } } // if a game object was attached to action, update fields here... if (data.heroGUID != 0) { HeroKitObject hko = HeroKitDatabase.GetHeroKitObject(data.heroGUID); if (hko != null) { go = hko.gameObject; } oldGUID = data.heroGUID; newGUID = data.heroGUID; SimpleLayout.Space(5); SimpleLayout.Button(" [X] " + data.objectName, new UnityAction <T>(DeleteGameObject), data, Button.StyleB, 205); if (oldGUID != newGUID) { data.heroGUID = newGUID; data.objectName = ""; data.targetHeroObject = null; go = null; } } // if there is a game object attached to the action field, populate it here if (go != null) { HeroKitObject hko = go.GetComponent <HeroKitObject>(); if (hko == null) { Debug.LogError("Game Object can't be added because it doesn't have a Hero Kit Object component. Add this component and re-add the game object."); return(data); } data.heroGUID = hko.heroGUID; data.objectName = go.name; // get the hero kit objects in the open scene(s) HeroKitObject[] heroKitObjects = Resources.FindObjectsOfTypeAll <HeroKitObject>(); // get the gameobject that has the GUID we need for (int i = 0; i < heroKitObjects.Count(); i++) { if (heroKitObjects[i].heroGUID == data.heroGUID) { data.targetHeroObject = heroKitObjects[i].heroObject; break; } } } else { data.targetHeroObject = null; } return(data); }
/// <summary> /// Convert a variable into a string. /// </summary> /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param> /// <param name="subString">The code for the variable (ex. [V-I-0]).</param> /// <param name="codeType">The type of variable to parse.</param> /// <returns>Parsed string.</returns> private static string GetValueForCode(HeroKitObject heroKitObject, string subString, CodeType codeType, bool isProperty = false) { string code = ""; int propertyID = 0; // convert the code into an integer. ex: [V-I-0] = 99 string slotValue = ""; int slotID = 0; if (!isProperty) { // get the code. ex: 0 int codeStartIndex = 5; int codeWidth = subString.Length - codeStartIndex - 1; code = subString.Substring(codeStartIndex, codeWidth); } // [P-2-I-5] if (isProperty) { // [p- int propertyStartIndex = 3; // 2-I (i = -) int propertyIdLength = subString.IndexOf("-", propertyStartIndex) - propertyStartIndex; // 2 string pID = subString.Substring(propertyStartIndex, propertyIdLength); bool parsed = Int32.TryParse(pID, out propertyID); if (!parsed) { return("???"); } // get last value in sequence (5) int codeStartIndex = propertyStartIndex + propertyIdLength + 3; int codeWidth = subString.Length - codeStartIndex - 1; code = subString.Substring(codeStartIndex, codeWidth); } // -------------------------------------------------------------- // Variables // -------------------------------------------------------------- if (Int32.TryParse(code, out slotID)) { if (codeType == CodeType.IntegerVariable) { // get the value from the variable list if (heroKitObject.heroList.ints.items != null && heroKitObject.heroList.ints.items.Count != 0 && heroKitObject.heroList.ints.items.Count > slotID) { slotValue = heroKitObject.heroList.ints.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Variable Integer Slot does not exist!"); } } else if (codeType == CodeType.BoolVariable) { // get the value from the variable list if (heroKitObject.heroList.bools.items != null && heroKitObject.heroList.bools.items.Count != 0 && heroKitObject.heroList.bools.items.Count > slotID) { slotValue = heroKitObject.heroList.bools.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Variable Bool Slot does not exist!"); } } else if (codeType == CodeType.StringVariable) { // get the value from the variable list if (heroKitObject.heroList.strings.items != null && heroKitObject.heroList.strings.items.Count != 0 && heroKitObject.heroList.strings.items.Count > slotID) { slotValue = heroKitObject.heroList.strings.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Variable String Slot does not exist!"); } } // -------------------------------------------------------------- // Properties // -------------------------------------------------------------- if (codeType == CodeType.IntegerProperty) { // get the hero property attached to hero object HeroProperties heroProperties = (heroKitObject.heroProperties.Length > propertyID) ? heroKitObject.heroProperties[propertyID] : null; // get the value from the variable list if (heroProperties != null && heroProperties.itemProperties.ints.items != null && heroProperties.itemProperties.ints.items.Count != 0 && heroProperties.itemProperties.ints.items.Count > slotID) { slotValue = heroProperties.itemProperties.ints.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Property Integer Slot does not exist!"); } } else if (codeType == CodeType.BoolProperty) { // get the hero property attached to hero object HeroProperties heroProperties = heroKitObject.heroProperties[propertyID]; // get the value from the variable list if (heroProperties != null && heroProperties.itemProperties.bools.items != null && heroProperties.itemProperties.bools.items.Count != 0 && heroProperties.itemProperties.bools.items.Count > slotID) { slotValue = heroProperties.itemProperties.bools.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Property Bool Slot does not exist!"); } } else if (codeType == CodeType.StringProperty) { // get the hero property attached to hero object HeroProperties heroProperties = heroKitObject.heroProperties[propertyID]; // get the value from the variable list if (heroProperties != null && heroProperties.itemProperties.strings.items != null && heroProperties.itemProperties.strings.items.Count != 0 && heroProperties.itemProperties.strings.items.Count > slotID) { slotValue = heroProperties.itemProperties.strings.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Property String Slot does not exist!"); } } // -------------------------------------------------------------- // Globals // -------------------------------------------------------------- if (codeType == CodeType.IntegerGlobal) { // get the value from the variable list if (HeroKitDatabase.GetGlobals().ints.items != null && HeroKitDatabase.GetGlobals().ints.items.Count != 0 && HeroKitDatabase.GetGlobals().ints.items.Count > slotID) { slotValue = HeroKitDatabase.GetGlobals().ints.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Global Integer Slot does not exist!"); } } else if (codeType == CodeType.BoolGlobal) { // get the value from the variable list if (HeroKitDatabase.GetGlobals().bools.items != null && HeroKitDatabase.GetGlobals().bools.items.Count != 0 && HeroKitDatabase.GetGlobals().bools.items.Count > slotID) { slotValue = HeroKitDatabase.GetGlobals().bools.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Global Bool Slot does not exist!"); } } else if (codeType == CodeType.StringGlobal) { // get the value from the variable list if (HeroKitDatabase.GetGlobals().strings.items != null && HeroKitDatabase.GetGlobals().strings.items.Count != 0 && HeroKitDatabase.GetGlobals().strings.items.Count > slotID) { slotValue = HeroKitDatabase.GetGlobals().strings.items[slotID].value.ToString(); } else if (heroKitObject.debugHeroObject) { Debug.LogError("Global String Slot does not exist!"); } } } return(slotValue); }
private string GetSaveGameData(GameSaveData existingGame) { // if save file existed, get date we need to transfer to new save file bool newGame = (existingGame == null); DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); TimeSpan gameplay = new TimeSpan(); if (newGame) { TimeSpan timeElapsed = TimeSpan.FromSeconds(Time.realtimeSinceStartup); startDate = DateTime.Now.Subtract(timeElapsed); endDate = DateTime.Now; gameplay = TimeSpan.FromSeconds(Time.realtimeSinceStartup); } else { startDate = new DateTime(existingGame.startYear, existingGame.startMonth, existingGame.startDay, existingGame.startHour, existingGame.startMinute, existingGame.startSecond); endDate = DateTime.Now; TimeSpan oldTime = new TimeSpan(existingGame.playtimeDays, existingGame.playtimeHours, existingGame.playtimeMinutes, existingGame.playtimeSeconds); TimeSpan newTime = TimeSpan.FromSeconds(Time.realtimeSinceStartup); gameplay = oldTime + newTime; } // get the json files DirectoryInfo directoryInfo = new DirectoryInfo(Application.temporaryCachePath + "/HeroScenes/"); FileInfo[] fileInfo = directoryInfo.GetFiles("*.json"); // set up the game save data class GameSaveData saveData = new GameSaveData(); saveData.scenes = new SceneSaveData[fileInfo.Length]; // build the game save data for (int i = 0; i < fileInfo.Length; i++) { //Debug.Log(fileInfo[i].Name); string jsonSceneText = GetCachedScene(fileInfo[i].Name); saveData.scenes[i] = JsonUtility.FromJson <SceneSaveData>(jsonSceneText); } // save the current scene name saveData.lastScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; saveData.lastSceneID = UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex; // add start date saveData.startYear = startDate.Year; saveData.startMonth = startDate.Month; saveData.startDay = startDate.Day; saveData.startHour = startDate.Hour; saveData.startMinute = startDate.Minute; saveData.startSecond = startDate.Second; // add current date saveData.endYear = endDate.Year; saveData.endMonth = endDate.Month; saveData.endDay = endDate.Day; saveData.endHour = endDate.Hour; saveData.endMinute = endDate.Minute; saveData.endSecond = endDate.Second; // add gameplay saveData.playtimeDays = (int)gameplay.TotalDays; saveData.playtimeHours = (int)gameplay.TotalHours; saveData.playtimeMinutes = (int)gameplay.TotalMinutes; saveData.playtimeSeconds = gameplay.Seconds; // variables saveData.globalInts = HeroKitDatabase.GetGlobals().ints.Save(); saveData.globalFloats = HeroKitDatabase.GetGlobals().floats.Save(); saveData.globalBools = HeroKitDatabase.GetGlobals().bools.Save(); saveData.globalStrings = HeroKitDatabase.GetGlobals().strings.Save(); // convert the game save data class to json string jsonGameText = JsonUtility.ToJson(saveData); // return the json file return(jsonGameText); }