예제 #1
0
        internal void SetNextScene()
        {
            bool runningIsTransition = RunningScene != null && RunningScene.IsTransition;// is CCTransitionScene;

            // If it is not a transition, call onExit/cleanup
            if (!NextScene.IsTransition)
            {
                if (RunningScene != null)
                {
                    RunningScene.OnExitTransitionDidStart();
                    RunningScene.OnExit();

                    // issue #709. the root node (scene) should receive the cleanup message too
                    // otherwise it might be leaked.
                    if (IsSendCleanupToScene)
                    {
                        RunningScene.Cleanup();
                    }
                }
            }

            if (NextScene.Director != this)
            {
                NextScene.Director = this;
            }

            RunningScene = NextScene;
            NextScene    = null;

            if (!runningIsTransition && RunningScene != null)
            {
                RunningScene.OnEnter();
                RunningScene.OnEnterTransitionDidFinish();
            }
        }
예제 #2
0
        internal void PurgeDirector()
        {
            if (RunningScene != null)
            {
                RunningScene.OnExitTransitionDidStart();
                RunningScene.OnExit();
                RunningScene.Cleanup();
            }

            RunningScene = null;
            NextScene    = null;

            // remove all objects, but don't release it.
            // runWithScene might be executed after 'end'.
            scenesStack.Clear();
        }
예제 #3
0
        // Write out the current state of the director and all of its scenes.
        public void SerializeState()
        {
            // open up isolated storage
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // if our screen manager directory already exists, delete the contents
                if (storage.DirectoryExists(storageDirName))
                {
                    DeleteState(storage);
                }

                // otherwise just create the directory
                else
                {
                    storage.CreateDirectory(storageDirName);
                }

                // create a file we'll use to store the list of screens in the stack

                CCLog.Log("Saving CCDirector state to file: " + Path.Combine(storageDirName, saveFileName));

                try
                {
                    using (IsolatedStorageFileStream stream = storage.OpenFile(Path.Combine(storageDirName, saveFileName), FileMode.OpenOrCreate))
                    {
                        using (StreamWriter writer = new StreamWriter(stream))
                        {
                            // write out the full name of all the types in our stack so we can
                            // recreate them if needed.
                            foreach (CCScene scene in scenesStack)
                            {
                                if (scene.IsSerializable)
                                {
                                    writer.WriteLine(scene.GetType().AssemblyQualifiedName);
                                }
                                else
                                {
                                    CCLog.Log("Scene is not serializable: " + scene.GetType().FullName);
                                }
                            }
                            // Write out our local state
                            if (RunningScene != null && RunningScene.IsSerializable)
                            {
                                writer.WriteLine("m_pRunningScene");
                                writer.WriteLine(RunningScene.GetType().AssemblyQualifiedName);
                            }
                            // Add my own state
                            // [*]name=value
                            //
                        }
                    }

                    // now we create a new file stream for each screen so it can save its state
                    // if it needs to. we name each file "ScreenX.dat" where X is the index of
                    // the screen in the stack, to ensure the files are uniquely named
                    int    screenIndex = 0;
                    string fileName    = null;
                    foreach (CCScene scene in scenesStack)
                    {
                        if (scene.IsSerializable)
                        {
                            fileName = string.Format(Path.Combine(storageDirName, sceneSaveFileName), screenIndex);

                            // open up the stream and let the screen serialize whatever state it wants
                            using (IsolatedStorageFileStream stream = storage.CreateFile(fileName))
                            {
                                scene.Serialize(stream);
                            }

                            screenIndex++;
                        }
                    }
                    // Write the current running scene
                    if (RunningScene != null && RunningScene.IsSerializable)
                    {
                        fileName = string.Format(Path.Combine(storageDirName, sceneSaveFileName), "XX");
                        // open up the stream and let the screen serialize whatever state it wants
                        using (IsolatedStorageFileStream stream = storage.CreateFile(fileName))
                        {
                            RunningScene.Serialize(stream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    CCLog.Log("Failed to serialize the CCDirector state. Erasing the save files.");
                    CCLog.Log(ex.ToString());
                    DeleteState(storage);
                }
            }
        }