Beispiel #1
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 #2
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 #3
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.");
            }
        }
    }