Beispiel #1
0
    private void DisplayArray(object obj, ES2EditorType valueType, ES2Header header, string tag)
    {
        object[] array = obj as object[];

        if (currentArrayFoldouts == null)
        {
            currentArrayFoldouts = new bool[array.Length];
        }

        EditorGUILayout.IntField("Length", array.Length);
        EditorGUILayout.Space();



        for (int i = 0; i < array.Length; i++)
        {
            if (currentArrayFoldouts[i] = EditorGUILayout.Foldout(currentArrayFoldouts[i], i.ToString()))
            {
                EditorGUI.indentLevel++;
                object guiFields = valueType.DisplayGUI(array[i]);
                EditorGUI.indentLevel--;

                if (guiFields == null)
                {
                    EditorGUILayout.LabelField("This type cannot be viewed.");
                }
                else
                {
                    array[i] = guiFields;
                }
            }
        }

        currentValue = array;
    }
Beispiel #2
0
    private void DisplayAddNewTag()
    {
        // Get Type List.
        Type[] types = ES2EditorType.GetTypes();

        // Get Type Names for dropdown list.
        string[] typeNames = new string[types.Length];
        for (int i = 0; i < types.Length; i++)
        {
            typeNames[i] = types[i].ToString();
        }

        // Display GUI for Add New Tag.
        EditorGUILayout.LabelField("Add New Tag", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();

        this.newTagName      = EditorGUILayout.TextField(this.newTagName);    // Type of new tag.
        this.newTagTypeIndex = EditorGUILayout.Popup(this.newTagTypeIndex, typeNames);

        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("+ Add Tag", EditorStyles.toolbarButton))
        {
            AddTag(this.newTagName, types[this.newTagTypeIndex]);
        }
    }
Beispiel #3
0
    public void AddTag(string tag, Type type)
    {
        ES2Settings settings = new ES2Settings();

        settings.tag = tag;
        ES2.Save(ES2EditorType.Get(type).CreateInstance(), currentFilePath, settings);
        OpenFile();
    }
Beispiel #4
0
    private void DisplayList(object obj, ES2EditorType valueType, ES2Header header, string tag)
    {
        List <object> array = obj as List <object>;
        int           count = array.Count;

        if (currentArrayFoldouts == null)
        {
            currentArrayFoldouts = new bool[count];
        }

        EditorGUILayout.IntField("Length", count);
        EditorGUILayout.Space();

        // If lengths are not equal, user has modified length field.

        /*if((Event.current.type == EventType.KeyUp) && (Event.current.keyCode == KeyCode.Return) && GUI.GetNameOfFocusedControl()=="arrayLength")
         * {
         *      if(length > array.Length)
         *      {
         *              int difference = length-array.Length;
         *              for(int i=0; i<difference; i++)
         *                      ArrayUtility.Add<object>(ref array, null);
         *      }
         *      else if(length < array.Length)
         *      {
         *              int difference = array.Length-length;
         *              for(int i=0; i<difference; i++)
         *                      ArrayUtility.RemoveAt<object>(ref array, array.Length-difference);
         *      }
         *
         *      es2Data.loadedData[tag] = array;
         * }*/

        for (int i = 0; i < count; i++)
        {
            if (currentArrayFoldouts[i] = EditorGUILayout.Foldout(currentArrayFoldouts[i], i.ToString()))
            {
                EditorGUI.indentLevel++;
                object guiFields = valueType.DisplayGUI(array[i]);
                EditorGUI.indentLevel--;

                if (guiFields == null)
                {
                    EditorGUILayout.LabelField("This type cannot be viewed.");
                }
                else
                {
                    array[i] = guiFields;
                }
            }
        }

        currentValue = array;
    }
Beispiel #5
0
    private void DisplayObject(object value, ES2EditorType valueType, string tag)
    {
        object guiFields = valueType.DisplayGUI(value);

        if (guiFields == null)
        {
            EditorGUILayout.LabelField("This type cannot be viewed.");
        }
        else
        {
            currentValue = guiFields;
        }
    }
Beispiel #6
0
 private string GetTypeName(ES2Header header, ES2EditorType valueType)
 {
     if (header.collectionType == ES2Keys.Key._Null)
     {
         return(valueType.type.ToString());
     }
     else if (header.collectionType == ES2Keys.Key._NativeArray)
     {
         return(valueType.type.ToString() + "[]");
     }
     else if (header.collectionType == ES2Keys.Key._Dictionary)
     {
         return("Dictionary<" + ES2TypeManager.GetES2Type(header.keyType).type.ToString() + "," + valueType.type.ToString() + ">");
     }
     else
     {
         string enumName = header.collectionType.ToString();
         return(enumName.Substring(1, enumName.Length - 1) + "<" + valueType.type.ToString() + ">");
     }
 }
Beispiel #7
0
    public static Dictionary <Type, ES2EditorType> GetEditorTypes()
    {
        Dictionary <Type, ES2EditorType> es2Types = new Dictionary <Type, ES2EditorType>();

        foreach (string assemblyName in editorAssemblies)
        {
            Assembly assembly = GetAssembly(assemblyName);
            if (assembly == null)
            {
                continue;
            }

            IEnumerable <Type> tempTypes = assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(ES2EditorType)));
            foreach (Type type in tempTypes)
            {
                ES2EditorType es2EditorType = Activator.CreateInstance(type) as ES2EditorType;
                es2Types[es2EditorType.type] = es2EditorType;
            }
        }

        return(es2Types);
    }
Beispiel #8
0
    private void DisplayDictionary(object obj, ES2EditorType valueType, ES2Header header, string tag)
    {
        Dictionary <object, object> dict = obj as Dictionary <object, object>;
        int count = dict.Count;

        object[] keys = dict.Keys.ToArray();

        if (currentArrayFoldouts == null)
        {
            currentArrayFoldouts = new bool[count];
        }

        EditorGUILayout.IntField("Count", count);
        EditorGUILayout.Space();

        // If lengths are not equal, user has modified length field.

        /*if((Event.current.type == EventType.KeyUp) && (Event.current.keyCode == KeyCode.Return) && GUI.GetNameOfFocusedControl()=="arrayLength")
         * {
         *      if(length > array.Length)
         *      {
         *              int difference = length-array.Length;
         *              for(int i=0; i<difference; i++)
         *                      ArrayUtility.Add<object>(ref array, null);
         *      }
         *      else if(length < array.Length)
         *      {
         *              int difference = array.Length-length;
         *              for(int i=0; i<difference; i++)
         *                      ArrayUtility.RemoveAt<object>(ref array, array.Length-difference);
         *      }
         *
         *      es2Data.loadedData[tag] = array;
         * }*/

        for (int i = 0; i < count; i++)
        {
            if (currentArrayFoldouts[i] = EditorGUILayout.Foldout(currentArrayFoldouts[i], i.ToString()))
            {
                EditorGUI.indentLevel++;

                EditorGUILayout.LabelField("Key", EditorStyles.boldLabel);
                EditorGUILayout.Space();

                EditorGUI.indentLevel++;
                // Display Key
                object keyFields = ES2EditorType.Get(header.keyType).DisplayGUI(keys[i]);
                if (keyFields == null)
                {
                    EditorGUILayout.LabelField("This type cannot be viewed.");
                }
                EditorGUI.indentLevel--;

                EditorGUILayout.LabelField("Value", EditorStyles.boldLabel);
                EditorGUILayout.Space();

                EditorGUI.indentLevel++;
                // Display Value
                object valueFields = valueType.DisplayGUI(dict[keys[i]]);
                if (valueFields == null)
                {
                    EditorGUILayout.LabelField("This type cannot be viewed.");
                }
                else
                {
                    dict[keys[i]] = valueFields;
                    currentValue  = dict;
                }
                EditorGUI.indentLevel--;

                EditorGUI.indentLevel--;
            }
        }
    }
Beispiel #9
0
    private void DisplayTagInfo()
    {
        // If a tag has been selected but requires a password, show password field...
        if (currentTag != null && this.currentTagRequiresPassword)
        {
            EditorGUILayout.LabelField("This tag requires a password to view");
            this.encryptionPassword = EditorGUILayout.TextField("Password", this.encryptionPassword);
            if (GUILayout.Button("Decrypt"))
            {
                OnTagChange();
            }
        }
        // If a tag has been selected and doesn't explicity require a password...
        else if (currentTag != null && currentValue != null)
        {
            // Get type names from ES2Header data.
            ES2Header     header    = headers[currentTag];
            ES2EditorType valueType = ES2EditorType.Get(header.valueType);

            // Only display this data if it's there's an ES2EditorType for it.
            if (valueType != null)
            {
                EditorGUILayout.BeginVertical();
                rightScrollPosition = EditorGUILayout.BeginScrollView(rightScrollPosition);

                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("Type", EditorStyles.boldLabel);
                EditorGUILayout.Space();
                EditorGUI.indentLevel++;
                EditorGUILayout.LabelField(GetTypeName(header, valueType));
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("Encryption", EditorStyles.boldLabel);
                EditorGUILayout.Space();
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                var tempLabelWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 90;
                header.settings.encrypt     = EditorGUILayout.Toggle("Encrypt?", header.settings.encrypt);
                if (header.settings.encrypt)
                {
                    header.settings.encryptionPassword = EditorGUILayout.TextField(header.settings.encryptionPassword);
                }
                EditorGUIUtility.labelWidth = tempLabelWidth;
                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();

                EditorGUILayout.LabelField("Value", EditorStyles.boldLabel);

                EditorGUILayout.Space();
                EditorGUI.indentLevel++;

                if (header.collectionType == ES2Keys.Key._Null)
                {
                    DisplayObject(currentValue, valueType, currentTag);
                }
                else if (header.collectionType == ES2Keys.Key._NativeArray)
                {
                    DisplayArray(currentValue, valueType, header, currentTag);
                }
                else if (header.collectionType == ES2Keys.Key._Dictionary)
                {
                    DisplayDictionary(currentValue, valueType, header, currentTag);
                }
                else if (header.collectionType == ES2Keys.Key._List)
                {
                    DisplayList(currentValue, valueType, header, currentTag);
                }
                else
                {
                    EditorGUILayout.LabelField("The File Editor does not currently support Collections of this type.");
                }

                EditorGUI.indentLevel--;
                EditorGUILayout.Space();
                EditorGUILayout.Space();

                EditorGUILayout.EndScrollView();

                // Save / Delete Tag Buttons
                EditorGUILayout.BeginHorizontal();

                if (valueType != null)
                {
                    if (GUILayout.Button("Save Tag", EditorStyles.toolbarButton))
                    {
                        SaveCurrentTag(header);
                    }
                }

                if (GUILayout.Button("Delete Tag", EditorStyles.toolbarButton))
                {
                    if (EditorUtility.DisplayDialog("Delete this Tag?", "Are you sure you want to permanently delete this tag?", "Delete Tag", "Cancel"))
                    {
                        DeleteCurrentTag();
                    }
                }

                // If adding something after 'delete tag', make sure tag hasn't been deleted first.

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }
            else
            {             // There's not an ES2EditorType for this data.
                EditorGUILayout.LabelField("The File Editor does not currently support this type.");
            }
        }
    }