コード例 #1
0
        void DrawStyleGUI()
        {
            bool canSetStyle = !isLine || (propGeometry.hasMultipleDifferentValues || propGeometry.enumValueIndex != (int)LineGeometry.Volumetric3D);

            if (canSetStyle)
            {
                using (new EditorGUILayout.HorizontalScope()) {
                    EditorGUILayout.PrefixLabel("Style");
                    ShapesUI.DrawTypeSwitchButtons(propType, UIAssets.LineDashButtonContents);
                }

                bool canEditStyle = propShapeModifier.hasMultipleDifferentValues || ((DashType)propType.enumValueIndex).HasModifier();
                using (new EditorGUI.DisabledScope(canEditStyle == false))
                    EditorGUILayout.PropertyField(propShapeModifier);
            }
            else                 // this else is only applicable for lines
            {
                using (new EditorGUI.DisabledScope(true)) {
                    using (new EditorGUILayout.HorizontalScope()) {
                        EditorGUILayout.PrefixLabel(new GUIContent("Style", "3D lines support basic dashes only"));
                        GUILayout.Toggle(true, UIAssets.LineDashButtonContents[0], ShapesUI.GetMiniButtonStyle(0, 3), GUILayout.MinHeight(20));
                        GUILayout.Toggle(false, UIAssets.LineDashButtonContents[1], ShapesUI.GetMiniButtonStyle(1, 3), GUILayout.MinHeight(20));
                        GUILayout.Toggle(false, UIAssets.LineDashButtonContents[2], ShapesUI.GetMiniButtonStyle(2, 3), GUILayout.MinHeight(20));
                    }
                }
            }
        }
コード例 #2
0
ファイル: ShapesUI.cs プロジェクト: pencilking2002/BioTower
        public static bool DrawTypeSwitchButtons(SerializedProperty prop, GUIContent[] guiContent, int[] indexOverride = null, int height = 20)
        {
            int GetEntryCount()
            {
                switch (prop.propertyType)
                {
                case SerializedPropertyType.Enum:    return(prop.enumNames.Length);

                case SerializedPropertyType.Integer: return(indexOverride.Length);

                default:                             throw new IndexOutOfRangeException("no, illegal >:I");
                }
            }

            bool[] multiselectPressedState = prop.TryGetMultiselectPressedStates(indexOverride, GetEntryCount());

            bool             changed     = false;
            SerializedObject so          = prop.serializedObject;
            bool             multiselect = so.isEditingMultipleObjects;

            EditorGUI.BeginChangeCheck();
            GUILayoutOption[] buttonLayout = { GUILayout.Height(height), GUILayout.MinWidth(height) };

            void EnumButton(int index)
            {
                GUIStyle style = ShapesUI.GetMiniButtonStyle(index, guiContent.Length);
                bool     btnState;

                if (multiselect)
                {
                    btnState = multiselectPressedState[index];
                }
                else
                {
                    btnState = index == prop.GetIntValue(indexOverride) && prop.hasMultipleDifferentValues == false;
                }
                bool btnStateNew = GUILayout.Toggle(btnState, guiContent[index], style, buttonLayout);

                bool pressedInMultiselect  = multiselect && btnState != btnStateNew;
                bool pressedInSingleselect = multiselect == false && btnStateNew && btnState == false;

                if (pressedInMultiselect || pressedInSingleselect)
                {
                    prop.SetIntValue(index, indexOverride);
                    changed = true;
                }
            }

            GUILayout.BeginHorizontal();
            for (int i = 0; i < guiContent.Length; i++)
            {
                EnumButton(i);
            }
            GUILayout.EndHorizontal();
            return(changed);
        }
コード例 #3
0
        public static bool DrawTypeSwitchButtons(SerializedProperty enumProp, GUIContent[] guiContent, int height = 32)
        {
            bool[] multiselectPressedState = enumProp.TryGetMultiselectPressedStates();

            bool             changed     = false;
            SerializedObject so          = enumProp.serializedObject;
            bool             multiselect = so.isEditingMultipleObjects;

            EditorGUI.BeginChangeCheck();
            GUILayoutOption[] buttonLayout = { GUILayout.Height(height), GUILayout.MinWidth(height) };

            void EnumButton(int index)
            {
                GUIStyle style = ShapesUI.GetMiniButtonStyle(index, guiContent.Length);
                bool     btnState;

                if (multiselect)
                {
                    btnState = multiselectPressedState[index];
                }
                else
                {
                    btnState = index == enumProp.enumValueIndex && enumProp.hasMultipleDifferentValues == false;
                }
                bool btnStateNew = GUILayout.Toggle(btnState, guiContent[index], style, buttonLayout);

                bool pressedInMultiselect  = multiselect && btnState != btnStateNew;
                bool pressedInSingleselect = multiselect == false && btnStateNew && btnState == false;

                if (pressedInMultiselect || pressedInSingleselect)
                {
                    enumProp.enumValueIndex = index;
                    changed = true;
                }
            }

            GUILayout.BeginHorizontal();
            for (int i = 0; i < guiContent.Length; i++)
            {
                EnumButton(i);
            }
            GUILayout.EndHorizontal();
            return(changed);
        }