コード例 #1
0
        public void OnGUI(Rect position, GUIContent label, bool showLabels, ref float y)
        {
            if (parent.chooseType)
            {
                var x = position.x;
                var remainingWidth = position.width;

                if (showLabels)
                {
                    var typeLabel = label == GUIContent.none ? new GUIContent("Type") : new GUIContent(label.text + " Type");

                    var typeLabelPosition = new Rect
                                            (
                        x,
                        y,
                        SystemObjectInspector.Styles.labelWidth,
                        EditorGUIUtility.singleLineHeight
                                            );

                    GUI.Label(typeLabelPosition, typeLabel, Inspector.ProcessLabelStyle(parent.metadata, null));

                    x += typeLabelPosition.width;
                    remainingWidth -= typeLabelPosition.width;
                }

                var typePosition = new Rect
                                   (
                    x,
                    y,
                    remainingWidth,
                    EditorGUIUtility.singleLineHeight
                                   );

                EditorGUI.BeginChangeCheck();

                var newType = LudiqGUI.TypeField(typePosition, GUIContent.none, parent.type, GetTypeOptions, new GUIContent("(Null)"));

                if (EditorGUI.EndChangeCheck())
                {
                    parent.metadata.RecordUndo();
                    parent.type = newType;
                    parent.SetValue();
                    parent.SetHeightDirty();
                }

                y += typePosition.height;
            }

            if (parent.chooseType && parent.showValue)
            {
                y += SystemObjectInspector.Styles.spaceBetweenTypeAndValue;
            }

            if (parent.showValue)
            {
                Rect valuePosition;

                if (parent.chooseType)
                {
                    var x = position.x;
                    var remainingWidth = position.width;

                    if (showLabels)
                    {
                        var valueLabel = label == GUIContent.none ? new GUIContent("Value") : new GUIContent(label.text + " Value");

                        var valueLabelPosition = new Rect
                                                 (
                            x,
                            y,
                            SystemObjectInspector.Styles.labelWidth,
                            EditorGUIUtility.singleLineHeight
                                                 );

                        GUI.Label(valueLabelPosition, valueLabel, Inspector.ProcessLabelStyle(parent.metadata, null));

                        x += valueLabelPosition.width;
                        remainingWidth -= valueLabelPosition.width;
                    }

                    valuePosition = new Rect
                                    (
                        x,
                        y,
                        remainingWidth,
                        EditorGUIUtility.singleLineHeight
                                    );

                    LudiqGUI.Inspector(parent.metadata.Cast(parent.type), valuePosition, GUIContent.none);
                }
                else
                {
                    valuePosition = new Rect
                                    (
                        position.x,
                        y,
                        position.width,
                        LudiqGUI.GetInspectorHeight(parent, parent.metadata.Cast(parent.type), position.width, label)
                                    );

                    LudiqGUI.Inspector(parent.metadata.Cast(parent.type), valuePosition, label);
                }

                y += valuePosition.height;
            }
            else
            {
                parent.metadata.value = null;
            }
        }
コード例 #2
0
 protected virtual void OnMemberGUI(Metadata member, Rect memberPosition)
 {
     LudiqGUI.Inspector(member, memberPosition);
 }
コード例 #3
0
 public void OnKeyGUI(Rect keyPosition)
 {
     LudiqGUI.Inspector(metadata["Key"], keyPosition, GUIContent.none);
 }
コード例 #4
0
        protected override void OnGUI(Rect position, GUIContent label)
        {
            // Super hacky hotfix:
            // If the value changes in between OnGUI calls,
            // the OnValueChange event will not be called, because
            // we don't even look at the value until showField is true.
            // For example, an object that was null and becomes non-null
            // will be reset to null by the inspector unless this line is here,
            // because type will be null and showField will thus be false.
            var haxHotfix = metadata.value;
            // TL;DR: storing a local private type field that does not
            // take the actual, current variable type into consideration is a
            // very bad idea and will inevitably cause inspector v. codebase fighting
            // or inspector v. inspector fighting.

            var showLabels = !adaptiveWidth && position.width >= 120;

            BeginBlock(metadata, position, GUIContent.none);

            if (chooseType)
            {
                var x = position.x;
                var remainingWidth = position.width;

                if (showLabels)
                {
                    var typeLabel = label == GUIContent.none ? new GUIContent("Type") : new GUIContent(label.text + " Type");

                    var typeLabelPosition = new Rect
                                            (
                        x,
                        y,
                        Styles.labelWidth,
                        EditorGUIUtility.singleLineHeight
                                            );

                    GUI.Label(typeLabelPosition, typeLabel, ProcessLabelStyle(metadata, null));

                    x += typeLabelPosition.width;
                    remainingWidth -= typeLabelPosition.width;
                }

                var typePosition = new Rect
                                   (
                    x,
                    y,
                    remainingWidth,
                    EditorGUIUtility.singleLineHeight
                                   );

                EditorGUI.BeginChangeCheck();

                var newType = LudiqGUI.TypeField(typePosition, GUIContent.none, type, GetTypeOptions, new GUIContent("(Null)"));

                if (EditorGUI.EndChangeCheck())
                {
                    metadata.RecordUndo();
                    type = newType;
                    EnforceType();
                    SetHeightDirty();
                }

                y += typePosition.height;
            }

            if (chooseType && showValue)
            {
                y += Styles.spaceBetweenTypeAndValue;
            }

            if (showValue)
            {
                Rect valuePosition;

                if (chooseType)
                {
                    var x = position.x;
                    var remainingWidth = position.width;

                    if (showLabels)
                    {
                        var valueLabel = label == GUIContent.none ? new GUIContent("Value") : new GUIContent(label.text + " Value");

                        var valueLabelPosition = new Rect
                                                 (
                            x,
                            y,
                            Styles.labelWidth,
                            EditorGUIUtility.singleLineHeight
                                                 );

                        GUI.Label(valueLabelPosition, valueLabel, ProcessLabelStyle(metadata, null));

                        x += valueLabelPosition.width;
                        remainingWidth -= valueLabelPosition.width;
                    }

                    valuePosition = new Rect
                                    (
                        x,
                        y,
                        remainingWidth,
                        EditorGUIUtility.singleLineHeight
                                    );

                    LudiqGUI.Inspector(metadata.Cast(type), valuePosition, GUIContent.none);
                }
                else
                {
                    valuePosition = new Rect
                                    (
                        position.x,
                        y,
                        position.width,
                        LudiqGUI.GetInspectorHeight(this, metadata.Cast(type), position.width, label)
                                    );

                    LudiqGUI.Inspector(metadata.Cast(type), valuePosition, label);
                }

                y += valuePosition.height;
            }
            else
            {
                metadata.value = null;
            }

            EndBlock(metadata);
        }
コード例 #5
0
 private void OnKeyGUI(Metadata keyMetadata, Rect keyPosition)
 {
     LudiqGUI.Inspector(keyMetadata, keyPosition, GUIContent.none);
 }
コード例 #6
0
 public void OnTypeGUI(Rect position)
 {
     LudiqGUI.Inspector(typeMetadata, position, GUIContent.none);
 }
コード例 #7
0
 protected override void OnGUI(Rect position, GUIContent label)
 {
     LudiqGUI.Inspector(declarationsMetadata, position, GUIContent.none);
 }
コード例 #8
0
 public void OnValueGUI(Rect valuePosition)
 {
     LudiqGUI.Inspector(valueMetadata, valuePosition, GUIContent.none);
 }
コード例 #9
0
        protected override void OnContentGUI()
        {
            GUILayout.BeginVertical(Styles.background, GUILayout.ExpandHeight(true));

            LudiqGUI.FlexibleSpace();

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            var text = "Choose the types you want to use for variables and units.\n"
                       + "MonoBehaviour types are always included.";

            GUILayout.Label(text, LudiqStyles.centeredLabel, GUILayout.MaxWidth(370));
            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.Space(10);

            var height = LudiqGUI.GetInspectorHeight(null, typeOptionsMetadata, Styles.optionsWidth, GUIContent.none);

            LudiqGUI.BeginHorizontal();

            LudiqGUI.FlexibleSpace();

            EditorGUI.BeginChangeCheck();

            var position = GUILayoutUtility.GetRect(Styles.optionsWidth, height);

            LudiqGUI.Inspector(typeOptionsMetadata, position, GUIContent.none);

            if (EditorGUI.EndChangeCheck())
            {
                typeOptionsMetadata.Save();
                Codebase.UpdateSettings();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.Space(10);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            if (GUILayout.Button("Reset to Defaults", Styles.defaultsButton))
            {
                typeOptionsMetadata.Reset(true);
                typeOptionsMetadata.Save();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.FlexibleSpace();

            LudiqGUI.Space(10);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            if (GUILayout.Button("Generate", Styles.completeButton))
            {
                Complete();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.FlexibleSpace();

            LudiqGUI.EndVertical();
        }
コード例 #10
0
 private void OnTypeGUI(Rect position)
 {
     LudiqGUI.Inspector(typeMetadata, position);
 }
コード例 #11
0
 protected void OnHideLabelGUI(Rect position)
 {
     LudiqGUI.Inspector(hideLabelMetadata, position);
 }
コード例 #12
0
 protected void OnDescriptionGUI(Rect position)
 {
     LudiqGUI.Inspector(descriptionMetadata, position);
 }
コード例 #13
0
 protected void OnKeyGUI(Rect position)
 {
     LudiqGUI.Inspector(keyMetadata, position);
 }
コード例 #14
0
 protected virtual void OnInspectorGUI(Rect position)
 {
     LudiqGUI.Inspector(metadata, position, GUIContent.none);
 }
コード例 #15
0
        private void OpenContents(Rect position, Rect container)
        {
            if ((bool)isOpenMeta.value)
            {
                var typeHeight  = LudiqGUI.GetInspectorHeight(typeMeta.Inspector(), typeMeta["type"], position.width, GUIContent.none);
                var valueHeight = LudiqGUI.GetInspectorHeight(typeMeta.Inspector(), typeMeta["value"], position.width, GUIContent.none);
                var typeLabel   = new Rect(container.x + 5, container.y + y + 10, 60, 16);
                var typeRect    = new Rect(container.x + 50, container.y + typeLabel.height + 16, container.width - 60, typeHeight);
                var defaultRect = new Rect(container.x + 50, typeRect.y + typeRect.height + 4, container.width - 60, typeHeight);
                var valueRect   = new Rect(container.x + 10, typeRect.y + typeRect.height + defaultRect.height + 8, container.width - 20, valueHeight + 8);
                EditorGUI.LabelField(typeLabel, new GUIContent("Type"));
                LudiqGUI.Inspector(typeMeta["type"], typeRect, GUIContent.none);

                var addedHeight = 0;

                if (!((System.Type)typeMeta["type"].value).InheritsType(typeof(UnityEngine.Object)))
                {
                    addedHeight += 16;

                    LudiqGUI.Inspector(typeMeta["hasDefault"], defaultRect, new GUIContent("Default"));

                    if ((bool)typeMeta["hasDefault"].value)
                    {
                        UtilityGUI.Container(valueRect, Color.black, 0.7f.Grey(), 1, 4, (valueContainer) =>
                        {
                            if (typeMeta["value"].value != null || ((System.Type)typeMeta["type"].value).InheritsType(typeof(UnityEngine.Object)))
                            {
                                LudiqGUI.Inspector(typeMeta["value"], valueContainer, GUIContent.none);

                                if ((System.Type)typeMeta["type"].value == typeof(bool))
                                {
                                    var boolLabel = valueContainer;
                                    boolLabel.x  += 18;
                                    GUI.Label(boolLabel, (nameMeta.value as string).Prettify());
                                }
                            }
                        });

                        addedHeight += (int)valueRect.height + 10;
                    }
                }

                var optionsRect    = Options(typeLabel, typeRect, addedHeight + defaultRect.height);
                var propertiesRect = optionsRect;
                propertiesRect.width  = typeLabel.width + typeRect.width;
                propertiesRect.x     -= 20;
                propertiesRect.y     += 86;
                propertiesRect.height = 56;
                var propertyHeight = propertyMeta.Inspector().GetCachedHeight(lastPosition.width, GUIContent.none, accessor.Inspector()) + addedHeight;

                var prop     = ((Property)propertyMeta.value);
                var propName = string.Empty;

                UAliveGUI.NestedSection(propertiesRect, e, "Property", UAliveResources.properties, addedHeight, (propertiesContainer) =>
                {
                    LudiqGUI.Inspector(propertyMeta, new Rect(propertiesContainer.x, propertiesContainer.y, propertiesContainer.width - 40, propertyHeight));
                }, isPropertyMeta);

                addedHeight += 30;

                y += typeHeight + defaultRect.height + optionsRect.height + propertiesRect.height + addedHeight + 4;
            }
        }
コード例 #16
0
        protected override void OnContentGUI()
        {
            GUILayout.BeginVertical(Styles.background, GUILayout.ExpandHeight(true));

            LudiqGUI.FlexibleSpace();

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            var text = "Choose the assemblies in which you want to look for units.\n"
                       + "By default, all project and Unity assemblies are included.\n"
                       + "Unless you use a third-party plugin distributed as a DLL, you shouldn't need to change this.";

            GUILayout.Label(text, LudiqStyles.centeredLabel, GUILayout.MaxWidth(370));
            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.Space(10);

            var height = LudiqGUI.GetInspectorHeight(null, assemblyOptionsMetadata, Styles.optionsWidth, GUIContent.none);

            LudiqGUI.BeginHorizontal();

            LudiqGUI.FlexibleSpace();

            EditorGUI.BeginChangeCheck();

            var position = GUILayoutUtility.GetRect(Styles.optionsWidth, height);

            LudiqGUI.Inspector(assemblyOptionsMetadata, position, GUIContent.none);

            if (EditorGUI.EndChangeCheck())
            {
                assemblyOptionsMetadata.Save();
                Codebase.UpdateSettings();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.Space(10);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            if (GUILayout.Button("Reset to Defaults", Styles.defaultsButton))
            {
                assemblyOptionsMetadata.Reset(true);
                assemblyOptionsMetadata.Save();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.FlexibleSpace();

            LudiqGUI.Space(10);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            if (GUILayout.Button(completeLabel, Styles.completeButton))
            {
                Complete();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.FlexibleSpace();

            LudiqGUI.EndVertical();
        }
コード例 #17
0
 private void OnInspectorGUI(Rect inspectorPosition)
 {
     LudiqGUI.Inspector(metadata, inspectorPosition, GUIContent.none);
 }
コード例 #18
0
 private void OnImplementationGUI(Rect implementationPosition)
 {
     LudiqGUI.Inspector(implementationMetadata, implementationPosition, GUIContent.none);
 }
コード例 #19
0
 private void OnDefaultValueGUI(Rect position)
 {
     LudiqGUI.Inspector(typedDefaultValueMetadata, position);
 }
コード例 #20
0
 private void OnValueGUI(Metadata valueMetadata, Rect valuePosition)
 {
     LudiqGUI.Inspector(valueMetadata, valuePosition, GUIContent.none);
 }
コード例 #21
0
ファイル: UAliveGUI.cs プロジェクト: calculosu123/UAlive
        public static Rect DrawSection(Rect position, Accessor _accessor, Accessor @base, Event e, string title, Texture2D icon, int heightModifier, bool togglable, int items, Accessor isOpen, bool isEditor = false, List <Rect> untouchableAreas = null)
        {
            var accessorHeight = isEditor ? _accessor.Editor().GetCachedHeight(position.width, GUIContent.none, @base.Editor()) : _accessor.Inspector().GetCachedHeight(position.width, GUIContent.none, @base.Inspector());
            var sectionRect    = position;

            sectionRect.y      = position.height + position.y - 2;
            sectionRect.height = (bool)isOpen.value ? accessorHeight + heightModifier : heightModifier;

            // Draw a rectangle that contains a border and is light grey. Color usage for differentiating sections.
            UtilityGUI.Container(sectionRect, Color.black, 0.6f.Grey(), 1, 10, (rootContainer) =>
            {
                UtilityGUI.Container(rootContainer, Color.black, 0.8f.Grey(), 1, 4, (container) =>
                {
                    var canTouch = true;

                    if (untouchableAreas != null)
                    {
                        foreach (Rect rect in untouchableAreas)
                        {
                            if (rect.Contains(e.mousePosition))
                            {
                                canTouch = false;
                                break;
                            }
                        }
                    }

                    if (canTouch && new Rect(container.x, container.y, container.width, 24).Contains(e.mousePosition))
                    {
                        if (e.type == EventType.MouseDown && e.button == 0)
                        {
                            isOpen.value = !(bool)isOpen.value;
                        }
                    }

                    UtilityGUI.BorderRect(new Rect(rootContainer.x, rootContainer.y, rootContainer.width, 24), 1, 0.3f.Grey(), Color.black, UtilityGUI.BorderDrawPlacement.Inside);
                    Graphics.DrawTexture(new Rect(rootContainer.x + 5, rootContainer.y + 4, 16, 16), icon);
                    EditorGUI.LabelField(new Rect(container.x + 20, container.y, container.width - 26, 16), title, new GUIStyle(EditorStyles.boldLabel)
                    {
                        normal = new GUIStyleState()
                        {
                            textColor = Color.white
                        }
                    });

                    var accessorRect = new Rect(container.x, container.y + 24, container.width, accessorHeight);

                    UtilityGUI.BorderRect(new Rect(rootContainer.x + 100, rootContainer.y + 3, 20, 18), 1, 0.4f.Grey(), Color.black, UtilityGUI.BorderDrawPlacement.Inside);
                    EditorGUI.LabelField(new Rect(rootContainer.x + 100, rootContainer.y + 3, 20, 18), items.ToString(), new GUIStyle(EditorStyles.whiteBoldLabel)
                    {
                        alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState()
                        {
                            textColor = 0.85f.Grey()
                        }
                    });

                    if (togglable)
                    {
                        if ((bool)isOpen.value)
                        {
                            LudiqGUI.Inspector(_accessor, accessorRect, GUIContent.none);
                        }
                        Texture2D arrow = (bool)isOpen.value ? UAliveResources.arrowDownWhite : UAliveResources.arrowRightWhite;
                        Graphics.DrawTexture(new Rect(container.x + container.width - 14, rootContainer.y + 6, 10, 10), arrow);
                        return;
                    }

                    if (!isEditor)
                    {
                        LudiqGUI.Inspector(_accessor, accessorRect, GUIContent.none);
                    }
                    else
                    {
                        LudiqGUI.Editor(_accessor, accessorRect);
                    }
                });
            });

            return(sectionRect);
        }