Exemple #1
0
    public ES2EditorProperty(FieldInfo info)
    {
        this.name        = info.Name;
        this.isSelected  = false;
        this.type        = info.FieldType;
        this.isComponent = typeof(Component).IsAssignableFrom(this.type);

        this.collectionType         = ES2EditorReflection.GetSupportedCollectionType(this.type);
        this.isCollection           = (collectionType != "");
        this.collectionContentTypes = ES2EditorReflection.GetSupportedCollectionTypes(type);

        // Determine if property can be saved.
        if (info.IsStatic)
        {
            isSupported            = false;
            unsupportedDescription = "Static properties should not be saved from an ES2Type.";
        }
        else if (info.IsInitOnly)
        {
            isSupported            = false;
            unsupportedDescription = "This field needs to be writable and readable to be able to save it.";
        }
        else
        {
            this.unsupportedDescription = ES2EditorManageTypes.TypeIsSupported(this.type);
            isSupported = (unsupportedDescription == "");
        }
    }
Exemple #2
0
 public static void Init()
 {
     if (editorTypes == null)
     {
         editorTypes = ES2EditorReflection.GetEditorTypes();
     }
 }
Exemple #3
0
    public ES2EditorProperty(PropertyInfo info)
    {
        this.name        = info.Name;
        this.isSelected  = false;
        this.type        = info.PropertyType;
        this.isComponent = typeof(Component).IsAssignableFrom(this.type);

        this.collectionType         = ES2EditorReflection.GetSupportedCollectionType(this.type);
        this.isCollection           = (collectionType != "");
        this.collectionContentTypes = ES2EditorReflection.GetSupportedCollectionTypes(type);

        bool hasGetter = (info.GetGetMethod() != null);
        bool hasSetter = (info.GetSetMethod() != null);

        // Determine if property can be saved.
        if (info.GetGetMethod().IsStatic)
        {
            isSupported            = false;
            unsupportedDescription = "Static properties should not be saved from an ES2Type.";
        }
        else if (!hasSetter || !hasGetter)
        {
            isSupported            = false;
            unsupportedDescription = "This property needs a getter and a setter to be able to save it.";
        }
        else
        {
            this.unsupportedDescription = ES2EditorManageTypes.TypeIsSupported(this.type);
            isSupported = (unsupportedDescription == "");
        }
    }
    public void OnGUI()
    {
        try
        {
            // If type list hasn't been initialised, initialise it.
            if (types.Count == 0)
            {
                GetTypes();
                es2Types = ES2EditorReflection.GetSupportedTypes();
            }

            GUILayout.Label("Easy Save 2: Manage Types", EditorStyles.largeLabel);
            //GUILayout.Label("Select a type to add support for it.", EditorStyles.boldLabel);

            GUI.skin.button.alignment = TextAnchor.MiddleCenter;
            if (GUILayout.Button(new GUIContent("Refresh ES2Init", "Use this to reset the type list if you manually remove an ES2Type, or if it becomes corrupt.")))
            {
                CreateES2UserInit();
                AssetDatabase.Refresh();
            }

            DisplaySearchField();

            GUILayout.BeginHorizontal(GUILayout.MinWidth(512f));

            GUI.skin.button.alignment = TextAnchor.MiddleLeft;
            // TYPE LIST
            leftScrollPosition = EditorGUILayout.BeginScrollView(leftScrollPosition, GUILayout.Width(typeListWidth));
            selected           = GUILayout.SelectionGrid(selected, typeNames, 1);
            // If the selected type has changed ...
            if (selected != previouslySelected)
            {
                OnTypeChange();
            }
            EditorGUILayout.EndScrollView();

            // TYPE INFO

            // If a type is selected
            rightScrollPosition = EditorGUILayout.BeginScrollView(rightScrollPosition, GUILayout.MinWidth(400));
            if (selected != -1)
            {
                DisplayType(types[selected]);
            }
            else
            {
                GUILayout.Label("<- Please select a type from the left.", EditorStyles.boldLabel);
            }
            EditorGUILayout.EndScrollView();


            EditorGUILayout.EndHorizontal();
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
        }
    }
 /* Gets all of the types of the assemblies in the assemblies array, but filters out generic and abstract types */
 private static void GetTypes()
 {
     types     = ES2EditorReflection.GetSupportableTypes(searchTerm);
     typeNames = new string[types.Count];
     for (int i = 0; i < types.Count; i++)
     {
         typeNames[i] = types[i].Name;
     }
 }
    /*
     *      Determines whether a type is supported.
     *      Returns a blank string if supported, or a message describing why it's not supported if not.
     */
    public static string TypeIsSupported(Type type)
    {
        // If this is a collection or array, see if the type of the contents are supported.
        if (ES2EditorReflection.IsCollectionType(type))
        {
            // If it's a generic collection ...
            if (type.IsGenericType)
            {
                // Check that it's a generic collection type supported by Easy Save.
                if (!(type.GetGenericTypeDefinition().IsAssignableFrom(typeof(List <>)) ||
                      type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary <,>)) ||
                      type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Queue <>)) ||
                      type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Stack <>)) ||
                      type.GetGenericTypeDefinition().IsAssignableFrom(typeof(HashSet <>))))
                {
                    return("This type of collection is not currently supported.");
                }
                else
                {
                    foreach (Type arg in type.GetGenericArguments())
                    {
                        if (!arg.IsEnum && !es2Types.ContainsKey(arg))
                        {
                            return("A type inside this collection is not supported, but you may be able to add support for it.");
                        }
                    }
                }
            }
            // Else if it's a normal array ...
            else if (type.IsArray)
            {
                // Check that it's a type of array that we support ...
                if (type.GetArrayRank() > 2)
                {
                    return("Only 1D and 2D arrays are supported.");
                }
                else if (!type.GetElementType().IsEnum&& !es2Types.ContainsKey(type.GetElementType()))
                {
                    return("The type of data inside this array is not supported, but you may be able to add support for it.");
                }
            }
        }
        else if (type.IsEnum)
        {
            return("");
        }
        // If there's not an ES2Type for this ...
        else if (!es2Types.ContainsKey(type))
        {
            return("Saving this type is not currently supported, but you may be able to add support for it.");
        }

        return("");
    }
Exemple #7
0
    /*
     *      Gets all ES2Type objects as a Dictionary containing it's appropriate type as the key
     */
    private static Dictionary <Type, ES2Type> GetSupportedTypes()
    {
        Dictionary <Type, ES2Type> es2Types = new Dictionary <Type, ES2Type>();

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

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

        return(es2Types);
    }
Exemple #8
0
    public void OpenFile()
    {
        if (string.IsNullOrEmpty(currentFilePath))
        {
            return;
        }

        if (!File.Exists(currentFilePath))
        {
            return;
        }
        // If this file exists, set it as the default file to be opened when we open the window.
        EditorPrefs.SetString("ES2EditorFileEditorFilePath", currentFilePath);
        // Reset the tag incase we're Refreshing a file, and the tag has been removed.
        currentTag   = null;
        currentIndex = -1;

        try
        {
            headers = ES2EditorReflection.GetHeadersFromFile(currentFilePath);
            tags    = headers.Keys.ToArray();
        }
        catch (Exception e)
        {
            Reset();
            EditorPrefs.DeleteKey("ES2EditorFileEditorFilePath");
            if (e is ES2InvalidDataException)
            {
                EditorUtility.DisplayDialog("Could not open file", "This file does not contain data which is readable by Easy Save.\nPlease make sure this file was created using Easy Save 2.", "Ok");
            }
            else
            {
                EditorUtility.DisplayDialog("Could not open file", "An error was thrown when trying to open this file. See below for details.\n\n" + "Details: " + e.Message, "Ok");
            }
            return;
        }
    }
 public void Awake()
 {
     GetTypes();
     es2Types = ES2EditorReflection.GetSupportedTypes();
 }