示例#1
0
        private static List <BuildMethod> GetBuildMethods()
        {
            var ret      = new List <BuildMethod>();
            var assembly = Assembly.Load("Saro.XAsset.Editor");
            var type     = assembly.GetType("Saro.XAsset.BuildMethods");
            var methods  = type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

            foreach (var method in methods)
            {
                var attr = method.GetCustomAttribute <BuildMethodAttribute>();
                if (attr != null)
                {
                    var buildMethod = new BuildMethod()
                    {
                        order       = attr.order,
                        description = attr.description,
                        required    = attr.required,
                        selected    = attr.required,
                        callback    = () =>
                        {
                            if (method.ReturnType == typeof(bool))
                            {
                                return((bool)method.Invoke(null, null));
                            }
                            else
                            {
                                try { method.Invoke(null, null); }
                                catch (Exception e)
                                {
                                    UnityEngine.Debug.LogException(e);
                                    return(false);
                                }
                                return(true);
                            }
                        }
                    };
                    ret.Add(buildMethod);
                }
            }

            ret.Sort((a, b) => a.order.CompareTo(b.order));

            return(ret);
        }
示例#2
0
        void DrawBuildMethod(int index, BuildMethod buildMethod)
        {
            if (buildMethod != null)
            {
                var rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight + 8);
                EditorGUI.HelpBox(rect, string.Empty, MessageType.None);

                var rect1 = rect;
                rect1.y    += 4f;
                rect1.x    += 10f;
                rect1.width = 50f;

                buildMethod.selected = (m_XAssetSettings.buildOptions & (1 << index)) != 0;
                buildMethod.selected = EditorGUI.ToggleLeft(rect1, string.Empty, buildMethod.selected);
                if (buildMethod.selected)
                {
                    m_XAssetSettings.buildOptions |= 1 << index;
                }
                else
                {
                    m_XAssetSettings.buildOptions &= ~(1 << index);
                }

                rect1.x     = 40f;
                rect1.width = 300f;
                EditorGUI.LabelField(rect1, string.Format("[{0:00}] {1}", buildMethod.order, buildMethod.description), buildMethod.required ? s_GUIStyles.style_FontBlodAndItalic : s_GUIStyles.style_FontItalic);
                rect1.x      = rect.width - 40;
                rect1.width  = 40;
                rect1.height = EditorGUIUtility.singleLineHeight;

                if (GUI.Button(rect1, "Run"))
                {
                    ExecuteAction(() =>
                    {
                        if (buildMethod.callback.Invoke() == false)
                        {
                            EditorUtility.DisplayDialog("Failed", string.Format("Execute {0} failed!", buildMethod.description), "OK");
                        }
                    });
                }
            }
        }