예제 #1
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal();
            {
                if (editorScript != null)
                {
                    //GUILayout.BeginVertical();
                    SirenixEditorGUI.BeginBox("脚本", true, GUILayout.Width(220), GUILayout.Height(450));
                    editorScript.OnGUI();
                    SirenixEditorGUI.EndBox();
                    //GUILayout.EndVertical();
                }

                // Layout_DrawLineV(Color.white);

                if (editorAsset != null)
                {
                    SirenixEditorGUI.BeginBox("资源", true, GUILayout.Width(220), GUILayout.Height(450));
                    editorAsset.OnGUI();
                    SirenixEditorGUI.EndBox();
                }

                // Layout_DrawLineV(Color.white);
                if (editorTable != null)
                {
                    SirenixEditorGUI.BeginBox("表格", true, GUILayout.Width(200), GUILayout.Height(450));
                    editorTable.OnGUI();
                    SirenixEditorGUI.EndBox();
                    //Layout_DrawLineV(Color.white);
                }
            }
            GUILayout.EndHorizontal();

            Layout_DrawLineH(Color.white);
            OnGUI_OneKeyExprot();
        }
        protected override void DrawPropertyLayout(GUIContent label)
        {
            // Count the frames.
            if (Event.current.type == EventType.Layout && this.counterEnabled)
            {
                this.counter++;
                GUIHelper.RequestRepaint();
            }

            // Draw the current frame count, and a start stop button.
            SirenixEditorGUI.BeginBox();
            {
                GUILayout.Label("Frame Count: " + this.counter);

                if (GUILayout.Button(this.counterEnabled ? "Stop" : "Start"))
                {
                    this.counterEnabled = !this.counterEnabled;
                }
            }
            SirenixEditorGUI.EndBox();

            // Continue the drawer chain.
            this.CallNextDrawer(label);
        }
예제 #3
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        //var rect = EditorGUI.IndentedRect( EditorGUILayout.GetControlRect(false));
        var rect = EditorGUI.IndentedRect(EditorGUILayout.BeginHorizontal());

        this.header.Draw(rect.width, rect.height, rect.x, rect.y);
        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10f);

        SirenixEditorGUI.Title("红点属性", "", TextAlignment.Left, true);
        EditorGUILayout.PropertyField(this.id, this.idcontent);

        //EditorGUILayout.PropertyField(this.idLayer);

        EditorGUILayout.PropertyField(this.redPoint, this.redPointContent);
        serializedObject.ApplyModifiedProperties();


        EditorGUILayout.Space(20f);
        SirenixEditorGUI.Title("UGUI内置Button属性", "", TextAlignment.Left, true);

        base.OnInspectorGUI();
    }
예제 #4
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, SceneObjectsOnlyAttribute attribute, GUIContent label)
        {
            for (int i = 0; i < entry.Values.Count; i++)
            {
                var val = entry.Values[i];
                if (val != null)
                {
                    if (AssetDatabase.Contains(val))
                    {
                        string name      = val.name;
                        var    component = val as Component;
                        if (component != null)
                        {
                            name = "from " + component.gameObject.name;
                        }

                        SirenixEditorGUI.ErrorMessageBox(val.GetType().GetNiceName() + " " + name + " may not be an asset.");
                        break;
                    }
                }
            }

            this.CallNextDrawer(entry.Property, label);
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var pushLabelWidth = this.Attribute.LabelWidth > 0;

            if (label == null)
            {
                if (pushLabelWidth)
                {
                    GUIHelper.PushLabelWidth(this.Attribute.LabelWidth);
                }

                this.CallNextDrawer(label);
                if (pushLabelWidth)
                {
                    GUIHelper.PopLabelWidth();
                }
            }
            else
            {
                SirenixEditorGUI.BeginVerticalPropertyLayout(label);
                if (pushLabelWidth)
                {
                    GUIHelper.PushLabelWidth(this.Attribute.LabelWidth);
                }
                for (int i = 0; i < this.Property.Children.Count; i++)
                {
                    var child = this.Property.Children[i];
                    child.Draw(child.Label);
                }
                if (pushLabelWidth)
                {
                    GUIHelper.PopLabelWidth();
                }
                SirenixEditorGUI.EndVerticalPropertyLayout();
            }
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var property  = this.Property;
            var attribute = this.Attribute;

            var context = property.Context.Get <TitleContext>(this, "TitleContext", (TitleContext)null);

            if (context.Value == null)
            {
                context.Value                = new TitleContext();
                context.Value.TitleHelper    = new StringMemberHelper(property, attribute.Title, ref context.Value.ErrorMessage);
                context.Value.SubtitleHelper = new StringMemberHelper(property, attribute.Subtitle, ref context.Value.ErrorMessage);
            }

            // Don't draw added emtpy space for the first property.
            if (property != property.Tree.GetRootProperty(0))
            {
                EditorGUILayout.Space();
            }

            if (context.Value.ErrorMessage != null)
            {
                SirenixEditorGUI.ErrorMessageBox(context.Value.ErrorMessage);
            }
            else
            {
                SirenixEditorGUI.Title(
                    context.Value.TitleHelper.GetString(property),
                    context.Value.SubtitleHelper.GetString(property),
                    (TextAlignment)attribute.TitleAlignment,
                    attribute.HorizontalLine,
                    attribute.Bold);
            }

            this.CallNextDrawer(label);
        }
예제 #7
0
파일: OdinEditor.cs 프로젝트: B-CK/P-Lua
        private bool MissingMonoBehaviourGUI()
        {
            this.serializedObject.Update();

            SerializedProperty serializedProperty = this.serializedObject.FindProperty("m_Script");
            bool result;

            if (serializedProperty == null)
            {
                result = false;
            }
            else
            {
                EditorGUILayout.PropertyField(serializedProperty, new GUILayoutOption[0]);
                MonoScript monoScript = serializedProperty.objectReferenceValue as MonoScript;

                bool invalid = true;

                if (monoScript != null)
                {
                    invalid = false;
                }

                if (invalid)
                {
                    SirenixEditorGUI.WarningMessageBox("The associated script can not be loaded.\nPlease fix any compile errors\nand assign a valid script.", true);
                }
                if (this.serializedObject.ApplyModifiedProperties())
                {
                    ActiveEditorTracker.sharedTracker.ForceRebuild();
                }

                result = true;
            }
            return(result);
        }
예제 #8
0
    protected override void OnBeginDrawEditors()
    {
        var selected      = this.MenuTree.Selection.FirstOrDefault();
        var toolbarHeight = this.MenuTree.Config.SearchToolbarHeight;

        // Draws a toolbar with the name of the currently selected menu item.
        SirenixEditorGUI.BeginHorizontalToolbar(toolbarHeight);
        {
            if (selected != null)
            {
                GUILayout.Label(selected.Name);
            }

            if (SirenixEditorGUI.ToolbarButton(new GUIContent("Create Buff Item")))
            {
                ScriptableObjectCreator.ShowDialog <CSBuff>("Assets/Editor/BuffEditor/Buff",
                                                            obj =>
                {
                    base.TrySelectMenuItemWithObject(obj);     // Selects the newly created item in the editor
                });
            }
        }
        SirenixEditorGUI.EndHorizontalToolbar();
    }
예제 #9
0
        private void DrawToolbar()
        {
            if (Event.current.type == EventType.Layout)
            {
                this.toolbarRect        = this.OuterRect;
                this.toolbarRect.height = this.toolbarHeight;
                this.toolbarRect.x     += 1;
                this.toolbarRect.width -= 1;
            }

            //if (Event.current.OnRepaint())
            //{
            //    SirenixEditorGUI.DrawBorders(new Rect(GUILayoutUtility.GetLastRect()) { height = this.toolbarHeight }, 1);
            //}

            SirenixEditorGUI.BeginHorizontalToolbar(this.toolbarHeight);
            foreach (var page in this.OrderedPages)
            {
                if (page.IsActive)
                {
                    if (SirenixEditorGUI.ToolbarTab(page == (this.nextPage ?? this.CurrentPage), page.Title))
                    {
                        this.nextPage = page;
                    }
                }
            }
            SirenixEditorGUI.EndHorizontalToolbar();

            if (Event.current.OnRepaint())
            {
                SirenixEditorGUI.DrawBorders(new Rect(GUILayoutUtility.GetLastRect())
                {
                    height = this.toolbarHeight
                }, 1, 1, 0, 0);
            }
        }
예제 #10
0
        /// <summary>
        /// Draws an enum selector field using the enum selector.
        /// </summary>
        public static T DrawEnumField(GUIContent label, GUIContent contentLabel, T value, GUIStyle style = null)
        {
            int  id;
            bool hasFocus;
            Rect rect;
            Action <EnumSelector <T> > bindSelector;
            Func <IEnumerable <T> >    getResult;

            SirenixEditorGUI.GetFeatureRichControlRect(label, out id, out hasFocus, out rect);

            if (DrawSelectorButton(rect, contentLabel, style ?? EditorStyles.popup, id, out bindSelector, out getResult))
            {
                var selector = new EnumSelector <T>();

                if (!EditorGUI.showMixedValue)
                {
                    selector.SetSelection(value);
                }

                var window = selector.ShowInPopup(new Vector2(rect.xMin, rect.yMax));

                if (isFlagEnum)
                {
                    window.OnClose += selector.SelectionTree.Selection.ConfirmSelection;
                }

                bindSelector(selector);
            }

            if (getResult != null)
            {
                value = getResult().FirstOrDefault();
            }

            return(value);
        }
예제 #11
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            if (GUI.enabled == false)
            {
                this.CallNextDrawer(label);
                return;
            }

            if (this.helper.ErrorMessage != null)
            {
                SirenixEditorGUI.ErrorMessageBox(this.helper.ErrorMessage);
                this.CallNextDrawer(label);
            }
            else if (this.helper.GetValue(this.Attribute.Value))
            {
                GUIHelper.PushGUIEnabled(false);
                this.CallNextDrawer(label);
                GUIHelper.PopGUIEnabled();
            }
            else
            {
                this.CallNextDrawer(label);
            }
        }
예제 #12
0
        public void AddErrorAndWarningIcons()
        {
            var errorCount   = new Dictionary <OdinMenuItem, int>();
            var warningCount = new Dictionary <OdinMenuItem, int>();
            var maxECount    = 0;
            var maxWCount    = 0;

            foreach (var mi in this.EnumerateTree())
            {
                var result = mi.Value as ValidationProfileResult;
                if (result == null || result.Results == null || result.Results.Count == 0)
                {
                    continue;
                }

                var ec = result.Results.Count(x => x.ResultType == ValidationResultType.Error);
                var wc = result.Results.Count(x => x.ResultType == ValidationResultType.Warning);

                foreach (var mm in mi.GetParentMenuItemsRecursive(true))
                {
                    if (!errorCount.ContainsKey(mm))
                    {
                        errorCount[mm] = 0;
                    }
                    if (!warningCount.ContainsKey(mm))
                    {
                        warningCount[mm] = 0;
                    }
                    maxECount = Math.Max(ec, errorCount[mm] += ec);
                    maxWCount = Math.Max(wc, warningCount[mm] += wc);
                }
            }

            var eCountWidth = SirenixGUIStyles.CenteredWhiteMiniLabel.CalcSize(new GUIContent(maxECount + " ")).x;
            var wCountWidth = SirenixGUIStyles.CenteredWhiteMiniLabel.CalcSize(new GUIContent(maxWCount + " ")).x;

            wCountWidth = eCountWidth = Mathf.Max(eCountWidth, wCountWidth);

            foreach (var mi in this.EnumerateTree())
            {
                if (!errorCount.ContainsKey(mi))
                {
                    errorCount[mi] = 0;
                }
                if (!warningCount.ContainsKey(mi))
                {
                    warningCount[mi] = 0;
                }

                var ec  = errorCount[mi];
                var wc  = warningCount[mi];
                var ecl = new GUIContent(ec + "");
                var wcl = new GUIContent(wc + "");
                var ncl = new GUIContent("0");
                //var result = mi.Value as ValidationProfileResult;

                mi.OnDrawItem = (m) =>
                {
                    if (Event.current.type == EventType.Repaint)
                    {
                        var rect = m.Rect.Padding(10, 5);
                        rect.height += 1;
                        var errorRect   = rect.AlignRight(eCountWidth);
                        var warningRect = errorRect.SubX(wCountWidth - 1);
                        warningRect.width = wCountWidth;

                        var hasErrors = ec > 0;
                        if (hasErrors)
                        {
                            //red.a = result == null ? 0.2f : 1;
                            SirenixEditorGUI.DrawSolidRect(errorRect, red);
                            errorRect.y -= 1;
                            errorRect.x += 1;
                            GUI.Label(errorRect, ecl, SirenixGUIStyles.CenteredWhiteMiniLabel);
                        }

                        var hasWarnings = wc > 0;
                        if (hasWarnings)
                        {
                            //orange.a = result == null ? 0.2f : 1;
                            warningRect.x -= 2;
                            SirenixEditorGUI.DrawSolidRect(warningRect, orange);
                            warningRect.y -= 1;
                            warningRect.x += 1;
                            GUI.Label(warningRect, wcl, SirenixGUIStyles.CenteredWhiteMiniLabel);
                        }

                        if (!hasErrors && !hasWarnings)
                        {
                            SirenixEditorGUI.DrawSolidRect(errorRect, green);
                            errorRect.y -= 1;
                            errorRect.x += 1;
                            GUI.Label(errorRect, ncl, SirenixGUIStyles.CenteredWhiteMiniLabel);
                        }
                    }
                };
            }
        }
예제 #13
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var property  = this.Property;
            var attribute = this.Attribute;

            var context = property.Context.Get(this, "Context", (Context)null);

            if (context.Value == null)
            {
                context.Value = new Context();
                if (attribute.Title != null)
                {
                    context.Value.TitleHelper = new StringMemberHelper(property, attribute.Title);
                }

                context.Value.Widths      = new float[property.Children.Count];
                context.Value.MinWidths   = new float[property.Children.Count];
                context.Value.MaxWidths   = new float[property.Children.Count];
                context.Value.LabelWidths = new float[property.Children.Count];
                context.Value.Margins     = new Vector2[property.Children.Count];
                context.Value.Paddings    = new Vector2[property.Children.Count];

                float percentageAllocated = 0;
                for (int i = 0; i < property.Children.Count; i++)
                {
                    var child = property.Children[i];
                    var attr  = child.Children.Recurse()
                                .AppendWith(child)
                                .SelectMany(a => a.GetAttributes <HorizontalGroupAttribute>())
                                .FirstOrDefault(x => x.GroupID == attribute.GroupID);

                    if (attr == null)
                    {
                        context.Value.Widths[i] = -1;
                    }
                    else
                    {
                        context.Value.Widths[i]      = attr.Width;
                        context.Value.MinWidths[i]   = attr.MinWidth;
                        context.Value.MaxWidths[i]   = attr.MaxWidth;
                        context.Value.LabelWidths[i] = attr.LabelWidth;

                        if (attr.Width > 0 && attr.Width < 1)
                        {
                            context.Value.ContainsPercentageWidth++;
                            percentageAllocated += attr.Width;

                            // If we allocate 100% there is no way to resize the window down.
                            // In those cases, we convert the attribute to adjust itself automatically and Unity will ensure that
                            // that it reaches the 100% for us.
                            if (percentageAllocated >= 0.97)
                            {
                                percentageAllocated    -= attr.Width;
                                context.Value.Widths[i] = 0;
                                attr.Width = 0;
                            }
                        }

                        if (attr.MinWidth > 0 && attr.MinWidth <= 1)
                        {
                            context.Value.ContainsPercentageWidth++;

                            percentageAllocated += attr.MinWidth;
                            // Same thing for MinWidth.
                            if (percentageAllocated >= 0.97)
                            {
                                percentageAllocated       -= attr.MinWidth;
                                context.Value.MinWidths[i] = 0;
                                attr.MinWidth = 0;
                            }
                        }

                        context.Value.Margins[i]  = new Vector2(attr.MarginLeft, attr.MarginRight);
                        context.Value.Paddings[i] = new Vector2(attr.PaddingLeft, attr.PaddingRight);
                    }
                }
            }

            if (context.Value.TitleHelper != null)
            {
                if (context.Value.TitleHelper.ErrorMessage != null)
                {
                    SirenixEditorGUI.ErrorMessageBox(context.Value.TitleHelper.ErrorMessage);
                }
                else
                {
                    SirenixEditorGUI.Title(context.Value.TitleHelper.GetString(property), null, TextAlignment.Left, false);
                }
            }

            SirenixEditorGUI.BeginIndentedHorizontal();
            // GUILayout.BeginHorizontal();
            {
                if (attribute.LabelWidth > 0)
                {
                    GUIHelper.PushLabelWidth(attribute.LabelWidth);
                }

                var prevFieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.fieldWidth = 40;

                for (int i = 0; i < property.Children.Count; i++)
                {
                    float   width, minWidth, maxWidth;
                    Vector2 padding, margin;

                    if (context.Value.ContainsPercentageWidth > 1 && context.Value.TotalWidth == 0)
                    {
                        width    = 20; // Start small and expand next frame. Instead of starting to big and slowly getting smaller.
                        minWidth = 0;
                        maxWidth = 0;
                        padding  = new Vector2();
                        margin   = new Vector2();
                    }
                    else
                    {
                        width    = context.Value.Widths[i];
                        minWidth = context.Value.MinWidths[i];
                        maxWidth = context.Value.MaxWidths[i];
                        margin   = context.Value.Margins[i];
                        padding  = context.Value.Paddings[i];

                        if (padding.x > 0 && padding.x <= 1)
                        {
                            padding.x = padding.x * context.Value.TotalWidth;
                        }
                        if (padding.y > 0 && padding.y <= 1)
                        {
                            padding.y = padding.y * context.Value.TotalWidth;
                        }
                        if (margin.x > 0 && margin.x <= 1)
                        {
                            margin.x = margin.x * context.Value.TotalWidth;
                        }
                        if (margin.y > 0 && margin.y <= 1)
                        {
                            margin.y = margin.y * context.Value.TotalWidth;
                        }

                        if (width <= 1)
                        {
                            width = width * context.Value.TotalWidth;
                        }

                        width -= padding.x + padding.y;

                        if (minWidth > 0)
                        {
                            if (minWidth <= 1)
                            {
                                minWidth = minWidth * context.Value.TotalWidth;
                            }
                            minWidth -= padding.x + padding.y;
                        }

                        if (maxWidth > 0)
                        {
                            if (maxWidth <= 1)
                            {
                                maxWidth = maxWidth * context.Value.TotalWidth;
                            }
                            maxWidth -= padding.x + padding.y;
                        }
                    }

                    GUILayoutOptions.GUILayoutOptionsInstance options = null;

                    if (minWidth > 0)
                    {
                        options = GUILayoutOptions.MinWidth(minWidth);
                    }
                    if (maxWidth > 0)
                    {
                        options = options == null?GUILayoutOptions.MaxWidth(maxWidth) : options.MaxWidth(maxWidth);
                    }
                    if (options == null)
                    {
                        options = GUILayoutOptions.Width(width < 0 ? 0 : width);
                    }

                    if ((margin.x + padding.x) != 0)
                    {
                        GUILayout.Space(margin.x + padding.x);
                    }

                    GUILayout.BeginVertical(options);
                    property.Children[i].Draw(property.Children[i].Label);
                    GUILayout.Space(-3);
                    GUILayout.EndVertical();

                    if ((margin.y + padding.y) != 0)
                    {
                        GUILayout.Space(margin.y + padding.y);
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    var newWidth = GUIHelper.GetCurrentLayoutRect().width;

                    if (context.Value.TotalWidth != newWidth)
                    {
                        GUIHelper.RequestRepaint();
                    }

                    context.Value.TotalWidth = newWidth;
                }

                EditorGUIUtility.fieldWidth = prevFieldWidth;
                if (attribute.LabelWidth > 0)
                {
                    GUIHelper.PopLabelWidth();
                }
            }
            // GUILayout.EndHorizontal();
            SirenixEditorGUI.EndIndentedHorizontal();
        }
예제 #14
0
        /// <summary>
        /// Draws the proprety.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var property = this.Property;
            var entry    = property.ValueEntry;

            if (SetAttribute == null || SetFieldInfo == null)
            {
                SirenixEditorGUI.ErrorMessageBox("Could not find the internal Unity fields 'PropertyDrawer.m_Attribute' or 'PropertyDrawer.m_FieldInfo'; UnityPropertyAttributeDrawer alias '" + typeof(UnityPropertyAttributeDrawer <TDrawer, TAttribute, TAttributeConstraint>).GetNiceName() + "' has been disabled.");
                return;
            }

            if (entry == null)
            {
                SirenixEditorGUI.ErrorMessageBox("Cannot put the attribute '" + typeof(TAttribute) + "' on a property of type '" + property.Info.PropertyType + "'.");
                return;
            }

            FieldInfo          fieldInfo;
            SerializedProperty unityProperty = property.Tree.GetUnityPropertyForPath(property.Path, out fieldInfo);

            if (unityProperty == null)
            {
                if (UnityVersion.IsVersionOrGreater(2017, 1))
                {
                    this.CallNextDrawer(label);
                }
                else
                {
                    SirenixEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'.");
                }

                return;
            }

            SetFieldInfo(ref this.drawer, fieldInfo);
            SetAttribute(ref this.drawer, this.Attribute);

            if (unityProperty.serializedObject.targetObject is EmittedScriptableObject)
            {
                var targetObjects = unityProperty.serializedObject.targetObjects;

                for (int i = 0; i < targetObjects.Length; i++)
                {
                    EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i];
                    target.SetWeakValue(entry.WeakValues[i]);
                }

                unityProperty.serializedObject.Update();
                unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath);
            }

            float height;

            if (this.propertyHandler != null)
            {
                height = UnityPropertyHandlerUtility.PropertyHandlerGetHeight(this.propertyHandler, unityProperty.Copy(), label, false);
            }
            else
            {
                height = this.drawer.GetPropertyHeight(unityProperty.Copy(), label);
            }

            Rect position = EditorGUILayout.GetControlRect(false, height);

            if (this.propertyHandler != null)
            {
                UnityPropertyHandlerUtility.PropertyHandlerOnGUI(this.propertyHandler, position, unityProperty, label, false);
            }
            else
            {
                this.drawer.OnGUI(position, unityProperty, label);
            }

            if (unityProperty.serializedObject.targetObject is EmittedScriptableObject)
            {
                unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo();
                var targetObjects = unityProperty.serializedObject.targetObjects;

                for (int i = 0; i < targetObjects.Length; i++)
                {
                    EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i];
                    entry.WeakValues[i] = target.GetWeakValue();
                }
            }
        }
예제 #15
0
 private void EndBox()
 {
     SirenixEditorGUI.EndBox();
 }
예제 #16
0
 private void DrawIntroInfoBox()
 {
     SirenixEditorGUI.InfoMessageBox("Out of the box, Odin significantly upgrades the drawing of lists and arrays in the inspector - across the board, without you ever lifting a finger.");
 }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, InfoBoxAttribute attribute, GUIContent label)
        {
            PropertyContext <InfoBoxContext> context = null;

            context = property.Context.Get(this, "Config_" + this.GetHashCode(), (InfoBoxContext)null);
            if (context.Value == null)
            {
                context.Value = new InfoBoxContext()
                {
                    MessageHelper = new StringMemberHelper(property.ParentType, attribute.Message)
                };

                context.Value.ErrorMessage = context.Value.MessageHelper.ErrorMessage;

                MemberInfo memberInfo;

                if (attribute.VisibleIf != null)
                {
                    // Parameter functions
                    if (property.ValueEntry != null &&
                        property.ParentType.FindMember()
                        .IsMethod()
                        .HasReturnType <bool>()
                        .HasParameters(property.ValueEntry.BaseValueType)
                        .IsNamed(attribute.VisibleIf)
                        .TryGetMember(out memberInfo, out context.Value.ErrorMessage))
                    {
                        if (context.Value.ErrorMessage == null)
                        {
                            if (memberInfo is MethodInfo)
                            {
                                if (memberInfo.IsStatic())
                                {
                                    context.Value.StaticValidationParameterMethod = memberInfo as MethodInfo;
                                }
                                else
                                {
                                    context.Value.InstanceValidationParameterMethod = memberInfo as MethodInfo;
                                }
                            }
                            else
                            {
                                context.Value.ErrorMessage = "Invalid member type!";
                            }
                        }
                    }
                    // Fields, properties, and no-parameter functions.
                    else if (property.ParentType.FindMember()
                             .HasReturnType <bool>()
                             .HasNoParameters()
                             .IsNamed(attribute.VisibleIf)
                             .TryGetMember(out memberInfo, out context.Value.ErrorMessage))
                    {
                        if (context.Value.ErrorMessage == null)
                        {
                            if (memberInfo is FieldInfo)
                            {
                                if (memberInfo.IsStatic())
                                {
                                    context.Value.StaticValidationCaller = EmitUtilities.CreateStaticFieldGetter <bool>(memberInfo as FieldInfo);
                                }
                                else
                                {
                                    context.Value.InstanceValueGetter = EmitUtilities.CreateWeakInstanceFieldGetter(property.ParentType, memberInfo as FieldInfo);
                                }
                            }
                            else if (memberInfo is PropertyInfo)
                            {
                                if (memberInfo.IsStatic())
                                {
                                    context.Value.StaticValidationCaller = EmitUtilities.CreateStaticPropertyGetter <bool>(memberInfo as PropertyInfo);
                                }
                                else
                                {
                                    context.Value.InstanceValueGetter = EmitUtilities.CreateWeakInstancePropertyGetter(property.ParentType, memberInfo as PropertyInfo);
                                }
                            }
                            else if (memberInfo is MethodInfo)
                            {
                                if (memberInfo.IsStatic())
                                {
                                    context.Value.StaticValidationCaller = (Func <bool>)Delegate.CreateDelegate(typeof(Func <bool>), memberInfo as MethodInfo);
                                }
                                else
                                {
                                    context.Value.InstanceValidationMethodCaller = EmitUtilities.CreateWeakInstanceMethodCallerFunc <bool>(memberInfo as MethodInfo);
                                }
                            }
                            else
                            {
                                context.Value.ErrorMessage = "Invalid member type!";
                            }
                        }
                    }
                }
            }

            if (context.Value.ErrorMessage != null)
            {
                SirenixEditorGUI.ErrorMessageBox(context.Value.ErrorMessage);
            }
            else
            {
                if (Event.current.type == EventType.Layout)
                {
                    var parentValue = property.ParentValues[0];

                    try
                    {
                        context.Value.DrawMessageBox =
                            attribute.VisibleIf == null ||
                            (context.Value.StaticValidationParameterMethod != null && (bool)context.Value.StaticValidationParameterMethod.Invoke(null, new object[] { property.ValueEntry.WeakSmartValue })) ||
                            (context.Value.InstanceValidationParameterMethod != null && (bool)context.Value.InstanceValidationParameterMethod.Invoke(null, new object[] { property.ParentValues[0], property.ValueEntry.WeakSmartValue })) ||
                            (context.Value.InstanceValidationMethodCaller != null && context.Value.InstanceValidationMethodCaller(property.ParentValues[0])) ||
                            (context.Value.InstanceValueGetter != null && (bool)context.Value.InstanceValueGetter(ref parentValue)) ||
                            (context.Value.StaticValidationCaller != null && context.Value.StaticValidationCaller());
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogException(ex);
                    }
                }

                if (context.Value.DrawMessageBox)
                {
                    switch (attribute.InfoMessageType)
                    {
                    case InfoMessageType.None:
                        SirenixEditorGUI.MessageBox(context.Value.MessageHelper.GetString(property));
                        break;

                    case InfoMessageType.Info:
                        SirenixEditorGUI.InfoMessageBox(context.Value.MessageHelper.GetString(property));
                        break;

                    case InfoMessageType.Warning:
                        SirenixEditorGUI.WarningMessageBox(context.Value.MessageHelper.GetString(property));
                        break;

                    case InfoMessageType.Error:
                        SirenixEditorGUI.ErrorMessageBox(context.Value.MessageHelper.GetString(property));
                        break;

                    default:
                        SirenixEditorGUI.ErrorMessageBox("Unknown InfoBoxType: " + attribute.InfoMessageType.ToString());
                        break;
                    }
                }
            }

            this.CallNextDrawer(property, label);
        }
예제 #18
0
        private void OnGUI()
        {
            if (this.behaviourValidationInfos == null)
            {
                this.FullScan();
            }

            if (Event.current.type == EventType.Layout)
            {
                if (this.validationInfoToSelect != null)
                {
                    this.selectedValidationInfo = this.validationInfoToSelect;
                    this.validationInfoToSelect = null;
                }
            }

            this.DrawToolbar();

            EditorGUILayout.BeginHorizontal();
            {
                var rect = EditorGUILayout.BeginVertical(GUILayoutOptions.Width(300 + this.offsetLeftSide));
                {
                    this.scrollLeftSide = EditorGUILayout.BeginScrollView(this.scrollLeftSide);
                    this.DrawHierachy();
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                {
                    SirenixEditorGUI.DrawSolidRect(GUIHelper.GetCurrentLayoutRect(), SirenixGUIStyles.DarkEditorBackground);
                    this.scrollRightRightSide = EditorGUILayout.BeginScrollView(this.scrollRightRightSide);
                    this.DrawPropertyTree();
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();

                rect.xMin = rect.xMax - 4;
                rect.x   += 4;
                SirenixEditorGUI.DrawSolidRect(rect, SirenixGUIStyles.BorderColor);
                rect.xMin          -= 2;
                rect.xMax          += 2;
                this.offsetLeftSide = this.offsetLeftSide + SirenixEditorGUI.SlideRect(rect).x;
            }
            EditorGUILayout.EndHorizontal();

            if (this.isScanning && (Event.current.type == EventType.Repaint))
            {
                this.warningCount = 0;
                this.errorCount   = 0;
                this.validCount   = 0;

                for (int i = 0; i < this.behaviourValidationInfos.Count; i++)
                {
                    var o = this.behaviourValidationInfos[i];
                    if (o.ErrorCount == 0 && o.WarningCount == 0)
                    {
                        this.validCount++;
                    }
                    this.errorCount   += o.ErrorCount;
                    this.warningCount += o.WarningCount;
                }
                this.behaviourValidationInfos = this.behaviourValidationInfos.OrderByDescending(x => x.ErrorCount).ThenByDescending(x => x.WarningCount).ThenBy(x => x.Name).ToList();
                this.isScanning = false;
            }
            else if (this.triggerScan && Event.current.type == EventType.Repaint)
            {
                this.isScanning  = true;
                this.triggerScan = false;
                this.Repaint();
            }

            this.RepaintIfRequested();
        }
예제 #19
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry     = this.ValueEntry;
            var attribute = this.Attribute;

            SirenixEditorGUI.BeginIndentedHorizontal();
            {
                var hideLabel = label == null;
                if (hideLabel == false)
                {
                    GUILayout.Label(label, GUILayoutOptions.Width(GUIHelper.BetterLabelWidth - 4).ExpandWidth(false));
                }
                else
                {
                    GUILayout.Space(5);
                }

                //var colorPaletDropDown = entry.Context.Get(this, "colorPalette", 0);
                //var currentName = entry.Context.Get(this, "currentName", attribute.PaletteName);
                //var showAlpha = entry.Context.Get(this, "showAlpha", attribute.ShowAlpha);
                //var names = ColorPaletteManager.Instance.GetColorPaletteNames();

                ColorPalette colorPalette;
                var          rect = EditorGUILayout.BeginHorizontal();
                {
                    rect.x    -= 3;
                    rect.width = 25;

                    entry.SmartValue = SirenixEditorGUI.DrawColorField(rect, entry.SmartValue, false, this.ShowAlpha);
                    bool openInEditorShown = false;
                    GUILayout.Space(28);
                    SirenixEditorGUI.BeginInlineBox();
                    {
                        if (attribute.PaletteName == null || ColorPaletteManager.Instance.ShowPaletteName)
                        {
                            SirenixEditorGUI.BeginToolbarBoxHeader();
                            {
                                if (attribute.PaletteName == null)
                                {
                                    var newValue = EditorGUILayout.Popup(this.PaletteIndex, this.Names, GUILayoutOptions.ExpandWidth(true));
                                    if (this.PaletteIndex != newValue)
                                    {
                                        this.PaletteIndex         = newValue;
                                        this.CurrentName          = this.Names[newValue];
                                        this.PersistentName.Value = this.CurrentName;
                                        GUIHelper.RemoveFocusControl();
                                    }
                                }
                                else
                                {
                                    GUILayout.Label(this.CurrentName);
                                    GUILayout.FlexibleSpace();
                                }
                                openInEditorShown = true;
                                if (SirenixEditorGUI.IconButton(EditorIcons.SettingsCog))
                                {
                                    ColorPaletteManager.Instance.OpenInEditor();
                                }
                            }
                            SirenixEditorGUI.EndToolbarBoxHeader();
                        }

                        if (attribute.PaletteName == null)
                        {
                            colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == this.Names[this.PaletteIndex]);
                        }
                        else
                        {
                            colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == this.NameGetter.GetString(entry));
                        }

                        if (colorPalette == null)
                        {
                            GUILayout.BeginHorizontal();
                            {
                                if (attribute.PaletteName != null)
                                {
                                    if (GUILayout.Button("Create color palette: " + this.NameGetter.GetString(entry)))
                                    {
                                        ColorPaletteManager.Instance.ColorPalettes.Add(new ColorPalette()
                                        {
                                            Name = this.NameGetter.GetString(entry)
                                        });
                                        ColorPaletteManager.Instance.OpenInEditor();
                                    }
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        else
                        {
                            this.CurrentName = colorPalette.Name;
                            this.ShowAlpha   = attribute.ShowAlpha && colorPalette.ShowAlpha;
                            if (openInEditorShown == false)
                            {
                                GUILayout.BeginHorizontal();
                            }
                            var color   = entry.SmartValue;
                            var stretch = ColorPaletteManager.Instance.StretchPalette;
                            var size    = ColorPaletteManager.Instance.SwatchSize;
                            var margin  = ColorPaletteManager.Instance.SwatchSpacing;
                            if (DrawColorPaletteColorPicker(entry, colorPalette, ref color, colorPalette.ShowAlpha, stretch, size, 20, margin))
                            {
                                entry.SmartValue = color;
                                //entry.ApplyChanges();
                            }
                            if (openInEditorShown == false)
                            {
                                GUILayout.Space(4);
                                if (SirenixEditorGUI.IconButton(EditorIcons.SettingsCog))
                                {
                                    ColorPaletteManager.Instance.OpenInEditor();
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    SirenixEditorGUI.EndInlineBox();
                }
                EditorGUILayout.EndHorizontal();
            }

            SirenixEditorGUI.EndIndentedHorizontal();
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TDrawnType> entry, GUIContent label)
        {
            if (SetFieldInfo == null)
            {
                SirenixEditorGUI.ErrorMessageBox("Could not find the internal Unity field 'PropertyDrawer.m_FieldInfo'; UnityPropertyDrawer alias '" + typeof(UnityPropertyDrawer <TDrawer, TDrawnType>).GetNiceName() + "' has been disabled.");
                return;
            }

            FieldInfo          fieldInfo;
            SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo);

            if (unityProperty == null)
            {
                if (UnityVersion.IsVersionOrGreater(2017, 1))
                {
                    this.CallNextDrawer(entry, label);
                }
                else
                {
                    SirenixEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'.");
                }

                return;
            }

            SetFieldInfo(ref this.drawer, fieldInfo);

            if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <TDrawnType> )
            {
                var targetObjects = unityProperty.serializedObject.targetObjects;

                for (int i = 0; i < targetObjects.Length; i++)
                {
                    EmittedScriptableObject <TDrawnType> target = (EmittedScriptableObject <TDrawnType>)targetObjects[i];
                    target.SetValue(entry.Values[i]);
                }

                unityProperty.serializedObject.Update();
            }
            else if (unityProperty.serializedObject.targetObject is EmittedScriptableObject)
            {
                var targetObjects = unityProperty.serializedObject.targetObjects;

                for (int i = 0; i < targetObjects.Length; i++)
                {
                    EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i];
                    target.SetWeakValue(entry.Values[i]);
                }

                unityProperty.serializedObject.Update();
                unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath);
            }

            float height   = this.drawer.GetPropertyHeight(unityProperty, label);
            Rect  position = EditorGUILayout.GetControlRect(false, height);

            EditorGUI.BeginChangeCheck();

            if (this.propertyHandler != null)
            {
                UnityPropertyHandlerUtility.PropertyHandlerOnGUI(this.propertyHandler, position, unityProperty, label, false);
            }
            else
            {
                this.drawer.OnGUI(position, unityProperty, label);
            }

            bool changed = EditorGUI.EndChangeCheck();

            if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <TDrawnType> )
            {
                if (unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo() || changed)
                {
                    var targetObjects = unityProperty.serializedObject.targetObjects;

                    for (int i = 0; i < targetObjects.Length; i++)
                    {
                        EmittedScriptableObject <TDrawnType> target = (EmittedScriptableObject <TDrawnType>)targetObjects[i];
                        entry.Values[i] = target.GetValue();
                    }

                    entry.Values.ForceMarkDirty();
                }
            }
            else if (unityProperty.serializedObject.targetObject is EmittedScriptableObject)
            {
                if (unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo() || changed)
                {
                    var targetObjects = unityProperty.serializedObject.targetObjects;

                    for (int i = 0; i < targetObjects.Length; i++)
                    {
                        EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i];
                        entry.Values[i] = (TDrawnType)target.GetWeakValue();
                    }

                    entry.Values.ForceMarkDirty();
                }
            }
        }
예제 #21
0
        private void DrawColumnHeaders()
        {
            var columnsRect = GUILayoutUtility.GetRect(0, this.Tree.Config.DefaultMenuStyle.Height, GUILayoutOptions.ExpandWidth(true));

            EditorGUI.DrawRect(columnsRect, SirenixGUIStyles.DarkEditorBackground);

            //SirenixGUIStyles.Temporary.Draw(columnsRect, GUIContent.none, 0);

            int   columnIndex = 0;
            float currentX    = columnsRect.xMin;

            for (int i = 0; i < AllDisplayOptions.Length; i++)
            {
                var option = AllDisplayOptions[i];

                if ((this.Display & option) == option)
                {
                    var width = this.columns[columnIndex].ColWidth;
                    var rect  = new Rect(currentX, columnsRect.yMin + 3, width - 0.5f, columnsRect.height);

                    rect.xMax = Math.Min(rect.xMax, columnsRect.xMax);

                    if (rect.width <= 0)
                    {
                        break;
                    }

                    var labelText = option == DisplayOptions.Category ? "" : option.ToString();

                    if (GUI.Button(rect, GUIHelper.TempContent(labelText), SirenixGUIStyles.BoldLabel))
                    {
                        if (this.SortBy == option)
                        {
                            this.SortAscending = !this.SortAscending;
                        }
                        else
                        {
                            this.SortBy        = option;
                            this.SortAscending = false;
                        }

                        this.shouldSort = true;
                    }

                    var        iconRect = rect.AlignRight(rect.height).Padding(3).SubY(3);
                    EditorIcon icon;

                    if (this.SortBy != option)
                    {
                        icon = EditorIcons.TriangleRight;
                        GUIHelper.PushColor(GUI.color * 0.7f);
                    }
                    else
                    {
                        icon = this.SortAscending ? EditorIcons.TriangleUp : EditorIcons.TriangleDown;
                    }

                    icon.Draw(iconRect);

                    if (this.SortBy != option)
                    {
                        GUIHelper.PopColor();
                    }

                    currentX += width;
                    columnIndex++;
                }
            }

            SirenixEditorGUI.DrawHorizontalLineSeperator(columnsRect.xMin, columnsRect.yMax, columnsRect.width, 0.5f);
        }
예제 #22
0
 private void EndDrawListElement(int index)
 {
     SirenixEditorGUI.EndBox();
 }
예제 #23
0
 private void BeginDrawListElement(int index)
 {
     SirenixEditorGUI.BeginBox(this.InjectListElementGUI[index].SomeString);
 }
예제 #24
0
            public void DrawMenu()
            {
                if (this.GameObject == null)
                {
                    return;
                }

                if (!this.IsIncluded)
                {
                    return;
                }

                GUIHelper.PushGUIEnabled(GUI.enabled && this.ErrorCount + this.WarningCount > 0);

                var rect = SirenixEditorGUI.BeginListItem(true);

                {
                    if (Event.current.rawType == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
                    {
                        if (this.IsSelected || this.Behaviour == null)
                        {
                            EditorGUIUtility.PingObject(this.GameObject);
                        }

                        this.Select();
                        GUIHelper.RequestRepaint();
                    }

                    if (this.IsSelected)
                    {
                        GUIHelper.PushGUIEnabled(true);
                        SirenixEditorGUI.DrawSolidRect(rect, SirenixGUIStyles.MenuButtonActiveBgColor);
                        GUIHelper.PushLabelColor(Color.white);
                        EditorGUILayout.LabelField(this.Name);
                        GUIHelper.PopLabelColor();
                        GUIHelper.PopGUIEnabled();
                    }
                    else
                    {
                        EditorGUILayout.LabelField(this.Name);
                    }
                    rect    = new Rect(rect.position, new Vector2(20, 20));
                    rect.x += 6;

                    const float offAlpha = 0.1f;
                    var         tmpColor = GUI.color;
                    GUI.color = this.WarningCount > 0 ? Color.white : new Color(1, 1, 1, offAlpha);
                    //GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                    GUI.DrawTexture(rect, EditorIcons.UnityWarningIcon);

                    rect.x   += 20;
                    GUI.color = this.ErrorCount > 0 ? Color.white : new Color(1, 1, 1, offAlpha);
                    GUI.DrawTexture(rect, EditorIcons.UnityErrorIcon);

                    if (this.IsIncluded && this.ErrorCount == 0 && this.WarningCount == 0)
                    {
                        rect.x   -= 10;
                        GUI.color = (this.ErrorCount + this.WarningCount) == 0 ? Color.green : new Color(0, 1, 0, offAlpha);
                        GUI.DrawTexture(rect, EditorIcons.Checkmark.Highlighted);
                    }
                    //GL.sRGBWrite = false;

                    GUI.color = tmpColor;
                }
                SirenixEditorGUI.EndListItem();

                GUIHelper.PopGUIEnabled();
            }
예제 #25
0
            public void DrawPropertyTree()
            {
                if (this.GameObject == null)
                {
                    return;
                }

                if (this.window.isScanning && Event.current.type == EventType.Repaint)
                {
                    OdinInspectorValidationChecker.BeginValidationCheck();
                }

                GUILayout.BeginVertical(new GUIStyle()
                {
                    padding = new RectOffset(10, 10, 6, 10)
                });
                {
                    if (this.propertyTree != null)
                    {
                        if (this.window.isScanning)
                        {
                            InspectorUtilities.BeginDrawPropertyTree(this.propertyTree, true);

                            foreach (var property in this.propertyTree.EnumerateTree(true))
                            {
                                try
                                {
                                    InspectorUtilities.DrawProperty(property);
                                }
                                catch (System.Exception ex)
                                {
                                    if (ex is ExitGUIException || ex.InnerException is ExitGUIException)
                                    {
                                        throw ex;
                                    }
                                    else
                                    {
                                        Debug.Log("The following exception was thrown when drawing property " + property.Path + ".");
                                        Debug.LogException(ex);
                                    }
                                }
                            }

                            InspectorUtilities.EndDrawPropertyTree(this.propertyTree);
                        }
                        else
                        {
                            this.propertyTree.Draw(true);
                        }
                    }
                    else
                    {
                        SirenixEditorGUI.ErrorMessageBox("Missing Reference.");
                    }
                }
                GUILayout.EndVertical();

                if (this.window.isScanning && Event.current.type == EventType.Repaint)
                {
                    // We can't count the correct the correct number of warnings and errors for each behavior
                    // until we have a proper way of drawing a property tree with the guarantee that every property will be drawn.
                    this.WarningCount = OdinInspectorValidationChecker.WarningMessages.Count();
                    this.ErrorCount   = OdinInspectorValidationChecker.ErrorMessages.Count();

                    OdinInspectorValidationChecker.EndValidationCheck();
                }
            }
예제 #26
0
        private void DrawToolbar(GUIContent label)
        {
            const int iconBtnSize = 23;
            var       rect        = GUILayoutUtility.GetRect(0, 22);
            var       isRepaint   = Event.current.type == EventType.Repaint;

            // Background
            if (isRepaint)
            {
                SirenixGUIStyles.ToolbarBackground.Draw(rect, GUIContent.none, 0);
            }

            // Add
            if (!this.isReadOnly)
            {
                var btnRect = rect.AlignRight(iconBtnSize);
                btnRect.width -= 1;
                rect.xMax      = btnRect.xMin;
                if (GUI.Button(btnRect, GUIContent.none, SirenixGUIStyles.ToolbarButton))
                {
                    this.picker.ShowObjectPicker(
                        null,
                        this.Property.GetAttribute <AssetsOnlyAttribute>() == null && !typeof(ScriptableObject).IsAssignableFrom(this.resolver.ElementType),
                        rect,
                        this.Property.ValueEntry.SerializationBackend == SerializationBackend.Unity);
                }
                EditorIcons.Plus.Draw(btnRect, 16);
            }

            // Draw as list toggle
            if (!this.isReadOnly)
            {
                var btnRect = rect.AlignRight(iconBtnSize);
                rect.xMax = btnRect.xMin;
                if (GUI.Button(btnRect, GUIContent.none, SirenixGUIStyles.ToolbarButton))
                {
                    this.drawAsList = !this.drawAsList;
                }

                EditorIcons.HamburgerMenu.Draw(btnRect, 13);
            }

            // Paging
            this.paging.DrawToolbarPagingButtons(ref rect, this.isVisible.Value, true);

            // Label
            if (label != null)
            {
                var labelRect = rect;
                labelRect.x     += 5;
                labelRect.y     += 3;
                labelRect.height = 16;
                if (this.Property.Children.Count > 0)
                {
                    GUIHelper.PushHierarchyMode(false);
                    if (this.Attribute.AlwaysExpanded)
                    {
                        GUI.Label(labelRect, label);
                    }
                    else
                    {
                        this.isVisible.Value = SirenixEditorGUI.Foldout(labelRect, this.isVisible.Value, label);
                    }
                    GUIHelper.PushHierarchyMode(true);
                }
                else if (isRepaint)
                {
                    GUI.Label(labelRect, label);
                }
            }
        }
예제 #27
0
        private void DrawDropdown()
        {
            IEnumerable <object> newResult = null;

            //if (this.Attribute.InlineSelector)
            //{
            //    bool recreateBecauseOfListChange = false;

            //    if (Event.current.type == EventType.Layout)
            //    {
            //        var _newCol = this.rawGetter.GetValue();
            //        if (_newCol != this.rawPrevGettedValue)
            //        {
            //            this.ReloadDropdownCollections();
            //            recreateBecauseOfListChange = true;
            //        }

            //        var iList = _newCol as IList;
            //        if (iList != null)
            //        {
            //            if (iList.Count != this.rawPrevGettedValueCount)
            //            {
            //                this.ReloadDropdownCollections();
            //                recreateBecauseOfListChange = true;
            //            }

            //            this.rawPrevGettedValueCount = iList.Count;
            //        }

            //        this.rawPrevGettedValue = _newCol;
            //    }

            //    if (this.inlineSelector == null || recreateBecauseOfListChange)
            //    {
            //        this.inlineSelector = this.CreateSelector();
            //        this.inlineSelector.SelectionChanged += (x) =>
            //        {
            //            this.nextResult = x;
            //        };
            //    }

            //    this.inlineSelector.OnInspectorGUI();

            //    if (this.nextResult != null)
            //    {
            //        newResult = this.nextResult;
            //        this.nextResult = null;
            //    }
            //}
            //else if (this.Attribute.AppendNextDrawer && !this.isList)
            if (this.Attribute.AppendNextDrawer && !this.isList)
            {
                GUILayout.BeginHorizontal();
                {
                    var width = 15f;
                    if (this.label != null)
                    {
                        width += GUIHelper.BetterLabelWidth;
                    }

                    newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, GUIContent.none, this.ShowSelector, GUIStyle.none, GUILayoutOptions.Width(width));

                    if (Event.current.type == EventType.Repaint)
                    {
                        var btnRect = GUILayoutUtility.GetLastRect().AlignRight(15);
                        btnRect.y += 4;
                        SirenixGUIStyles.PaneOptions.Draw(btnRect, GUIContent.none, 0);
                    }

                    GUILayout.BeginVertical();
                    bool disable = this.Attribute.DisableGUIInAppendedDrawer;
                    if (disable)
                    {
                        GUIHelper.PushGUIEnabled(false);
                    }
                    this.CallNextDrawer(null);
                    if (disable)
                    {
                        GUIHelper.PopGUIEnabled();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                string valueName = GetCurrentValueName();

                if (this.Attribute.HideChildProperties == false && this.Property.Children.Count > 0)
                {
                    Rect valRect;
                    this.isToggled.Value = SirenixEditorGUI.Foldout(this.isToggled.Value, this.label, out valRect);
                    newResult            = GenericSelector <object> .DrawSelectorDropdown(valRect, valueName, this.ShowSelector);

                    if (SirenixEditorGUI.BeginFadeGroup(this, this.isToggled.Value))
                    {
                        EditorGUI.indentLevel++;
                        for (int i = 0; i < this.Property.Children.Count; i++)
                        {
                            var child = this.Property.Children[i];
                            child.Draw(child.Label);
                        }
                        EditorGUI.indentLevel--;
                    }
                    SirenixEditorGUI.EndFadeGroup();
                }
                else
                {
                    newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, valueName, this.ShowSelector);
                }
            }

            if (newResult != null && newResult.Any())
            {
                this.AddResult(newResult);
            }
        }
예제 #28
0
파일: ActionWindow.cs 프로젝트: B-CK/P-Lua
        void OnGUI()
        {
            if (EditorApplication.isCompiling)
            {
                Debug.Log("[行为窗口]脚本正在编译,所以自动关闭窗口!");
                Close();
                return;
            }

            SirenixEditorGUI.BeginBox();
            {
                SirenixEditorGUI.BeginBoxHeader();
                GUILayout.Label(_selfModelEditor.ModelName, _nameStyle);
                SirenixEditorGUI.EndBoxHeader();
                switch (_modelAction.ActState)
                {
                case ModelActionEditor.ActionState.New:
                    _actionName = EditorGUILayout.TextField("动作行为", _actionName);
                    break;

                case ModelActionEditor.ActionState.Inherit:
                case ModelActionEditor.ActionState.Override:
                    GUILayout.Label("动作行为");
                    GUILayout.Label(_actionName, EditorStyles.textField, GUILayout.Width(EditorGUIUtility.fieldWidth));
                    break;
                }

                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Label("动画来源", GUILayout.Width(145));
                    if (GUILayout.Button("自己", _isFromOther ? SirenixGUIStyles.ButtonLeft : SirenixGUIStyles.ButtonLeftSelected))
                    {
                        _clipIndex   = -1;
                        _isFromOther = false;
                        _otherModel  = string.Empty;
                        _actClipList = _selfModelEditor.GetActionClips();
                    }
                    if (GUILayout.Button("其他", _isFromOther ? SirenixGUIStyles.ButtonRightSelected : SirenixGUIStyles.ButtonRight))
                    {
                        _isFromOther = true;
                        _clipIndex   = -1;
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (_isFromOther)
                {
                    GUIHelper.PushGUIEnabled(!string.IsNullOrEmpty(_otherModel));
                }
                EditorGUILayout.BeginHorizontal();
                {
                    _clipIndex = EditorGUILayout.Popup("动画文件", _clipIndex, _actClipList);
                    if (GUILayout.Button("X", GUILayout.Width(20), GUILayout.Height(EditorGUIUtility.singleLineHeight)))
                    {
                        _clipIndex = -1;
                    }
                }
                EditorGUILayout.EndHorizontal();
                if (_isFromOther)
                {
                    GUIHelper.PopGUIEnabled();
                }

                if (_isFromOther)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        GUIHelper.PushColor(_color);
                        GUILayout.Label("其他角色", SirenixGUIStyles.BoldLabel, GUILayout.Width(147));
                        GUILayout.Label(_otherModel, EditorStyles.textField);
                        if (GUILayout.Button("修改", GUILayout.Width(45)))
                        {
                            var list = HomeConfigPreview.Instance.GetAllModelList();
                            list.Remove(_selfModelEditor.ModelName);
                            SimplePopupCreator.ShowDialog(list, (name) =>
                            {
                                _otherModel       = name;
                                _otherModelEditor = HomeConfigPreview.Instance.GetModelEditor(name);
                                _actClipList      = _otherModelEditor.GetActionClips();
                            });
                        }
                        if (GUILayout.Button("X", GUILayout.Width(20), GUILayout.Height(EditorGUIUtility.singleLineHeight)))
                        {
                            _otherModel = string.Empty;
                        }
                        GUIHelper.PopColor();
                    }
                    EditorGUILayout.EndHorizontal();
                }

                GUILayout.FlexibleSpace();
                EditorGUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("修改行为", GUILayout.Height(50)))
                    {
                        _modelAction.ActionName  = _actionName;
                        _modelAction.IsFromOther = _isFromOther;
                        bool hasClip = !(_clipIndex < 0 || _actClipList.Length == 0);
                        _modelAction.ActionClip     = hasClip ? _actClipList[_clipIndex] : string.Empty;
                        _modelAction.OtherModelName = _otherModel;

                        bool hasSame = false;
                        if (!_modelAction.IsSkillAction)
                        {
                            foreach (var item in _selfModelEditor.ModelActions)
                            {
                                if (item.ActionName.Equals(_actionName))
                                {
                                    hasSame = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            foreach (var item in _selfModelEditor.SkillActions)
                            {
                                if (item.ActionName.Equals(_actionName))
                                {
                                    hasSame = true;
                                    break;
                                }
                            }
                        }
                        if (!hasSame)
                        {
                            if (_result != null)
                            {
                                _result(_modelAction);
                            }
                            Close();
                        }
                        else
                        {
                            EditorUtility.DisplayDialog("动作配置错误", "动作名重复,请重新配置!!!", "确定");
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndHorizontal();
        }
예제 #29
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry     = this.ValueEntry;
            var attribute = this.Attribute;

            var config = entry.Property.Context.Get(this, "Test", (CurrentContext)null);

            if (config.Value == null)
            {
                config.Value           = new CurrentContext();
                config.Value.Attribute = attribute;
                config.Value.Tags      = attribute.Tags != null?attribute.Tags.Trim().Split(',').Select(i => i.Trim()).ToArray() : null;

                config.Value.LayerNames = attribute.LayerNames != null?attribute.LayerNames.Trim().Split(',').Select(i => i.Trim()).ToArray() : null;

                config.Value.Property = entry.Property;
                if (attribute.Path != null)
                {
                    var path = attribute.Path.Trim('/', ' ');
                    path = "Assets/" + path + "/";
                    path = Application.dataPath + "/" + path;

                    config.Value.AssetsFolderLocation = new DirectoryInfo(path);

                    path = attribute.Path.TrimStart('/').TrimEnd('/');
                    config.Value.PrettyPath = "/" + path.TrimStart('/');
                }

                if (attribute.CustomFilterMethod != null)
                {
                    MethodInfo methodInfo;
                    string     error;
                    if (MemberFinder.Start(entry.ParentType)
                        .IsMethod()
                        .IsNamed(attribute.CustomFilterMethod)
                        .HasReturnType <bool>()
                        .HasParameters <TElement>()
                        .TryGetMember <MethodInfo>(out methodInfo, out error))
                    {
                        if (methodInfo.IsStatic)
                        {
                            config.Value.StaticCustomIncludeMethod = (Func <TElement, bool>)Delegate.CreateDelegate(typeof(Func <TElement, bool>), methodInfo, true);
                        }
                        else
                        {
                            config.Value.InstanceCustomIncludeMethod = EmitUtilities.CreateWeakInstanceMethodCaller <bool, TElement>(methodInfo);
                        }
                    }

                    config.Value.ErrorMessage = error;
                }

                if (config.Value.ErrorMessage != null)
                {
                    // We can get away with lag on load.
                    config.Value.MaxSearchDurationPrFrameInMS = 20;
                    config.Value.EnsureListPopulation();
                    config.Value.MaxSearchDurationPrFrameInMS = 1;
                }
            }

            var currentValue = (UnityEngine.Object)entry.WeakSmartValue;

            if (config.Value.ErrorMessage != null)
            {
                SirenixEditorGUI.ErrorMessageBox(config.Value.ErrorMessage);
            }
            else
            {
                config.Value.EnsureListPopulation();
            }

            SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            {
                SirenixEditorGUI.BeginHorizontalToolbar();
                if (label != null)
                {
                    GUILayout.Label(label);
                }

                GUILayout.FlexibleSpace();
                if (config.Value.PrettyPath != null)
                {
                    GUILayout.Label(config.Value.PrettyPath, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    SirenixEditorGUI.VerticalLineSeparator();
                }

                if (config.Value.IsPopulated)
                {
                    GUILayout.Label(config.Value.AvailableAsset.Count + " items", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    GUIHelper.PushGUIEnabled(GUI.enabled && (config.Value.AvailableAsset.Count > 0 && config.Value.ErrorMessage == null));
                }
                else
                {
                    GUILayout.Label("Scanning " + config.Value.CurrentSearchingIndex + " / " + config.Value.NumberOfResultsToSearch, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    GUIHelper.PushGUIEnabled(false);
                }

                SirenixEditorGUI.VerticalLineSeparator();

                bool drawConflict = entry.Property.ParentValues.Count > 1;
                if (drawConflict == false)
                {
                    var index = config.Value.AvailableAsset.IndexOf(currentValue) + 1;
                    if (index > 0)
                    {
                        GUILayout.Label(index.ToString(), SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    }
                    else
                    {
                        drawConflict = true;
                    }
                }

                if (drawConflict)
                {
                    GUILayout.Label("-", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                }

                if (SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleLeft) && config.Value.IsPopulated)
                {
                    var index = config.Value.AvailableAsset.IndexOf(currentValue) - 1;
                    index = index < 0 ? config.Value.AvailableAsset.Count - 1 : index;
                    entry.WeakSmartValue = config.Value.AvailableAsset[index];
                }

                if (SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleDown) && config.Value.IsPopulated)
                {
                    GenericMenu m            = new GenericMenu();
                    var         selected     = currentValue;
                    int         itemsPrPage  = 40;
                    bool        showPages    = config.Value.AvailableAsset.Count > 50;
                    string      page         = "";
                    int         selectedPage = (config.Value.AvailableAsset.IndexOf(entry.WeakSmartValue as UnityEngine.Object) / itemsPrPage);
                    for (int i = 0; i < config.Value.AvailableAsset.Count; i++)
                    {
                        var obj = config.Value.AvailableAsset[i];
                        if (obj != null)
                        {
                            var path       = AssetDatabase.GetAssetPath(obj);
                            var name       = string.IsNullOrEmpty(path) ? obj.name : path.Substring(7).Replace("/", "\\");
                            var localEntry = entry;

                            if (showPages)
                            {
                                var p = (i / itemsPrPage);
                                page = (p * itemsPrPage) + " - " + Mathf.Min(((p + 1) * itemsPrPage), config.Value.AvailableAsset.Count - 1);
                                if (selectedPage == p)
                                {
                                    page += " (contains selected)";
                                }
                                page += "/";
                            }

                            m.AddItem(new GUIContent(page + name), obj == selected, () =>
                            {
                                localEntry.Property.Tree.DelayActionUntilRepaint(() => localEntry.WeakSmartValue = obj);
                            });
                        }
                    }
                    m.ShowAsContext();
                }

                if (SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleRight) && config.Value.IsPopulated)
                {
                    var index = config.Value.AvailableAsset.IndexOf(currentValue) + 1;
                    entry.WeakSmartValue = config.Value.AvailableAsset[index % config.Value.AvailableAsset.Count];
                }

                GUIHelper.PopGUIEnabled();

                SirenixEditorGUI.EndHorizontalToolbar();
                SirenixEditorGUI.BeginVerticalList();
                SirenixEditorGUI.BeginListItem(false, padding);
                this.CallNextDrawer(null);
                SirenixEditorGUI.EndListItem();
                SirenixEditorGUI.EndVerticalList();
            }
            SirenixEditorGUI.EndIndentedVertical();
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            if (this.errorMessage != null)
            {
                SirenixEditorGUI.ErrorMessageBox(this.errorMessage);
            }
            else
            {
                if (Event.current.type == EventType.Layout)
                {
                    try
                    {
                        var entry = this.Property.ValueEntry;
                        if (entry != null)
                        {
                            var parentValue = entry.Property.ParentValues[0];
                            this.drawMessageBox =
                                this.Attribute.VisibleIf == null ||
                                (this.staticValidationParameterMethodCaller != null && this.staticValidationParameterMethodCaller(entry.WeakSmartValue)) ||
                                (this.instanceValidationParameterMethodCaller != null && this.instanceValidationParameterMethodCaller(entry.Property.ParentValues[0], entry.WeakSmartValue)) ||
                                (this.instanceValidationMethodCaller != null && this.instanceValidationMethodCaller(entry.Property.ParentValues[0])) ||
                                (this.instanceValueGetter != null && (bool)this.instanceValueGetter(ref parentValue)) ||
                                (this.staticValidationCaller != null && this.staticValidationCaller());
                        }
                        else
                        {
                            this.drawMessageBox = true;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogException(ex);
                    }
                }

                if (this.drawMessageBox)
                {
                    UnityEditor.MessageType type = UnityEditor.MessageType.None;

                    switch (this.Attribute.InfoMessageType)
                    {
                    case InfoMessageType.None:
                        type = UnityEditor.MessageType.None;
                        break;

                    case InfoMessageType.Info:
                        type = UnityEditor.MessageType.Info;
                        break;

                    case InfoMessageType.Warning:
                        type = UnityEditor.MessageType.Warning;
                        break;

                    case InfoMessageType.Error:
                        type = UnityEditor.MessageType.Error;
                        break;

                    default:
                        SirenixEditorGUI.ErrorMessageBox("Unknown InfoBoxType: " + this.Attribute.InfoMessageType.ToString());
                        break;
                    }

                    this.hideDetailedMessage = SirenixEditorGUI.DetailedMessageBox(this.messageHelper.GetString(this.Property), this.detailsHelper.GetString(this.Property), type, this.hideDetailedMessage);
                }
            }

            this.CallNextDrawer(label);
        }