private bool LoadSaveGameData(GameSaveData saveData) { if (saveData == null) { return(false); } // create scene json files and save them in the temp directory for (int i = 0; i < saveData.scenes.Length; i++) { string path = Application.temporaryCachePath + "/HeroScenes/" + saveData.scenes[i].sceneName + ".json"; string jsonSceneText = JsonUtility.ToJson(saveData.scenes[i]); File.WriteAllText(path, jsonSceneText); } // load the global variables HeroList globals = HeroKitDatabase.globals; HeroKitCommonScene.AddVariables(globals.ints.items, saveData.globalInts); HeroKitCommonScene.AddVariables(globals.floats.items, saveData.globalFloats); HeroKitCommonScene.AddVariables(globals.bools.items, saveData.globalBools); HeroKitCommonScene.AddVariables(globals.strings.items, saveData.globalStrings); HeroKitDatabase.globals = globals; // load the scene that was last opened Vector3 defaultCoords = new Vector3(-999999, -999999, -999999); HeroKitCommonScene.LoadScene(saveData.lastScene, false, false, defaultCoords, defaultCoords); return(true); }
// 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); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; // Get the hero kit object to move HeroKitObject targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1, false)[0]; // Get the scene object string sceneName = UnityObjectFieldValue.GetValueA(heroKitObject, 2).sceneName; // get new position for target object Vector3 defaultPosition = new Vector3(-999999, -999999, -999999); Vector3 targetPosition = CoordinatesValue.GetValue(heroKitObject, 3, 4, 5, 6, 7, 8, defaultPosition); // get new rotation for target object Vector3 targetDirection = defaultPosition; int directionType = DropDownListValue.GetValue(heroKitObject, 9); switch (directionType) { case 1: // retain break; case 2: // left targetDirection.y = -90f; break; case 3: // right targetDirection.y = 90f; break; case 4: // up targetDirection.y = 0f; break; case 5: // down targetDirection.y = 180f; break; case 6: // custom targetDirection = CoordinatesValue.GetValue(heroKitObject, 10, 11, 12, 13, 14, 15, defaultPosition); break; } // move camera to object's position? bool moveCameraPos = BoolValue.GetValue(heroKitObject, 16); // move camera to object's rotation? bool moveCameraRotation = BoolValue.GetValue(heroKitObject, 17); // scene transition settings bool useDefaultScene = BoolValue.GetValue(heroKitObject, 18); bool removeNonPersistent = BoolValue.GetValue(heroKitObject, 19); bool saveCurrentScene = !BoolValue.GetValue(heroKitObject, 20); bool runThis = (targetObject != null && sceneName != ""); // NEXT STEP: // save current scene, // check if object is persistant. if it is, load next scene, change direction and rotation of object. // if it isn't see what we can do to physically move it from one scene to another. Keep in mind that object could exist in two scenes after this (if it is saved in scene data) // maybe disable it in current scene and create a new verison in the next scene. if (runThis) { // 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.LoadSceneWithObject(sceneName, useDefaultScene, removeNonPersistent, targetPosition, targetDirection, targetObject, moveCameraPos, moveCameraRotation); } if (targetObject == null) { Debug.LogError("There is no object to move to the next scene! Terminating action early."); } // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Scene: " + sceneName + "\n" + "Move this object: " + targetObject + "\n" + "To this position: " + targetPosition; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } // Return value return(-99); }