Пример #1
0
    public static void ToggleHideAutoSaveComponents()
    {
        bool hide = !AutoSaveComponentsAreHidden();

        EditorPrefs.SetBool("HideAutoSaveComponents", hide);
        HideFlags goHideFlags        = hide ? HideFlags.HideInHierarchy : HideFlags.None;
        HideFlags componentHideFlags = hide ? HideFlags.HideInInspector : HideFlags.None;

        // Hide scene components.
        if (mgr != null)
        {
            mgr.gameObject.hideFlags = goHideFlags;
            EditorSceneManager.MarkAllScenesDirty();

            foreach (ES2AutoSave autoSave in mgr.sceneObjects)
            {
                autoSave.hideFlags = componentHideFlags;
            }
        }

        // Hide Prefab components.
        List <GameObject> prefabs = GetPrefabs();

        for (int i = 0; i < prefabs.Count; i++)
        {
            ES2AutoSave autoSave = prefabs[i].GetComponent <ES2AutoSave>();
            if (autoSave != null)
            {
                autoSave.hideFlags = componentHideFlags;
            }
        }
    }
Пример #2
0
    /*
     *  Refreshes the variables and Components for all Auto Saves attached to prefabs.
     *  Should be called after scripts are recompiled.
     */
    public static void RefreshPrefabAutoSaves()
    {
        ES2AutoSaveGlobalManager globalMgr = ES2EditorAutoSaveUtility.globalMgr;

        if (globalMgr == null)
        {
            return;
        }
        // Clear all prefabs and start from fresh.
        globalMgr.prefabArray = new ES2AutoSave[0];
        globalMgr.ids         = new HashSet <string>();

        List <GameObject> prefabs = GetPrefabs();

        for (int i = 0; i < prefabs.Count; i++)
        {
            if (prefabs[i] == null)
            {
                continue;
            }
            ES2AutoSave autoSave = prefabs[i].GetComponent <ES2AutoSave>();
            if (autoSave != null)
            {
                ArrayUtility.Add(ref globalMgr.prefabArray, autoSave);
            }
        }


        // Recurse over top-level scene objects, and recursively update them and their children.
        foreach (ES2AutoSave autoSave in globalMgr.prefabArray)
        {
            UpdatePrefabAutoSaveRecursive(autoSave);
        }
    }
Пример #3
0
    public static ES2AutoSave AddAutoSave(GameObject go, Color color, bool hide, bool generateID, string id)
    {
        ES2AutoSave autoSave = go.AddComponent <ES2AutoSave>();

        autoSave.color     = color;
        autoSave.transform = go.transform;

        if (hide)
        {
            autoSave.hideFlags = HideFlags.HideInInspector;
        }

        // Add instance variables of GameObject.
        // parent.
        autoSave.parentVariable = new ES2AutoSaveVariableInfo("parent", typeof(string), true, autoSave, null);
        // activeSelf.
        autoSave.activeSelfVariable = new ES2AutoSaveVariableInfo("activeSelf", typeof(bool), true, autoSave, null);
        // name.
        autoSave.nameVariable = new ES2AutoSaveVariableInfo("name", typeof(string), true, autoSave, null);
        // tag.
        autoSave.tagVariable = new ES2AutoSaveVariableInfo("tag", typeof(string), true, autoSave, null);
        // layer.
        autoSave.layerVariable = new ES2AutoSaveVariableInfo("layer", typeof(int), true, autoSave, null);

        // Generate a GUID (without dashes) if necessary.
        if (generateID)
        {
            autoSave.id = GenerateID();
        }
        if (id != "")
        {
            autoSave.id = id;
        }
        return(autoSave);
    }
Пример #4
0
    private static void UpdatePrefabAutoSaveRecursive(ES2AutoSave autoSave)
    {
        // If this prefab has been created from a scene object, or the prefab has been duplicated,
        // generate a new ID for it.
        if (String.IsNullOrEmpty(autoSave.prefabID) || globalMgr.ids.Contains(autoSave.prefabID))
        {
            autoSave.prefabID = ES2AutoSave.GenerateID();
        }

        // If this prefab has been created from a scene object, we'll also need to remove it's id.
        if (!String.IsNullOrEmpty(autoSave.id))
        {
            autoSave.id = "";
        }

        globalMgr.ids.Add(autoSave.prefabID);

        UpdateAutoSave(autoSave);

        foreach (Transform t in autoSave.transform)
        {
            ES2AutoSave childAutoSave = t.GetComponent <ES2AutoSave>();
            if (childAutoSave != null)
            {
                UpdatePrefabAutoSaveRecursive(childAutoSave);
            }
        }
    }
Пример #5
0
    protected void WriteAllComponents(ES2AutoSave autoSave, ES2Writer writer)
    {
        Component[] components = autoSave.GetComponents <Component>();

        foreach (Component c in components)
        {
            if (c == null)
            {
                continue;
            }

            ES2Type type;
            ES2AutoSaveComponentInfo info = autoSave.GetComponentInfo(c);

            type = ES2TypeManager.GetES2Type(c.GetType());
            if (type == null)
            {
                continue;
            }

            if (info == null)
            {
                info = new ES2AutoSaveComponentInfo(c, autoSave);
            }
            WriteVariableRecursive(autoSave, info, writer, c);
        }
    }
Пример #6
0
    private void ReadComponent(ES2AutoSave autoSave, ES2Reader reader)
    {
        string componentID = reader.reader.ReadString();
        int    endPosition = (int)reader.stream.Position;
        int    length      = reader.reader.ReadInt32();

        endPosition += length;

        // Read collection type byte which is not relevant to Components.
        reader.reader.ReadByte();

        int     typeHash = reader.reader.ReadInt32();
        ES2Type type     = ES2TypeManager.GetES2Type(typeHash);

        // If there's no ES2Type for this type of Component, skip it.
        if (type == null)
        {
            reader.stream.Position = endPosition;
            return;
        }

        // Get or create the Component.
        Component c;
        ES2AutoSaveComponentInfo componentInfo = autoSave.GetComponentInfo(componentID);

        if (componentInfo == null || componentInfo.component == null)
        {
            // If no Component info, look for the Component, or otherwise, add one.
            if (!(c = autoSave.gameObject.GetComponent(type.type)))
            {
                c = autoSave.gameObject.AddComponent(type.type);
            }
        }
        else
        {
            c = componentInfo.component;
        }

        string dataType = reader.reader.ReadString();

        if (dataType == "data")
        {
            reader.Read <System.Object>(type, c);
            return;
        }
        else if (dataType == "vars")        // Else we're reading a series of variables denoted by "vars".
        {
            while (reader.stream.Position != endPosition)
            {
                ReadVariableRecursive(autoSave, componentInfo, reader, c);
            }
        }
        else
        {
            reader.stream.Position = endPosition;
            return;
        }
    }
Пример #7
0
 public ES2AutoSaveComponentInfo(Component c, ES2AutoSave autoSave)
 {
     this.component   = c;
     this.type        = c.GetType();
     this.name        = this.type.Name;
     this.id          = ES2AutoSave.GenerateID();
     this.autoSave    = autoSave;
     this.isComponent = true;
 }
Пример #8
0
 /*
  *  Constructor for displaying instance variables of GameObject.
  */
 public ES2AutoSaveComponentInfo(string name, Type type, ES2AutoSave autoSave)
 {
     this.component   = autoSave;
     this.type        = type;
     this.name        = name;
     this.id          = ES2AutoSave.GenerateID();
     this.autoSave    = autoSave;
     this.isComponent = false;
     this.isProperty  = true;
 }
Пример #9
0
 private static void GetChildrenForAutoSave(ES2AutoSave autoSave)
 {
     foreach (Transform t in autoSave.transform)
     {
         ES2AutoSave child = ES2AutoSave.GetAutoSave(t.gameObject);
         if (child == null)
         {
             child = ES2AutoSave.AddAutoSave(t.gameObject, RandomColor(), AutoSaveComponentsAreHidden(), true, "");
         }
         GetChildrenForAutoSave(child);
     }
 }
Пример #10
0
 public ES2AutoSaveVariableInfo(string name, Type type, bool isProperty, ES2AutoSave autoSave, ES2AutoSaveVariableInfo previous)
 {
     this.name       = name;
     this.id         = ES2AutoSave.GenerateID();
     this.type       = type;
     this.autoSave   = autoSave;
     this.isProperty = isProperty;
     if (previous != null)
     {
         this.previousID = previous.id;
     }
 }
Пример #11
0
    public static void RemoveAutoSaveFromPrefabRecursive(GameObject go)
    {
        ES2AutoSave autoSave = go.GetComponent <ES2AutoSave>();

        if (autoSave != null)
        {
            Undo.DestroyObjectImmediate(autoSave);
        }
        foreach (Transform childTransform in go.transform)
        {
            RemoveAutoSaveFromPrefabRecursive(childTransform.gameObject);
        }
    }
Пример #12
0
    /*
     *  Refreshes the variables and Components for all Auto Saves in this scene.
     *  Should be called after a change is made to the scene, or scripts are recompiled.
     */
    public static void RefreshSceneAutoSaves()
    {
        // Only refresh if Easy Save is enabled for this scene.
        if (mgr == null || EditorApplication.isPlayingOrWillChangePlaymode)
        {
            return;
        }

        mgr.sceneObjects = new ES2AutoSave[0];
        mgr.ids          = new HashSet <string>();

        Transform[] transforms = Resources.FindObjectsOfTypeAll <Transform>();

        // Recurse over top-level scene objects and display their children hierarchically.
        foreach (Transform t in transforms)
        {
            if (t.parent == null && t.hideFlags == HideFlags.None)
            {
                ES2AutoSave autoSave = ES2AutoSave.GetAutoSave(t.gameObject);
                if (autoSave == null)
                {
                    autoSave = ES2AutoSave.AddAutoSave(t.gameObject, RandomColor(), AutoSaveComponentsAreHidden(), true, "");

                    if (AutoSaveComponentsAreHidden())
                    {
                        autoSave.hideFlags = HideFlags.HideInInspector;
                    }
                }

                // If a prefab has been added to the scene, give it an ID and treat it as a scene object.
                if (string.IsNullOrEmpty(autoSave.id))
                {
                    autoSave.id       = ES2AutoSave.GenerateID();
                    autoSave.prefabID = "";
                }

                // Check for duplicate IDs.
                if (mgr.ids.Contains(autoSave.id))
                {
                    autoSave.id = ES2AutoSave.GenerateID();
                }
                mgr.ids.Add(autoSave.id);

                UpdateAutoSave(autoSave);
                AddAutoSaveToManager(autoSave);

                GetOrAddChildrenForAutoSave(autoSave);
            }
        }
    }
Пример #13
0
    public override void OnInspectorGUI()
    {
        ES2AutoSave autoSave = (ES2AutoSave)target;

        EditorGUI.indentLevel++;
        showAdvancedSettings = EditorGUILayout.Foldout(showAdvancedSettings, "Show Advanced Settings");
        if (showAdvancedSettings)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.LabelField("Warning! Please do not modify anything below.", EditorStyles.boldLabel);
            DrawDefaultInspector();
            EditorGUI.indentLevel--;
        }
        EditorGUI.indentLevel--;
    }
Пример #14
0
    /*
     *  Gets any variables which are at the end of the variable chain.
     *  i.e. it is button selected, but it has no child variables which are button selected.
     *  Excludes Components.
     */
    private static List <ES2AutoSaveVariableInfo> GetVariablesAtEndOfChains(ES2AutoSave autoSave)
    {
        List <ES2AutoSaveVariableInfo> variables = new List <ES2AutoSaveVariableInfo>();

        // Check if any variables are at the end of a variable chain.
        foreach (ES2AutoSaveVariableInfo variable in autoSave.variableCache)
        {
            if (variable.buttonSelected && !variable.HasButtonSelectedVariables)
            {
                variables.Add(variable);
            }
        }

        return(variables);
    }
Пример #15
0
    public void Awake()
    {
        ES2AutoSaveManager._instance = this;

        for (int i = 0; i < sceneObjects.Length; i++)
        {
            ES2AutoSave autoSave = sceneObjects[i];
            if (autoSave == null)
            {
                continue;
            }
            autoSaves[autoSave.id]         = autoSave;
            transforms[autoSave.transform] = autoSave;
        }
    }
Пример #16
0
    protected void GetColumnsForAutoSave(ES2AutoSave autoSave, int hierarchyDepth)
    {
        ES2EditorColumn column = GetColumn(0);
        ES2EditorRow    row    = column.AddRow(autoSave.gameObject.name, autoSave, ES2EditorWindow.instance.style.saveButtonStyle, ES2EditorWindow.instance.style.saveButtonSelectedStyle, hierarchyDepth);

        if (autoSave.selected)
        {
            if (autoSave.selectionChanged)
            {
                ES2EditorAutoSaveUtility.UpdateAutoSave(autoSave);
            }

            GetComponentsColumnForAutoSave(autoSave, column, row);
        }

        if (autoSave.buttonSelected && autoSave.buttonSelectionChanged)
        {
            // Add support for any Components which are currently unsupported.
            Component[] components = autoSave.GetComponents <Component>();
            foreach (Component c in components)
            {
                // Handle unassigned components.
                if (c == null)
                {
                    continue;
                }
                // If this Component isn't currently supported, add support for it and isn't an ES2AutoSave.
                if (!ES2EditorTypeUtility.TypeIsSupported(c.GetType()) &&
                    !typeof(ES2AutoSave).IsAssignableFrom(c.GetType()) &&
                    !typeof(ES2AutoSaveManager).IsAssignableFrom(c.GetType()))
                {
                    ES2EditorTypeUtility.AddType(c.GetType());
                }
            }
        }

        foreach (Transform t in autoSave.transform)
        {
            ES2AutoSave child = ES2AutoSave.GetAutoSave(t.gameObject);
            if (child != null)
            {
                GetColumnsForAutoSave(child, hierarchyDepth + 1);
            }
        }
    }
Пример #17
0
    public static void UpdateAutoSave(ES2AutoSave autoSave)
    {
        // Delete any null values from Components array.
        for (int i = 0; i < autoSave.components.Count; i++)
        {
            if (autoSave.components[i] == null || autoSave.components[i].component == null)
            {
                autoSave.components.RemoveAt(i);
                i--;
            }
        }

        Component[] components = autoSave.gameObject.GetComponents(typeof(Component));

        for (int i = 0; i < components.Length; i++)
        {
            Component c = components[i];

            if (c == null)
            {
                continue;
            }

            // Exclude Easy Save components.
            Type type = c.GetType();
            if (typeof(ES2AutoSave).IsAssignableFrom(type) ||
                typeof(ES2AutoSaveManager) == type)
            {
                continue;
            }

            ES2AutoSaveComponentInfo componentInfo = autoSave.GetComponentInfo(c);
            // If the Component Info for this Component hasn't been added to the Auto Save, add it.
            if (componentInfo == null)
            {
                componentInfo = autoSave.AddComponentInfo(new ES2AutoSaveComponentInfo(c, autoSave));
            }

            // Get variables column if this Component is selected.
            if (componentInfo.selected)
            {
                UpdateVariablesForVariable(componentInfo);
            }
        }
    }
Пример #18
0
    private static void GetOrAddChildrenForAutoSave(ES2AutoSave autoSave)
    {
        if (autoSave == null)
        {
            return;
        }

        foreach (Transform t in autoSave.transform)
        {
            ES2AutoSave child = ES2AutoSave.GetAutoSave(t.gameObject);
            if (child == null)
            {
                child = ES2AutoSave.AddAutoSave(t.gameObject, RandomColor(), AutoSaveComponentsAreHidden(), true, "");
            }
            UpdateAutoSave(child);
            AddAutoSaveToManager(child);
            GetOrAddChildrenForAutoSave(child);
        }
    }
Пример #19
0
    public void WriteAutoSaves(ES2Writer writer)
    {
        // Save scene objects.
        foreach (KeyValuePair <Transform, ES2AutoSave> kvp in transforms)
        {
            ES2AutoSave autoSave = kvp.Value;
            Transform   t        = kvp.Key;

            if (autoSave == null || t == null || t.parent != null)
            {
                continue;
            }

            WriteAutoSaveRecursive(t, autoSave, writer);
        }

        // Signify that we have no more Auto Saves to load.
        writer.writer.Write("null");
    }
Пример #20
0
    public static void RemoveAutoSaveFromScene()
    {
        object[] objs = Resources.FindObjectsOfTypeAll(typeof(GameObject));

        for (int i = 0; i < objs.Length; i++)
        {
            GameObject  go       = (GameObject)objs[i];
            ES2AutoSave autoSave = go.GetComponent <ES2AutoSave>();
            if (autoSave != null)
            {
                Undo.DestroyObjectImmediate(autoSave);
            }
        }

        GameObject mgr = GameObject.Find("ES2 Auto Save Manager");

        if (mgr != null)
        {
            Undo.DestroyObjectImmediate(mgr);
        }
    }
Пример #21
0
    private void WriteAutoSaveRecursive(Transform transform, ES2AutoSave autoSave, ES2Writer writer)
    {
        // Get child Auto Saves to see if any are selected, as this may mean we need to save the parent even if it's unselected.
        bool hasSelectedChildren = false;
        var  children            = new List <ES2AutoSave>();

        foreach (Transform t in transform)
        {
            if (t == null)
            {
                continue;
            }
            ES2AutoSave child;
            if (transforms.TryGetValue(t, out child))
            {
                children.Add(child);
                if (child.buttonSelected)
                {
                    hasSelectedChildren = true;
                }
            }
        }

        // Only write the Auto Save if it has it's button selected, or we need to save the parent.
        if (autoSave.buttonSelected || hasSelectedChildren)
        {
            WriteAutoSave(autoSave, transform, writer);
        }

        // Don't recursively write children for prefabs as it has it's own routine for writing children.
        if (!autoSave.isPrefab)
        {
            foreach (var childAutoSave in children)
            {
                WriteAutoSaveRecursive(childAutoSave.transform, childAutoSave, writer);
            }
        }
    }
Пример #22
0
    public void Load()
    {
        ES2Settings settings = new ES2Settings();

        settings.encrypt            = encrypt;
        settings.encryptionPassword = encryptionPassword;

        // If we want to delete instantiated prefabs before loading, do so.
        if (deletePrefabsOnLoad)
        {
            List <string> keysToRemove = new List <string>();
            foreach (KeyValuePair <string, ES2AutoSave> kvp in autoSaves)
            {
                ES2AutoSave autoSave = kvp.Value;
                if (autoSave != null && autoSave.isPrefab)
                {
                    keysToRemove.Add(kvp.Key);
                    transforms.Remove(autoSave.transform);
                    Destroy(autoSave.gameObject);
                }
            }
            for (int i = 0; i < keysToRemove.Count; i++)
            {
                autoSaves.Remove(keysToRemove[i]);
            }
        }

        if (!ES2.Exists(filePath + "?tag=" + tag, settings))
        {
            return;
        }

        using (ES2Reader reader = ES2Reader.Create(filePath, settings))
        {
            reader.Read <ES2AutoSaveManager>(tag, this);
        }
    }
Пример #23
0
    // Enable Auto Save for a prefab and it's children.
    public static void EnableAutoSaveForSelectedPrefabRecursive(GameObject prefab)
    {
        ES2AutoSave autoSave = prefab.GetComponent <ES2AutoSave>();

        // Only add an Auto Save if this prefab doesn't already have one.
        if (autoSave == null)
        {
            // Add an ES2AutoSave to the prefab and add it to the Auto Save manager prefab.
            autoSave = ES2AutoSave.AddAutoSave(prefab, RandomColor(), AutoSaveComponentsAreHidden(), false, "");

            ES2AutoSaveGlobalManager globalManager = globalMgr;

            // Don't add prefab to prefab array if it's a child prefab.
            if (autoSave.transform.parent == null)
            {
                ArrayUtility.Add(ref globalManager.prefabArray, autoSave);
            }
        }

        foreach (Transform childTransform in prefab.transform)
        {
            EnableAutoSaveForSelectedPrefabRecursive(childTransform.gameObject);
        }
    }
Пример #24
0
    public ES2AutoSaveVariableInfo AddVariableInfo(string name, Type type, bool isProperty, ES2AutoSave autoSave = null, ES2AutoSaveVariableInfo previous = null)
    {
        if (previous == null)
        {
            previous = this;
        }
        if (autoSave == null)
        {
            autoSave = previous.autoSave;
        }

        ES2AutoSaveVariableInfo info = new ES2AutoSaveVariableInfo(name, type, isProperty, autoSave, previous);

        autoSave.CacheVariableInfo(info);
        variableIDs.Add(info.id);
        return(info);
    }
Пример #25
0
    /*
     *  Reads an Auto Save from a reader.
     *  Returns false if there are no more Auto Saves to load.
     *  Optionally allows you to specify an Auto Save to load it into.
     */
    private bool ReadAutoSave(ES2Reader reader, ES2AutoSave autoSave = null)
    {
        // If we've not already read the Auto Save's ID, read it.
        string autoSaveID = reader.reader.ReadString();

        if (autoSaveID == "null")
        {
            return(false);
        }

        int endPosition = (int)reader.stream.Position;
        int length      = reader.reader.ReadInt32();

        endPosition += length;

        bool   isPrefab = reader.reader.ReadBoolean();
        string prefabID = isPrefab ? reader.reader.ReadString() : "";

        if (autoSave != null)
        {
            // If an Auto Save has already been specified, do nothing.
            // i.e. this happens when loading a child Auto Save.
        }
        // Manage loading of scene objects.
        else if (!isPrefab)
        {
            // If no Auto Save exists, create a GameObject and Auto Save for it.
            if ((autoSave = GetAutoSave(autoSaveID)) == null)
            {
                autoSave = ES2AutoSave.AddAutoSave(new GameObject(), Color.red, true, false, autoSaveID);
            }
        }
        // Manage loading of prefabs.
        else
        {
            ES2AutoSave   prefabAutoSave = null;
            ES2AutoSave[] prefabs        = globalManager.prefabArray;
            // TODO: Use Dictionary for performance?
            for (int i = 0; i < prefabs.Length; i++)
            {
                if (prefabs[i] != null && prefabs[i].prefabID == prefabID)
                {
                    prefabAutoSave = prefabs[i];
                    break;
                }
            }

            GameObject instance;

            if (prefabAutoSave == null)
            {
                // If Auto Save with ID doesn't exist, create a blank object with a new Auto Save instead.
                instance          = new GameObject();
                autoSave          = ES2AutoSave.AddAutoSave(instance, Color.clear, true, false, autoSaveID);
                autoSave.prefabID = prefabID;
            }
            else
            {
                // If an object with this ID doesn't already exist, instantiate the prefab.
                if (autoSaves.TryGetValue(autoSaveID, out autoSave))
                {
                    instance = autoSave.gameObject;
                }
                else
                {
                    instance    = Instantiate(prefabAutoSave.gameObject);
                    autoSave    = instance.GetComponent <ES2AutoSave>();
                    autoSave.id = autoSaveID;
                    AddAutoSave(autoSave, autoSaveID);
                }
            }
        }

        /* Read Instance Variables. */

        // Parent
        string parentID = reader.reader.ReadString();

        if (parentID != "")
        {
            if (parentID == "null")
            {
                autoSave.transform.SetParent(null, false);
            }
            else
            {
                ES2AutoSave parentAutoSave;
                if (!autoSaves.TryGetValue(parentID, out parentAutoSave))
                {
                    // Only set parent if the parent actually exists.
                }
                else
                {
                    autoSave.transform.SetParent(parentAutoSave.transform, false);
                }
            }
        }

        // activeSelf
        string activeSelf = reader.reader.ReadString();

        if (activeSelf == "True")
        {
            autoSave.gameObject.SetActive(true);
        }
        if (activeSelf == "False")
        {
            autoSave.gameObject.SetActive(false);
        }

        // name
        string name = reader.reader.ReadString();

        if (name != "")
        {
            autoSave.name = name;
        }

        // tag
        string tag = reader.reader.ReadString();

        if (tag != "")
        {
            autoSave.tag = tag;
        }

        // layer
        int layer = reader.reader.ReadInt32();

        if (layer > -1)
        {
            autoSave.gameObject.layer = layer;
        }

        // If this is a prefab, we'll need to load it's children too.
        if (autoSave.isPrefab)
        {
            List <string> childPrefabIDs = reader.ReadList <string>();
            for (int i = 0; i < childPrefabIDs.Count; i++)
            {
                bool foundAutoSave = false;
                // Get the child with the given prefab ID, and load the data into it.
                foreach (Transform t in autoSave.transform)
                {
                    ES2AutoSave childAutoSave = t.GetComponent <ES2AutoSave>();
                    if (childAutoSave != null)
                    {
                        if (childAutoSave.prefabID == childPrefabIDs[i])
                        {
                            foundAutoSave = true;
                            ReadAutoSave(reader, childAutoSave);
                            break;
                        }
                    }
                }
                // If we didn't find an appropriate Auto Save, it's likely that this has been made a child of
                // the prefab at runtime, so load it as a normal auto save.
                if (!foundAutoSave)
                {
                    ReadAutoSave(reader, null);

                    /*
                     * // Skip the Auto Save.
                     * reader.reader.ReadString();
                     * int endPos = (int)reader.stream.Position;
                     * int len = reader.reader.ReadInt32();
                     * endPos += len;
                     * reader.stream.Position = endPos;*/
                }
            }
        }

        while (reader.stream.Position != endPosition)
        {
            ReadComponent(autoSave, reader);
        }

        return(true);
    }
Пример #26
0
    private void ReadVariableRecursive(ES2AutoSave autoSave, ES2AutoSaveVariableInfo variable, ES2Reader reader, object obj)
    {
        string variableID  = reader.reader.ReadString();
        int    endPosition = (int)reader.stream.Position;
        int    length      = reader.reader.ReadInt32();

        endPosition += length;

        // Read Type data
        ES2Keys.Key collectionType = (ES2Keys.Key)reader.reader.ReadByte();
        int         typeHash       = reader.reader.ReadInt32();
        int         dictValueHash  = 0;

        if (collectionType == ES2Keys.Key._Dictionary)
        {
            dictValueHash = reader.reader.ReadInt32();
        }

        ES2AutoSaveVariableInfo info = autoSave.GetCachedVariableInfo(variableID);

        if (info == null)
        {
            reader.stream.Position = endPosition;
            return;
        }

        string dataType = reader.reader.ReadString();

        if (dataType == "data")
        {
            // Get ES2Types.
            ES2Type type          = ES2TypeManager.GetES2Type(typeHash);
            ES2Type dictValueType = null;
            if (collectionType == ES2Keys.Key._Dictionary)
            {
                dictValueType = ES2TypeManager.GetES2Type(dictValueHash);
            }

            // If the type of data we're loading isn't supported, skip it.
            if (type == null || (collectionType == ES2Keys.Key._Dictionary && dictValueType == null))
            {
                reader.stream.Position = endPosition;
                return;
            }

            bool valueWasSet = false;

            if (collectionType == ES2Keys.Key._Null)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.Read <System.Object>(type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._NativeArray)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadSystemArray(type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._List)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(List <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Queue)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(Queue <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Stack)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(Stack <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._HashSet)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(HashSet <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Dictionary)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadIDictionary(typeof(Dictionary <,>), type, dictValueType), info.isProperty);
            }

            if (!valueWasSet)
            {
                reader.stream.Position = endPosition;
                return;
            }
        }
        // Else, we have variables to load.
        else if (dataType == "vars")
        {
            object thisObj = ES2Reflection.GetValue(obj, info.name, info.isProperty);
            if (thisObj == null)
            {
                reader.stream.Position = endPosition;
            }
            ReadVariableRecursive(autoSave, info, reader, thisObj);
        }
        else
        {
            reader.stream.Position = endPosition;
            return;
        }
    }
Пример #27
0
 public void AddAutoSave(ES2AutoSave autoSave, string id)
 {
     autoSaves[id] = autoSave;
     transforms[autoSave.transform] = autoSave;
 }
Пример #28
0
 /* Adds a child Auto Save, which should not be added to the main Auto Save dictionary,
  * but should be added to the transforms Dictionary */
 public void AddChildAutoSave(ES2AutoSave autoSave, string id)
 {
     transforms[autoSave.transform] = autoSave;
 }
Пример #29
0
    protected void GetComponentsColumnForAutoSave(ES2AutoSave autoSave, ES2EditorColumn previousColumn, ES2EditorRow previousRow)
    {
        ES2EditorColumn column = GetColumn(1);

        ES2EditorRow firstRow = null;

        // GameObject instance variables. These have to be handled seperately.
        ES2AutoSaveVariableInfo[] instanceVariables = new ES2AutoSaveVariableInfo[] { autoSave.activeSelfVariable, autoSave.parentVariable, autoSave.nameVariable, autoSave.tagVariable, autoSave.layerVariable };
        for (int i = 0; i < instanceVariables.Length; i++)
        {
            ES2AutoSaveVariableInfo variable = instanceVariables[i];

            ES2EditorRow newRow = column.AddRow(variable.name, variable, ES2EditorWindow.instance.style.saveButtonStyle, ES2EditorWindow.instance.style.saveButtonSelectedStyle, 0);
            if (firstRow == null)
            {
                firstRow = newRow;
            }

            SetTooltips(variable, newRow);

            // If this component was selected, also select it's Auto Save.
            if (variable.buttonSelectionChanged && variable.buttonSelected)
            {
                autoSave.buttonSelected = true;
            }

            // If the button for the Auto Save of this Component was deselected, deselect this one too.
            if (autoSave.buttonSelectionChanged && !autoSave.buttonSelected)
            {
                newRow.obj.buttonSelected = false;
            }

            // Get variables column if this Component is selected.
            if (variable.selected)
            {
                // Update this component if we've only just selected this Component.
                if (variable.selectionChanged)
                {
                    ES2EditorAutoSaveUtility.UpdateVariablesForVariable(variable);
                }

                GetVariablesColumnForVariable(variable, column, newRow, 2);
            }
        }

        // Create rows for Component's attached to this GameObject.
        for (int i = 0; i < autoSave.components.Count; i++)
        {
            ES2AutoSaveComponentInfo componentInfo = autoSave.components[i];
            ES2EditorRow             newRow        = column.AddRow(componentInfo.name, componentInfo, ES2EditorWindow.instance.style.saveButtonStyle, ES2EditorWindow.instance.style.saveButtonSelectedStyle, 0);
            if (firstRow == null)
            {
                firstRow = newRow;
            }

            SetTooltips(componentInfo, newRow);

            // If this component was selected ...
            if (componentInfo.buttonSelectionChanged && componentInfo.buttonSelected)
            {
                // ... also select it's Auto Save.
                autoSave.buttonSelected = true;
                // If this Component isn't currently supported, add support for it.
                if (!ES2EditorTypeUtility.TypeIsSupported(componentInfo.type))
                {
                    ES2EditorTypeUtility.AddType(componentInfo.type);
                }
            }

            // If the button for the Auto Save of this Component was deselected, deselect this one too.
            if (autoSave.buttonSelectionChanged && !autoSave.buttonSelected)
            {
                newRow.obj.buttonSelected = false;
            }

            // Get variables column if this Component is selected.
            if (componentInfo.selected)
            {
                // Update this component if we've only just selected this Component.
                if (componentInfo.selectionChanged)
                {
                    ES2EditorAutoSaveUtility.UpdateVariablesForVariable(componentInfo);
                }

                GetVariablesColumnForVariable(componentInfo, column, newRow, 2);
            }
        }

        if (autoSave.components.Count == 0)
        {
            firstRow = column.AddRow("No supportable Components", null, null, null, 0);
        }

        // Add seperator row.
        column.AddRow("", null, null, null);
        // Add curve line between columns.
        ArrayUtility.Add(ref curves, new ES2EditorRowCurve(previousColumn, previousRow, column, firstRow, autoSave.color));
    }
Пример #30
0
 private static void AddAutoSaveToManager(ES2AutoSave autoSave)
 {
     ArrayUtility.Add(ref mgr.sceneObjects, autoSave);
 }