Ejemplo n.º 1
0
        public static void OnSceneGUI(SceneView sceneView)
        {
            // TODO: put somewhere else
            var curSkin = EditorGUIUtility.isProSkin;

            if (toolbarStyle == null ||
                prevSkin != curSkin)
            {
                toolbarStyle             = new GUIStyle(EditorStyles.toolbar);
                toolbarStyle.fixedHeight = kBottomBarHeight;

                toggleStyle             = new GUIStyle(EditorStyles.toolbarButton);
                toggleStyle.fixedHeight = kBottomBarHeight;

                buttonStyle             = new GUIStyle(EditorStyles.toolbarButton);
                buttonStyle.fixedHeight = kBottomBarHeight;

                floatWidthLayout = GUILayout.Width(kFloatFieldWidth);

                prevSkin = curSkin;
                ChiselEditorSettings.Load();
            }


            // Calculate size of bottom bar and draw it
            Rect position = sceneView.position;

            position.x      = 0;
            position.y      = position.height - kBottomBarHeight;
            position.height = kBottomBarHeight;

            GUILayout.Window(bottomBarGuiId, position, OnBottomBarUI, "", toolbarStyle);
            ChiselEditorUtility.ConsumeUnusedMouseEvents(BottomBarGUIHash, position);
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            InitTypes();

            CheckForTransformationChanges(serializedObject);

            if (IsDefaultModel())
            {
                EditorGUILayout.HelpBox(DefaultModelContents.text, MessageType.Warning);
            }

            EditorGUI.BeginChangeCheck();
            {
                EditorGUILayout.PropertyField(createRenderComponentsProp, CreateRenderComponentsContents);
                EditorGUI.BeginDisabledGroup(!createRenderComponentsProp.boolValue);
                {
                    EditorGUI.indentLevel++;

                    MeshRendererLightingGUI();
                    RenderRenderingLayer();
                    CullDynamicFieldGUI();
                    // TODO: Make Position show up instead of "None" when nothing is selected
                    ChiselEditorUtility.EnumFlagsField(VertexChannelMaskContents, vertexChannelMaskProp, typeof(VertexChannelFlags), EditorStyles.popup);

                    EditorGUI.indentLevel--;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(createColliderComponentsProp, CreateColliderComponentsContents);
                EditorGUI.BeginDisabledGroup(!createColliderComponentsProp.boolValue);
                {
                    EditorGUI.indentLevel++;

                    EditorGUI.indentLevel++;
                    using (new EditorGUI.DisabledScope(!convexProp.boolValue))
                    {
                        EditorGUILayout.PropertyField(isTriggerProp, IsTriggerContents);
                    }
                    EditorGUI.indentLevel--;

                    {
                        ChiselEditorUtility.EnumFlagsField(CookingOptionsContents, cookingOptionsProp, typeof(MeshColliderCookingOptions), EditorStyles.popup);
                    }

                    EditorGUI.indentLevel--;
                }
                EditorGUI.EndDisabledGroup();
            }
            if (EditorGUI.EndChangeCheck())
            {
                ForceUpdateNodeContents(serializedObject);
            }
        }
Ejemplo n.º 3
0
        public static void OnSceneGUI(SceneView sceneView)
        {
            // Calculate size of bottom bar and draw it
            Rect position = sceneView.position;

            position.x      = -2;
            position.y      = position.height - ChiselSceneGUIStyle.kBottomBarHeight + 1;
            position.width += 4;
            position.height = ChiselSceneGUIStyle.kBottomBarHeight;

            GUI.Window(kBottomBarID, position, OnBottomBarUI, string.Empty, ChiselSceneGUIStyle.toolbarStyle);

            ChiselEditorUtility.ConsumeUnusedMouseEvents(BottomBarGUIHash, position);
        }
Ejemplo n.º 4
0
        void RenderProbeFieldsGUI()
        {
            bool isDeferredRenderingPath = ChiselEditorUtility.IsUsingDeferredRenderingPath();
            bool isDeferredReflections   = isDeferredRenderingPath && ChiselEditorUtility.IsDeferredReflections();
            bool areLightProbesAllowed   = AreLightProbesAllowed();

            RenderLightProbeUsage(areLightProbesAllowed);

            RenderLightProbeProxyVolumeWarningNote();

            RenderReflectionProbeUsage(isDeferredRenderingPath, isDeferredReflections);

            RenderProbeAnchor();
        }
Ejemplo n.º 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Keyboard), label);

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            bool prevShowMixedValue    = EditorGUI.showMixedValue;
            bool deferredRenderingPath = ChiselEditorUtility.IsUsingDeferredRenderingPath();

            EditorGUI.showMixedValue = prevShowMixedValue || property.hasMultipleDifferentValues;
            try
            {
                var surfaceFlags = (SurfaceFlags)property.intValue;

                bool isTextureLocked = (surfaceFlags & SurfaceFlags.TextureIsInWorldSpace) == 0;

                EditorGUI.BeginChangeCheck();
                {
                    isTextureLocked = EditorGUI.ToggleLeft(position, kTextureLockedContent, isTextureLocked);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    if (isTextureLocked)
                    {
                        surfaceFlags &= ~SurfaceFlags.TextureIsInWorldSpace;
                    }
                    else
                    {
                        surfaceFlags |= SurfaceFlags.TextureIsInWorldSpace;
                    }

                    property.intValue = (int)surfaceFlags;
                }
            }
            catch (ExitGUIException) { }
            catch (Exception ex) { Debug.LogException(ex); }

            // Set indent back to what it was
            EditorGUI.indentLevel    = indent;
            EditorGUI.showMixedValue = prevShowMixedValue;
            EditorGUI.EndProperty();
        }
Ejemplo n.º 6
0
        public void Show(Rect draggableArea)
        {
            currentDraggableArea = draggableArea;
            if (GUIUtility.hotControl == 0)
            {
                prevWindowRect = position;
            }

            currentDraggableArea.x      += kGap;
            currentDraggableArea.y      += kGap;
            currentDraggableArea.width  -= kGap + kGap;
            currentDraggableArea.height -= kGap + kGap;

            int windowId = GUIUtility.GetControlID(kWindowHash, FocusType.Passive);
            var prevSkin = GUI.skin;

            GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
            position = GUI.Window(windowId, position, HandleWindowLogic, title);
            GUI.skin = prevSkin;

            if (position.width < minWidth)
            {
                position.width = minWidth;
            }
            if (position.height < minHeight)
            {
                position.height = minHeight;
            }

            position.x = Mathf.Clamp(position.x, currentDraggableArea.xMin, currentDraggableArea.xMax - position.width);
            position.y = Mathf.Clamp(position.y, currentDraggableArea.yMin, currentDraggableArea.yMax - position.height);

            position.xMax = Mathf.Clamp(position.xMax, currentDraggableArea.xMin + position.width, currentDraggableArea.xMax);
            position.yMax = Mathf.Clamp(position.yMax, currentDraggableArea.yMin + position.height, currentDraggableArea.yMax);

            var tempPosition = position;

            tempPosition.height -= kWindowTitleBarHeight;
            ChiselEditorUtility.ConsumeUnusedMouseEvents(kWindowHash, tempPosition);
        }
Ejemplo n.º 7
0
        internal void RenderReflectionProbeUsage(bool isDeferredRenderingPath, bool isDeferredReflections)
        {
#if UNITY_2018_1_OR_ABOVE
            if (!SupportedRenderingFeatures.active.rendererSupportsReflectionProbes)
            {
                return;
            }
#endif

            using (new EditorGUI.DisabledScope(isDeferredRenderingPath))
            {
                // reflection probe usage field; UI disabled when using deferred reflections
                if (isDeferredReflections)
                {
                    EditorGUILayout.EnumPopup(ReflectionProbeUsageContents, (reflectionProbeUsageProp.intValue != (int)ReflectionProbeUsage.Off) ? ReflectionProbeUsage.Simple : ReflectionProbeUsage.Off);
                }
                else
                {
                    Rect r = EditorGUILayout.GetControlRect(true, kSingleLineHeight, EditorStyles.popup);
                    ChiselEditorUtility.Popup(r, reflectionProbeUsageProp, ReflectionProbeUsageOptionsContents, ReflectionProbeUsageContents);
                }
            }
        }
Ejemplo n.º 8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            bool prevShowMixedValue    = EditorGUI.showMixedValue;
            bool deferredRenderingPath = ChiselEditorUtility.IsUsingDeferredRenderingPath();

            EditorGUI.showMixedValue = prevShowMixedValue || property.hasMultipleDifferentValues;
            try
            {
                var layerUsage = (LayerUsageFlags)property.intValue;

                bool isRenderable     = (layerUsage & LayerUsageFlags.Renderable) != 0;
                bool isCastShadows    = (layerUsage & LayerUsageFlags.CastShadows) != 0;
                bool isReceiveShadows = (layerUsage & LayerUsageFlags.ReceiveShadows) != 0;
                bool isCollidable     = (layerUsage & LayerUsageFlags.Collidable) != 0;

                // Draw label
                position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Keyboard), label);

                EditorGUI.BeginChangeCheck();
                {
                    // Don't make child fields be indented
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel = 0;

                    var toggleStyle = EditorStyles.label;

                    var halfWidth      = position.width / 2.0f;
                    var textWidthRight = toggleStyle.CalcSize(ReceiveShadowsContent).x;
                    var textWidthLeft  = toggleStyle.CalcSize(CollidableContent).x;
                    var offset         = (position.width - (textWidthRight + textWidthLeft)) / 2;
                    if (offset < 0)
                    {
                        textWidthRight = position.width - textWidthLeft;
                    }
                    else
                    {
                        textWidthLeft  += offset;
                        textWidthRight += offset;
                    }

                    var button1 = position;
                    var button2 = position;
                    button1.height = button2.height = EditorGUIUtility.singleLineHeight;
                    button1.width  = textWidthLeft;
                    button2.width  = textWidthRight;
                    button2.x     += button1.width;

                    var button3 = button1;
                    var button4 = button2;
                    button3.y += button1.height;
                    button4.y += button2.height;

                    isRenderable = EditorGUI.ToggleLeft(button1, VisibleContent, isRenderable, toggleStyle);
                    EditorGUI.BeginDisabledGroup(deferredRenderingPath || !isRenderable);
                    if (!isRenderable)
                    {
                        EditorGUI.ToggleLeft(button2, ReceiveShadowsContent, false, toggleStyle);
                    }
                    else if (deferredRenderingPath)
                    {
                        EditorGUI.ToggleLeft(button2, ReceiveShadowsContent, true, toggleStyle);
                    }
                    else
                    {
                        isReceiveShadows = EditorGUI.ToggleLeft(button2, ReceiveShadowsContent, isReceiveShadows, toggleStyle);
                    }
                    EditorGUI.EndDisabledGroup();
                    isCollidable  = EditorGUI.ToggleLeft(button3, CollidableContent, isCollidable, toggleStyle);
                    isCastShadows = EditorGUI.ToggleLeft(button4, CastShadowsContent, isCastShadows, toggleStyle);

                    // Set indent back to what it was
                    EditorGUI.indentLevel = indent;
                }
                if (EditorGUI.EndChangeCheck())
                {
                    if (isRenderable)
                    {
                        layerUsage |= LayerUsageFlags.Renderable;
                    }
                    else
                    {
                        layerUsage &= ~LayerUsageFlags.Renderable;
                    }

                    if (isCastShadows)
                    {
                        layerUsage |= LayerUsageFlags.CastShadows;
                    }
                    else
                    {
                        layerUsage &= ~LayerUsageFlags.CastShadows;
                    }

                    if (isReceiveShadows)
                    {
                        layerUsage |= LayerUsageFlags.ReceiveShadows;
                    }
                    else
                    {
                        layerUsage &= ~LayerUsageFlags.ReceiveShadows;
                    }

                    if (isCollidable)
                    {
                        layerUsage |= LayerUsageFlags.Collidable;
                    }
                    else
                    {
                        layerUsage &= ~LayerUsageFlags.Collidable;
                    }

                    property.intValue = (int)layerUsage;
                }
            }
            catch (ExitGUIException) { }
            catch (Exception ex) { Debug.LogException(ex); }

            EditorGUI.showMixedValue = prevShowMixedValue;
            EditorGUI.EndProperty();
        }
Ejemplo n.º 9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            try
            {
                SerializedProperty layerUsageProp      = property.FindPropertyRelative(ChiselBrushMaterial.kLayerUsageFieldName);
                SerializedProperty renderMaterialProp  = property.FindPropertyRelative(ChiselBrushMaterial.kRenderMaterialFieldName);
                SerializedProperty physicsMaterialProp = property.FindPropertyRelative(ChiselBrushMaterial.kPhysicsMaterialFieldName);

                // Don't make child fields be indented
                var originalPosition = position;
                position = EditorGUI.IndentedRect(position);
                var indentOffset = position.x - originalPosition.x;

                var showMaterial = (ChiselEditorUtility.GetContextWidth() > 430);

                var physicMaterialPrefixRect = originalPosition;
                physicMaterialPrefixRect.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.ExposedReference, GUIContent.none);
                originalPosition.yMin          += physicMaterialPrefixRect.height + kSpacing;

                var previewSize        = originalPosition.height;
                var materialPrefixRect = originalPosition;
                materialPrefixRect.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.ExposedReference, GUIContent.none);
                originalPosition.yMin    += materialPrefixRect.height + kSpacing;

                var materialPreviewRect = materialPrefixRect;
                materialPreviewRect.width  = previewSize;
                materialPreviewRect.height = previewSize;

                var layerUsagePropRect = originalPosition;

                EditorGUI.BeginChangeCheck();
                {
                    {
                        var materialLabelID  = EditorGUIUtility.GetControlID(kBrushMaterialEditorHashCode, FocusType.Keyboard, materialPrefixRect);
                        var materialPropRect = EditorGUI.PrefixLabel(materialPrefixRect, materialLabelID, kRenderMaterialContents);
                        materialPreviewRect.x  = materialPropRect.x;
                        materialPropRect.xMin -= indentOffset;
                        if (showMaterial)
                        {
                            materialPropRect.xMin += previewSize + kSpacing;
                        }
                        layerUsagePropRect.xMin = materialPropRect.xMin;
                        EditorGUI.PropertyField(materialPropRect, renderMaterialProp, GUIContent.none, false);
                    }

                    {
                        EditorGUI.PropertyField(layerUsagePropRect, layerUsageProp, GUIContent.none, false);
                    }

                    {
                        var physicMaterialLabelID  = EditorGUIUtility.GetControlID(kBrushPhysicMaterialEditorHashCode, FocusType.Keyboard, physicMaterialPrefixRect);
                        var physicMaterialPropRect = EditorGUI.PrefixLabel(physicMaterialPrefixRect, physicMaterialLabelID, kPhysicRenderMaterialContents);

                        physicMaterialPropRect.xMin -= indentOffset;
                        EditorGUI.PropertyField(physicMaterialPropRect, physicsMaterialProp, GUIContent.none, false);
                    }

                    // Render material preview
                    if (showMaterial)
                    {
                        if (styles == null)
                        {
                            styles = new Styles();
                        }
                        OnPreviewGUI(materialPreviewRect, styles.background, renderMaterialProp.objectReferenceValue as Material);
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    property.serializedObject.ApplyModifiedProperties();
                }
            }
            catch (ExitGUIException) { }
            catch (Exception ex) { Debug.LogException(ex); }

            EditorGUI.EndProperty();
        }
Ejemplo n.º 10
0
        public override void OnInspectorGUI()
        {
            try
            {
                const float spacing = 2;
                EditorGUI.BeginChangeCheck();
                {
                    EditorGUILayout.PropertyField(physicsMaterialProp, true);

                    if (!ShowMaterialIcon)
                    {
                        float materialPropHeight = EditorGUI.GetPropertyHeight(SerializedPropertyType.ExposedReference, GUIContent.none);

                        var materialPropRect = EditorGUILayout.GetControlRect(GUILayout.Height(materialPropHeight));
                        EditorGUI.PropertyField(materialPropRect, renderMaterialProp, RenderMaterialContents, true);

                        var layerUsagePropRect = EditorGUILayout.GetControlRect(GUILayout.Height(materialPropHeight * 2));
                        EditorGUI.PropertyField(layerUsagePropRect, layerUsageProp, LayerUsageContents, true);
                    }
                    else
                    {
                        #if UNITY_2017_1_OR_ABOVE
                        float lineHeight = EditorGUILayout.singleLineHeight;
                        #else
                        float lineHeight = 16;
                        #endif
                        float materialSize = 3 * lineHeight;

                        // Calculate rects
                        var materialPart        = EditorGUILayout.GetControlRect(GUILayout.Height(materialSize));
                        var materialLabelID     = EditorGUIUtility.GetControlID(SurfaceEditorHashCode, FocusType.Keyboard, materialPart);
                        var materialPropRect    = EditorGUI.PrefixLabel(materialPart, materialLabelID, RenderMaterialContents);
                        var materialPreviewRect = materialPropRect;
                        var showMaterial        = (ChiselEditorUtility.GetContextWidth() > 320);

                        float materialPropHeight = EditorGUI.GetPropertyHeight(SerializedPropertyType.ExposedReference, GUIContent.none);
                        if (showMaterial)
                        {
                            materialPreviewRect.width = materialSize;
                            materialPropRect.x       += materialSize + spacing;
                            materialPropRect.width   -= materialSize + spacing;
                        }

                        var layerUsagePropRect = materialPropRect;
                        layerUsagePropRect.y   += materialPropHeight;
                        materialPropRect.height = materialPropHeight;

                        // Show material prop
                        var prevIndentLevel = EditorGUI.indentLevel;
                        EditorGUI.indentLevel = 0;
                        {
                            EditorGUI.PropertyField(materialPropRect, renderMaterialProp, GUIContent.none, true);
                            EditorGUI.PropertyField(layerUsagePropRect, layerUsageProp, GUIContent.none, true);
                        }
                        EditorGUI.indentLevel = prevIndentLevel;

                        // Render material preview
                        if (showMaterial)
                        {
                            if (styles == null)
                            {
                                styles = new Styles();
                            }
                            OnPreviewGUI(materialPreviewRect, styles.background);
                        }
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            }
            catch (ExitGUIException) { }
            catch (Exception ex) { Debug.LogException(ex); }
        }
Ejemplo n.º 11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            bool visible = true;

            // Draw label
            if (label != null)
            {
                EditorGUI.BeginChangeCheck();
                visible = SessionState.GetBool(property.propertyPath, false);
                var foldOutPosition = position;
                foldOutPosition.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Generic, GUIContent.none);
                visible = EditorGUI.Foldout(foldOutPosition, visible, label);
                if (EditorGUI.EndChangeCheck())
                {
                    SessionState.SetBool(property.propertyPath, visible);
                }
                position.yMin += foldOutPosition.height;
            }

            if (visible)
            {
                position.xMin += EditorGUIUtility.labelWidth;

                // Don't make child fields be indented
                var indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;

                var leftStyle   = EditorStyles.miniButtonLeft;
                var rightStyle  = EditorStyles.miniButtonRight;
                var middleStyle = EditorStyles.miniButtonMid;

                bool prevShowMixedValue    = EditorGUI.showMixedValue;
                bool deferredRenderingPath = ChiselEditorUtility.IsUsingDeferredRenderingPath();
                EditorGUI.showMixedValue = prevShowMixedValue || property.hasMultipleDifferentValues;
                try
                {
                    SerializedProperty ValueProp = property.FindPropertyRelative(nameof(SmoothingGroup.value));
                    var smoothingGroup           = (uint)ValueProp.intValue;

                    EditorGUI.BeginChangeCheck();
                    {
                        var startPosition = position;
                        position.width /= kBitsWide;
                        position.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Boolean, GUIContent.none);
                        for (int y = 0, i = 0; y < kBitsHigh; y++)
                        {
                            position.x = startPosition.x;
                            for (int x = 0; x < kBitsWide; x++, i++)
                            {
                                var toggleStyle = (x == 0) ? leftStyle :
                                                  (x == kBitsWide - 1) ? rightStyle :
                                                  middleStyle;
                                var bit     = (1u << i);
                                var enabled = GUI.Toggle(position, (smoothingGroup & bit) != 0, kBits[i], toggleStyle);
                                if (enabled)
                                {
                                    smoothingGroup = (smoothingGroup | bit);
                                }
                                else
                                {
                                    smoothingGroup = (smoothingGroup & ~bit);
                                }
                                position.x += position.width;
                            }
                            position.y += position.height + kSpacing;
                        }
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        ValueProp.intValue = (int)smoothingGroup;
                    }
                }
                catch (ExitGUIException) { }
                catch (Exception ex) { Debug.LogException(ex); }

                // Set indent back to what it was
                EditorGUI.indentLevel    = indent;
                EditorGUI.showMixedValue = prevShowMixedValue;
            }
            EditorGUI.EndProperty();
        }