Exemplo n.º 1
0
        public static void ReloadExtensions()
        {
            List <Type> loadedTypes = GCommon.GetAllLoadedTypes();

            extensions = new List <GExtensionInfo>();
            for (int i = 0; i < loadedTypes.Count; ++i)
            {
                Type t = loadedTypes[i];
                if (string.IsNullOrEmpty(t.Namespace))
                {
                    continue;
                }
                if (!t.Namespace.EndsWith(".GriffinExtension"))
                {
                    continue;
                }

                GExtensionInfo info = GExtensionInfo.CreateFromType(t);
                if (!t.Namespace.StartsWith("Pinwheel.") &&
                    info.Publisher.Equals("Pinwheel Studio"))
                {
                    string error = string.Format(
                        "Griffin Extension: Error on initiating '{0}/{1}'. " +
                        "Publisher name 'Pinwheel Studio' is reserved. Please choose another name.",
                        t.Name,
                        info.Name);
                    Debug.Log(error);
                }
                else
                {
                    extensions.Add(info);
                }
            }

            extensions.RemoveAll(e =>
                                 string.IsNullOrEmpty(e.Publisher) ||
                                 string.IsNullOrEmpty(e.Name) ||
                                 e.OpenSupportLinkMethod == null);

            extensions.Sort((e0, e1) => e0.Name.CompareTo(e1.Name));
        }
Exemplo n.º 2
0
        private void DrawExtension(GExtensionInfo ex)
        {
            GUI.enabled = !EditorApplication.isCompiling;
            string filter = SearchString.ToLower();

            if (!ex.Name.ToLower().Contains(filter) &&
                !ex.Publisher.ToLower().Contains(filter) &&
                !ex.Description.ToLower().Contains(filter))
            {
                return;
            }

            string id    = "griffin-extension" + ex.Name + ex.Publisher;
            string label = ex.Name;

            GEditorCommon.Foldout(label, false, id, () =>
            {
                try
                {
                    EditorGUILayout.LabelField("Publisher", ex.Publisher);
                    EditorGUILayout.LabelField("Version", ex.Version);
                    EditorGUILayout.LabelField("Description", ex.Description, GEditorCommon.WordWrapLeftLabel);
                    if (ex.OpenUserGuideMethod != null || ex.OpenSupportLinkMethod != null)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PrefixLabel("Link");
                        using (EditorGUI.IndentLevelScope level = new EditorGUI.IndentLevelScope(-1))
                        {
                            Rect r = EditorGUILayout.GetControlRect();
                            List <string> linkLabels = new List <string>();
                            linkLabels.Add("Support");
                            if (ex.OpenUserGuideMethod != null)
                            {
                                linkLabels.Add("User Guide");
                            }

                            List <Rect> linkRects = EditorGUIUtility.GetFlowLayoutedRects(r, EditorStyles.label, 7, 0, linkLabels);
                            for (int i = 0; i < linkRects.Count; ++i)
                            {
                                EditorGUIUtility.AddCursorRect(linkRects[i], MouseCursor.Link);
                            }

                            if (GUI.Button(linkRects[0], "Support", EditorStyles.label))
                            {
                                ex.OpenSupportLinkMethod.Invoke(null, null);
                            }
                            GEditorCommon.DrawBottomLine(linkRects[0], EditorStyles.label.normal.textColor);

                            if (ex.OpenUserGuideMethod != null)
                            {
                                if (GUI.Button(linkRects[1], "User Guide", EditorStyles.label))
                                {
                                    ex.OpenUserGuideMethod.Invoke(null, null);
                                }
                                GEditorCommon.DrawBottomLine(linkRects[1], EditorStyles.label.normal.textColor);
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    if (ex.ButtonMethods.Count > 0)
                    {
                        GEditorCommon.Separator();
                        for (int i = 0; i < ex.ButtonMethods.Count; ++i)
                        {
                            MethodInfo method = ex.ButtonMethods[i];
                            if (method == null)
                            {
                                continue;
                            }

                            string buttonLabel = ObjectNames.NicifyVariableName(method.Name.Substring(GExtensionInfo.BUTTON_METHOD_PREFIX.Length));
                            if (GUILayout.Button(buttonLabel))
                            {
                                method.Invoke(null, null);
                            }
                        }
                    }

                    if (ex.GuiMethod != null)
                    {
                        GEditorCommon.Separator();
                        ex.GuiMethod.Invoke(null, null);
                    }
                }
                catch (System.Exception e)
                {
                    EditorGUILayout.LabelField(string.Format("<color=red>Error: {0}</color>", e.ToString()), GEditorCommon.RichTextLabel);
                    Debug.LogException(e);
                }
            });
            GUI.enabled = true;
        }
Exemplo n.º 3
0
        public static GExtensionInfo CreateFromType(Type t)
        {
            GExtensionInfo info = new GExtensionInfo();

            MethodInfo getPublisherMethod = t.GetMethod(
                GET_PUBLISHER_METHOD_NAME,
                BindingFlags.Public | BindingFlags.Static);

            if (getPublisherMethod != null &&
                getPublisherMethod.ReturnType == typeof(string))
            {
                info.Publisher = (string)getPublisherMethod.Invoke(null, null);
            }

            MethodInfo getNameMethod = t.GetMethod(
                GET_EXTENSION_NAME_METHOD_NAME,
                BindingFlags.Public | BindingFlags.Static);

            if (getNameMethod != null &&
                getNameMethod.ReturnType == typeof(string))
            {
                info.Name = (string)getNameMethod.Invoke(null, null);
            }

            MethodInfo getDescriptionMethod = t.GetMethod(
                GET_DESCRIPTION_METHOD_NAME,
                BindingFlags.Public | BindingFlags.Static);

            if (getDescriptionMethod != null &&
                getDescriptionMethod.ReturnType == typeof(string))
            {
                info.Description = (string)getDescriptionMethod.Invoke(null, null);
            }

            MethodInfo getVersionMethod = t.GetMethod(
                GET_VERSION_METHOD_NAME,
                BindingFlags.Public | BindingFlags.Static);

            if (getVersionMethod != null &&
                getVersionMethod.ReturnType == typeof(string))
            {
                info.Version = (string)getVersionMethod.Invoke(null, null);
            }

            MethodInfo openDocMethod = t.GetMethod(
                OPEN_USER_GUIDE_METHOD_NAME,
                BindingFlags.Public | BindingFlags.Static);

            info.OpenUserGuideMethod = openDocMethod;

            MethodInfo supportMethod = t.GetMethod(
                OPEN_SUPPORT_LINK_METHOD_NAME,
                BindingFlags.Public | BindingFlags.Static);

            info.OpenSupportLinkMethod = supportMethod;

            MethodInfo guiMethod = t.GetMethod(
                GUI_METHOD,
                BindingFlags.Public | BindingFlags.Static);

            info.GuiMethod = guiMethod;

            List <MethodInfo> allMethods = new List <MethodInfo>(t.GetMethods(BindingFlags.Public | BindingFlags.Static));

            info.buttonMethods = allMethods.FindAll(m => m.Name.StartsWith(BUTTON_METHOD_PREFIX));

            return(info);
        }