Example #1
0
        /// <summary>
        /// Get the extension logo
        /// </summary>
        /// <param name="instance">Extension instance</param>
        public static Texture GetLogo(UNExtension instance)
        {
            if (instance.AssetLogoName == "")
            {
                return(null);
            }

            #if UNITY_EDITOR
            if (instance.logo == null)
            {
                var guids = UnityEditor.AssetDatabase.FindAssets(instance.AssetLogoName);

                string path;

                for (int i = 0; i < guids.Length; i++)
                {
                    path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[i]);

                    if (path.Contains(instance.AssetLogoName))
                    {
                        instance.logo = UnityEditor.AssetDatabase.LoadAssetAtPath <Texture>(path);
                        break;
                    }
                }
            }

            return(instance.logo);
            #else
            return(null);
            #endif
        }
Example #2
0
        /// <summary>
        /// Open the asset store page of the extension
        /// <param name="instance">Extension instance</param>
        /// </summary>
        public static void OpenAssetStore(UNExtension instance)
        {
            #if UNITY_EDITOR
            if (instance.AssetStoreAdress == "")
            {
                return;
            }

            Application.OpenURL(instance.AssetStoreAdress);
            #endif
        }
Example #3
0
        /// <summary>
        /// Load helper methods from an instance.
        /// </summary>
        /// <param name="instance">Extension instance</param>
        public static void LoadMethods(UNExtension instance, Type type)
        {
            #if UNITY_EDITOR
            instance.HelperMethods = new List <MethodInfo>();

            MethodInfo[] methods = type.GetMethods();
            MethodInfo   method;

            for (int i = 0; i < methods.Length; i++)
            {
                method = methods[i];

                if (method.GetCustomAttributes(true).Select(x => (MethodHelperAttribute)x).Count() > 0)
                {
                    instance.HelperMethods.Add(method);
                }
            }
            #endif
        }
        void Init()
        {
            extensions = new Dictionary <string, List <UNExtension> >();
            System.Type[] types = Assembly.GetAssembly(typeof(UNExtension)).GetTypes();

            for (int i = 0; i < types.Length; i++)
            {
                if (types[i].BaseType != typeof(UNExtension) || types[i].IsAbstract)
                {
                    continue;
                }

                UNExtension extension = (UNExtension)System.Activator.CreateInstance(types[i]);
                UNExtension.LoadMethods(extension, types[i]);

                if (!extensions.ContainsKey(extension.PublisherName))
                {
                    extensions.Add(extension.PublisherName, new List <UNExtension>());
                }

                extensions[extension.PublisherName].Add(extension);
            }
        }
Example #5
0
        /// <summary>
        /// Open the documentation of the extension
        /// <param name="instance">Extension instance</param>
        /// </summary>
        public static void OpenDocs(UNExtension instance)
        {
            #if UNITY_EDITOR
            if (instance.AssetDocumentationName == "")
            {
                return;
            }

            var files = Directory.GetFiles(@"Assets", instance.AssetDocumentationName, SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Contains(instance.AssetDocumentationName))
                {
                    if (File.Exists(files[i]))
                    {
                        System.Diagnostics.Process.Start(files[i]);
                        return;
                    }
                }
            }
            #endif
        }
        void OnGUI()
        {
            if (invisibleButtonStyle == null)
            {
                invisibleButtonStyle = new GUIStyle("Button");

                invisibleButtonStyle.normal.background  = null;
                invisibleButtonStyle.focused.background = null;
                invisibleButtonStyle.hover.background   = null;
                invisibleButtonStyle.active.background  = null;
            }
            if (boxStyle == null)
            {
                boxStyle = new GUIStyle("Box");

                boxStyle.normal.textColor  = invisibleButtonStyle.normal.textColor;
                boxStyle.focused.textColor = invisibleButtonStyle.focused.textColor;
                boxStyle.hover.textColor   = invisibleButtonStyle.hover.textColor;
                boxStyle.active.textColor  = invisibleButtonStyle.active.textColor;
            }

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            foreach (var extensionGroup in extensions)
            {
                GUILayout.BeginVertical(extensionGroup.Key, boxStyle);

                GUILayout.Space(15);

                foreach (var extension in extensionGroup.Value)
                {
                    GUILayout.BeginHorizontal();
                    extension.isViewed = EditorGUILayout.Foldout(extension.isViewed, extension.AssetName, extension.Featured ? featuredFoldoutStyle : "Foldout");

                    if (extension.Featured)
                    {
                        GUILayout.Label(featuredIcon, GUILayout.Width(20), GUILayout.Height(20));
                    }

                    GUILayout.EndHorizontal();

                    if (extension.isViewed)
                    {
                        GUILayout.BeginHorizontal();

                        GUILayout.Space(15);

                        GUILayout.BeginVertical();

                        if (!extension.IsDefault)
                        {
                            extension.isActivated = EditorGUILayout.Toggle("Activated :", extension.isActivated);
                        }

                        GUILayout.Space(10);

                        GUILayout.BeginHorizontal();

                        Texture logo = UNExtension.GetLogo(extension);

                        if (logo != null)
                        {
                            GUILayout.Label(logo, GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false));
                        }
                        EditorGUILayout.LabelField(extension.AssetDescription, GUILayout.Height(logo == null ? 50 : logo.height)); // draw description

                        GUILayout.EndHorizontal();

                        if (extension.isActivated && extension.HelperMethods.Count > 0)
                        {
                            GUILayout.Space(15);

                            GUILayout.BeginVertical("Tools : ", boxStyle);

                            GUILayout.Space(25);

                            for (int i = 0; i < extension.HelperMethods.Count; i++)
                            {
                                GUILayout.Space(2);

                                if (GUILayout.Button(extension.HelperMethods[i].Name))
                                {
                                    extension.HelperMethods[i].Invoke(extension, null);
                                }
                            }

                            GUILayout.EndVertical();
                        }

                        GUILayout.Space(15);

                        GUILayout.BeginHorizontal();

                        if (GUILayout.Button("Open Documentation", boxStyle))
                        {
                            UNExtension.OpenDocs(extension);
                        }
                        if (GUILayout.Button("Asset Store", boxStyle))
                        {
                            UNExtension.OpenAssetStore(extension);
                        }

                        GUILayout.EndHorizontal();

                        GUILayout.EndVertical();

                        GUILayout.EndHorizontal();
                    }

                    GUILayout.Space(5);
                }

                GUILayout.EndVertical();

                GUILayout.Space(5);
            }

            EditorGUILayout.EndScrollView();
        }