コード例 #1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TList> entry, GUIContent label)
        {
            var property = entry.Property;
            int minCount = int.MaxValue;
            int maxCount = 0;

            PropertyContext <bool> isVisible;

            if (entry.Context.Get(this, "is_visible", out isVisible))
            {
                isVisible.Value = GeneralDrawerConfig.Instance.OpenListsByDefault;
            }

            for (int i = 0; i < entry.ValueCount; i++)
            {
                if (entry.Values[i].Count > maxCount)
                {
                    maxCount = entry.Values[i].Count;
                }

                if (entry.Values[i].Count < minCount)
                {
                    minCount = entry.Values[i].Count;
                }
            }

            AllEditorGUI.BeginHorizontalToolbar();
            isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, GUIHelper.TempContent("SyncList " + label.text + "  [" + typeof(TList).Name + "]"));
            EditorGUILayout.LabelField(GUIHelper.TempContent(minCount == maxCount ? (minCount == 0 ? "Empty" : minCount + " items") : minCount + " (" + maxCount + ") items"), SirenixGUIStyles.RightAlignedGreyMiniLabel);
            AllEditorGUI.EndHorizontalToolbar();

            if (AllEditorGUI.BeginFadeGroup(isVisible, isVisible.Value))
            {
                GUIHelper.PushGUIEnabled(false);
                AllEditorGUI.BeginVerticalList();
                {
                    var elementLabel = new GUIContent();
                    for (int i = 0; i < maxCount; i++)
                    {
                        AllEditorGUI.BeginListItem();
                        elementLabel.text = "Item " + i;

                        if (i < minCount)
                        {
                            InspectorUtilities.DrawProperty(property.Children[i], elementLabel);
                        }
                        else
                        {
                            EditorGUILayout.LabelField(elementLabel, "—");
                        }
                        AllEditorGUI.EndListItem();
                    }
                }
                AllEditorGUI.EndVerticalList();
                GUIHelper.PopGUIEnabled();
            }
            AllEditorGUI.EndFadeGroup();
        }
コード例 #2
0
 private void DrawHierachy()
 {
     if (this.behaviourValidationInfos != null)
     {
         AllEditorGUI.BeginVerticalList();
         for (int i = 0; i < this.behaviourValidationInfos.Count; i++)
         {
             this.behaviourValidationInfos[i].DrawMenu();
         }
         AllEditorGUI.EndVerticalList();
     }
 }
コード例 #3
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TElement> entry, AssetListAttribute attribute, GUIContent label)
        {
            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)
            {
                AllEditorGUI.ErrorMessageBox(config.Value.ErrorMessage);
            }
            else
            {
                config.Value.EnsureListPopulation();
            }

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

                GUILayout.FlexibleSpace();
                if (config.Value.PrettyPath != null)
                {
                    GUILayout.Label(config.Value.PrettyPath, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    AllEditorGUI.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);
                }

                AllEditorGUI.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 (AllEditorGUI.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 (AllEditorGUI.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 (AllEditorGUI.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();

                AllEditorGUI.EndHorizontalToolbar();
                AllEditorGUI.BeginVerticalList();
                AllEditorGUI.BeginListItem(false, padding);
                this.CallNextDrawer(entry.Property, null);
                AllEditorGUI.EndListItem();
                AllEditorGUI.EndVerticalList();
            }
            AllEditorGUI.EndIndentedVertical();
        }
コード例 #4
0
        private void DrawItems(ListDrawerConfigInfo info)
        {
            int  from   = 0;
            int  to     = info.Count;
            bool paging = info.CustomListDrawerOptions.PagingHasValue ? info.CustomListDrawerOptions.ShowPaging : true;

            if (paging && info.ShowAllWhilePageing == false)
            {
                from = Mathf.Clamp(info.StartIndex, 0, info.Count);
                to   = Mathf.Clamp(info.EndIndex, 0, info.Count);
            }

            var   drawEmptySpace = info.DropZone.IsBeingHovered || info.IsDroppingUnityObjects;
            float height         = drawEmptySpace ? info.IsDroppingUnityObjects ? 16 : (DragAndDropManager.CurrentDraggingHandle.Rect.height - 3) : 0;
            var   rect           = AllEditorGUI.BeginVerticalList();

            {
                for (int i = 0, j = from, k = from; j < to; i++, j++)
                {
                    var dragHandle = this.BeginDragHandle(info, j, i);
                    {
                        if (drawEmptySpace)
                        {
                            var topHalf = dragHandle.Rect;
                            topHalf.height /= 2;
                            if (topHalf.Contains(info.LayoutMousePosition) || topHalf.y > info.LayoutMousePosition.y && i == 0)
                            {
                                GUILayout.Space(height);
                                drawEmptySpace = false;
                                info.InsertAt  = k;
                            }
                        }

                        if (dragHandle.IsDragging == false)
                        {
                            k++;
                            this.DrawItem(info, info.property.Children[j], dragHandle, j);
                        }
                        else
                        {
                            GUILayout.Space(3);
                            ListDrawerStaticInfo.DelayedGUIDrawer.Begin(dragHandle.Rect.width, dragHandle.Rect.height, dragHandle.CurrentMethod != DragAndDropMethods.Move);
                            DragAndDropManager.AllowDrop = false;
                            this.DrawItem(info, info.property.Children[j], dragHandle, j);
                            DragAndDropManager.AllowDrop = true;
                            ListDrawerStaticInfo.DelayedGUIDrawer.End();
                            if (dragHandle.CurrentMethod != DragAndDropMethods.Move)
                            {
                                GUILayout.Space(3);
                            }
                        }

                        if (drawEmptySpace)
                        {
                            var bottomHalf = dragHandle.Rect;
                            bottomHalf.height /= 2;
                            bottomHalf.y      += bottomHalf.height;

                            if (bottomHalf.Contains(info.LayoutMousePosition) || bottomHalf.yMax < info.LayoutMousePosition.y && j + 1 == to)
                            {
                                GUILayout.Space(height);
                                drawEmptySpace = false;
                                info.InsertAt  = Mathf.Min(k, to);
                            }
                        }
                    }
                    this.EndDragHandle(info, i);
                }

                if (drawEmptySpace)
                {
                    GUILayout.Space(height);
                    info.InsertAt = Event.current.mousePosition.y > rect.center.y ? to : from;
                }

                if (to == info.property.Children.Count && info.property.ValueEntry.ValueState == PropertyValueState.CollectionLengthConflict)
                {
                    AllEditorGUI.BeginListItem(false);
                    GUILayout.Label(GUIHelper.TempContent("------"), EditorStyles.centeredGreyMiniLabel);
                    AllEditorGUI.EndListItem();
                }
            }
            AllEditorGUI.EndVerticalList();

            if (Event.current.type == EventType.Repaint)
            {
                info.LayoutMousePosition = Event.current.mousePosition;
            }
        }
コード例 #5
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TDictionary> entry, GUIContent label)
        {
            var context = entry.Property.Context.Get(this, "context", (Context)null);

            if (context.Value == null)
            {
                context.Value                = new Context();
                context.Value.Toggled        = entry.Context.GetPersistent(this, "Toggled", GeneralDrawerConfig.Instance.OpenListsByDefault);
                context.Value.KeyWidthOffset = 130;
                context.Value.Label          = label ?? new GUIContent(typeof(TDictionary).GetNiceName());
                context.Value.AttrSettings   = entry.Property.Info.GetAttribute <DictionaryDrawerSettings>() ?? new DictionaryDrawerSettings();
                context.Value.DisableAddKey  = entry.Property.Tree.HasPrefabs && !entry.GetDictionaryHandler().SupportsPrefabModifications;

                if (!context.Value.DisableAddKey)
                {
                    context.Value.TempKeyValue = new TempKeyValue();

                    var tree = PropertyTree.Create(context.Value.TempKeyValue);
                    tree.UpdateTree();

                    context.Value.TempKeyEntry   = (IPropertyValueEntry <TKey>)tree.GetPropertyAtPath("Key").ValueEntry;
                    context.Value.TempValueEntry = (IPropertyValueEntry <TValue>)tree.GetPropertyAtPath("Value").ValueEntry;
                }
            }

            context.Value.DictionaryHandler           = (DictionaryHandler <TDictionary, TKey, TValue>)entry.GetDictionaryHandler();
            context.Value.Config                      = GeneralDrawerConfig.Instance;
            context.Value.Paging.NumberOfItemsPerPage = context.Value.Config.NumberOfItemsPrPage;
            context.Value.ListItemStyle.padding.right = !entry.IsEditable || context.Value.AttrSettings.IsReadOnly ? 4 : 20;

            //if (!IsSupportedKeyType)
            //{
            //    var message = entry.Property.Context.Get(this, "error_message", (string)null);
            //    var detailedMessage = entry.Property.Context.Get(this, "error_message_detailed", (string)null);
            //    var folded = entry.Property.Context.Get(this, "error_message_folded", true);

            //    if (message.Value == null)
            //    {
            //        string str = "";

            //        if (label != null)
            //        {
            //            str += label.text + "\n\n";
            //        }

            //        str += "The dictionary key type '" + typeof(TKey).GetNiceFullName() + "' is not supported in prefab instances. Expand this box to see which key types are supported.";

            //        message.Value = str;
            //    }

            //    if (detailedMessage.Value == null)
            //    {
            //        var sb = new StringBuilder("The following key types are supported:");

            //        sb.AppendLine()
            //          .AppendLine();

            //        foreach (var type in DictionaryKeyUtility.GetPersistentPathKeyTypes())
            //        {
            //            sb.AppendLine(type.GetNiceName());
            //        }

            //        sb.AppendLine("Enums of any type");

            //        detailedMessage.Value = sb.ToString();
            //    }

            //    folded.Value = AllEditorGUI.DetailedMessageBox(message.Value, detailedMessage.Value, MessageType.Error, folded.Value);

            //    return;
            //}

            AllEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            {
                context.Value.Paging.Update(elementCount: entry.Property.Children.Count);
                this.DrawToolbar(entry, context.Value);
                context.Value.Paging.Update(elementCount: entry.Property.Children.Count);

                if (!context.Value.DisableAddKey && context.Value.AttrSettings.IsReadOnly == false)
                {
                    this.DrawAddKey(entry, context.Value);
                }

                float t;
                GUIHelper.BeginLayoutMeasuring();
                if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), context.Value.Toggled.Value, out t))
                {
                    var rect = AllEditorGUI.BeginVerticalList(false);
                    if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine)
                    {
                        var maxWidth = rect.width - 90;
                        rect.xMin = context.Value.KeyWidthOffset + 22;
                        rect.xMax = rect.xMin + 10;
                        context.Value.KeyWidthOffset = context.Value.KeyWidthOffset + AllEditorGUI.SlideRect(rect).x;

                        if (Event.current.type == EventType.Repaint)
                        {
                            context.Value.KeyWidthOffset = Mathf.Clamp(context.Value.KeyWidthOffset, 90, maxWidth);
                        }

                        if (context.Value.Paging.ElementCount != 0)
                        {
                            var headerRect = AllEditorGUI.BeginListItem(false);
                            {
                                GUILayout.Space(14);
                                if (Event.current.type == EventType.Repaint)
                                {
                                    GUI.Label(headerRect.SetWidth(context.Value.KeyWidthOffset), context.Value.AttrSettings.KeyLabel, SirenixGUIStyles.LabelCentered);
                                    GUI.Label(headerRect.AddXMin(context.Value.KeyWidthOffset), context.Value.AttrSettings.ValueLabel, SirenixGUIStyles.LabelCentered);
                                    AllEditorGUI.DrawSolidRect(headerRect.AlignBottom(1), SirenixGUIStyles.BorderColor);
                                }
                            }
                            AllEditorGUI.EndListItem();
                        }
                    }

                    this.DrawElements(entry, label, context.Value);
                    AllEditorGUI.EndVerticalList();
                }
                AllEditorGUI.EndFadeGroup();

                // Draw borders
                var outerRect = GUIHelper.EndLayoutMeasuring();
                if (t > 0.01f && Event.current.type == EventType.Repaint)
                {
                    Color col = SirenixGUIStyles.BorderColor;
                    outerRect.yMin -= 1;
                    AllEditorGUI.DrawBorders(outerRect, 1, col);
                    col.a *= t;
                    if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine)
                    {
                        // Draw Slide Rect Border
                        outerRect.width = 1;
                        outerRect.x    += context.Value.KeyWidthOffset + 13;
                        AllEditorGUI.DrawSolidRect(outerRect, col);
                    }
                }
            }
            AllEditorGUI.EndIndentedVertical();
        }
コード例 #6
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <InspectorTypeDrawingConfig> entry, GUIContent label)
        {
            var searchLabel = entry.Context.Get(this, "searchLabel", (GUIContent)null);
            var searchText  = entry.Context.Get(this, "searchText", "");
            var displayType = entry.Context.Get(this, "displayType", DisplayType.AllUnityObjects);
            var scrollPos   = entry.Context.Get(this, "scrollPos", Vector2.zero);

            //var autoRecompileOnChangesDetected = entry.Property.Tree.GetPropertyAtPath("autoRecompileOnChangesDetected").ValueEntry as IPropertyValueEntry<bool>;

            //var defaultEditorBehaviour = entry.Property.Tree.GetPropertyAtPath("defaultEditorBehaviour").ValueEntry as PropertyValueEntry<InspectorDefaultEditorBehaviour>;
            //var processMouseMoveInInspector = entry.Property.Tree.GetPropertyAtPath("processMouseMoveInInspector").ValueEntry as PropertyValueEntry<bool>;

            if (searchLabel.Value == null)
            {
                searchLabel.Value = new GUIContent("Filter");
            }

            //GUILayout.BeginHorizontal();

            ////const string autoRecompileString = " Rebuild editors automatically when changes are detected";

            ////if (autoRecompileOnChangesDetected.SmartValue)
            ////{
            ////    autoRecompileOnChangesDetected.SmartValue = GUILayout.Toggle(autoRecompileOnChangesDetected.SmartValue, autoRecompileString);
            ////}
            ////else
            ////{
            ////    GUILayout.BeginVertical();
            ////    {
            ////        autoRecompileOnChangesDetected.SmartValue = GUILayout.Toggle(autoRecompileOnChangesDetected.SmartValue, autoRecompileString);
            ////        AllEditorGUI.WarningMessageBox("Note that with automatic rebuilding disabled, you may get error messages from Unity on startup, stating that inspected types have gone missing. While annoying, this is expected behaviour, and can be safely ignored.");
            ////    }
            ////    GUILayout.EndVertical();
            ////}

            //GUILayout.FlexibleSpace();

            //if (GUILayout.Button("Update Editors"))
            //{
            //    //AssetDatabase.SaveAssets();
            //    //AssetDatabase.Refresh();
            //    //EditorApplication.delayCall += () => EditorCompilation.CompileEditors(GetEditors());

            //    InspectorConfig.Instance.UpdateOdinEditors();
            //}
            ////if (GUILayout.Button("Recompile Editors"))
            ////{
            ////    AssetDatabase.SaveAssets();
            ////    AssetDatabase.Refresh();
            ////    EditorApplication.delayCall += () => EditorCompilation.CompileEditors(GetEditors());
            ////}
            //GUILayout.EndHorizontal();
            //GUILayout.Space(10);

            AllEditorGUI.BeginHorizontalToolbar();
            GUILayout.Label("Draw ODIN for", GUILayoutOptions.ExpandWidth(false));
            GUILayout.FlexibleSpace();
            AllEditorGUI.VerticalLineSeparator();

            GUI.changed      = false;
            searchText.Value = AllEditorGUI.ToolbarSearchField(searchText.Value, true);
            if (GUI.changed)
            {
                UpdateRootGroupsSearch(searchText.Value, displayType.Value);
            }

            if (AllEditorGUI.ToolbarButton(new GUIContent(" Reset to default ")))
            {
                var asset = InspectorConfig.Instance;

                if (EditorUtility.DisplayDialog("Reset " + asset.name + " to default", "Are you sure you want to reset all settings on " + asset.name + " to default values? This cannot be undone.", "Yes", "No"))
                {
                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(asset));
                    AssetDatabase.Refresh();
                    UnityEngine.Object.DestroyImmediate(asset);
                }
            }
            AllEditorGUI.EndHorizontalToolbar();
            AllEditorGUI.BeginVerticalList(true, false, GUILayoutOptions.ExpandHeight(false));
            {
                scrollPos.Value = EditorGUILayout.BeginScrollView(scrollPos.Value, GUILayoutOptions.ExpandWidth(true));
                {
                    DrawRootTypeGroup(InspectorDefaultEditors.UserTypes, entry, searchText.Value);
                    DrawRootTypeGroup(InspectorDefaultEditors.PluginTypes, entry, searchText.Value);
                    DrawRootTypeGroup(InspectorDefaultEditors.UnityTypes, entry, searchText.Value);
                    DrawRootTypeGroup(InspectorDefaultEditors.OtherTypes, entry, searchText.Value);
                }
                EditorGUILayout.EndScrollView();
            }
            AllEditorGUI.EndVerticalList();
        }