public override void OnInspectorGUI()
        {
            RememberTransform _target = (RememberTransform)target;

            CustomGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Transform", EditorStyles.boldLabel);
            _target.transformSpace    = (GlobalLocal)CustomGUILayout.EnumPopup("Co-ordinate space:", _target.transformSpace, "", "The co-ordinate space to store position and rotation values in");
            _target.saveParent        = CustomGUILayout.Toggle("Save change in Parent?", _target.saveParent, "", "If True, the GameObject's change in parent should be recorded");
            _target.saveScenePresence = CustomGUILayout.Toggle("Save scene presence?", _target.saveScenePresence, "", "If True, the GameObject's change in scene presence should be recorded");

            if (_target.saveScenePresence)
            {
                if (Application.isPlaying && _target.gameObject.IsPersistent())
                {
                    EditorGUILayout.HelpBox("Objects that survive scene-changes cannot have their scene presence saved.", MessageType.Warning);
                }
                else
                {
                    _target.linkedPrefabID = CustomGUILayout.IntField("Linked prefab ConstantID:", _target.linkedPrefabID, "", "If non-zero, the Constant ID number of the prefab to re-spawn if not present in the scene, but saveScenePresence = true.  If zero, the prefab will be assumed to have the same ID as this.");
                    EditorGUILayout.HelpBox("If the above is non-zero, the Resources prefab with that ID number will be spawned if this is not present in the scene.  This allows for multiple instances of the object to be spawned.", MessageType.Info);

                    _target.retainInPrefab = true;
                    EditorGUILayout.HelpBox("This prefab must be placed in a 'Resources' asset folder", MessageType.Info);
                }
            }
            CustomGUILayout.EndVertical();

            SharedGUI();
        }
Пример #2
0
        private void UnloadTransformData(List <TransformData> _transforms)
        {
            // Delete any objects (if told to)
            RememberTransform[] currentTransforms = FindObjectsOfType(typeof(RememberTransform)) as RememberTransform[];
            foreach (RememberTransform transformOb in currentTransforms)
            {
                if (transformOb.saveScenePresence)
                {
                    // Was object not saved?
                    bool found = false;
                    foreach (TransformData _transform in _transforms)
                    {
                        if (_transform.objectID == transformOb.constantID)
                        {
                            found = true;
                        }
                    }

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

            foreach (TransformData _transform in _transforms)
            {
                RememberTransform saveObject = Serializer.returnComponent <RememberTransform> (_transform.objectID);

                // Restore any deleted objects (if told to)
                if (saveObject == null && _transform.bringBack)
                {
                    Object[] assets = Resources.LoadAll("", typeof(GameObject));
                    foreach (Object asset in assets)
                    {
                        if (asset is GameObject)
                        {
                            GameObject assetObject = (GameObject)asset;
                            if (assetObject.GetComponent <RememberTransform>() && assetObject.GetComponent <RememberTransform>().constantID == _transform.objectID)
                            {
                                GameObject newObject = (GameObject)Instantiate(assetObject.gameObject);
                                newObject.name = assetObject.name;
                                saveObject     = newObject.GetComponent <RememberTransform>();
                            }
                        }
                    }
                    Resources.UnloadUnusedAssets();
                }

                if (saveObject != null)
                {
                    saveObject.LoadTransformData(_transform);
                }
            }
            KickStarter.stateHandler.GatherObjects();
        }
Пример #3
0
        public override void OnInspectorGUI()
        {
            RememberTransform _target = (RememberTransform)target;

            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Transform", EditorStyles.boldLabel);
            _target.saveParent        = EditorGUILayout.Toggle("Save change in Parent?", _target.saveParent);
            _target.saveScenePresence = EditorGUILayout.Toggle("Save scene presence?", _target.saveScenePresence);
            if (_target.saveScenePresence)
            {
                EditorGUILayout.HelpBox("This prefab must be placed in a 'Resources' asset folder", MessageType.Info);
            }
            EditorGUILayout.EndVertical();

            SharedGUI();
        }
Пример #4
0
        public override void OnInspectorGUI()
        {
            RememberTransform _target = (RememberTransform)target;

            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Transform", EditorStyles.boldLabel);
            _target.saveParent        = EditorGUILayout.Toggle("Save change in Parent?", _target.saveParent);
            _target.saveScenePresence = EditorGUILayout.Toggle("Save scene presence?", _target.saveScenePresence);

            if (_target.saveScenePresence)
            {
                _target.linkedPrefabID = EditorGUILayout.IntField("Linked prefab ConstantID:", _target.linkedPrefabID);
                EditorGUILayout.HelpBox("If the above is non-zero, the Resources prefab with that ID number will be spawned if this is not present in the scene.  This allows for multiple instances of the object to be spawned.", MessageType.Info);

                _target.retainInPrefab = true;
                EditorGUILayout.HelpBox("This prefab must be placed in a 'Resources' asset folder", MessageType.Info);
            }
            EditorGUILayout.EndVertical();

            SharedGUI();
        }
        public override void OnInspectorGUI()
        {
            RememberTransform _target = (RememberTransform)target;

            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Transform", EditorStyles.boldLabel);
            _target.saveParent        = CustomGUILayout.Toggle("Save change in Parent?", _target.saveParent, "", "If True, the GameObject's change in parent should be recorded");
            _target.saveScenePresence = CustomGUILayout.Toggle("Save scene presence?", _target.saveScenePresence, "", "If True, the GameObject's change in scene presence should be recorded");

            if (_target.saveScenePresence)
            {
                _target.linkedPrefabID = CustomGUILayout.IntField("Linked prefab ConstantID:", _target.linkedPrefabID, "", "If non-zero, the Constant ID number of the prefab to re-spawn if not present in the scene, but saveScenePresence = true.  If zero, the prefab will be assumed to have the same ID as this.");
                EditorGUILayout.HelpBox("If the above is non-zero, the Resources prefab with that ID number will be spawned if this is not present in the scene.  This allows for multiple instances of the object to be spawned.", MessageType.Info);

                _target.retainInPrefab = true;
                EditorGUILayout.HelpBox("This prefab must be placed in a 'Resources' asset folder", MessageType.Info);
            }
            EditorGUILayout.EndVertical();

            SharedGUI();
        }
        override public float Run()
        {
            if (_gameObject == null)
            {
                return(0f);
            }

            if (invAction == InvAction.Add)
            {
                // Instantiate

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (_gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    RememberTransform rememberTransform = oldOb.GetComponent <RememberTransform>();

                    if (rememberTransform != null && rememberTransform.saveScenePresence && rememberTransform.linkedPrefabID != 0)
                    {
                        // Bypass this check
                    }
                    else
                    {
                        ACDebug.LogWarning(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                        return(0f);
                    }
                }

                Vector3    position = _gameObject.transform.position;
                Quaternion rotation = _gameObject.transform.rotation;

                if (positionRelativeTo != PositionRelativeTo.Nothing)
                {
                    float forward = _gameObject.transform.position.z;
                    float right   = _gameObject.transform.position.x;
                    float up      = _gameObject.transform.position.y;

                    if (positionRelativeTo == PositionRelativeTo.RelativeToActiveCamera)
                    {
                        Transform mainCam = KickStarter.mainCamera.transform;
                        position              = mainCam.position + (mainCam.forward * forward) + (mainCam.right * right) + (mainCam.up * up);
                        rotation.eulerAngles += mainCam.transform.rotation.eulerAngles;
                    }
                    else if (positionRelativeTo == PositionRelativeTo.RelativeToPlayer)
                    {
                        if (KickStarter.player)
                        {
                            Transform playerTranform = KickStarter.player.transform;
                            position              = playerTranform.position + (playerTranform.forward * forward) + (playerTranform.right * right) + (playerTranform.up * up);
                            rotation.eulerAngles += playerTranform.rotation.eulerAngles;
                        }
                    }
                    else if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject)
                    {
                        if (relativeGameObject != null)
                        {
                            Transform relativeTransform = relativeGameObject.transform;
                            position              = relativeTransform.position + (relativeTransform.forward * forward) + (relativeTransform.right * right) + (relativeTransform.up * up);
                            rotation.eulerAngles += relativeTransform.rotation.eulerAngles;
                        }
                    }
                    else if (positionRelativeTo == PositionRelativeTo.EnteredValue)
                    {
                        position += relativeVector;
                    }
                    else if (positionRelativeTo == PositionRelativeTo.VectorVariable)
                    {
                        if (variableLocation == VariableLocation.Global)
                        {
                            position += GlobalVariables.GetVector3Value(vectorVarID);
                        }
                        else if (variableLocation == VariableLocation.Local && !isAssetFile)
                        {
                            position += LocalVariables.GetVector3Value(vectorVarID);
                        }
                    }
                }

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;

                if (newObject.GetComponent <RememberTransform>())
                {
                    newObject.GetComponent <RememberTransform>().OnSpawn();
                }

                KickStarter.stateHandler.IgnoreNavMeshCollisions();
            }
            else if (invAction == InvAction.Remove)
            {
                // Delete
                KickStarter.sceneChanger.ScheduleForDeletion(_gameObject);
            }
            else if (invAction == InvAction.Replace)
            {
                if (replaceGameObject == null)
                {
                    ACDebug.LogWarning("Cannot perform swap because the object to remove was not found in the scene.");
                    return(0f);
                }

                Vector3    position = replaceGameObject.transform.position;
                Quaternion rotation = replaceGameObject.transform.rotation;

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    ACDebug.Log(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                    return(0f);
                }

                KickStarter.sceneChanger.ScheduleForDeletion(replaceGameObject);

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;
                KickStarter.stateHandler.IgnoreNavMeshCollisions();
            }

            return(0f);
        }
Пример #7
0
        private void UnloadTransformData(List <TransformData> _transforms, SubScene subScene)
        {
            // Delete any objects (if told to)
            RememberTransform[] currentTransforms = UnityVersionHandler.GetOwnSceneComponents <RememberTransform> ((subScene != null) ? subScene.gameObject : null);
            foreach (RememberTransform transformOb in currentTransforms)
            {
                if (transformOb.saveScenePresence)
                {
                    // Was object not saved?
                    bool found = false;
                    foreach (TransformData _transform in _transforms)
                    {
                        if (_transform.objectID == transformOb.constantID)
                        {
                            found = !_transform.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("", typeof(GameObject));
            }

            foreach (TransformData _transform in _transforms)
            {
                RememberTransform saveObject = Serializer.returnComponent <RememberTransform> (_transform.objectID, (subScene != null) ? subScene.gameObject : null);

                if (saveObject == null)
                {
                    // Restore any deleted objects (if told to)
                    if (_transform.bringBack && !_transform.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 ((_transform.linkedPrefabID != 0 && prefabID == _transform.linkedPrefabID) ||
                                        (_transform.linkedPrefabID == 0 && prefabID == _transform.objectID))
                                    {
                                        GameObject newObject = (GameObject)Instantiate(prefabGameObject);
                                        newObject.name = prefabGameObject.name;
                                        saveObject     = newObject.GetComponent <RememberTransform>();
                                        foundObject    = true;

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

                                        break;
                                    }
                                }
                            }
                        }

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

                if (saveObject != null)
                {
                    saveObject.LoadTransformData(_transform);
                }
            }

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