public override void OnInspectorGUI()
        {
            this.serializedObject.Update();
            EditorGUILayout.PropertyField(this.editorComment);
            this.serializedObject.ApplyModifiedProperties();

            base.OnInspectorGUI();

            if (this.targets.Length == 1)
            {
                var target = (DataConfigTemplate)this.target;
                if (target.usedIn.Count > 0)
                {
                    GUILayoutExt.Separator(6f);
                    GUILayoutExt.DrawHeader("Used by Configs:");
                    GUILayoutExt.Separator();

                    var rect        = new Rect(0f, 0f, EditorGUIUtility.currentViewWidth, 1000f);
                    var style       = new GUIStyle("AssetLabel Partial");
                    var buttonRects = EditorGUIUtility.GetFlowLayoutedRects(rect, style, 4f, 4f, target.usedIn.Select(x => {
                        var config = x;
                        if (config == null)
                        {
                            return(string.Empty);
                        }

                        return(config.name);
                    }).ToList());
                    GUILayout.BeginHorizontal();
                    GUILayout.EndHorizontal();
                    var areaRect = GUILayoutUtility.GetLastRect();
                    for (int i = 0; i < buttonRects.Count; ++i)
                    {
                        areaRect.height = Mathf.Max(0f, buttonRects[i].yMax);
                    }

                    GUILayoutUtility.GetRect(areaRect.width, areaRect.height);

                    GUI.BeginGroup(areaRect);
                    for (int i = 0; i < target.usedIn.Count; ++i)
                    {
                        var config = target.usedIn[i];
                        if (config == null)
                        {
                            continue;
                        }

                        if (GUI.Button(buttonRects[i], config.name, style) == true)
                        {
                            EditorGUIUtility.PingObject(config);
                        }
                    }

                    GUI.EndGroup();
                }
            }
        }
        private static void DrawFieldsFlowLayout(GUIContent label, dynamic target, Rect rect)
        {
            Type type = Assembly.GetAssembly(typeof(BehaviorTreeElement)).GetType(target.ElementType);

            FieldInfo[] fields = type.GetFields();

            var items = new List <string>();

            foreach (FieldInfo field in fields)
            {
                items.Add(field.Name);
            }

            var style = EditorStyles.objectField;

            style.stretchWidth = false;
            style.fixedWidth   = EditorGUIUtility.fieldWidth + EditorGUIUtility.labelWidth + 4;

            var boxes = EditorGUIUtility.GetFlowLayoutedRects(rect, style, 4, 4, items);

            for (int i = 0; i < items.Count; ++i)
            {
                using (new GUILayout.AreaScope(boxes[i], "", EditorStyles.boldLabel))
                {
                    //EditorGUILayout.LabelField(items[i]);
                    if (fields[i].FieldType == typeof(int))
                    {
                        fields[i].SetValue(target, EditorGUILayout.IntField(
                                               MakeLabel(fields[i]), (int)fields[i].GetValue(target)));
                    }
                    else if (fields[i].FieldType == typeof(float))
                    {
                        fields[i].SetValue(target, EditorGUILayout.FloatField(
                                               MakeLabel(fields[i]), (float)fields[i].GetValue(target)));
                    }
                    else if (fields[i].FieldType == typeof(string))
                    {
                        fields[i].SetValue(target, EditorGUILayout.TextField(
                                               MakeLabel(fields[i]), (string)fields[i].GetValue(target)));
                    }
                    else
                    {
                        Debug.LogError(
                            "DrawFields does not support fields of type " +
                            fields[i].FieldType);
                    }
                }
            }
        }
示例#3
0
        protected override void OnToolbarGUI(Rect r)
        {
            base.OnToolbarGUI(r);

            List <string> buttonLabels = new List <string>()
            {
                "Atlas",
                "Normal",
                "Flipbook",
                "",
                "A"
            };
            List <Rect> buttonRects = EditorGUIUtility.GetFlowLayoutedRects(r, EditorStyles.toolbarButton, 0, 0, buttonLabels);

            for (int i = 0; i < 3; ++i)
            {
                if (GUI.Button(buttonRects[i], buttonLabels[i], EditorStyles.toolbarButton))
                {
                    mode = (GBillboardRenderMode)i;
                    RenderPreview();
                }
                if (i == (int)mode)
                {
                    Color highlightColor = EditorGUIUtility.isProSkin ? new Color(1, 1, 1, 0.1f) : new Color(1, 1, 1, 0.3f);
                    EditorGUI.DrawRect(buttonRects[i], highlightColor);
                }
            }

            if (GUI.Button(buttonRects[4], buttonLabels[4], EditorStyles.toolbarButton))
            {
                alphaBlend = !alphaBlend;
            }
            if (alphaBlend)
            {
                Color highlightColor = EditorGUIUtility.isProSkin ? new Color(1, 1, 1, 0.1f) : new Color(1, 1, 1, 0.3f);
                EditorGUI.DrawRect(buttonRects[4], highlightColor);
            }

            Rect saveButtonRect = new Rect(
                r.max.x - 100 - 2,
                r.min.y,
                100,
                r.height);

            if (GUI.Button(saveButtonRect, "Save", EditorStyles.toolbarButton))
            {
                SaveAssets();
            }
        }
示例#4
0
 public static List <Rect> GetFlowLayoutedRects(Rect rect, GUIStyle style, float horizontalSpacing, float verticalSpacing, List <string> items)
 {
     return(EditorGUIUtility.GetFlowLayoutedRects(rect, style, horizontalSpacing, verticalSpacing, items));
 }
示例#5
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;
        }
示例#6
0
        private void DrawTemplates(ME.ECS.DataConfigs.DataConfig dataConfig)
        {
            GUILayoutExt.Separator(6f);
            GUILayoutExt.DrawHeader("Used Templates:");
            GUILayoutExt.Separator();

            var usedComponents = new System.Collections.Generic.HashSet <ME.ECS.DataConfigs.DataConfigTemplate>();

            if (dataConfig.templates != null)
            {
                var rect        = new Rect(0f, 0f, EditorGUIUtility.currentViewWidth, 1000f);
                var style       = new GUIStyle("AssetLabel Partial");
                var buttonRects = EditorGUIUtility.GetFlowLayoutedRects(rect, style, 4f, 4f, dataConfig.templates.Select(x => {
                    var guid = x;
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        return(string.Empty);
                    }

                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    if (string.IsNullOrEmpty(path) == true)
                    {
                        return(string.Empty);
                    }

                    var template = AssetDatabase.LoadAssetAtPath <ME.ECS.DataConfigs.DataConfigTemplate>(path);
                    if (template == null)
                    {
                        return(string.Empty);
                    }

                    return(template.name);
                }).ToList());
                GUILayout.BeginHorizontal();
                GUILayout.EndHorizontal();
                var areaRect = GUILayoutUtility.GetLastRect();
                for (int i = 0; i < buttonRects.Count; ++i)
                {
                    areaRect.height = Mathf.Max(0f, buttonRects[i].yMax);
                }

                GUILayoutUtility.GetRect(areaRect.width, areaRect.height);

                GUI.BeginGroup(areaRect);
                for (int i = 0; i < dataConfig.templates.Length; ++i)
                {
                    var guid = dataConfig.templates[i];
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        continue;
                    }

                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    if (string.IsNullOrEmpty(path) == true)
                    {
                        continue;
                    }

                    var template = AssetDatabase.LoadAssetAtPath <ME.ECS.DataConfigs.DataConfigTemplate>(path);
                    if (template == null)
                    {
                        continue;
                    }

                    if (usedComponents.Contains(template) == false)
                    {
                        usedComponents.Add(template);
                    }
                }

                for (int i = 0; i < dataConfig.templates.Length; ++i)
                {
                    var guid = dataConfig.templates[i];
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        continue;
                    }

                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    if (string.IsNullOrEmpty(path) == true)
                    {
                        continue;
                    }

                    var template = AssetDatabase.LoadAssetAtPath <ME.ECS.DataConfigs.DataConfigTemplate>(path);
                    if (template == null)
                    {
                        continue;
                    }

                    if (GUI.Button(buttonRects[i], template.name, style) == true)
                    {
                        EditorGUIUtility.PingObject(template);
                        //this.RemoveTemplate(dataConfig, template, usedComponents);
                    }
                }
                GUI.EndGroup();
            }

            GUILayoutExt.DrawManageDataConfigTemplateMenu(usedComponents, (template, isUsed) => {
                var path = AssetDatabase.GetAssetPath(template);
                var guid = AssetDatabase.AssetPathToGUID(path);
                if (string.IsNullOrEmpty(guid) == true)
                {
                    return;
                }

                if (isUsed == true)
                {
                    usedComponents.Remove(template);
                    for (int i = 0; i < dataConfig.templates.Length; ++i)
                    {
                        if (dataConfig.templates[i] == guid)
                        {
                            this.RemoveTemplate(dataConfig, template, usedComponents);
                            break;
                        }
                    }
                }
                else
                {
                    usedComponents.Add(template);
                    if (dataConfig.templates == null)
                    {
                        dataConfig.templates = new string[0];
                    }
                    System.Array.Resize(ref dataConfig.templates, dataConfig.templates.Length + 1);
                    dataConfig.templates[dataConfig.templates.Length - 1] = guid;
                    dataConfig.AddTemplate(template);
                    dataConfig.OnScriptLoad();
                    this.Save(dataConfig);
                    AssetDatabase.ForceReserializeAssets(new [] { AssetDatabase.GetAssetPath(dataConfig) }, ForceReserializeAssetsOptions.ReserializeAssetsAndMetadata);
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(dataConfig), ImportAssetOptions.ForceUpdate);
                    AssetDatabase.SaveAssets();
                }
            });
        }
        protected override void OnToolbarGUI(Rect r)
        {
            base.OnToolbarGUI(r);
            List <string> channelButtonLabels = new List <string>()
            {
                "RGB",
                "R",
                "G",
                "B",
                "A"
            };
            List <int> channelValue = new List <int>()
            {
                PREVIEW_RGB,
                PREVIEW_R,
                PREVIEW_G,
                PREVIEW_B,
                PREVIEW_A
            };

            List <Rect> channelButtonRects = EditorGUIUtility.GetFlowLayoutedRects(r, EditorStyles.toolbarButton, 0, 0, channelButtonLabels);

            for (int i = 0; i < channelButtonLabels.Count; ++i)
            {
                if (GUI.Button(channelButtonRects[i], channelButtonLabels[i], EditorStyles.toolbarButton))
                {
                    previewMode = channelValue[i];
                }
                if (previewMode == channelValue[i])
                {
                    Color highlightColor = EditorGUIUtility.isProSkin ? new Color(1, 1, 1, 0.1f) : new Color(1, 1, 1, 0.3f);
                    EditorGUI.DrawRect(channelButtonRects[i], highlightColor);
                }
            }

            List <string> filterButtonLabels = new List <string>()
            {
                "==============",
                "Point",
                "Bilinear"
            };
            List <int> filterValue = new List <int>()
            {
                0,
                FILTER_POINT,
                FILTER_BILINEAR
            };

            List <Rect> filterButtonRects = EditorGUIUtility.GetFlowLayoutedRects(r, EditorStyles.toolbarButton, 0, 0, filterButtonLabels);

            for (int i = 1; i < filterButtonLabels.Count; ++i)
            {
                if (GUI.Button(filterButtonRects[i], filterButtonLabels[i], EditorStyles.toolbarButton))
                {
                    filterMode = filterValue[i];
                }
                if (filterMode == filterValue[i])
                {
                    Color highlightColor = EditorGUIUtility.isProSkin ? new Color(1, 1, 1, 0.1f) : new Color(1, 1, 1, 0.3f);
                    EditorGUI.DrawRect(filterButtonRects[i], highlightColor);
                }
            }

            Rect saveButtonRect = new Rect(
                r.max.x - 100 - 2,
                r.min.y,
                100,
                r.height);

            if (GUI.Button(saveButtonRect, "Save", EditorStyles.toolbarButton))
            {
                SaveAsset();
            }
        }