// 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; // 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 + "\n" + "Hero Kit Object: " + targetObject; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// 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); }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 2); AudioClip audioClip = (unityObject.value != null) ? (AudioClip)unityObject.value : null; bool changeSettings = BoolValue.GetValue(heroKitObject, 3); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], audioClip, changeSettings); } // show debug message if (heroKitObject.debugHeroObject) { string debugMessage = "BGM: " + audioClip; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
private void SetPortraitInfo(int portraitID, int changePortrait, int portraitSprite, int flipImage, int changeScale, int newScale, int changeXPos, int newXPos, int changeYPos, int newYPos, int changeZPos, int newZPos) { // get values for left portrait uiDialog.changePortrait[portraitID] = BoolValue.GetValue(heroKitObject, changePortrait); if (uiDialog.changePortrait[portraitID]) { UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, portraitSprite); uiDialog.portraitSprite[portraitID] = (unityObject.value != null) ? (Sprite)unityObject.value : null; uiDialog.flipImage[portraitID] = BoolValue.GetValue(heroKitObject, flipImage); uiDialog.changeScale[portraitID] = BoolValue.GetValue(heroKitObject, changeScale); if (uiDialog.changeScale[portraitID]) { uiDialog.newScale[portraitID] = FloatFieldValue.GetValueA(heroKitObject, newScale) * 0.01f; } uiDialog.changeXPos[portraitID] = BoolValue.GetValue(heroKitObject, changeXPos); if (uiDialog.changeXPos[portraitID]) { uiDialog.newXPos[portraitID] = FloatFieldValue.GetValueA(heroKitObject, newXPos); } uiDialog.changeYPos[portraitID] = BoolValue.GetValue(heroKitObject, changeYPos); if (uiDialog.changeYPos[portraitID]) { uiDialog.newYPos[portraitID] = FloatFieldValue.GetValueA(heroKitObject, newYPos); } uiDialog.changeZPos[portraitID] = BoolValue.GetValue(heroKitObject, changeZPos); if (uiDialog.changeZPos[portraitID]) { uiDialog.newZPos[portraitID] = DropDownListValue.GetValue(heroKitObject, newZPos); } } }
// 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); UnityObjectField objectData = UnityObjectFieldValue.GetValueA(heroKitObject, 2); string scriptName = (objectData.value != null) ? objectData.value.name : ""; bool runThis = (targetObject != null && scriptName != ""); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], 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) { heroKitObject = hko; // get the hero object where the parameters are stored HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); UnityObjectField objectData = UnityObjectFieldValue.GetValueA(heroKitObject, 2); string scriptName = (objectData.value != null) ? objectData.value.name : ""; MethodInfo method = MethodValue.GetValue(heroKitObject, 3); string[] debugInfo = new string[targetObject.Length]; bool runThis = (targetObject != null && scriptName != "" && method != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { debugInfo[i] = ExecuteOnTarget(targetObject[i], scriptName, method); } //------------------------------------ // debug message //------------------------------------ if (heroKitObject.debugHeroObject) { string strDebugInfo = (debugInfo != null && debugInfo.Length > 0) ? debugInfo[0] : ""; string debugMessage = "MonoScript: " + scriptName + "\n" + "Method: " + method + "\n" + "Parameters: " + strDebugInfo; 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); }
/// <summary> /// A list field for Unity Objects. /// </summary> /// <param name="unityObjectField">The Unity Object field.</param> /// <param name="objectType">The type of unity object that can used in this field.</param> /// <param name="fieldWidth">The width of the field.</param> /// <returns>The unity object in the list field.</returns> public static Object UnityObjectListField(UnityObjectField unityObjectField, int objectType, int fieldWidth) { int height = 20; Object value = unityObjectField.value; BeginHorizontal(); Object result = EditorGUILayout.ObjectField(value, typeof(Object), false, GUILayout.Width(fieldWidth), GUILayout.Height(height)); EndHorizontal(); return(result); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; SceneObjectValueData objectData = SceneObjectValue.GetValue(heroKitObject, 0, 1, false); UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 2); Sprite sprite = (unityObject.value != null) ? (Sprite)unityObject.value : null; Image image = null; // object is hero object if (objectData.heroKitObject != null) { image = objectData.heroKitObject[0].GetHeroComponent <Image>("Image"); } // object is game object else if (objectData.gameObject != null) { image = heroKitObject.GetGameObjectComponent <Image>("Image", false, objectData.gameObject[0]); } if (image != null) { image.sprite = sprite; } //------------------------------------ // debug message //------------------------------------ if (heroKitObject.debugHeroObject) { string strImage = (image != null) ? image.gameObject.name : ""; string strSprite = (image != null && image.sprite != null) ? image.sprite.name : ""; string debugMessage = "Game Object: " + strImage + "\n" + "Image: " + strSprite; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; UnityObjectField storeObjectHere = UnityObjectFieldValue.GetValueB(heroKitObject, 0); UnityObjectField getThisObject = UnityObjectFieldValue.GetValueA(heroKitObject, 1); bool runThis = (storeObjectHere != null && getThisObject != null); if (runThis) { UnityObjectFieldValue.SetValueB(heroKitObject, 0, getThisObject); } // show debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Unity Object: " + getThisObject; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; // write messages? bool print = BoolValue.GetValue(heroKitObject, 0); if (print) { HeroKitCommonRuntime.writeMessage = BoolValue.GetValue(heroKitObject, 1); if (HeroKitCommonRuntime.writeMessage) { float messageSpeed = SliderValue.GetValue(heroKitObject, 2); if (messageSpeed < 0) { messageSpeed = 0; } if (messageSpeed > 100) { messageSpeed = 100; } // 0=100, 100=0. Then change to 0 to 1. float waitTime = (100 - messageSpeed) * 0.01f; HeroKitCommonRuntime.messageWaitTime = waitTime; } } // change message alignment? bool changeAlignment = BoolValue.GetValue(heroKitObject, 3); if (changeAlignment) { int alignID = DropDownListValue.GetValue(heroKitObject, 4); switch (alignID) { case 1: HeroKitCommonRuntime.messageAlignment = TextAnchor.UpperLeft; break; case 2: HeroKitCommonRuntime.messageAlignment = TextAnchor.UpperCenter; break; case 3: HeroKitCommonRuntime.messageAlignment = TextAnchor.UpperRight; break; case 4: HeroKitCommonRuntime.messageAlignment = TextAnchor.MiddleLeft; break; case 5: HeroKitCommonRuntime.messageAlignment = TextAnchor.MiddleCenter; break; case 6: HeroKitCommonRuntime.messageAlignment = TextAnchor.MiddleRight; break; case 7: HeroKitCommonRuntime.messageAlignment = TextAnchor.LowerLeft; break; case 8: HeroKitCommonRuntime.messageAlignment = TextAnchor.LowerCenter; break; case 9: HeroKitCommonRuntime.messageAlignment = TextAnchor.LowerRight; break; } } // change background alpha bool changeBackgroundAlpha = BoolValue.GetValue(heroKitObject, 5); if (changeBackgroundAlpha) { // get new alpha float alpha = SliderValue.GetValue(heroKitObject, 6); // keep alpha between 0 - 100 if (alpha > 100) { alpha = 100; } else if (alpha < 0) { alpha = 0; } // switch to 0 - 1 scale alpha *= .01f; // change alpha HeroKitCommonRuntime.messageBackgroundAlpha = alpha; HeroKitCommonRuntime.changeMessageBackgroundTransparency = true; } // change background alpha bool changeButtonAlpha = BoolValue.GetValue(heroKitObject, 19); if (changeButtonAlpha) { // get new alpha float alpha = SliderValue.GetValue(heroKitObject, 20); // keep alpha between 0 - 100 if (alpha > 100) { alpha = 100; } else if (alpha < 0) { alpha = 0; } // switch to 0 - 1 scale alpha *= .01f; // change alpha HeroKitCommonRuntime.messageButtonAlpha = alpha; HeroKitCommonRuntime.changeMessageButtonTransparency = true; } // change background image bool changeBackgroundImage = BoolValue.GetValue(heroKitObject, 7); if (changeBackgroundImage) { UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 8); HeroKitCommonRuntime.messageBackgroundImage = (unityObject.value != null) ? (Sprite)unityObject.value : null; HeroKitCommonRuntime.changeMessageBackground = true; } // change button image bool changeButtonImage = BoolValue.GetValue(heroKitObject, 9); if (changeButtonImage) { UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 10); HeroKitCommonRuntime.messageButtonImage = (unityObject.value != null) ? (Sprite)unityObject.value : null; HeroKitCommonRuntime.changeMessageButton = true; } // change button layout bool changeButtonLayout = BoolValue.GetValue(heroKitObject, 11); if (changeButtonLayout) { HeroKitCommonRuntime.messageButtonLayout = DropDownListValue.GetValue(heroKitObject, 12); HeroKitCommonRuntime.changeMessageButtonLayout = true; } // change text color bool changeTextColor = BoolValue.GetValue(heroKitObject, 13); if (changeTextColor) { HeroKitCommonRuntime.messageTextColor = ColorValue.GetValue(heroKitObject, 14); HeroKitCommonRuntime.changeMessageTextColor = true; } // change heading color bool changeHeadingColor = BoolValue.GetValue(heroKitObject, 15); if (changeHeadingColor) { HeroKitCommonRuntime.messageHeadingColor = ColorValue.GetValue(heroKitObject, 16); HeroKitCommonRuntime.changeMessageHeadingColor = true; } // change button text color bool changeButtonTextColor = BoolValue.GetValue(heroKitObject, 17); if (changeButtonTextColor) { HeroKitCommonRuntime.messageButtonTextColor = ColorValue.GetValue(heroKitObject, 18); HeroKitCommonRuntime.changeMessageButtonTextColor = true; } // change active button color bool changeButtonActiveColor = BoolValue.GetValue(heroKitObject, 21); if (changeButtonActiveColor) { HeroKitCommonRuntime.messageButtonActiveColor = ColorValue.GetValue(heroKitObject, 22); HeroKitCommonRuntime.changeMessageButtonActiveColor = true; } if (heroKitObject.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, (""))); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; // get common values HeroKitObject targetObject = HeroKitCommonRuntime.GetPrefabFromAssets(HeroKitCommonRuntime.settingsInfo.dialogBox, true); bool runThis = (targetObject != null); if (runThis) { targetObject.gameObject.SetActive(true); // get the dialog script uiDialog = targetObject.GetHeroComponent <UIDialog>("UIDialog", true); uiDialog.textAction = UIDialog.TextAction.showDialog; uiDialog.heroKitObject = heroKitObject; uiDialog.dontHideCanvas = BoolValue.GetValue(heroKitObject, 30); uiDialog.eventID = heroKitObject.heroStateData.eventBlock; uiDialog.actionID = heroKitObject.heroStateData.action; // get values for title uiDialog.setTitle = BoolValue.GetValue(heroKitObject, 0); if (uiDialog.setTitle) { uiDialog.title = StringFieldValue.GetValueA(heroKitObject, 1, true); uiDialog.changeTitleAlignment = BoolValue.GetValue(heroKitObject, 26); if (uiDialog.changeTitleAlignment) { uiDialog.titleAlignmentType = DropDownListValue.GetValue(heroKitObject, 27); } } // get values for message uiDialog.message = StringFieldValue.GetValueA(heroKitObject, 2, true); // get values for audio UnityObjectField unityObjectAudio = UnityObjectFieldValue.GetValueA(heroKitObject, 28, false); uiDialog.audioClip = (unityObjectAudio.value != null) ? (AudioClip)unityObjectAudio.value : null; // get values for message choices uiDialog.addChoices = BoolValue.GetValue(heroKitObject, 21); if (uiDialog.addChoices) { uiDialog.selectedChoiceID = 29; uiDialog.numberOfChoices = DropDownListValue.GetValue(heroKitObject, 22); uiDialog.choiceText = new UnityEngine.UI.Text[3]; uiDialog.choice = new string[uiDialog.numberOfChoices]; if (uiDialog.numberOfChoices >= 1) { uiDialog.choice[0] = StringFieldValue.GetValueA(heroKitObject, 23, true); } if (uiDialog.numberOfChoices >= 2) { uiDialog.choice[1] = StringFieldValue.GetValueA(heroKitObject, 24, true); } if (uiDialog.numberOfChoices >= 3) { uiDialog.choice[2] = StringFieldValue.GetValueA(heroKitObject, 25, true); } } // get values for left portrait SetPortraitInfo(0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 31, 32); // get values for right portrait SetPortraitInfo(1, 12, 13, 14, 15, 16, 17, 18, 19, 20, 33, 34); // enable the dialog script uiDialog.enabled = true; uiDialog.Initialize(); eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); } // show debug message if (heroKitObject.debugHeroObject) { string dialogText = (uiDialog != null) ? uiDialog.message : ""; string debugMessage = "Message: " + dialogText; 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 = AddImageGroup(imageGroupPrefabName); if (imageGroup != null) { // get the game object that contains the image GameObject targetObject = AddImage(imagePrefabName, imageID, imageGroup); if (targetObject != null) { // get the image component on the game object Image image = heroKitObject.GetGameObjectComponent <Image>("Image", false, targetObject); if (image != null) { bool changeSprite = BoolValue.GetValue(heroKitObject, 1); if (changeSprite) { UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 2); Sprite sprite = (unityObject.value != null) ? (Sprite)unityObject.value : null; image.sprite = sprite; RectTransform rectTransform = heroKitObject.GetGameObjectComponent <RectTransform>("RectTransform", false, image.gameObject); rectTransform.sizeDelta = new Vector2(sprite.rect.width, sprite.rect.height); rectTransform.localPosition = new Vector3(); } bool flipSprite = BoolValue.GetValue(heroKitObject, 3); if (flipSprite) { Vector3 eulerAngles = new Vector3(); eulerAngles = image.transform.eulerAngles; eulerAngles.y += 180f; image.transform.eulerAngles = eulerAngles; } bool changeScale = BoolValue.GetValue(heroKitObject, 4); if (changeScale) { float newScale = FloatFieldValue.GetValueA(heroKitObject, 5); image.transform.localScale = new Vector3(newScale, newScale, newScale) * 0.01f; } bool changeXPos = BoolValue.GetValue(heroKitObject, 6); if (changeXPos) { float xPos = FloatFieldValue.GetValueA(heroKitObject, 7); image.transform.localPosition = new Vector3(xPos, image.transform.localPosition.y, image.transform.localPosition.z); } bool changeYPos = BoolValue.GetValue(heroKitObject, 8); if (changeYPos) { float yPos = FloatFieldValue.GetValueA(heroKitObject, 9); image.transform.localPosition = new Vector3(image.transform.localPosition.x, yPos, image.transform.localPosition.z); } } // change the color (alpha = transparent if image is null) Color color = image.color; color.a = (image.sprite == null) ? color.a = 0 : color.a = 1; image.color = color; // enable the game object targetObject.SetActive(true); } } // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Image ID: " + imageID; 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> /// Set the value for a unity object in a unity 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 unity object field.</param> public static void SetValueB(HeroKitObject heroKitObject, int actionFieldID, UnityObjectField newValue) { // 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]; // don't get item. Item type was never specified if (itemType == 0) { Debug.LogError("Unity 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 object int slotID = action.actionFields[actionFieldID].ints[2] - 1; // Get the object from the object list if (itemType == 1) { for (int i = 0; i < targetHKO.Length; i++) { if (targetHKO[i].heroList.unityObjects.items.Count <= slotID || slotID < 0) { Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Variables", "Hero Object", slotID, 0, heroKitObject)); return; } // Set the object UnityObjectField itemField = targetHKO[i].heroList.unityObjects.items[slotID]; targetHKO[i].heroList.unityObjects.items[slotID] = itemField.Clone(newValue); } } // Get the object from the property list if (itemType == 2) { for (int i = 0; i < targetHKO.Length; i++) { int propertyID = action.actionFields[actionFieldID].ints[6] - 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", "Unity Object", slotID, 0, heroKitObject)); return; } // Set the object UnityObjectField itemField = targetHKO[i].heroProperties[propertyID].itemProperties.unityObjects.items[slotID]; targetHKO[i].heroProperties[propertyID].itemProperties.unityObjects.items[slotID] = itemField.Clone(newValue); } } } // set item in global list if (itemType == 3) { // Get the slot in the list that contains the item 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; } UnityObjectField itemField = HeroKitDatabase.GetGlobals().unityObjects.items[slotID]; HeroKitDatabase.GetGlobals().unityObjects.items[slotID] = itemField.Clone(newValue); } }
/// <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 unity object 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 unity object field.</returns> public static UnityObjectField GetValueC(HeroKitObject heroKitObject, int actionFieldID, HeroObject heroObject) { // exit early if object does not exist if (heroObject == null) { return(null); } // Get the action HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action]; // Get the item type int itemType = action.actionFields[actionFieldID].ints[3]; UnityObjectField itemValue = new UnityObjectField(); itemValue.sceneID = -1; // Get the slot in the list that contains the item int slotID = action.actionFields[actionFieldID].ints[2] - 1; // Get the lists UnityObjectList targetList = null; string itemTypeName = ""; string heroName = ""; if (itemType == 0) { Debug.LogError("Unity Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject)); return(null); } if (itemType == 1) { heroName = heroObject.name; itemTypeName = "Variables"; targetList = heroObject.lists.unityObjects; } else if (itemType == 2) { heroName = heroObject.name; itemTypeName = "Properties"; int propertyID = action.actionFields[actionFieldID].ints[6] - 1; if (propertyID < 0) { Debug.LogError("Property slot does not exist!"); } targetList = heroObject.propertiesList.properties[propertyID].itemProperties.unityObjects; } else if (itemType == 3) { heroName = "n/a"; itemTypeName = "Globals"; targetList = HeroKitDatabase.GetGlobals().unityObjects; } // 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, "Hero Object", slotID, 0, heroKitObject)); return(null); } // get the item in the list slot itemValue = itemValue.Clone(targetList.items[slotID]); // Return the item return(itemValue); }