static void OnSceneGUI(SceneView sceneView) { var dragArea = ChiselGUIUtility.GetRectForEditorWindow(sceneView); GridOnSceneGUI(sceneView); ChiselEditModeGUI.OnSceneGUI(sceneView, dragArea); ChiselOutlineRenderer.Instance.OnSceneGUI(sceneView); ChiselSceneBottomGUI.OnSceneGUI(sceneView); ChiselDragAndDropManager.Instance.OnSceneGUI(sceneView); ChiselClickSelectionManager.Instance.OnSceneGUI(sceneView); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (ChiselNodeEditorBase.InSceneSettingsContext) { EditorGUI.BeginProperty(position, label, property); EditorGUI.EndProperty(); return; } var hasLabel = ChiselGUIUtility.LabelHasContent(label); SerializedProperty uv0Prop = property.FindPropertyRelative(nameof(SurfaceDescription.UV0)); SerializedProperty surfaceFlagsProp = property.FindPropertyRelative(nameof(SurfaceDescription.surfaceFlags)); SerializedProperty smoothingGroupProp = property.FindPropertyRelative(nameof(SurfaceDescription.smoothingGroup)); EditorGUI.BeginProperty(position, label, property); bool prevShowMixedValue = EditorGUI.showMixedValue; try { property.serializedObject.Update(); EditorGUI.BeginChangeCheck(); { position.height = SurfaceFlagsPropertyDrawer.DefaultHeight; EditorGUI.PropertyField(position, surfaceFlagsProp, !hasLabel ? GUIContent.none : kSurfaceFlagsContents, false); position.y += position.height + kSpacing; position.height = UVMatrixPropertyDrawer.DefaultHeight; EditorGUI.PropertyField(position, uv0Prop, !hasLabel ? GUIContent.none : kUV0Contents, false); position.y += position.height + kSpacing; position.height = SmoothingGroupPropertyDrawer.GetDefaultHeight(smoothingGroupProp.propertyPath, true); EditorGUI.PropertyField(position, smoothingGroupProp, !hasLabel ? GUIContent.none : kSmoothingGroupContents, false); } if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } } catch (ExitGUIException) { } catch (Exception ex) { Debug.LogException(ex); } EditorGUI.showMixedValue = prevShowMixedValue; EditorGUI.EndProperty(); }
static void OnDuringSceneGUI(SceneView sceneView) { var prevSkin = GUI.skin; GUI.skin = ChiselSceneGUIStyle.GetSceneSkin(); try { var dragArea = ChiselGUIUtility.GetRectForEditorWindow(sceneView); GridOnSceneGUI(sceneView); ChiselEditModeGUI.OnSceneGUI(sceneView, dragArea); ChiselOutlineRenderer.Instance.OnSceneGUI(sceneView); ChiselDragAndDropManager.Instance.OnSceneGUI(sceneView); ChiselClickSelectionManager.Instance.OnSceneGUI(sceneView); } finally { GUI.skin = prevSkin; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { SerializedProperty UProp = property.FindPropertyRelative(nameof(UVMatrix.U)); SerializedProperty VProp = property.FindPropertyRelative(nameof(UVMatrix.V)); int translationID = GUIUtility.GetControlID(FocusType.Keyboard); int scaleID = GUIUtility.GetControlID(FocusType.Keyboard); int rotationID = GUIUtility.GetControlID(FocusType.Keyboard); var uvMatrix = new UVMatrix(UProp.vector4Value, VProp.vector4Value); var state = (UVMatrixState)EditorGUIUtility.GetStateObject(typeof(UVMatrixState), translationID); if (!state.initialized || state.uvMatrix.U != uvMatrix.U || state.uvMatrix.V != uvMatrix.V) { uvMatrix.Decompose(out state.translation, out state.rotation, out state.scale); state.uvMatrix = uvMatrix; state.initialized = true; } var hasLabel = ChiselGUIUtility.LabelHasContent(label); var prevIndenLevel = EditorGUI.indentLevel; EditorGUI.BeginProperty(position, label, property); { EditorGUI.BeginChangeCheck(); var prevMixedValues = EditorGUI.showMixedValue; EditorGUI.showMixedValue = property.hasMultipleDifferentValues; var translationContent = (label == null) ? GUIContent.none : kTranslationContent; var scaleContent = (label == null) ? GUIContent.none : kScaleContent; var rotationContent = (label == null) ? GUIContent.none : kRotationContent; position.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector2, GUIContent.none); var fieldRect = EditorGUI.PrefixLabel(position, translationID, !hasLabel ? GUIContent.none : translationContent); EditorGUI.indentLevel = 0; state.translation = EditorGUI.Vector2Field(fieldRect, GUIContent.none, state.translation); EditorGUI.indentLevel = prevIndenLevel; position.y += position.height + kSpacing; position.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector2, GUIContent.none); fieldRect = EditorGUI.PrefixLabel(position, scaleID, !hasLabel ? GUIContent.none : scaleContent); EditorGUI.indentLevel = 0; state.scale = EditorGUI.Vector2Field(fieldRect, GUIContent.none, state.scale); EditorGUI.indentLevel = prevIndenLevel; position.y += position.height + kSpacing; position.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Float, GUIContent.none); fieldRect = EditorGUI.PrefixLabel(position, rotationID, !hasLabel ? GUIContent.none : rotationContent); EditorGUI.indentLevel = 0; state.rotation = EditorGUI.FloatField(fieldRect, GUIContent.none, state.rotation); EditorGUI.indentLevel = prevIndenLevel; position.y += position.height + kSpacing; EditorGUI.showMixedValue = prevMixedValues; if (EditorGUI.EndChangeCheck()) { state.scale.x = (float)Math.Max(Math.Abs(state.scale.x), UVMatrix.kMinScale) * Math.Sign(state.scale.x); state.scale.y = (float)Math.Max(Math.Abs(state.scale.y), UVMatrix.kMinScale) * Math.Sign(state.scale.y); uvMatrix = UVMatrix.TRS(state.translation, state.rotation, state.scale); UProp.vector4Value = uvMatrix.U; VProp.vector4Value = uvMatrix.V; state.uvMatrix = uvMatrix; property.serializedObject.ApplyModifiedProperties(); } } EditorGUI.EndProperty(); /* * * SerializedProperty UxProp = property.FindPropertyRelative($"{nameof(UVMatrix.U)}.{nameof(UVMatrix.U.x)}"); * SerializedProperty VxProp = property.FindPropertyRelative($"{nameof(UVMatrix.V)}.{nameof(UVMatrix.V.x)}"); * * EditorGUI.BeginProperty(position, label, property); * { * position.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector4, GUIContent.none); * position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Keyboard), label); * * EditorGUI.MultiPropertyField(position, xyzw, UxProp); * position.y += position.height + kSpace; * * EditorGUI.MultiPropertyField(position, xyzw, VxProp); * } * EditorGUI.EndProperty(); */ }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); bool visible = true; // Draw label if (ChiselGUIUtility.LabelHasContent(label)) { 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; 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(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (ChiselNodeEditorBase.InSceneSettingsContext) { EditorGUI.BeginProperty(position, label, property); EditorGUI.EndProperty(); return; } EditorGUI.BeginProperty(position, label, property); try { var materialProperty = property; SerializedProperty layerUsageProp = materialProperty.FindPropertyRelative(ChiselBrushMaterial.kLayerUsageFieldName); SerializedProperty renderMaterialProp = materialProperty.FindPropertyRelative(ChiselBrushMaterial.kRenderMaterialFieldName); SerializedProperty physicsMaterialProp = materialProperty.FindPropertyRelative(ChiselBrushMaterial.kPhysicsMaterialFieldName); // Don't make child fields be indented var originalPosition = position; position = EditorGUI.IndentedRect(position); var indentOffset = position.x - originalPosition.x; var physicMaterialPrefixRect = originalPosition; physicMaterialPrefixRect.height = EditorGUIUtility.singleLineHeight; originalPosition.yMin += physicMaterialPrefixRect.height + kSpacing; var previewSize = originalPosition.height; var materialPrefixRect = originalPosition; materialPrefixRect.height = EditorGUIUtility.singleLineHeight; originalPosition.yMin += materialPrefixRect.height + kSpacing; var hasLabel = ChiselGUIUtility.LabelHasContent(label); EditorGUI.BeginChangeCheck(); { { var physicMaterialLabelID = EditorGUIUtility.GetControlID(kBrushPhysicMaterialEditorHashCode, FocusType.Keyboard, physicMaterialPrefixRect); var physicMaterialPropRect = EditorGUI.PrefixLabel(physicMaterialPrefixRect, physicMaterialLabelID, !hasLabel ? GUIContent.none : kPhysicRenderMaterialContents); physicMaterialPropRect.xMin -= indentOffset; if (physicsMaterialProp != null) { EditorGUI.PropertyField(physicMaterialPropRect, physicsMaterialProp, GUIContent.none, false); } } Rect propRect; { var materialLabelID = EditorGUIUtility.GetControlID(kBrushMaterialEditorHashCode, FocusType.Keyboard, materialPrefixRect); propRect = EditorGUI.PrefixLabel(materialPrefixRect, materialLabelID, !hasLabel ? GUIContent.none : kRenderMaterialContents); } propRect.height = previewSize; ShowMaterialLayerUsage(propRect, renderMaterialProp, layerUsageProp); } if (EditorGUI.EndChangeCheck()) { #if MATERIAL_IS_SCRIPTABLEOBJECT materialObject.ApplyModifiedProperties(); #else materialProperty.serializedObject.ApplyModifiedProperties(); #endif } } catch (ExitGUIException) { } catch (Exception ex) { Debug.LogException(ex); } EditorGUI.EndProperty(); }