// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get field values GameObject targetObject = GameObjectFieldValue.GetValueA(heroKitObject, 0); bool runThis = (targetObject != null); if (runThis) { // destroy game object UnityEngine.Object.Destroy(targetObject); } //------------------------------------ // debug message //------------------------------------ if (heroKitObject.debugHeroObject) { string debugMessage = "Game Object: " + targetObject; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get the hero object where the parameters are stored HeroKitObject targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1)[0]; UnityObjectField objectData = UnityObjectFieldValue.GetValueA(heroKitObject, 2); string scriptName = (objectData.value != null) ? objectData.value.name : ""; bool runThis = (targetObject != null && scriptName != ""); if (runThis) { ExecuteOnTarget(targetObject, scriptName); } //------------------------------------ // debug message //------------------------------------ if (heroKitObject.debugHeroObject) { string debugMessage = "MonoScript: " + scriptName; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; String imageGroupPrefabName = "HeroKit Image Canvas"; String imagePrefabName = "HeroKit Image Sprite"; int imageID = IntegerFieldValue.GetValueA(heroKitObject, 0); // get the game object that contains the images GameObject imageGroup = GetImageGroup(imageGroupPrefabName); if (imageGroup != null) { // get the game object that contains the image GameObject targetObject = GetImage(imagePrefabName, imageID, imageGroup); if (targetObject != null) { // disable the targetObject targetObject.SetActive(false); } } // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Image ID: " + imageID; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
/// <summary> /// Set multiple properties in a script. /// </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="component">The script that contains the properties.</param> public static void SetValueA(HeroKitObject heroKitObject, int actionFieldID, MonoBehaviour component) { // Get the action HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action]; // something we need isn't available. exit early. if (component == null) { Debug.LogError(HeroKitCommonRuntime.NoComponentDebugInfo(action.actionTemplate.name, "MonoScript", 0, heroKitObject)); return; } // Get the start field, end field int propertyFieldStart = action.actionFields[actionFieldID].ints[1]; int propertyFieldEnd = action.actionFields[actionFieldID].ints[2]; // Get the properties PropertyInfo[] properties = GetProperties(component); // Set the properties int availablePropertySlots = propertyFieldEnd - propertyFieldStart; if (properties != null && properties.Length != 0) { for (int i = 0; i < properties.Length && i < availablePropertySlots; i++) { // Get the property PropertyInfo property = properties[i]; // Set the property SetPropertyOnScript(heroKitObject, propertyFieldStart + i, property, component); } } }
/// <summary> /// Get a value from a property in a script and save this value on a hero kit object. /// </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="component">The script that contains the property.</param> public static void SetValueB(HeroKitObject heroKitObject, int actionFieldID, int actionFieldIDB, MonoBehaviour component) { // Get the action HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action]; // something we need isn't available. exit early. if (component == null) { Debug.LogError(HeroKitCommonRuntime.NoComponentDebugInfo(action.actionTemplate.name, "MonoScript", 0, heroKitObject)); return; } // Get the property ID int valueID = action.actionFields[actionFieldID].ints[0]; // Get the properties PropertyInfo[] properties = GetProperties(component); // Get the property if (properties != null && properties.Length != 0 && valueID > 0) { // Get the property PropertyInfo property = properties[valueID - 1]; // Set the property SetPropertyOnHero(heroKitObject, actionFieldIDB, property, component); } }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 4); UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 1); AudioClip audioClip = (unityObject.value != null) ? (AudioClip)unityObject.value : null; bool fadeBGM = BoolValue.GetValue(heroKitObject, 2); bool fadeBGS = BoolValue.GetValue(heroKitObject, 3); bool changeSettings = BoolValue.GetValue(heroKitObject, 5); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], audioClip, fadeBGM, fadeBGS, changeSettings); } // set up the long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); // show debug message if (heroKitObject.debugHeroObject) { string debugMessage = "SE: " + audioClip; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// No actions for the End action public int Execute(HeroKitObject hko) { // assign variables heroKitObject = hko; eventID = heroKitObject.heroStateData.eventBlock; int actionID = heroKitObject.heroStateData.action; int nextAction = -99; // the last time Do While action was hit, was the evaluation successful? bool conditionsMet = heroKitObject.heroState.heroEvent[eventID].actions[actionID].actionFields[0].bools[0]; // if conditions were met, go to beginning of loop and re-test conditions if (conditionsMet) { nextAction = heroKitObject.heroState.heroEvent[eventID].actions[actionID].actionFields[0].ints[0] - 1; } heroKitObject.heroState.heroEvent[eventID].actions[actionID].actionFields[0].ints[1]++; //if (heroKitObject.heroState.heroEvent[eventID].actions[actionID].actionField[0].ints[1] > 4) //{ // Debug.Log("too many loops"); // return -99; //} if (heroKitObject.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject)); } return(nextAction); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); HeroKitObject avoidObject = HeroObjectFieldValue.GetValueA(heroKitObject, 2)[0]; bool runThis = (targetObject != null && avoidObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], avoidObject); } // set up the long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Move toward this object: " + avoidObject; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// execute this action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get field values HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); string childName = ChildObjectValue.GetValue(heroKitObject, 2, 3); int colliderType = DropDownListValue.GetValue(heroKitObject, 4); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], childName, colliderType); } //----------------------------------------- // debugging stuff //----------------------------------------- if (heroKitObject.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject)); } // return value return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // add menu to scene if it doesn't exist HeroKitObject targetObject = HeroKitCommonRuntime.GetPrefabFromAssets(HeroKitCommonRuntime.settingsInfo.gameoverMenu, true); bool runThis = (targetObject != null); if (runThis) { targetObject.gameObject.SetActive(true); // save the scene to load UnityObjectField objectData = UnityObjectFieldValue.GetValueA(heroKitObject, 0); targetObject.heroList.unityObjects.items[0] = objectData; // enable the canvas Canvas canvas = targetObject.GetHeroComponent <Canvas>("Canvas"); canvas.enabled = true; // play event 0 targetObject.PlayEvent(0); } if (heroKitObject.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // save the current scene SaveScene saveScene = new SaveScene(); saveScene.SaveSceneData(heroKitObject, false); // save scene objects saveScene.SaveSceneData(heroKitObject, true); // save persistent objects // get the path where you want to put the save game file on the player's device string saveGameName = StringFieldValue.GetValueA(heroKitObject, 0, true); string path = Application.persistentDataPath + "/HeroSaves/" + saveGameName + ".json"; // if there is an existing save file, get the seconds played GameSaveData existingGame = HeroKitCommonRuntime.GetSaveGame(saveGameName); // convert game data to json data string jsonText = GetSaveGameData(existingGame); // save the json data to player's device File.WriteAllText(path, jsonText); // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Save Game Name: " + saveGameName + "\n" + "Full Path: " + path; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i]); } // set up the long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); if (heroKitObject.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get field values SceneObjectValueData data = SceneObjectValue.GetValue(heroKitObject, 0, 1, false); GameObject[] targetObject = HeroKitCommonRuntime.GetGameObjectsFromSceneObjects(data); int layer = DropDownListValue.GetValue(heroKitObject, 2) - 1; bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], layer); } // debug info if (heroKitObject.debugHeroObject) { string debugMessage = "Layer: " + layer; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get field values HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); string childName = ChildObjectValue.GetValue(heroKitObject, 2, 3); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], childName); } // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Child (if used): " + childName + "\n" + "Position to Change: " + position; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); float timeToWait = FloatFieldValue.GetValueA(heroKitObject, 2) + Time.time; float speed = FloatFieldValue.GetValueA(heroKitObject, 3); wait = !BoolValue.GetValue(heroKitObject, 4); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], timeToWait, speed); } // set up update for long action heroKitObject.heroState.heroEvent[eventID].waiting = wait; updateIsDone = false; heroKitObject.longActions.Add(this); // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Speed: " + speed; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
/// <summary> /// Get a value from a field in a script and save this value on a hero kit object. /// </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="component">The script that contains the field.</param> public static void SetValueB(HeroKitObject heroKitObject, int actionFieldIDA, int actionFieldIDB, MonoBehaviour component) { // Get the action HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action]; // something we need isn't available. exit early. if (component == null) { Debug.LogError(HeroKitCommonRuntime.NoComponentDebugInfo(action.actionTemplate.name, "MonoScript", 0, heroKitObject)); return; } // Get the field ID int valueID = action.actionFields[actionFieldIDA].ints[0]; // Get the fields FieldInfo[] fields = GetFields(component); // Get the field if (fields != null && fields.Length != 0 && valueID > 0) { // Get the field FieldInfo field = fields[valueID - 1]; // Set the field SetFieldOnHero(heroKitObject, actionFieldIDB, field, component); } }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); float duration = FloatFieldValue.GetValueA(heroKitObject, 2); if (duration < 0) { duration = 0; } bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], duration); } // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Duration: " + duration; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get object to play particles on HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 2); ParticleSystem particlesPrefab = (unityObject.value != null) ? (ParticleSystem)unityObject.value : null; bool changePosition = BoolValue.GetValue(heroKitObject, 3); bool changeRotation = BoolValue.GetValue(heroKitObject, 10); wait = BoolValue.GetValue(heroKitObject, 17); bool runThis = (targetObject != null && particlesPrefab != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], particlesPrefab, changePosition, changeRotation); } // 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); }
// Gets objects in a scene that match a certerin criteria public int Execute(HeroKitObject hko) { // Get variables heroKitObject = hko; //----------------------------------------- // Get the game objects in the scene that match specific parameters //----------------------------------------- int actionType = DropDownListValue.GetValue(heroKitObject, 0); int objectCount = IntegerFieldValue.GetValueA(heroKitObject, 2); string name = StringFieldValue.GetValueA(heroKitObject, 3); // filter the hero kit objects in the scene List <HeroKitObject> filteredObjects = HeroActionCommonRuntime.GetHeroObjectsByName(HeroActionCommonRuntime.GetHeroObjectsInScene(), objectCount, name); // assign the hero kit objects to the list HeroActionCommonRuntime.AssignObjectsToList(heroKitObject, 1, filteredObjects, actionType); //----------------------------------------- // debugging stuff //----------------------------------------- if (heroKitObject.debugHeroObject) { string countStr = (filteredObjects != null) ? filteredObjects.Count.ToString() : 0.ToString(); string debugMessage = "Get objects with this name: " + name + "\n" + "Maximum number of objects to get: " + objectCount + "\n" + "Objects found: " + countStr; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; GameObject menuTemplate = PrefabValue.GetValue(heroKitObject, 0); bool runThis = (menuTemplate != null); if (runThis) { // if new prefab is not in scene, delete the old one from scene and attach new prefab to settings. GameObject prefab = HeroKitCommonRuntime.settingsInfo.startMenu; if (prefab != null && prefab != menuTemplate) { HeroKitCommonRuntime.DeletePrefabFromScene(prefab, true); HeroKitCommonRuntime.settingsInfo.startMenu = menuTemplate; } } if (heroKitObject.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); float duration = FloatFieldValue.GetValueA(heroKitObject, 2); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], duration); } // set up update for long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); // show debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Duration: " + duration; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Check to see if an integer meets certain conditions in an if statement // This is used by both If and Else If public int Execute(HeroKitObject hko) { // assign variables heroKitObject = hko; eventID = heroKitObject.heroStateData.eventBlock; int actionID = heroKitObject.heroStateData.action; int currentIndent = heroKitObject.heroState.heroEvent[eventID].actions[actionID].indent; // evaluate the if statement int comparison = DropDownListValue.GetValue(heroKitObject, 2); bool value1 = BoolFieldValue.GetValueB(heroKitObject, 1); bool value2 = BoolFieldValue.GetValueA(heroKitObject, 3); bool evaluation = HeroActionCommonRuntime.CompareBools(comparison, value1, value2); // next we need to get the action that we want the game loop to think just executed // this checks to see if the if statement should be run // if it should run, it disables the next conditional action if it is "Else" or "Else If" int thisAction = HeroActionCommonRuntime.RunConditionalIfAction(heroKitObject, eventID, actionID, currentIndent, evaluation); // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Bool A: " + value1 + "\n" + "Bool B: " + value2 + "\n" + "Result: " + evaluation; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } // return the action that we want the game loop to think just executed return(thisAction); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // get field values HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); int speed = IntegerFieldValue.GetValueA(heroKitObject, 8); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], speed); } // set up update for long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Speed: " + speed + "\n" + "Euler Angles: " + degreesToChange; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// skips this action (comments are just for developers) public int Execute(HeroKitObject hko) { if (hko.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(hko, "")); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); bool changeMove = BoolValue.GetValue(heroKitObject, 2); bool changeFace = BoolValue.GetValue(heroKitObject, 3); string[] moveNames = new string[0]; if (changeMove) { moveNames = new string[9]; // movement moveNames[0] = StringFieldValue.GetValueA(heroKitObject, 5); moveNames[1] = StringFieldValue.GetValueA(heroKitObject, 6); moveNames[2] = StringFieldValue.GetValueA(heroKitObject, 7); moveNames[3] = StringFieldValue.GetValueA(heroKitObject, 8); moveNames[4] = StringFieldValue.GetValueA(heroKitObject, 9); moveNames[5] = StringFieldValue.GetValueA(heroKitObject, 10); moveNames[6] = StringFieldValue.GetValueA(heroKitObject, 11); moveNames[7] = StringFieldValue.GetValueA(heroKitObject, 12); moveNames[8] = StringFieldValue.GetValueA(heroKitObject, 13); } string[] faceNames = new string[0]; if (changeFace) { faceNames = new string[9]; // face faceNames[0] = StringFieldValue.GetValueA(heroKitObject, 14); faceNames[1] = StringFieldValue.GetValueA(heroKitObject, 15); faceNames[2] = StringFieldValue.GetValueA(heroKitObject, 16); faceNames[3] = StringFieldValue.GetValueA(heroKitObject, 17); faceNames[4] = StringFieldValue.GetValueA(heroKitObject, 18); faceNames[5] = StringFieldValue.GetValueA(heroKitObject, 19); faceNames[6] = StringFieldValue.GetValueA(heroKitObject, 20); faceNames[7] = StringFieldValue.GetValueA(heroKitObject, 21); faceNames[8] = StringFieldValue.GetValueA(heroKitObject, 22); } bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], moveNames, faceNames); } // debug message if (heroKitObject.debugHeroObject) { string debugMessage = ""; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Gets objects in a scene that match a certerin criteria public int Execute(HeroKitObject hko) { // Get variables heroKitObject = hko; eventID = heroKitObject.heroStateData.eventBlock; int actionCount = heroKitObject.heroState.heroEvent[eventID].actions.Count; //----------------------------------------- // Get the game objects in the scene that match specific parameters //----------------------------------------- int actionType = DropDownListValue.GetValue(heroKitObject, 0); int getHeroFieldID = 1; int objectCount = IntegerFieldValue.GetValueA(heroKitObject, 2); HeroKitObject originHKO = HeroObjectFieldValue.GetValueA(heroKitObject, 3)[0]; List <HeroKitObject> listObjects = HeroObjectFieldValue.GetValueB(heroKitObject, 4); string childName = ChildObjectValue.GetValue(heroKitObject, 5, 6); int rayDirectionType = DropDownListValue.GetValue(heroKitObject, 7); int fieldOfView = IntegerFieldValue.GetValueA(heroKitObject, 8); // get origin object GameObject originObject = null; Transform transform = null; if (childName == "") { transform = originHKO.transform; } else { transform = originHKO.GetHeroChildComponent <Transform>("Transform", childName); } originObject = transform.gameObject; // convert list objects to array HeroKitObject[] arrayObjects = (listObjects != null) ? listObjects.ToArray() : null; // filter the hero kit objects in the scene List <HeroKitObject> filteredObjects = HeroActionCommonRuntime.GetHeroObjectsFOV(arrayObjects, objectCount, originObject, fieldOfView, rayDirectionType); // assign the hero kit objects to the list HeroActionCommonRuntime.AssignObjectsToList(heroKitObject, getHeroFieldID, filteredObjects, actionType); //----------------------------------------- // debugging stuff //----------------------------------------- if (heroKitObject.debugHeroObject) { string countStr = (filteredObjects != null) ? filteredObjects.Count.ToString() : 0.ToString(); string name = (originObject != null) ? originObject.name : ""; string debugMessage = "Get objects in field of view of this object: " + name + "\n" + "Objects found: " + countStr; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Check to see if an integer meets certain conditions in an if statement // This is used by both If and Else If public int Execute(HeroKitObject hko) { // assign variables heroKitObject = hko; eventID = heroKitObject.heroStateData.eventBlock; int actionID = heroKitObject.heroStateData.action; int currentIndent = heroKitObject.heroState.heroEvent[eventID].actions[actionID].indent; int actionCount = heroKitObject.heroState.heroEvent[eventID].actions.Count; int nextAction = -99; // get the conditional action that follows this action in the if / if else / else / end sequence int nextConditionalAction = HeroActionCommonRuntime.GetNextConditionAction(heroKitObject, eventID, actionID, currentIndent); // evaluate the if statement int comparison = DropDownListValue.GetValue(heroKitObject, 2); int value1 = IntegerFieldValue.GetValueB(heroKitObject, 1); int value2 = IntegerFieldValue.GetValueA(heroKitObject, 3); bool evaluation = HeroActionCommonRuntime.CompareIntegers(comparison, value1, value2); // if there are no actions inside a do while loop, show error message and break out of loop if (actionID == nextConditionalAction) { Debug.LogWarning("Loop has no actions! Breaking out of loop early."); heroKitObject.heroState.heroEvent[eventID].actions[nextConditionalAction + 1].actionFields[0].bools[0] = false; return(-99); } // if the conditional action that follows is an End Do While, we need to set a value. if (nextConditionalAction != -99) { if (heroKitObject.heroState.heroEvent[eventID].actions[nextConditionalAction + 1].actionTemplate.name == "End Do While") { // Was beginning of do while a success? Assign this to the End Do While action. heroKitObject.heroState.heroEvent[eventID].actions[nextConditionalAction + 1].actionFields[0].bools[0] = evaluation; // if sucess was true, what is the id assigned to beginning of do while? heroKitObject.heroState.heroEvent[eventID].actions[nextConditionalAction + 1].actionFields[0].ints[0] = actionID; } } // if evaluation is false, go to end of loop. if (!evaluation) { nextAction = nextConditionalAction; } // show debug message if (heroKitObject.debugHeroObject) { string debugMessage = heroKitObject.heroState.heroEvent[eventID].actions[actionID].name + " = " + evaluation; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } // return the action that we want the game loop to think just executed return(nextAction); }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; String imageGroupPrefabName = "HeroKit Image Canvas"; String imagePrefabName = "HeroKit Image Sprite"; int imageID = IntegerFieldValue.GetValueA(heroKitObject, 0); int speed = IntegerFieldValue.GetValueA(heroKitObject, 1); float scale = IntegerFieldValue.GetValueA(heroKitObject, 2) * 0.01f; wait = BoolValue.GetValue(heroKitObject, 3); HeroKitObject targetObject = null; Vector3 currentScale = new Vector3(); Vector3 targetScale = new Vector3(); // get the game object that contains the images GameObject imageGroup = GetImageGroup(imageGroupPrefabName); if (imageGroup != null) { // get the game object that contains the image GameObject imageObject = GetImage(imagePrefabName, imageID, imageGroup); if (imageObject != null) { // get the hero kit object targetObject = heroKitObject.GetGameObjectComponent <HeroKitObject>("HeroKitObject", false, imageObject); // get the current position currentScale = targetObject.transform.localScale; targetScale = new Vector3(scale, scale, targetObject.transform.localScale.z); } } // pan the camera uiScale = targetObject.GetHeroComponent <UIScale>("UIScale", true); uiScale.targetScale = targetScale; uiScale.speed = speed; uiScale.Initialize(); // set up update for long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = wait; updateIsDone = false; heroKitObject.longActions.Add(this); // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Image ID: " + imageID + "\n" + "Scale: " + scale * 100 + "\n" + "Speed: " + speed; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // Get the scene object string sceneName = UnityObjectFieldValue.GetValueA(heroKitObject, 0).sceneName; Vector3 cameraPosition = new Vector3(); Vector3 cameraRotation = new Vector3(); bool runThis = (sceneName != ""); if (runThis) { bool useDefaultScene = BoolValue.GetValue(heroKitObject, 1); bool removeNonPersistent = BoolValue.GetValue(heroKitObject, 2); bool saveCurrentScene = !BoolValue.GetValue(heroKitObject, 3); // get position bool getPosition = BoolValue.GetValue(heroKitObject, 4); Vector3 defaultPosition = new Vector3(-999999, -999999, -999999); cameraPosition = (getPosition) ? CoordinatesValue.GetValue(heroKitObject, 5, 6, 7, 8, 9, 10, defaultPosition) : defaultPosition; // get rotation bool getRotation = BoolValue.GetValue(heroKitObject, 11); Vector3 defaultRotation = new Vector3(-999999, -999999, -999999); cameraRotation = (getRotation) ? CoordinatesValue.GetValue(heroKitObject, 12, 13, 14, 15, 16, 17, defaultRotation) : defaultRotation; // Save the current scene if (saveCurrentScene) { SaveScene saveScene = new SaveScene(); saveScene.SaveSceneData(heroKitObject, false); // save scene objects saveScene.SaveSceneData(heroKitObject, true); // save persistent objects } // Load the scene. Load any cached data for the scene. HeroKitCommonScene.LoadScene(sceneName, useDefaultScene, removeNonPersistent, cameraPosition, cameraRotation); // set up update for long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); } // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Scene ID: " + sceneName + "\n" + "Camera Position: " + cameraPosition + "\n" + "Camera Rotation: " + cameraRotation; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } // Return value return(-99); }
public string ExecuteOnTarget(HeroKitObject targetObject, string scriptName, MethodInfo method) { //------------------------------------ // get the component that contains the script //------------------------------------ MonoBehaviour component = HeroKitCommonRuntime.GetComponentFromScript(heroKitObject, targetObject, scriptName); //------------------------------------ // get the parameters for the script //------------------------------------ System.Object[] parameters = new System.Object[0]; if (component != null) { parameters = ParameterValue.GetValueA(heroKitObject, 4, method); } else { Debug.LogError(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, "Component does not exist on the game object.")); } //------------------------------------ // invoke the method in the script //------------------------------------ System.Object returnValue = method.Invoke(component, parameters); //------------------------------------ // save the return value in the hero object //------------------------------------ ParameterValue.SetValueB(heroKitObject, 20, 21, returnValue); // debug string string debugInfo = ""; if (heroKitObject.debugHeroObject) { string argumentNames = ""; for (int i = 0; i < parameters.Length; i++) { if (parameters[i] != null) { argumentNames += ", arg[" + i + "]=" + parameters[i].ToString(); } } string returnName = ""; if (returnValue != null) { returnName += ", return=" + returnValue.ToString(); } debugInfo = argumentNames + returnName; } return(debugInfo); }