Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        // 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);
        }