コード例 #1
0
ファイル: LevelStorage.cs プロジェクト: cvkumar/out-of-body
        private void UnloadScriptData(List <ScriptData> allScriptData, Scene scene)
        {
            HashSet <Remember> saveObjects = ConstantID.GetComponents <Remember> (scene);

            foreach (ScriptData _scriptData in allScriptData)
            {
                if (_scriptData.data != null && _scriptData.data.Length > 0)
                {
                    foreach (Remember saveObject in saveObjects)
                    {
                        if (saveObject.constantID == _scriptData.objectID)
                        {
                            saveObject.LoadData(_scriptData.data);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: LevelStorage.cs プロジェクト: Keraunic-Tonic/GJ2021
        private List <TransformData> PopulateTransformData(Scene scene)
        {
            List <TransformData>        allTransformData = new List <TransformData>();
            HashSet <RememberTransform> transforms       = ConstantID.GetComponents <RememberTransform> (scene);

            foreach (RememberTransform _transform in transforms)
            {
                if (_transform.constantID != 0)
                {
                    allTransformData.Add(_transform.SaveTransformData());
                }
                else
                {
                    ACDebug.LogWarning("GameObject " + _transform.name + " was not saved because its ConstantID has not been set!", _transform);
                }
            }

            return(allTransformData);
        }
コード例 #3
0
ファイル: LevelStorage.cs プロジェクト: cvkumar/out-of-body
        private List <ScriptData> PopulateScriptData(Scene scene)
        {
            List <ScriptData>  allScriptData = new List <ScriptData>();
            HashSet <Remember> scripts       = ConstantID.GetComponents <Remember> (scene);

            foreach (Remember _script in scripts)
            {
                if (_script.constantID != 0)
                {
                    allScriptData.Add(new ScriptData(_script.constantID, _script.SaveData()));
                }
                else
                {
                    ACDebug.LogWarning("GameObject " + _script.name + " was not saved because its ConstantID has not been set!", _script);
                }
            }

            return(allScriptData);
        }
コード例 #4
0
ファイル: LevelStorage.cs プロジェクト: Keraunic-Tonic/GJ2021
        private void UnloadTransformData(List <TransformData> allTransformData, Scene scene)
        {
            // Delete any objects (if told to)
            HashSet <RememberTransform> currentTransforms = ConstantID.GetComponents <RememberTransform> (scene);

            foreach (RememberTransform transformOb in currentTransforms)
            {
                if (transformOb.saveScenePresence)
                {
                    // Was object not saved?
                    bool found = false;
                    foreach (TransformData transformData in allTransformData)
                    {
                        if (transformData.objectID == transformOb.constantID)
                        {
                            found = !transformData.savePrevented;
                        }
                    }

                    if (!found)
                    {
                        // Can't find: delete
                        KickStarter.sceneChanger.ScheduleForDeletion(transformOb.gameObject);
                    }
                }
            }

            Object[] prefabAssets = Resources.LoadAll("SaveableData/Prefabs", typeof(GameObject));
            if (prefabAssets == null || prefabAssets.Length == 0)
            {
                prefabAssets = Resources.LoadAll(string.Empty, typeof(GameObject));
            }

            foreach (TransformData transformData in allTransformData)
            {
                RememberTransform saveObject = ConstantID.GetComponent <RememberTransform> (transformData.objectID, scene);

                if (saveObject == null)
                {
                    // Restore any deleted objects (if told to)
                    if (transformData.bringBack && !transformData.savePrevented)
                    {
                        bool foundObject = false;
                        foreach (Object prefabAsset in prefabAssets)
                        {
                            if (prefabAsset is GameObject)
                            {
                                GameObject prefabGameObject = (GameObject)prefabAsset;
                                if (prefabGameObject.GetComponent <RememberTransform>())
                                {
                                    int prefabID = prefabGameObject.GetComponent <ConstantID>().constantID;
                                    if ((transformData.linkedPrefabID != 0 && prefabID == transformData.linkedPrefabID) ||
                                        (transformData.linkedPrefabID == 0 && prefabID == transformData.objectID))
                                    {
                                        GameObject newObject = (GameObject)Instantiate(prefabGameObject);
                                        newObject.name = prefabGameObject.name;
                                        saveObject     = newObject.GetComponent <RememberTransform>();
                                        foundObject    = true;

                                        if (transformData.linkedPrefabID != 0 && prefabID == transformData.linkedPrefabID)
                                        {
                                            // Spawned object has wrong ID, re-assign it
                                            ConstantID[] idScripts = saveObject.GetComponents <ConstantID>();
                                            foreach (ConstantID idScript in idScripts)
                                            {
                                                idScript.constantID = transformData.objectID;
                                            }
                                        }

                                        break;
                                    }
                                }
                            }
                        }

                        if (!foundObject)
                        {
                            ACDebug.LogWarning("Could not find Resources prefab with ID " + transformData.objectID + " - is it placed in a Resources folder?");
                        }
                    }
                }

                if (saveObject)
                {
                    saveObject.LoadTransformData(transformData);
                }
            }

            Resources.UnloadUnusedAssets();
            KickStarter.stateHandler.IgnoreNavMeshCollisions();
        }