public static void RecordObjects(UnityObject[] targets, string name) { if (targets.IsNull()) { return; } UnityUndo.RecordObjects(targets, name); }
public static void RegisterUndo(UnityObject[] targets, string name) { #if UNITY_3_0 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 UnityUndo.RegisterUndo(targets, name); #else UnityUndo.RecordObjects(targets, name); #endif }
internal bool DrawInspector(Rect contentRect) { int num6; bool flag4; if (s_styles == null) { s_styles = new Styles(); } base.serializedObject.Update(); GameObject target = this.target as GameObject; EditorGUIUtility.labelWidth = 52f; bool enabled = GUI.enabled; GUI.enabled = true; GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig); GUI.enabled = enabled; float width = contentRect.width; float y = contentRect.y; GUIContent goIcon = null; PrefabType none = PrefabType.None; if (this.m_AllOfSamePrefabType) { none = PrefabUtility.GetPrefabType(target); switch (none) { case PrefabType.None: goIcon = s_styles.goIcon; break; case PrefabType.Prefab: case PrefabType.PrefabInstance: case PrefabType.DisconnectedPrefabInstance: goIcon = s_styles.prefabIcon; break; case PrefabType.ModelPrefab: case PrefabType.ModelPrefabInstance: case PrefabType.DisconnectedModelPrefabInstance: goIcon = s_styles.modelIcon; break; case PrefabType.MissingPrefabInstance: goIcon = s_styles.prefabIcon; break; } } else { goIcon = s_styles.typelessIcon; } EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), base.targets, true, goIcon.image as Texture2D, this.m_Icon); EditorGUI.BeginDisabledGroup(none == PrefabType.ModelPrefab); EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none); float num3 = s_styles.staticFieldToggleWidth + 15f; float num4 = ((width - 52f) - num3) - 5f; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = this.m_Name.hasMultipleDifferentValues; string name = EditorGUI.DelayedTextField(new Rect(52f, (4f + y) + 1f, num4, 16f), target.name, null, EditorStyles.textField); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { foreach (UnityEngine.Object obj3 in base.targets) { ObjectNames.SetNameSmart(obj3 as GameObject, name); } } Rect totalPosition = new Rect(width - num3, 4f + y, s_styles.staticFieldToggleWidth, 16f); EditorGUI.BeginProperty(totalPosition, GUIContent.none, this.m_StaticEditorFlags); EditorGUI.BeginChangeCheck(); Rect position = totalPosition; EditorGUI.showMixedValue |= ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue); Event current = Event.current; EventType type = current.type; bool flag2 = (current.type == EventType.MouseDown) && (current.button != 0); if (flag2) { current.type = EventType.Ignore; } bool flagValue = EditorGUI.ToggleLeft(position, "Static", target.isStatic); if (flag2) { current.type = type; } EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, -1, flagValue); base.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.EndProperty(); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues; EditorGUI.EnumMaskField(new Rect(totalPosition.x + s_styles.staticFieldToggleWidth, totalPosition.y, 10f, 14f), GameObjectUtility.GetStaticEditorFlags(target), s_styles.staticDropdown, out num6, out flag4); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, num6, flag4); base.serializedObject.SetIsDifferentCacheDirty(); } float num7 = 4f; float num8 = 4f; EditorGUIUtility.fieldWidth = ((((width - num7) - 52f) - s_styles.layerFieldWidth) - num8) / 2f; string tag = null; try { tag = target.tag; } catch (Exception) { tag = "Undefined"; } EditorGUIUtility.labelWidth = s_styles.tagFieldWidth; Rect rect3 = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Tag); EditorGUI.BeginChangeCheck(); string str3 = EditorGUI.TagField(rect3, EditorGUIUtility.TempContent("Tag"), tag); if (EditorGUI.EndChangeCheck()) { this.m_Tag.stringValue = str3; Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle); foreach (UnityEngine.Object obj4 in base.targets) { (obj4 as GameObject).tag = str3; } } EditorGUI.EndProperty(); EditorGUIUtility.labelWidth = s_styles.layerFieldWidth; rect3 = new Rect((52f + EditorGUIUtility.fieldWidth) + num7, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Layer); EditorGUI.BeginChangeCheck(); int layer = EditorGUI.LayerField(rect3, EditorGUIUtility.TempContent("Layer"), target.layer); if (EditorGUI.EndChangeCheck()) { GameObjectUtility.ShouldIncludeChildren children = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(base.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(layer) + " for all child objects as well?"); if (children != GameObjectUtility.ShouldIncludeChildren.Cancel) { this.m_Layer.intValue = layer; this.SetLayer(layer, children == GameObjectUtility.ShouldIncludeChildren.IncludeChildren); } } EditorGUI.EndProperty(); if (!this.m_HasInstance || EditorApplication.isPlayingOrWillChangePlaymode) { goto Label_0992; } float num11 = ((width - 52f) - 5f) / 3f; Rect rect4 = new Rect(52f + (num11 * 0f), 44f + y, num11, 15f); Rect rect5 = new Rect(52f + (num11 * 1f), 44f + y, num11, 15f); Rect rect6 = new Rect(52f + (num11 * 2f), 44f + y, num11, 15f); Rect rect7 = new Rect(52f, 44f + y, num11 * 3f, 15f); GUIContent content2 = (base.targets.Length <= 1) ? s_styles.goTypeLabel[(int)none] : s_styles.goTypeLabelMultiple; if (content2 != null) { float x = GUI.skin.label.CalcSize(content2).x; switch (none) { case PrefabType.DisconnectedModelPrefabInstance: case PrefabType.MissingPrefabInstance: case PrefabType.DisconnectedPrefabInstance: GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; if (none == PrefabType.MissingPrefabInstance) { GUI.Label(new Rect(52f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel); } else { GUI.Label(new Rect((52f - x) - 5f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel); } GUI.contentColor = Color.white; goto Label_078B; } Rect rect8 = new Rect((52f - x) - 5f, 44f + y, x, 18f); GUI.Label(rect8, content2); } Label_078B: if (base.targets.Length > 1) { GUI.Label(rect7, "Instance Management Disabled", s_styles.instanceManagementInfo); } else { if ((none != PrefabType.MissingPrefabInstance) && GUI.Button(rect4, "Select", "MiniButtonLeft")) { Selection.activeObject = PrefabUtility.GetPrefabParent(this.target); EditorGUIUtility.PingObject(Selection.activeObject); } if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo(target, "Revert to prefab"); PrefabUtility.ReconnectToLastPrefab(target); PrefabUtility.RevertPrefabInstance(target); this.CalculatePrefabStatus(); Undo.RegisterCreatedObjectUndo(target, "Reconnect prefab"); GUIUtility.ExitGUI(); } bool flag5 = GUI.enabled; GUI.enabled = GUI.enabled && !AnimationMode.InAnimationMode(); if (((none == PrefabType.ModelPrefabInstance) || (none == PrefabType.PrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo(target, "Revert Prefab Instance"); PrefabUtility.RevertPrefabInstance(target); this.CalculatePrefabStatus(); GUIUtility.ExitGUI(); } if ((none == PrefabType.PrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance)) { GameObject source = PrefabUtility.FindValidUploadPrefabInstanceRoot(target); GUI.enabled = (source != null) && !AnimationMode.InAnimationMode(); if (GUI.Button(rect6, "Apply", "MiniButtonRight")) { UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(source); string assetPath = AssetDatabase.GetAssetPath(prefabParent); string[] assets = new string[] { assetPath }; if (Provider.PromptAndCheckoutIfNeeded(assets, "The version control requires you to check out the prefab before applying changes.")) { PrefabUtility.ReplacePrefab(source, prefabParent, ReplacePrefabOptions.ConnectToPrefab); this.CalculatePrefabStatus(); GUIUtility.ExitGUI(); } } } GUI.enabled = flag5; if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.ModelPrefabInstance)) && GUI.Button(rect6, "Open", "MiniButtonRight")) { AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target)); GUIUtility.ExitGUI(); } } Label_0992: EditorGUI.EndDisabledGroup(); base.serializedObject.ApplyModifiedProperties(); return(true); }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Rect handleRect = Tools.handleRect; Quaternion handleRectRotation = Tools.handleRectRotation; Vector3[] vector3Array = new Vector3[4]; for (int index = 0; index < 4; ++index) { Vector3 localRectPoint = (Vector3)RectTool.GetLocalRectPoint(handleRect, index); vector3Array[index] = handleRectRotation * localRectPoint + handlePosition; } RectHandles.RenderRectWithShadow(false, vector3Array); Color color1 = GUI.color; if ((bool)((Object)Camera.current)) { Vector3 planeNormal = !Camera.current.orthographic ? handlePosition + handleRectRotation * (Vector3)handleRect.center - Camera.current.transform.position : Camera.current.transform.forward; Vector3 vector1 = handleRectRotation * Vector3.right * handleRect.width; Vector3 vector2 = handleRectRotation * Vector3.up * handleRect.height; float num = Mathf.Clamp01((float)(((double)(Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector1, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude) / HandleUtility.GetHandleSize(handlePosition)) - 0.200000002980232) / 0.200000002980232 * 2.0)); Color color2 = color1; color2.a *= num; GUI.color = color2; } Vector3 handlePosition1 = Tools.GetHandlePosition(); if (!Tools.vertexDragging) { RectTransform component = Selection.activeTransform.GetComponent <RectTransform>(); bool flag1 = Selection.transforms.Length > 1; bool flag2 = !flag1 && Tools.pivotMode == PivotMode.Pivot && (Object)component != (Object)null; EditorGUI.BeginDisabledGroup(!flag1 && !flag2); EditorGUI.BeginChangeCheck(); Vector3 vector3 = RectTool.PivotHandleGUI(handleRect, handlePosition1, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (flag1) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (vector3 - handlePosition1); } else if (flag2) { Transform activeTransform = Selection.activeTransform; Undo.RecordObject((Object)component, "Move Rectangle Pivot"); Transform transform = !Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform) ? activeTransform : activeTransform.parent; Vector2 vector2_1 = (Vector2)transform.InverseTransformVector(vector3 - handlePosition1); vector2_1.x /= component.rect.width; vector2_1.y /= component.rect.height; Vector2 vector2_2 = component.pivot + vector2_1; RectTransformEditor.SetPivotSmart(component, vector2_2.x, 0, true, (Object)transform != (Object)component.transform); RectTransformEditor.SetPivotSmart(component, vector2_2.y, 1, true, (Object)transform != (Object)component.transform); } } EditorGUI.EndDisabledGroup(); } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { EditorGUI.BeginChangeCheck(); Vector3 scalePivot = handlePosition; Vector3 scaleDelta = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out scalePivot); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scaleDelta, scalePivot, handleRectRotation); } bool flag = true; if (Tools.rectBlueprintMode) { foreach (Component transform in Selection.transforms) { if ((Object)transform.GetComponent <RectTransform>() != (Object)null) { flag = false; } } } if (flag) { EditorGUI.BeginChangeCheck(); Quaternion quaternion = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { float angle; Vector3 axis1; (Quaternion.Inverse(handleRectRotation) * quaternion).ToAngleAxis(out angle, out axis1); Vector3 axis2 = handleRectRotation * axis1; Undo.RecordObjects((Object[])Selection.transforms, "Rotate"); foreach (Transform transform in Selection.transforms) { transform.RotateAround(handlePosition, axis2, angle); if ((Object)transform.parent != (Object)null) { transform.SendTransformChangedScale(); } } Tools.handleRotation = Quaternion.AngleAxis(angle, axis2) * Tools.handleRotation; } } } int num1 = (int)TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); Vector3 vector3_1 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetPositionDelta(vector3_1 - TransformManipulator.mouseDownHandlePosition); } int num2 = (int)TransformManipulator.EndManipulationHandling(); GUI.color = color1; }
private void OnGUI() { if (SnapSettings.ms_Styles == null) { SnapSettings.ms_Styles = new SnapSettings.Styles(); } GUILayout.Space(5f); EditorGUI.BeginChangeCheck(); Vector3 move = SnapSettings.move; move.x = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveX, move.x, new GUILayoutOption[0]); move.y = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveY, move.y, new GUILayoutOption[0]); move.z = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveZ, move.z, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { if (move.x <= 0f) { move.x = SnapSettings.move.x; } if (move.y <= 0f) { move.y = SnapSettings.move.y; } if (move.z <= 0f) { move.z = SnapSettings.move.z; } SnapSettings.move = move; } SnapSettings.scale = EditorGUILayout.FloatField(SnapSettings.ms_Styles.scale, SnapSettings.scale, new GUILayoutOption[0]); SnapSettings.rotation = EditorGUILayout.FloatField(SnapSettings.ms_Styles.rotation, SnapSettings.rotation, new GUILayoutOption[0]); GUILayout.Space(5f); bool flag = false; bool flag2 = false; bool flag3 = false; GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button(SnapSettings.ms_Styles.snapAllAxes, SnapSettings.ms_Styles.buttonLeft, new GUILayoutOption[0])) { flag = true; flag2 = true; flag3 = true; } if (GUILayout.Button(SnapSettings.ms_Styles.snapX, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0])) { flag = true; } if (GUILayout.Button(SnapSettings.ms_Styles.snapY, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0])) { flag2 = true; } if (GUILayout.Button(SnapSettings.ms_Styles.snapZ, SnapSettings.ms_Styles.buttonRight, new GUILayoutOption[0])) { flag3 = true; } GUILayout.EndHorizontal(); if (flag | flag2 | flag3) { Vector3 vector = new Vector3(1f / SnapSettings.move.x, 1f / SnapSettings.move.y, 1f / SnapSettings.move.z); Undo.RecordObjects(Selection.transforms, "Snap " + ((Selection.transforms.Length != 1) ? " selection" : Selection.activeGameObject.name) + " to grid"); Transform[] transforms = Selection.transforms; for (int i = 0; i < transforms.Length; i++) { Transform transform = transforms[i]; Vector3 position = transform.position; if (flag) { position.x = Mathf.Round(position.x * vector.x) / vector.x; } if (flag2) { position.y = Mathf.Round(position.y * vector.y) / vector.y; } if (flag3) { position.z = Mathf.Round(position.z * vector.z) / vector.z; } transform.position = position; } } }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Rect rect = Tools.handleRect; Quaternion rectRotation = Tools.handleRectRotation; // Draw rect Vector3[] verts = new Vector3[4]; for (int i = 0; i < 4; i++) { Vector3 pos = GetLocalRectPoint(rect, i); verts[i] = rectRotation * pos + handlePosition; } RectHandles.RenderRectWithShadow(false, verts); // Handle fading Color oldColor = GUI.color; float faded = 1; if (Camera.current) { Vector3 viewDir = Camera.current.orthographic ? Camera.current.transform.forward : (handlePosition + rectRotation * rect.center - Camera.current.transform.position); Vector3 rectRight = rectRotation * Vector3.right * rect.width; Vector3 rectUp = rectRotation * Vector3.up * rect.height; float visibleSize = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(rectRight, viewDir), Vector3.ProjectOnPlane(rectUp, viewDir)).magnitude); visibleSize /= HandleUtility.GetHandleSize(handlePosition); faded = Mathf.Clamp01((visibleSize - kMinVisibleSize) / kMinVisibleSize * 2); Color fadedColor = oldColor; fadedColor.a *= faded; GUI.color = fadedColor; } Vector3 oldPivot = Tools.GetHandlePosition(); // Pivot handle if (!Tools.vertexDragging) { RectTransform rectTransform = Selection.activeTransform.GetComponent <RectTransform>(); bool groupPivot = Selection.transforms.Length > 1; bool rectTransformPivot = !groupPivot && Tools.pivotMode == PivotMode.Pivot && rectTransform != null; using (new EditorGUI.DisabledScope(!groupPivot && !rectTransformPivot)) { EditorGUI.BeginChangeCheck(); Vector3 newPivot = PivotHandleGUI(rect, oldPivot, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (groupPivot) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (newPivot - oldPivot); } else if (rectTransformPivot) { Transform tr = Selection.activeTransform; Undo.RecordObject(rectTransform, "Move Rectangle Pivot"); Transform space = Tools.rectBlueprintMode && UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(tr) ? tr.parent : tr; Vector2 offset = space.InverseTransformVector(newPivot - oldPivot); offset.x /= rectTransform.rect.width; offset.y /= rectTransform.rect.height; Vector2 pivot = rectTransform.pivot + offset; RectTransformEditor.SetPivotSmart(rectTransform, pivot.x, 0, true, space != rectTransform.transform); RectTransformEditor.SetPivotSmart(rectTransform, pivot.y, 1, true, space != rectTransform.transform); } } } } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { // Resize handles EditorGUI.BeginChangeCheck(); Vector3 scalePivot = handlePosition; Vector3 scale = ResizeHandlesGUI(rect, handlePosition, rectRotation, out scalePivot); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scale, scalePivot, rectRotation); } bool enableRotation = true; if (Tools.rectBlueprintMode) { foreach (Transform t in Selection.transforms) { if (t.GetComponent <RectTransform>() != null) { enableRotation = false; } } } if (enableRotation) { // Rotation handles EditorGUI.BeginChangeCheck(); Quaternion after = RotationHandlesGUI(rect, handlePosition, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { Quaternion delta = Quaternion.Inverse(rectRotation) * after; float angle; Vector3 axis; delta.ToAngleAxis(out angle, out axis); axis = rectRotation * axis; Undo.RecordObjects(Selection.transforms, "Rotate"); foreach (Transform t in Selection.transforms) { t.RotateAround(handlePosition, axis, angle); // sync euler hints after a rotate tool update tyo fake continuous rotation t.SetLocalEulerHint(t.GetLocalEulerAngles(t.rotationOrder)); if (t.parent != null) { t.SendTransformChangedScale(); // force scale update, needed if transform has non-uniformly scaled parent. } } Tools.handleRotation = Quaternion.AngleAxis(angle, axis) * Tools.handleRotation; } } } TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); // Move handle EditorGUI.BeginChangeCheck(); Vector3 newPos = MoveHandlesGUI(rect, handlePosition, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (GridSnapping.active) { newPos = GridSnapping.Snap(newPos); } if (TransformManipulator.HandleHasMoved(newPos)) { TransformManipulator.SetPositionDelta(newPos, TransformManipulator.mouseDownHandlePosition); } } TransformManipulator.EndManipulationHandling(); GUI.color = oldColor; }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Rect handleRect = Tools.handleRect; Quaternion handleRectRotation = Tools.handleRectRotation; Vector3[] array = new Vector3[4]; for (int i = 0; i < 4; i++) { Vector3 point = RectTool.GetLocalRectPoint(handleRect, i); array[i] = handleRectRotation * point + handlePosition; } RectHandles.RenderRectWithShadow(false, array); Color color = GUI.color; if (Camera.current) { Vector3 planeNormal = (!Camera.current.orthographic) ? (handlePosition + handleRectRotation * handleRect.center - Camera.current.transform.position) : Camera.current.transform.forward; Vector3 vector = handleRectRotation * Vector3.right * handleRect.width; Vector3 vector2 = handleRectRotation * Vector3.up * handleRect.height; float num = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude); num /= HandleUtility.GetHandleSize(handlePosition); float num2 = Mathf.Clamp01((num - 0.2f) / 0.2f * 2f); Color color2 = color; color2.a *= num2; GUI.color = color2; } Vector3 handlePosition2 = Tools.GetHandlePosition(); if (!Tools.vertexDragging) { RectTransform component = Selection.activeTransform.GetComponent <RectTransform>(); bool flag = Selection.transforms.Length > 1; bool flag2 = !flag && Tools.pivotMode == PivotMode.Pivot && component != null; using (new EditorGUI.DisabledScope(!flag && !flag2)) { EditorGUI.BeginChangeCheck(); Vector3 a = RectTool.PivotHandleGUI(handleRect, handlePosition2, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (flag) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (a - handlePosition2); } else if (flag2) { Transform activeTransform = Selection.activeTransform; Undo.RecordObject(component, "Move Rectangle Pivot"); Transform transform = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent; Vector2 b = transform.InverseTransformVector(a - handlePosition2); b.x /= component.rect.width; b.y /= component.rect.height; Vector2 vector3 = component.pivot + b; RectTransformEditor.SetPivotSmart(component, vector3.x, 0, true, transform != component.transform); RectTransformEditor.SetPivotSmart(component, vector3.y, 1, true, transform != component.transform); } } } } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { EditorGUI.BeginChangeCheck(); Vector3 pivotPosition = handlePosition; Vector3 scaleDelta = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out pivotPosition); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scaleDelta, pivotPosition, handleRectRotation); } bool flag3 = true; if (Tools.rectBlueprintMode) { Transform[] transforms = Selection.transforms; for (int j = 0; j < transforms.Length; j++) { Transform transform2 = transforms[j]; if (transform2.GetComponent <RectTransform>() != null) { flag3 = false; } } } if (flag3) { EditorGUI.BeginChangeCheck(); Quaternion rhs = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { float angle; Vector3 vector4; (Quaternion.Inverse(handleRectRotation) * rhs).ToAngleAxis(out angle, out vector4); vector4 = handleRectRotation * vector4; Undo.RecordObjects(Selection.transforms, "Rotate"); Transform[] transforms2 = Selection.transforms; for (int k = 0; k < transforms2.Length; k++) { Transform transform3 = transforms2[k]; transform3.RotateAround(handlePosition, vector4, angle); transform3.SetLocalEulerHint(transform3.GetLocalEulerAngles(transform3.rotationOrder)); if (transform3.parent != null) { transform3.SendTransformChangedScale(); } } Tools.handleRotation = Quaternion.AngleAxis(angle, vector4) * Tools.handleRotation; } } } TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); Vector3 a2 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { Vector3 positionDelta = a2 - TransformManipulator.mouseDownHandlePosition; TransformManipulator.SetPositionDelta(positionDelta); } TransformManipulator.EndManipulationHandling(); GUI.color = color; }
public void RotationField(bool disabled) { Transform transform0 = targets[0] as Transform; Vector3 eulerAngles0 = transform0.GetLocalEulerAngles(transform0.rotationOrder); int differentRotationMask = 0b000; bool differentRotationOrder = false; for (int i = 1; i < targets.Length; i++) { Transform otherTransform = (targets[i] as Transform); if (differentRotationMask != 0b111) { Vector3 otherLocalEuler = otherTransform.GetLocalEulerAngles(otherTransform.rotationOrder); for (int j = 0; j < 3; j++) { if (otherLocalEuler[j] != eulerAngles0[j]) { differentRotationMask |= 1 << j; } } } differentRotationOrder |= otherTransform.rotationOrder != transform0.rotationOrder; } Rect r = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); GUIContent label = EditorGUI.BeginProperty(r, rotationContent, m_Rotation); m_EulerFloats[0].doubleVal = eulerAngles0.x; m_EulerFloats[1].doubleVal = eulerAngles0.y; m_EulerFloats[2].doubleVal = eulerAngles0.z; int id = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, r); if (AnimationMode.InAnimationMode() && transform0.rotationOrder != RotationOrder.OrderZXY) { string rotationLabel = differentRotationOrder ? "Mixed" : transform0.rotationOrder.ToString().Substring(RotationOrder.OrderXYZ.ToString().Length - 3); label.text = label.text + " (" + rotationLabel + ")"; } // Using manual 3 float fields here instead of MultiFloatField or Vector3Field // since we want to query expression validity of each individually, and // so that the label and the fields can be disabled separately, similar to // regular property fields. Also want to avoid superfluous label, which // creates a focus target even when there's no content (Case 953241). r = EditorGUI.MultiFieldPrefixLabel(r, id, label, 3); r.height = EditorGUIUtility.singleLineHeight; int eulerChangedMask = 0; using (new EditorGUI.DisabledScope(disabled)) { var eCount = m_EulerFloats.Length; float w = (r.width - (eCount - 1) * EditorGUI.kSpacingSubLabel) / eCount; Rect nr = new Rect(r) { width = w }; var prevWidth = EditorGUIUtility.labelWidth; var prevIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; for (int i = 0; i < m_EulerFloats.Length; i++) { EditorGUIUtility.labelWidth = EditorGUI.GetLabelWidth(s_XYZLabels[i]); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = (differentRotationMask & (1 << i)) != 0; EditorGUI.FloatField(nr, s_XYZLabels[i], ref m_EulerFloats[i]); if (EditorGUI.EndChangeCheck() && m_EulerFloats[i].hasResult) { eulerChangedMask |= 1 << i; } nr.x += w + EditorGUI.kSpacingSubLabel; } EditorGUIUtility.labelWidth = prevWidth; EditorGUI.indentLevel = prevIndent; } if (eulerChangedMask != 0) { eulerAngles0 = new Vector3( MathUtils.ClampToFloat(m_EulerFloats[0].doubleVal), MathUtils.ClampToFloat(m_EulerFloats[1].doubleVal), MathUtils.ClampToFloat(m_EulerFloats[2].doubleVal)); Undo.RecordObjects(targets, "Inspector"); // Generic undo title as remove duplicates will discard the name. Undo.SetCurrentGroupName(string.Format("Set Rotation")); for (var idx = 0; idx < targets.Length; ++idx) { var tr = targets[idx] as Transform; if (tr == null) { continue; } var trEuler = tr.GetLocalEulerAngles(tr.rotationOrder); // if we have any per-object expressions just entered, we need to evaluate // it for each object with their own individual input value for (int c = 0; c < 3; ++c) { if ((eulerChangedMask & (1 << c)) != 0) { if (m_EulerFloats[c].expression != null) { double trEulerComp = eulerAngles0[c]; if (m_EulerFloats[c].expression.Evaluate(ref trEulerComp, idx, targets.Length)) { trEuler[c] = MathUtils.ClampToFloat(trEulerComp); } } else { trEuler[c] = MathUtils.ClampToFloat(eulerAngles0[c]); } } } tr.SetLocalEulerAngles(trEuler, tr.rotationOrder); if (tr.parent != null) { tr.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent. } } m_Rotation.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.showMixedValue = false; if (differentRotationOrder) { EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning); } EditorGUI.EndProperty(); }
public void RotationField(bool disabled) { Transform transform = this.targets[0] as Transform; Vector3 localEulerAngles = transform.GetLocalEulerAngles(transform.rotationOrder); if (this.m_OldEulerAngles.x != localEulerAngles.x || this.m_OldEulerAngles.y != localEulerAngles.y || this.m_OldEulerAngles.z != localEulerAngles.z || this.m_OldRotationOrder != transform.rotationOrder) { this.m_EulerAngles = transform.GetLocalEulerAngles(transform.rotationOrder); this.m_OldRotationOrder = transform.rotationOrder; } bool flag = false; bool flag2 = false; for (int i = 1; i < this.targets.Length; i++) { Transform transform2 = this.targets[i] as Transform; Vector3 localEulerAngles2 = transform2.GetLocalEulerAngles(transform2.rotationOrder); flag |= (localEulerAngles2.x != localEulerAngles.x || localEulerAngles2.y != localEulerAngles.y || localEulerAngles2.z != localEulerAngles.z); flag2 |= (transform2.rotationOrder != transform.rotationOrder); } Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (float)((!EditorGUIUtility.wideMode) ? 2 : 1), new GUILayoutOption[0]); GUIContent gUIContent = EditorGUI.BeginProperty(rect, this.rotationContent, this.m_Rotation); EditorGUI.showMixedValue = flag; EditorGUI.BeginChangeCheck(); int controlID = GUIUtility.GetControlID(TransformRotationGUI.s_FoldoutHash, FocusType.Keyboard, rect); if (AnimationMode.InAnimationMode() && transform.rotationOrder != RotationOrder.OrderZXY) { string text; if (flag2) { text = "Mixed"; } else { text = transform.rotationOrder.ToString(); text = text.Substring(text.Length - 3); } gUIContent.text = gUIContent.text + " (" + text + ")"; } rect = EditorGUI.MultiFieldPrefixLabel(rect, controlID, gUIContent, 3); rect.height = EditorGUIUtility.singleLineHeight; using (new EditorGUI.DisabledScope(disabled)) { this.m_EulerAngles = EditorGUI.Vector3Field(rect, GUIContent.none, this.m_EulerAngles); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(this.targets, "Inspector"); UnityEngine.Object[] array = this.targets; for (int j = 0; j < array.Length; j++) { Transform transform3 = (Transform)array[j]; transform3.SetLocalEulerAngles(this.m_EulerAngles, transform3.rotationOrder); if (transform3.parent != null) { transform3.SendTransformChangedScale(); } } this.m_Rotation.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.showMixedValue = false; if (flag2) { EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning); } EditorGUI.EndProperty(); }
public void RotationField(bool disabled) { Transform t = targets[0] as Transform; Vector3 localEuler = t.GetLocalEulerAngles(t.rotationOrder); if ( m_OldEulerAngles.x != localEuler.x || m_OldEulerAngles.y != localEuler.y || m_OldEulerAngles.z != localEuler.z || m_OldRotationOrder != t.rotationOrder ) { m_EulerAngles = t.GetLocalEulerAngles(t.rotationOrder); m_OldRotationOrder = t.rotationOrder; } var targetRotationOrder = t.rotationOrder; bool differentRotation = false; bool differentRotationOrder = false; for (int i = 1; i < targets.Length; i++) { Transform otherTransform = (targets[i] as Transform); if (!differentRotation) { Vector3 otherLocalEuler = otherTransform.GetLocalEulerAngles(otherTransform.rotationOrder); differentRotation = (otherLocalEuler.x != localEuler.x || otherLocalEuler.y != localEuler.y || otherLocalEuler.z != localEuler.z); } differentRotationOrder |= otherTransform.rotationOrder != targetRotationOrder; } Rect r = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); GUIContent label = EditorGUI.BeginProperty(r, rotationContent, m_Rotation); m_EulerFloats[0] = m_EulerAngles.x; m_EulerFloats[1] = m_EulerAngles.y; m_EulerFloats[2] = m_EulerAngles.z; EditorGUI.showMixedValue = differentRotation; EditorGUI.BeginChangeCheck(); int id = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, r); string rotationLabel = ""; if (AnimationMode.InAnimationMode() && t.rotationOrder != RotationOrder.OrderZXY) { if (differentRotationOrder) { rotationLabel = "Mixed"; } else { rotationLabel = (t.rotationOrder).ToString(); rotationLabel = rotationLabel.Substring(rotationLabel.Length - 3); } label.text = label.text + " (" + rotationLabel + ")"; } // Using MultiFieldPrefixLabel/MultiFloatField here instead of Vector3Field // so that the label and the float fields can be disabled separately, // similar to other property-driven controls // Using MultiFloatField instead of Vector3Field to avoid superfluous label // (which creates a focus target even when there's no content (Case 953241)) r = EditorGUI.MultiFieldPrefixLabel(r, id, label, 3); r.height = EditorGUIUtility.singleLineHeight; using (new EditorGUI.DisabledScope(disabled)) EditorGUI.MultiFloatField(r, s_XYZLabels, m_EulerFloats); if (EditorGUI.EndChangeCheck()) { m_EulerAngles = new Vector3(m_EulerFloats[0], m_EulerFloats[1], m_EulerFloats[2]); Undo.RecordObjects(targets, "Inspector"); // Generic undo title to be consistent with Position and Scale changes. foreach (Transform tr in targets) { tr.SetLocalEulerAngles(m_EulerAngles, tr.rotationOrder); if (tr.parent != null) { tr.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent. } } m_Rotation.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.showMixedValue = false; if (differentRotationOrder) { EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning); } EditorGUI.EndProperty(); }
internal bool DrawInspector(Rect contentRect) { if (GameObjectInspector.s_styles == null) { GameObjectInspector.s_styles = new GameObjectInspector.Styles(); } this.serializedObject.Update(); GameObject target1 = this.target as GameObject; EditorGUIUtility.labelWidth = 52f; bool enabled1 = GUI.enabled; GUI.enabled = true; GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig); GUI.enabled = enabled1; float width1 = contentRect.width; float y = contentRect.y; GUIContent guiContent = (GUIContent)null; PrefabType prefabType = PrefabType.None; if (this.m_AllOfSamePrefabType) { prefabType = PrefabUtility.GetPrefabType((UnityEngine.Object)target1); switch (prefabType) { case PrefabType.None: guiContent = GameObjectInspector.s_styles.goIcon; break; case PrefabType.Prefab: case PrefabType.PrefabInstance: case PrefabType.DisconnectedPrefabInstance: guiContent = GameObjectInspector.s_styles.prefabIcon; break; case PrefabType.ModelPrefab: case PrefabType.ModelPrefabInstance: case PrefabType.DisconnectedModelPrefabInstance: guiContent = GameObjectInspector.s_styles.modelIcon; break; case PrefabType.MissingPrefabInstance: guiContent = GameObjectInspector.s_styles.prefabIcon; break; } } else { guiContent = GameObjectInspector.s_styles.typelessIcon; } EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), this.targets, true, guiContent.image as Texture2D, this.m_Icon); EditorGUI.BeginDisabledGroup(prefabType == PrefabType.ModelPrefab); EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none); float num1 = GameObjectInspector.s_styles.staticFieldToggleWidth + 15f; float width2 = (float)((double)width1 - 52.0 - (double)num1 - 5.0); EditorGUI.DelayedTextField(new Rect(52f, (float)(4.0 + (double)y + 1.0), width2, 16f), this.m_Name, GUIContent.none); Rect totalPosition = new Rect(width1 - num1, 4f + y, GameObjectInspector.s_styles.staticFieldToggleWidth, 16f); EditorGUI.BeginProperty(totalPosition, GUIContent.none, this.m_StaticEditorFlags); EditorGUI.BeginChangeCheck(); Rect position1 = totalPosition; EditorGUI.showMixedValue |= GameObjectInspector.ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue); Event current = Event.current; EventType type = current.type; bool flag = current.type == EventType.MouseDown && current.button != 0; if (flag) { current.type = EventType.Ignore; } bool flagValue = EditorGUI.ToggleLeft(position1, "Static", target1.isStatic); if (flag) { current.type = type; } EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(this.targets, -1, flagValue); this.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.EndProperty(); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues; int changedFlags; bool changedToValue; EditorGUI.EnumMaskField(new Rect(totalPosition.x + GameObjectInspector.s_styles.staticFieldToggleWidth, totalPosition.y, 10f, 14f), (Enum)GameObjectUtility.GetStaticEditorFlags(target1), GameObjectInspector.s_styles.staticDropdown, out changedFlags, out changedToValue); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(this.targets, changedFlags, changedToValue); this.serializedObject.SetIsDifferentCacheDirty(); } float num2 = 4f; float num3 = 4f; EditorGUIUtility.fieldWidth = (float)(((double)width1 - (double)num2 - 52.0 - (double)GameObjectInspector.s_styles.layerFieldWidth - (double)num3) / 2.0); string tag; try { tag = target1.tag; } catch (Exception ex) { tag = "Undefined"; } EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.tagFieldWidth; Rect rect = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect, GUIContent.none, this.m_Tag); EditorGUI.BeginChangeCheck(); string str = EditorGUI.TagField(rect, EditorGUIUtility.TempContent("Tag"), tag); if (EditorGUI.EndChangeCheck()) { this.m_Tag.stringValue = str; Undo.RecordObjects(this.targets, "Change Tag of " + this.targetTitle); foreach (UnityEngine.Object target2 in this.targets) { (target2 as GameObject).tag = str; } } EditorGUI.EndProperty(); EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.layerFieldWidth; rect = new Rect(52f + EditorGUIUtility.fieldWidth + num2, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect, GUIContent.none, this.m_Layer); EditorGUI.BeginChangeCheck(); int layer = EditorGUI.LayerField(rect, EditorGUIUtility.TempContent("Layer"), target1.layer); if (EditorGUI.EndChangeCheck()) { GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(this.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(layer) + " for all child objects as well?"); if (shouldIncludeChildren != GameObjectUtility.ShouldIncludeChildren.Cancel) { this.m_Layer.intValue = layer; this.SetLayer(layer, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren); } } EditorGUI.EndProperty(); if (this.m_HasInstance && !EditorApplication.isPlayingOrWillChangePlaymode) { float width3 = (float)(((double)width1 - 52.0 - 5.0) / 3.0); Rect position2 = new Rect((float)(52.0 + (double)width3 * 0.0), 44f + y, width3, 15f); Rect position3 = new Rect((float)(52.0 + (double)width3 * 1.0), 44f + y, width3, 15f); Rect position4 = new Rect((float)(52.0 + (double)width3 * 2.0), 44f + y, width3, 15f); Rect position5 = new Rect(52f, 44f + y, width3 * 3f, 15f); GUIContent content = this.targets.Length <= 1 ? GameObjectInspector.s_styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_styles.goTypeLabelMultiple; if (content != null) { float x = GUI.skin.label.CalcSize(content).x; if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; if (prefabType == PrefabType.MissingPrefabInstance) { GUI.Label(new Rect(52f, 44f + y, (float)((double)width1 - 52.0 - 5.0), 18f), content, EditorStyles.whiteLabel); } else { GUI.Label(new Rect((float)(52.0 - (double)x - 5.0), 44f + y, (float)((double)width1 - 52.0 - 5.0), 18f), content, EditorStyles.whiteLabel); } GUI.contentColor = Color.white; } else { GUI.Label(new Rect((float)(52.0 - (double)x - 5.0), 44f + y, x, 18f), content); } } if (this.targets.Length > 1) { GUI.Label(position5, "Instance Management Disabled", GameObjectInspector.s_styles.instanceManagementInfo); } else { if (prefabType != PrefabType.MissingPrefabInstance && GUI.Button(position2, "Select", (GUIStyle)"MiniButtonLeft")) { Selection.activeObject = PrefabUtility.GetPrefabParent(this.target); EditorGUIUtility.PingObject(Selection.activeObject); } if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) && GUI.Button(position3, "Revert", (GUIStyle)"MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo((UnityEngine.Object)target1, "Revert to prefab"); PrefabUtility.ReconnectToLastPrefab(target1); PrefabUtility.RevertPrefabInstance(target1); this.CalculatePrefabStatus(); Undo.RegisterCreatedObjectUndo((UnityEngine.Object)target1, "Reconnect prefab"); GUIUtility.ExitGUI(); } bool enabled2 = GUI.enabled; GUI.enabled = GUI.enabled && !AnimationMode.InAnimationMode(); if ((prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance) && GUI.Button(position3, "Revert", (GUIStyle)"MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo((UnityEngine.Object)target1, "Revert Prefab Instance"); PrefabUtility.RevertPrefabInstance(target1); this.CalculatePrefabStatus(); Undo.RegisterCreatedObjectUndo((UnityEngine.Object)target1, "Revert prefab"); GUIUtility.ExitGUI(); } if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GameObject prefabInstanceRoot = PrefabUtility.FindValidUploadPrefabInstanceRoot(target1); GUI.enabled = (UnityEngine.Object)prefabInstanceRoot != (UnityEngine.Object)null && !AnimationMode.InAnimationMode(); if (GUI.Button(position4, "Apply", (GUIStyle)"MiniButtonRight")) { UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent((UnityEngine.Object)prefabInstanceRoot); if (Provider.PromptAndCheckoutIfNeeded(new string[1] { AssetDatabase.GetAssetPath(prefabParent) }, "The version control requires you to check out the prefab before applying changes.")) { PrefabUtility.ReplacePrefab(prefabInstanceRoot, prefabParent, ReplacePrefabOptions.ConnectToPrefab); this.CalculatePrefabStatus(); EditorSceneManager.MarkSceneDirty(prefabInstanceRoot.scene); GUIUtility.ExitGUI(); } } } GUI.enabled = enabled2; if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) && GUI.Button(position4, "Open", (GUIStyle)"MiniButtonRight")) { AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target)); GUIUtility.ExitGUI(); } } } EditorGUI.EndDisabledGroup(); this.serializedObject.ApplyModifiedProperties(); return(true); }
public static bool SetStaticFlags(Object[] targetObjects, int changedFlags, bool flagValue) { bool allFlagsAreChanged = (changedFlags == int.MaxValue); var msgChangedFlags = changedFlags; if (msgChangedFlags < 0 && !allFlagsAreChanged) { //In order to have a list of human readable list of changed flags, //we need to filter out bits that does not correspont to any option. int allPossibleValues = 0; var values = Enum.GetValues(typeof(StaticEditorFlags)); foreach (var value in values) { allPossibleValues |= (int)value; } msgChangedFlags = msgChangedFlags & allPossibleValues; } StaticEditorFlags flag = allFlagsAreChanged ? (StaticEditorFlags)0 : (StaticEditorFlags)Enum.Parse(typeof(StaticEditorFlags), msgChangedFlags.ToString()); // Should we include child objects? GameObjectUtility.ShouldIncludeChildren includeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(targetObjects.OfType <GameObject>(), "Change Static Flags", allFlagsAreChanged ? "Do you want to " + (flagValue ? "enable" : "disable") + " the static flags for all the child objects as well?" : "Do you want to " + (flagValue ? "enable" : "disable") + " the " + ObjectNames.NicifyVariableName(flag.ToString()) + " flag for all the child objects as well?"); if (includeChildren == GameObjectUtility.ShouldIncludeChildren.Cancel) { EditorGUIUtility.ExitGUI(); return(false); } var objects = GetObjects(targetObjects, includeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren); Undo.RecordObjects(objects, "Change Static Flags"); // Calculate new flags value separately for each object so other flags are not affected. foreach (GameObject go in objects) { int goFlags = (int)GameObjectUtility.GetStaticEditorFlags(go); // Following change is for backward compatibility after fixing case 1221145 if (goFlags < 0) { goFlags = int.MaxValue; } // MaxValue will cause issues when changing it to other values so we set it to the max possible value // that Static Editor flags can have before doing anything else with it if (goFlags == int.MaxValue && flagValue == false) { goFlags = (int)Math.Pow(2, Enum.GetNames(typeof(StaticEditorFlags)).Length - 1) - 1; } goFlags = flagValue ? goFlags | changedFlags : goFlags & ~changedFlags; GameObjectUtility.SetStaticEditorFlags(go, (StaticEditorFlags)goFlags); } return(true); }
private void OnGUI() { if (SnapSettings.ms_Styles == null) { SnapSettings.ms_Styles = new SnapSettings.Styles(); } GUILayout.Space(5f); EditorGUI.BeginChangeCheck(); Vector3 move = SnapSettings.move; move.x = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveX, move.x, new GUILayoutOption[0]); move.y = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveY, move.y, new GUILayoutOption[0]); move.z = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveZ, move.z, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { if ((double)move.x <= 0.0) { move.x = SnapSettings.move.x; } if ((double)move.y <= 0.0) { move.y = SnapSettings.move.y; } if ((double)move.z <= 0.0) { move.z = SnapSettings.move.z; } SnapSettings.move = move; } SnapSettings.scale = EditorGUILayout.FloatField(SnapSettings.ms_Styles.scale, SnapSettings.scale, new GUILayoutOption[0]); SnapSettings.rotation = EditorGUILayout.FloatField(SnapSettings.ms_Styles.rotation, SnapSettings.rotation, new GUILayoutOption[0]); GUILayout.Space(5f); bool flag1 = false; bool flag2 = false; bool flag3 = false; GUILayout.BeginHorizontal(); if (GUILayout.Button(SnapSettings.ms_Styles.snapAllAxes, SnapSettings.ms_Styles.buttonLeft, new GUILayoutOption[0])) { flag1 = true; flag2 = true; flag3 = true; } if (GUILayout.Button(SnapSettings.ms_Styles.snapX, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0])) { flag1 = true; } if (GUILayout.Button(SnapSettings.ms_Styles.snapY, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0])) { flag2 = true; } if (GUILayout.Button(SnapSettings.ms_Styles.snapZ, SnapSettings.ms_Styles.buttonRight, new GUILayoutOption[0])) { flag3 = true; } GUILayout.EndHorizontal(); if (!(flag1 | flag2 | flag3)) { return; } Vector3 vector3 = new Vector3(1f / SnapSettings.move.x, 1f / SnapSettings.move.y, 1f / SnapSettings.move.z); Undo.RecordObjects((Object[])Selection.transforms, "Snap " + (Selection.transforms.Length != 1 ? " selection" : Selection.activeGameObject.name) + " to grid"); foreach (Transform transform in Selection.transforms) { Vector3 position = transform.position; if (flag1) { position.x = Mathf.Round(position.x * vector3.x) / vector3.x; } if (flag2) { position.y = Mathf.Round(position.y * vector3.y) / vector3.y; } if (flag3) { position.z = Mathf.Round(position.z * vector3.z) / vector3.z; } transform.position = position; } }
private void CellGUI(Rect cellRect, SerializedPropertyTreeView.SerializedPropertyItem item, int columnIndex, ref TreeView.RowGUIArgs args) { Profiler.BeginSample("SerializedPropertyTreeView.CellGUI"); base.CenterRectUsingSingleLineHeight(ref cellRect); SerializedPropertyDataStore.Data data = item.GetData(); SerializedPropertyTreeView.Column column = (SerializedPropertyTreeView.Column)base.multiColumnHeader.GetColumn(columnIndex); if (column.drawDelegate == SerializedPropertyTreeView.DefaultDelegates.s_DrawName) { Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.LabelField"); TreeView.DefaultGUI.Label(cellRect, data.name, base.IsSelected(args.item.id), false); Profiler.EndSample(); } else if (column.drawDelegate != null) { SerializedProperty[] properties = data.properties; int num = (column.dependencyIndices == null) ? 0 : column.dependencyIndices.Length; for (int i = 0; i < num; i++) { this.m_ColumnsInternal[columnIndex].dependencyProps[i] = properties[column.dependencyIndices[i]]; } if (args.item.id == base.state.lastClickedID && base.HasFocus() && columnIndex == base.multiColumnHeader.state.visibleColumns[(base.multiColumnHeader.state.visibleColumns[0] != 0) ? 0 : 1]) { GUI.SetNextControlName(SerializedPropertyTreeView.Styles.focusHelper); } SerializedProperty serializedProperty = data.properties[columnIndex]; EditorGUI.BeginChangeCheck(); Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.drawDelegate"); column.drawDelegate(cellRect, serializedProperty, this.m_ColumnsInternal[columnIndex].dependencyProps); Profiler.EndSample(); if (EditorGUI.EndChangeCheck()) { this.m_ChangedId = ((column.filter == null || !column.filter.Active()) ? this.m_ChangedId : GUIUtility.keyboardControl); data.Store(); IList <int> selection = base.GetSelection(); if (selection.Contains(data.objectId)) { IList <TreeViewItem> list = base.FindRows(selection); Undo.RecordObjects((from r in list select((SerializedPropertyTreeView.SerializedPropertyItem)r).GetData().serializedObject.targetObject).ToArray <UnityEngine.Object>(), "Modify Multiple Properties"); foreach (TreeViewItem current in list) { if (current.id != args.item.id) { SerializedPropertyDataStore.Data data2 = ((SerializedPropertyTreeView.SerializedPropertyItem)current).GetData(); if (SerializedPropertyTreeView.IsEditable(data2.serializedObject.targetObject)) { if (column.copyDelegate != null) { column.copyDelegate(data2.properties[columnIndex], serializedProperty); } else { SerializedPropertyTreeView.DefaultDelegates.s_CopyDefault(data2.properties[columnIndex], serializedProperty); } data2.Store(); } } } } } Profiler.EndSample(); } }
public void RotationField(bool disabled) { Transform transform = this.targets[0] as Transform; Vector3 localEulerAngles = transform.GetLocalEulerAngles(transform.rotationOrder); if (((this.m_OldEulerAngles.x != localEulerAngles.x) || (this.m_OldEulerAngles.y != localEulerAngles.y)) || ((this.m_OldEulerAngles.z != localEulerAngles.z) || (this.m_OldRotationOrder != transform.rotationOrder))) { this.m_EulerAngles = transform.GetLocalEulerAngles(transform.rotationOrder); this.m_OldRotationOrder = transform.rotationOrder; } bool flag = false; bool flag2 = false; for (int i = 1; i < this.targets.Length; i++) { Transform transform2 = this.targets[i] as Transform; Vector3 vector2 = transform2.GetLocalEulerAngles(transform2.rotationOrder); flag |= ((vector2.x != localEulerAngles.x) || (vector2.y != localEulerAngles.y)) || !(vector2.z == localEulerAngles.z); flag2 |= transform2.rotationOrder != transform.rotationOrder; } Rect totalPosition = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (!EditorGUIUtility.wideMode ? ((float)2) : ((float)1)), new GUILayoutOption[0]); GUIContent label = EditorGUI.BeginProperty(totalPosition, this.rotationContent, this.m_Rotation); EditorGUI.showMixedValue = flag; EditorGUI.BeginChangeCheck(); int id = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, totalPosition); string str = ""; if (UnityEditor.AnimationMode.InAnimationMode() && (transform.rotationOrder != RotationOrder.OrderZXY)) { if (flag2) { str = "Mixed"; } else { str = transform.rotationOrder.ToString(); str = str.Substring(str.Length - 3); } label.text = label.text + " (" + str + ")"; } totalPosition = EditorGUI.MultiFieldPrefixLabel(totalPosition, id, label, 3); totalPosition.height = EditorGUIUtility.singleLineHeight; using (new EditorGUI.DisabledScope(disabled)) { this.m_EulerAngles = EditorGUI.Vector3Field(totalPosition, GUIContent.none, this.m_EulerAngles); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(this.targets, "Inspector"); foreach (Transform transform3 in this.targets) { transform3.SetLocalEulerAngles(this.m_EulerAngles, transform3.rotationOrder); if (transform3.parent != null) { transform3.SendTransformChangedScale(); } } this.m_Rotation.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.showMixedValue = false; if (flag2) { EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning); } EditorGUI.EndProperty(); }
public static SerializedPropertyTreeView.Column[] CreateEmissivesColumns(out string[] propNames) { var columns = new[] { new SerializedPropertyTreeView.Column // 0: Icon { headerContent = Styles.SelectObjects, headerTextAlignment = TextAlignment.Left, sortedAscending = true, sortingArrowAlignment = TextAlignment.Center, width = 20, minWidth = 20, maxWidth = 20, autoResize = false, allowToggleVisibility = true, propertyName = "m_LightmapFlags", dependencyIndices = null, compareDelegate = null, drawDelegate = (Rect r, SerializedProperty prop, SerializedProperty[] dep) => { if (GUI.Button(r, Styles.SelectObjectsButton, "label")) { SearchableEditorWindow.SearchForReferencesToInstanceID(prop.serializedObject.targetObject.GetInstanceID()); } } }, new SerializedPropertyTreeView.Column // 1: Name { headerContent = Styles.Name, headerTextAlignment = TextAlignment.Left, sortedAscending = true, sortingArrowAlignment = TextAlignment.Center, width = 200, minWidth = 100, autoResize = false, allowToggleVisibility = true, propertyName = null, dependencyIndices = null, compareDelegate = SerializedPropertyTreeView.DefaultDelegates.s_CompareName, drawDelegate = SerializedPropertyTreeView.DefaultDelegates.s_DrawName, filter = new SerializedPropertyFilters.Name() }, new SerializedPropertyTreeView.Column // 2: GI { headerContent = Styles.GlobalIllumination, headerTextAlignment = TextAlignment.Left, sortedAscending = true, sortingArrowAlignment = TextAlignment.Center, width = 120, minWidth = 70, autoResize = false, allowToggleVisibility = true, propertyName = "m_LightmapFlags", dependencyIndices = null, compareDelegate = SerializedPropertyTreeView.DefaultDelegates.s_CompareInt, drawDelegate = (Rect r, SerializedProperty prop, SerializedProperty[] dep) => { if (!prop.serializedObject.targetObject.GetType().Equals(typeof(Material))) { return; } using (new EditorGUI.DisabledScope(!IsEditable(prop.serializedObject.targetObject))) { MaterialGlobalIlluminationFlags giFlags = ((prop.intValue & (int)MaterialGlobalIlluminationFlags.BakedEmissive) != 0) ? MaterialGlobalIlluminationFlags.BakedEmissive : MaterialGlobalIlluminationFlags.RealtimeEmissive; int[] lightmapEmissiveValues = { (int)MaterialGlobalIlluminationFlags.RealtimeEmissive, (int)MaterialGlobalIlluminationFlags.BakedEmissive }; EditorGUI.BeginChangeCheck(); giFlags = (MaterialGlobalIlluminationFlags)EditorGUI.IntPopup(r, (int)giFlags, Styles.LightmapEmissiveStrings, lightmapEmissiveValues); if (EditorGUI.EndChangeCheck()) { Material material = (Material)prop.serializedObject.targetObject; Undo.RecordObjects(new Material[] { material }, "Modify GI Settings of " + material.name); material.globalIlluminationFlags = giFlags; prop.serializedObject.Update(); } } } }, new SerializedPropertyTreeView.Column // 3: Color { headerContent = Styles.Color, headerTextAlignment = TextAlignment.Left, sortedAscending = true, sortingArrowAlignment = TextAlignment.Center, width = 70, minWidth = 40, autoResize = false, allowToggleVisibility = true, propertyName = "m_Shader", dependencyIndices = null, compareDelegate = (SerializedProperty lhs, SerializedProperty rhs) => { float lh, ls, lv, rh, rs, rv; Color.RGBToHSV(((Material)lhs.serializedObject.targetObject).GetColor("_EmissionColor"), out lh, out ls, out lv); Color.RGBToHSV(((Material)rhs.serializedObject.targetObject).GetColor("_EmissionColor"), out rh, out rs, out rv); return(lv.CompareTo(rv)); }, drawDelegate = (Rect r, SerializedProperty prop, SerializedProperty[] dep) => { if (!prop.serializedObject.targetObject.GetType().Equals(typeof(Material))) { return; } using (new EditorGUI.DisabledScope(!IsEditable(prop.serializedObject.targetObject))) { Material material = (Material)prop.serializedObject.targetObject; Color color = material.GetColor("_EmissionColor"); EditorGUI.BeginChangeCheck(); Color newValue = EditorGUI.ColorField(r, GUIContent.Temp(""), color, true, false, true); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new Material[] { material }, "Modify Emission Color of " + material.name); material.SetColor("_EmissionColor", newValue); } } }, copyDelegate = (SerializedProperty target, SerializedProperty source) => { Material sourceMaterial = (Material)source.serializedObject.targetObject; Color color = sourceMaterial.GetColor("_EmissionColor"); Material targetMaterial = (Material)target.serializedObject.targetObject; targetMaterial.SetColor("_EmissionColor", color); } } }; return(FinalizeColumns(columns, out propNames)); }
void ResetSettings(object userData, string[] options, int selected) { Undo.RecordObjects(new[] { RenderSettings.GetRenderSettings(), LightmapEditorSettings.GetLightmapSettings() }, "Reset Lighting Settings"); Unsupported.SmartReset(RenderSettings.GetRenderSettings()); Unsupported.SmartReset(LightmapEditorSettings.GetLightmapSettings()); }
private void OnGUI() { if (ms_Styles == null) { ms_Styles = new Styles(); } GUILayout.Space(5f); EditorGUI.BeginChangeCheck(); Vector3 move = SnapSettings.move; move.x = EditorGUILayout.FloatField(ms_Styles.moveX, move.x, new GUILayoutOption[0]); move.y = EditorGUILayout.FloatField(ms_Styles.moveY, move.y, new GUILayoutOption[0]); move.z = EditorGUILayout.FloatField(ms_Styles.moveZ, move.z, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { if (move.x <= 0f) { move.x = SnapSettings.move.x; } if (move.y <= 0f) { move.y = SnapSettings.move.y; } if (move.z <= 0f) { move.z = SnapSettings.move.z; } SnapSettings.move = move; } scale = EditorGUILayout.FloatField(ms_Styles.scale, scale, new GUILayoutOption[0]); rotation = EditorGUILayout.FloatField(ms_Styles.rotation, rotation, new GUILayoutOption[0]); GUILayout.Space(5f); bool flag = false; bool flag2 = false; bool flag3 = false; GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button(ms_Styles.snapAllAxes, ms_Styles.buttonLeft, new GUILayoutOption[0])) { flag = true; flag2 = true; flag3 = true; } if (GUILayout.Button(ms_Styles.snapX, ms_Styles.buttonMid, new GUILayoutOption[0])) { flag = true; } if (GUILayout.Button(ms_Styles.snapY, ms_Styles.buttonMid, new GUILayoutOption[0])) { flag2 = true; } if (GUILayout.Button(ms_Styles.snapZ, ms_Styles.buttonRight, new GUILayoutOption[0])) { flag3 = true; } GUILayout.EndHorizontal(); if ((flag | flag2) | flag3) { Vector3 vector2 = new Vector3(1f / SnapSettings.move.x, 1f / SnapSettings.move.y, 1f / SnapSettings.move.z); Undo.RecordObjects(Selection.transforms, "Snap " + ((Selection.transforms.Length != 1) ? " selection" : Selection.activeGameObject.name) + " to grid"); foreach (Transform transform in Selection.transforms) { Vector3 position = transform.position; if (flag) { float introduced15 = Mathf.Round(position.x * vector2.x); position.x = introduced15 / vector2.x; } if (flag2) { float introduced16 = Mathf.Round(position.y * vector2.y); position.y = introduced16 / vector2.y; } if (flag3) { float introduced17 = Mathf.Round(position.z * vector2.z); position.z = introduced17 / vector2.z; } transform.position = position; } } }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Rect handleRect = Tools.handleRect; Quaternion handleRectRotation = Tools.handleRectRotation; Vector3[] corners = new Vector3[4]; for (int i = 0; i < 4; i++) { Vector3 localRectPoint = (Vector3)GetLocalRectPoint(handleRect, i); corners[i] = ((Vector3)(handleRectRotation * localRectPoint)) + handlePosition; } RectHandles.RenderRectWithShadow(false, corners); Color color = GUI.color; float num2 = 1f; if (Camera.current != null) { Vector3 planeNormal = !Camera.current.orthographic ? ((handlePosition + (handleRectRotation * handleRect.center)) - Camera.current.transform.position) : Camera.current.transform.forward; Vector3 vector = (Vector3)((handleRectRotation * Vector3.right) * handleRect.width); Vector3 vector4 = (Vector3)((handleRectRotation * Vector3.up) * handleRect.height); float num3 = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector4, planeNormal)).magnitude) / HandleUtility.GetHandleSize(handlePosition); num2 = Mathf.Clamp01(((num3 - 0.2f) / 0.2f) * 2f); Color color2 = color; color2.a *= num2; GUI.color = color2; } Vector3 pivot = Tools.GetHandlePosition(); if (!Tools.vertexDragging) { RectTransform component = Selection.activeTransform.GetComponent <RectTransform>(); bool flag = Selection.transforms.Length > 1; bool flag2 = (!flag && (Tools.pivotMode == PivotMode.Pivot)) && (component != null); EditorGUI.BeginDisabledGroup(!flag && !flag2); EditorGUI.BeginChangeCheck(); Vector3 vector6 = PivotHandleGUI(handleRect, pivot, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (flag) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (vector6 - pivot); } else if (flag2) { Transform activeTransform = Selection.activeTransform; Undo.RecordObject(component, "Move Rectangle Pivot"); Transform transform3 = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent; Vector2 vector7 = transform3.InverseTransformVector(vector6 - pivot); vector7.x /= component.rect.width; vector7.y /= component.rect.height; Vector2 vector8 = component.pivot + vector7; RectTransformEditor.SetPivotSmart(component, vector8.x, 0, true, transform3 != component.transform); RectTransformEditor.SetPivotSmart(component, vector8.y, 1, true, transform3 != component.transform); } } EditorGUI.EndDisabledGroup(); } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { EditorGUI.BeginChangeCheck(); Vector3 scalePivot = handlePosition; Vector3 scaleDelta = ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out scalePivot); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scaleDelta, scalePivot, handleRectRotation); } bool flag3 = true; if (Tools.rectBlueprintMode) { foreach (Transform transform4 in Selection.transforms) { if (transform4.GetComponent <RectTransform>() != null) { flag3 = false; } } } if (flag3) { EditorGUI.BeginChangeCheck(); Quaternion quaternion2 = RotationHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { float num5; Vector3 vector11; (Quaternion.Inverse(handleRectRotation) * quaternion2).ToAngleAxis(out num5, out vector11); vector11 = (Vector3)(handleRectRotation * vector11); Undo.RecordObjects(Selection.transforms, "Rotate"); foreach (Transform transform5 in Selection.transforms) { transform5.RotateAround(handlePosition, vector11, num5); if (transform5.parent != null) { transform5.SendTransformChangedScale(); } } Tools.handleRotation = Quaternion.AngleAxis(num5, vector11) * Tools.handleRotation; } } } TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); Vector3 vector12 = MoveHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { Vector3 positionDelta = vector12 - TransformManipulator.mouseDownHandlePosition; TransformManipulator.SetPositionDelta(positionDelta); } TransformManipulator.EndManipulationHandling(); GUI.color = color; }
internal bool DrawInspector(Rect contentRect) { if (GameObjectInspector.s_styles == null) { GameObjectInspector.s_styles = new GameObjectInspector.Styles(); } base.serializedObject.Update(); GameObject gameObject = this.target as GameObject; EditorGUIUtility.labelWidth = 52f; bool enabled = GUI.enabled; GUI.enabled = true; GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig); GUI.enabled = enabled; float width = contentRect.width; float y = contentRect.y; GUIContent gUIContent = null; PrefabType prefabType = PrefabType.None; if (this.m_AllOfSamePrefabType) { prefabType = PrefabUtility.GetPrefabType(gameObject); switch (prefabType) { case PrefabType.None: gUIContent = GameObjectInspector.s_styles.goIcon; break; case PrefabType.Prefab: case PrefabType.PrefabInstance: case PrefabType.DisconnectedPrefabInstance: gUIContent = GameObjectInspector.s_styles.prefabIcon; break; case PrefabType.ModelPrefab: case PrefabType.ModelPrefabInstance: case PrefabType.DisconnectedModelPrefabInstance: gUIContent = GameObjectInspector.s_styles.modelIcon; break; case PrefabType.MissingPrefabInstance: gUIContent = GameObjectInspector.s_styles.prefabIcon; break; } } else { gUIContent = GameObjectInspector.s_styles.typelessIcon; } EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), base.targets, true, gUIContent.image as Texture2D, this.m_Icon); EditorGUI.BeginDisabledGroup(prefabType == PrefabType.ModelPrefab); EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none); float num = GameObjectInspector.s_styles.staticFieldToggleWidth + 15f; float width2 = width - 52f - num - 5f; EditorGUI.DelayedTextField(new Rect(52f, 4f + y + 1f, width2, 16f), this.m_Name, GUIContent.none); Rect rect = new Rect(width - num, 4f + y, GameObjectInspector.s_styles.staticFieldToggleWidth, 16f); EditorGUI.BeginProperty(rect, GUIContent.none, this.m_StaticEditorFlags); EditorGUI.BeginChangeCheck(); Rect position = rect; EditorGUI.showMixedValue |= GameObjectInspector.ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue); Event current = Event.current; EventType type = current.type; bool flag = current.type == EventType.MouseDown && current.button != 0; if (flag) { current.type = EventType.Ignore; } bool flagValue = EditorGUI.ToggleLeft(position, "Static", gameObject.isStatic); if (flag) { current.type = type; } EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, -1, flagValue); base.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.EndProperty(); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues; int changedFlags; bool flagValue2; EditorGUI.EnumMaskField(new Rect(rect.x + GameObjectInspector.s_styles.staticFieldToggleWidth, rect.y, 10f, 14f), GameObjectUtility.GetStaticEditorFlags(gameObject), GameObjectInspector.s_styles.staticDropdown, out changedFlags, out flagValue2); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, changedFlags, flagValue2); base.serializedObject.SetIsDifferentCacheDirty(); } float num2 = 4f; float num3 = 4f; EditorGUIUtility.fieldWidth = (width - num2 - 52f - GameObjectInspector.s_styles.layerFieldWidth - num3) / 2f; string tag = null; try { tag = gameObject.tag; } catch (Exception) { tag = "Undefined"; } EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.tagFieldWidth; Rect rect2 = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect2, GUIContent.none, this.m_Tag); EditorGUI.BeginChangeCheck(); string text = EditorGUI.TagField(rect2, EditorGUIUtility.TempContent("Tag"), tag); if (EditorGUI.EndChangeCheck()) { this.m_Tag.stringValue = text; Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle); UnityEngine.Object[] targets = base.targets; for (int i = 0; i < targets.Length; i++) { UnityEngine.Object @object = targets[i]; (@object as GameObject).tag = text; } } EditorGUI.EndProperty(); EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.layerFieldWidth; rect2 = new Rect(52f + EditorGUIUtility.fieldWidth + num2, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect2, GUIContent.none, this.m_Layer); EditorGUI.BeginChangeCheck(); int num4 = EditorGUI.LayerField(rect2, EditorGUIUtility.TempContent("Layer"), gameObject.layer); if (EditorGUI.EndChangeCheck()) { GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(base.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(num4) + " for all child objects as well?"); if (shouldIncludeChildren != GameObjectUtility.ShouldIncludeChildren.Cancel) { this.m_Layer.intValue = num4; this.SetLayer(num4, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren); } } EditorGUI.EndProperty(); if (this.m_HasInstance && !EditorApplication.isPlayingOrWillChangePlaymode) { float num5 = (width - 52f - 5f) / 3f; Rect position2 = new Rect(52f + num5 * 0f, 44f + y, num5, 15f); Rect position3 = new Rect(52f + num5 * 1f, 44f + y, num5, 15f); Rect position4 = new Rect(52f + num5 * 2f, 44f + y, num5, 15f); Rect position5 = new Rect(52f, 44f + y, num5 * 3f, 15f); GUIContent gUIContent2 = (base.targets.Length <= 1) ? GameObjectInspector.s_styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_styles.goTypeLabelMultiple; if (gUIContent2 != null) { float x = GUI.skin.label.CalcSize(gUIContent2).x; if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; if (prefabType == PrefabType.MissingPrefabInstance) { GUI.Label(new Rect(52f, 44f + y, width - 52f - 5f, 18f), gUIContent2, EditorStyles.whiteLabel); } else { GUI.Label(new Rect(52f - x - 5f, 44f + y, width - 52f - 5f, 18f), gUIContent2, EditorStyles.whiteLabel); } GUI.contentColor = Color.white; } else { Rect position6 = new Rect(52f - x - 5f, 44f + y, x, 18f); GUI.Label(position6, gUIContent2); } } if (base.targets.Length > 1) { GUI.Label(position5, "Instance Management Disabled", GameObjectInspector.s_styles.instanceManagementInfo); } else { if (prefabType != PrefabType.MissingPrefabInstance && GUI.Button(position2, "Select", "MiniButtonLeft")) { Selection.activeObject = PrefabUtility.GetPrefabParent(this.target); EditorGUIUtility.PingObject(Selection.activeObject); } if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) && GUI.Button(position3, "Revert", "MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert to prefab"); PrefabUtility.ReconnectToLastPrefab(gameObject); PrefabUtility.RevertPrefabInstance(gameObject); this.CalculatePrefabStatus(); Undo.RegisterCreatedObjectUndo(gameObject, "Reconnect prefab"); GUIUtility.ExitGUI(); } bool enabled2 = GUI.enabled; GUI.enabled = (GUI.enabled && !AnimationMode.InAnimationMode()); if ((prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance) && GUI.Button(position3, "Revert", "MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert Prefab Instance"); PrefabUtility.RevertPrefabInstance(gameObject); this.CalculatePrefabStatus(); Undo.RegisterCreatedObjectUndo(gameObject, "Revert prefab"); GUIUtility.ExitGUI(); } if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GameObject gameObject2 = PrefabUtility.FindValidUploadPrefabInstanceRoot(gameObject); GUI.enabled = (gameObject2 != null && !AnimationMode.InAnimationMode()); if (GUI.Button(position4, "Apply", "MiniButtonRight")) { UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(gameObject2); string assetPath = AssetDatabase.GetAssetPath(prefabParent); bool flag2 = Provider.PromptAndCheckoutIfNeeded(new string[] { assetPath }, "The version control requires you to check out the prefab before applying changes."); if (flag2) { PrefabUtility.ReplacePrefab(gameObject2, prefabParent, ReplacePrefabOptions.ConnectToPrefab); this.CalculatePrefabStatus(); GUIUtility.ExitGUI(); } } } GUI.enabled = enabled2; if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) && GUI.Button(position4, "Open", "MiniButtonRight")) { AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target)); GUIUtility.ExitGUI(); } } } EditorGUI.EndDisabledGroup(); base.serializedObject.ApplyModifiedProperties(); return(true); }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Handles.TransformHandleIds @default = Handles.TransformHandleIds.Default; TransformManipulator.BeginManipulationHandling(false); if (@default.scale.Has(GUIUtility.hotControl) || @default.rotation.Has(GUIUtility.hotControl)) { Tools.LockHandlePosition(); } else { Tools.UnlockHandlePosition(); } EditorGUI.BeginChangeCheck(); if (Event.current.type == EventType.MouseDown) { TransformTool.s_Scale = Vector3.one; } Vector3 vector = handlePosition; Quaternion handleRotation = Tools.handleRotation; Quaternion quaternion = handleRotation; Vector3 vector2 = TransformTool.s_Scale; Vector3 vector3 = vector2; Handles.TransformHandle(@default, ref vector, ref quaternion, ref vector3, Handles.TransformHandleParam.Default); TransformTool.s_Scale = vector3; if (EditorGUI.EndChangeCheck() && !isStatic) { Undo.RecordObjects(Selection.transforms, "Transform Manipulation"); if (TransformManipulator.HandleHasMoved(vector)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); TransformManipulator.SetPositionDelta(vector, TransformManipulator.mouseDownHandlePosition); } float num; Vector3 point; (Quaternion.Inverse(handleRotation) * quaternion).ToAngleAxis(out num, out point); if (!Mathf.Approximately(num, 0f)) { Transform[] transforms = Selection.transforms; for (int i = 0; i < transforms.Length; i++) { Transform transform = transforms[i]; if (Tools.pivotMode == PivotMode.Center) { transform.RotateAround(handlePosition, handleRotation * point, num); } else if (TransformManipulator.individualSpace) { transform.Rotate(transform.rotation * point, num, Space.World); } else { transform.Rotate(handleRotation * point, num, Space.World); } transform.SetLocalEulerHint(transform.GetLocalEulerAngles(transform.rotationOrder)); if (transform.parent != null) { transform.SendTransformChangedScale(); } } Tools.handleRotation = quaternion; } if (vector3 != vector2) { TransformManipulator.SetScaleDelta(vector3, quaternion); } } TransformManipulator.EndManipulationHandling(); }
void DoVertexStreamsArea(Material material) { // Display list of streams required to make this shader work bool useLighting = (material.GetFloat("_LightingEnabled") > 0.0f); bool useFlipbookBlending = (material.GetFloat("_FlipbookMode") > 0.0f); bool useTangents = useLighting && material.GetTexture("_BumpMap"); bool useGPUInstancing = ShaderUtil.HasProceduralInstancing(material.shader); if (useGPUInstancing && m_RenderersUsingThisMaterial.Count > 0) { if (!m_RenderersUsingThisMaterial[0].enableGPUInstancing || m_RenderersUsingThisMaterial[0].renderMode != ParticleSystemRenderMode.Mesh) { useGPUInstancing = false; } } GUILayout.Label(Styles.streamPositionText, EditorStyles.label); if (useLighting) { GUILayout.Label(Styles.streamNormalText, EditorStyles.label); } GUILayout.Label(useGPUInstancing ? Styles.streamColorInstancedText : Styles.streamColorText, EditorStyles.label); GUILayout.Label(Styles.streamUVText, EditorStyles.label); if (useTangents) { GUILayout.Label(Styles.streamTangentText, EditorStyles.label); } if (useGPUInstancing) { GUILayout.Label(Styles.streamAnimFrameText, EditorStyles.label); } else if (useFlipbookBlending && !useGPUInstancing) { GUILayout.Label(Styles.streamUV2Text, EditorStyles.label); GUILayout.Label(Styles.streamAnimBlendText, EditorStyles.label); } // Build the list of expected vertex streams List <ParticleSystemVertexStream> streams = new List <ParticleSystemVertexStream>(); streams.Add(ParticleSystemVertexStream.Position); if (useLighting) { streams.Add(ParticleSystemVertexStream.Normal); } streams.Add(ParticleSystemVertexStream.Color); streams.Add(ParticleSystemVertexStream.UV); if (useTangents) { streams.Add(ParticleSystemVertexStream.Tangent); } List <ParticleSystemVertexStream> instancedStreams = new List <ParticleSystemVertexStream>(streams); if (useGPUInstancing) { instancedStreams.Add(ParticleSystemVertexStream.AnimFrame); } if (useFlipbookBlending) { streams.Add(ParticleSystemVertexStream.UV2); streams.Add(ParticleSystemVertexStream.AnimBlend); } // Set the streams on all systems using this material if (GUILayout.Button(Styles.streamApplyToAllSystemsText, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { Undo.RecordObjects(m_RenderersUsingThisMaterial.Where(r => r != null).ToArray(), Styles.undoApplyCustomVertexStreams); foreach (ParticleSystemRenderer renderer in m_RenderersUsingThisMaterial) { if (renderer != null) { if (useGPUInstancing && renderer.renderMode == ParticleSystemRenderMode.Mesh && renderer.supportsMeshInstancing) { renderer.SetActiveVertexStreams(instancedStreams); } else { renderer.SetActiveVertexStreams(streams); } } } } // Display a warning if any renderers have incorrect vertex streams string Warnings = ""; List <ParticleSystemVertexStream> rendererStreams = new List <ParticleSystemVertexStream>(); foreach (ParticleSystemRenderer renderer in m_RenderersUsingThisMaterial) { if (renderer != null) { renderer.GetActiveVertexStreams(rendererStreams); bool streamsValid; if (useGPUInstancing && renderer.renderMode == ParticleSystemRenderMode.Mesh && renderer.supportsMeshInstancing) { streamsValid = CompareVertexStreams(rendererStreams, instancedStreams); } else { streamsValid = CompareVertexStreams(rendererStreams, streams); } if (!streamsValid) { Warnings += " " + renderer.name + "\n"; } } } if (Warnings != "") { EditorGUILayout.HelpBox("The following Particle System Renderers are using this material with incorrect Vertex Streams:\n" + Warnings + "Use the Apply to Systems button to fix this", MessageType.Warning, true); } EditorGUILayout.Space(); }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { var ids = Handles.TransformHandleIds.Default; TransformManipulator.BeginManipulationHandling(false); // Lock position when scaling or rotating if (ids.scale.Has(GUIUtility.hotControl) || ids.rotation.Has(GUIUtility.hotControl)) { Tools.LockHandlePosition(); } else { Tools.UnlockHandlePosition(); } EditorGUI.BeginChangeCheck(); if (Event.current.type == EventType.MouseDown) { s_Scale = Vector3.one; } var startPosition = handlePosition; var endPosition = startPosition; var startRotation = Tools.handleRotation; var endRotation = startRotation; var startScale = s_Scale; var endScale = startScale; Handles.TransformHandle(ids, ref endPosition, ref endRotation, ref endScale, Handles.TransformHandleParam.Default); s_Scale = endScale; if (EditorGUI.EndChangeCheck() && !isStatic) { Undo.RecordObjects(Selection.transforms, "Transform Manipulation"); if (TransformManipulator.HandleHasMoved(endPosition)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); TransformManipulator.SetPositionDelta(endPosition, TransformManipulator.mouseDownHandlePosition); } Quaternion deltaRotation = Quaternion.Inverse(startRotation) * endRotation; float angle; Vector3 axis; deltaRotation.ToAngleAxis(out angle, out axis); if (!Mathf.Approximately(angle, 0)) { foreach (Transform t in Selection.transforms) { // Rotate around handlePosition (Global or Local axis). if (Tools.pivotMode == PivotMode.Center) { t.RotateAround(handlePosition, startRotation * axis, angle); } // Local rotation (Pivot mode with Local axis). else if (TransformManipulator.individualSpace) { t.Rotate(t.rotation * axis, angle, Space.World); } // Pivot mode with Global axis. else { t.Rotate(startRotation * axis, angle, Space.World); } // sync euler hints after a rotate tool update tyo fake continuous rotation t.SetLocalEulerHint(t.GetLocalEulerAngles(t.rotationOrder)); if (t.parent != null) { t.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent. } } Tools.handleRotation = endRotation; } if (endScale != startScale) { TransformManipulator.SetScaleDelta(endScale, endRotation); } } TransformManipulator.EndManipulationHandling(); }
void CellGUI(Rect cellRect, SerializedPropertyItem item, int columnIndex, ref RowGUIArgs args) { Profiler.BeginSample("SerializedPropertyTreeView.CellGUI"); CenterRectUsingSingleLineHeight(ref cellRect); var ltd = item.GetData(); Column column = (Column)this.multiColumnHeader.GetColumn(columnIndex); if (column.drawDelegate == DefaultDelegates.DrawName) { // default drawing Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.LabelField"); DefaultGUI.Label(cellRect, ltd.name, IsSelected(args.item.id), false); Profiler.EndSample(); } else if (column.drawDelegate != null) { SerializedProperty[] props = ltd.properties; int depcnt = column.dependencyIndices != null ? column.dependencyIndices.Length : 0; for (int i = 0; i < depcnt; i++) { m_ColumnsInternal[columnIndex].dependencyProps[i] = props[column.dependencyIndices[i]]; } // allow to capture tabs if (args.item.id == state.lastClickedID && HasFocus() && columnIndex == multiColumnHeader.state.visibleColumns[multiColumnHeader.state.visibleColumns[0] == 0 ? 1 : 0]) { GUI.SetNextControlName(Styles.focusHelper); } SerializedProperty prop = ltd.properties[columnIndex]; EditorGUI.BeginChangeCheck(); Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.drawDelegate"); column.drawDelegate(cellRect, prop, m_ColumnsInternal[columnIndex].dependencyProps); Profiler.EndSample(); if (EditorGUI.EndChangeCheck()) { // if we changed a value in a filtered column we'll have to reload the table m_ChangedId = ((column.filter != null) && column.filter.Active()) ? GUIUtility.keyboardControl : m_ChangedId; // update all selected items if the current row was part of the selection list ltd.Store(); var selIds = GetSelection(); if (selIds.Contains(ltd.objectId)) { IList <TreeViewItem> rows = FindRows(selIds); Undo.RecordObjects(rows.Select(r => ((SerializedPropertyItem)r).GetData().serializedObject.targetObject).ToArray(), "Modify Multiple Properties"); foreach (var r in rows) { if (r.id == args.item.id) { continue; } var data = ((SerializedPropertyItem)r).GetData(); if (!IsEditable(data.serializedObject.targetObject)) { continue; } if (column.copyDelegate != null) { column.copyDelegate(data.properties[columnIndex], prop); } else { DefaultDelegates.CopyDefault(data.properties[columnIndex], prop); } data.Store(); } } } Profiler.EndSample(); } }
void OnGUI() { if (ms_Styles == null) { ms_Styles = new Styles(); } GUILayout.Space(5); EditorGUI.BeginChangeCheck(); Vector3 m = move; m.x = EditorGUILayout.FloatField(ms_Styles.moveX, m.x); m.y = EditorGUILayout.FloatField(ms_Styles.moveY, m.y); m.z = EditorGUILayout.FloatField(ms_Styles.moveZ, m.z); if (EditorGUI.EndChangeCheck()) { if (m.x <= 0) { m.x = move.x; } if (m.y <= 0) { m.y = move.y; } if (m.z <= 0) { m.z = move.z; } move = m; } scale = EditorGUILayout.FloatField(ms_Styles.scale, scale); rotation = EditorGUILayout.FloatField(ms_Styles.rotation, rotation); GUILayout.Space(5); bool snapX = false, snapY = false, snapZ = false; GUILayout.BeginHorizontal(); if (GUILayout.Button(ms_Styles.snapAllAxes, ms_Styles.buttonLeft)) { snapX = true; snapY = true; snapZ = true; } if (GUILayout.Button(ms_Styles.snapX, ms_Styles.buttonMid)) { snapX = true; } if (GUILayout.Button(ms_Styles.snapY, ms_Styles.buttonMid)) { snapY = true; } if (GUILayout.Button(ms_Styles.snapZ, ms_Styles.buttonRight)) { snapZ = true; } GUILayout.EndHorizontal(); if (snapX | snapY | snapZ) { Vector3 scaleTmp = new Vector3(1.0f / move.x, 1.0f / move.y, 1.0f / move.z); Undo.RecordObjects(Selection.transforms, "Snap " + (Selection.transforms.Length == 1 ? Selection.activeGameObject.name : " selection") + " to grid"); foreach (Transform t in Selection.transforms) { Vector3 pos = t.position; if (snapX) { pos.x = Mathf.Round(pos.x * scaleTmp.x) / scaleTmp.x; } if (snapY) { pos.y = Mathf.Round(pos.y * scaleTmp.y) / scaleTmp.y; } if (snapZ) { pos.z = Mathf.Round(pos.z * scaleTmp.z) / scaleTmp.z; } t.position = pos; } } }
public void RotationField(bool disabled) { Transform t = targets[0] as Transform; Vector3 localEuler = t.GetLocalEulerAngles(t.rotationOrder); if ( m_OldEulerAngles.x != localEuler.x || m_OldEulerAngles.y != localEuler.y || m_OldEulerAngles.z != localEuler.z || m_OldRotationOrder != t.rotationOrder ) { m_EulerAngles = t.GetLocalEulerAngles(t.rotationOrder); m_OldRotationOrder = t.rotationOrder; } bool differentRotation = false; bool differentRotationOrder = false; for (int i = 1; i < targets.Length; i++) { Transform otherTransform = (targets[i] as Transform); Vector3 otherLocalEuler = otherTransform.GetLocalEulerAngles(otherTransform.rotationOrder); differentRotation |= (otherLocalEuler.x != localEuler.x || otherLocalEuler.y != localEuler.y || otherLocalEuler.z != localEuler.z); differentRotationOrder |= otherTransform.rotationOrder != t.rotationOrder; } Rect r = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); GUIContent label = EditorGUI.BeginProperty(r, rotationContent, m_Rotation); EditorGUI.showMixedValue = differentRotation; EditorGUI.BeginChangeCheck(); int id = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, r); string rotationLabel = ""; if (AnimationMode.InAnimationMode() && t.rotationOrder != RotationOrder.OrderZXY) { if (differentRotationOrder) { rotationLabel = "Mixed"; } else { rotationLabel = (t.rotationOrder).ToString(); rotationLabel = rotationLabel.Substring(rotationLabel.Length - 3); } label.text = label.text + " (" + rotationLabel + ")"; } r = EditorGUI.MultiFieldPrefixLabel(r, id, label, 3); r.height = EditorGUIUtility.singleLineHeight; using (new EditorGUI.DisabledScope(disabled)) { m_EulerAngles = EditorGUI.Vector3Field(r, GUIContent.none, m_EulerAngles); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(targets, "Inspector"); // Generic undo title to be consistent with Position and Scale changes. foreach (Transform tr in targets) { tr.SetLocalEulerAngles(m_EulerAngles, tr.rotationOrder); if (tr.parent != null) { tr.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent. } } m_Rotation.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.showMixedValue = false; if (differentRotationOrder) { EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning); } EditorGUI.EndProperty(); }
public void IconSectionGUI(NamedBuildTarget namedBuildTarget, ISettingEditorExtension settingsExtension, int platformID, int sectionIndex) { m_SelectedPlatform = platformID; if (!m_Owner.BeginSettingsBox(sectionIndex, SettingsContent.iconTitle)) { m_Owner.EndSettingsBox(); return; } var platformUsesStandardIcons = true; if (settingsExtension != null) { platformUsesStandardIcons = settingsExtension.UsesStandardIcons(); } if (platformUsesStandardIcons) { var selectedDefault = (m_SelectedPlatform < 0); // Set default platform variables BuildPlatform platform = null; namedBuildTarget = NamedBuildTarget.Standalone; var platformName = ""; // Override if a platform is selected if (!selectedDefault) { platform = m_ValidPlatforms[m_SelectedPlatform]; namedBuildTarget = platform.namedBuildTarget; platformName = platform.name; } if (namedBuildTarget == NamedBuildTarget.WebGL || namedBuildTarget == NamedBuildTarget.Server) { PlayerSettingsEditor.ShowNoSettings(); EditorGUILayout.Space(); } else if (namedBuildTarget != NamedBuildTarget.WindowsStoreApps) // UWP does this in its editor extension { // Both default icon and Legacy icons are serialized to the same map // That's why m_LegacyPlatformIcons can be excluded in two places (other place in CommonSettings()) using (var vertical = new EditorGUILayout.VerticalScope()) using (new EditorGUI.PropertyScope(vertical.rect, GUIContent.none, m_LegacyPlatformIcons)) { // Get icons and icon sizes for selected platform (or default) var icons = PlayerSettings.GetPlatformIconsForTargetIcons(platformName, IconKind.Any, m_AllLegacyIcons); var widths = PlayerSettings.GetIconWidthsForPlatform(platformName, IconKind.Any); var heights = PlayerSettings.GetIconHeightsForPlatform(platformName, IconKind.Any); var kinds = PlayerSettings.GetIconKindsForPlatform(platformName); var overrideIcons = true; if (!selectedDefault) { // If the list of icons for this platform is not empty (and has the correct size), // consider the icon overridden for this platform EditorGUI.BeginChangeCheck(); overrideIcons = (icons.Length == widths.Length); overrideIcons = GUILayout.Toggle(overrideIcons, string.Format(L10n.Tr("Override for {0}"), platform.title.text)); EditorGUI.BeginDisabled(!overrideIcons); var changed = EditorGUI.EndChangeCheck(); if (changed || (!overrideIcons && icons.Length > 0)) { // Set the list of icons to correct length if overridden, otherwise to an empty list if (overrideIcons) { icons = new Texture2D[widths.Length]; } else { icons = new Texture2D[0]; } if (changed) { SetLegacyPlatformIcons(platformName, icons, IconKind.Any, ref m_AllLegacyIcons); } } } // Show the icons for this platform (or default) EditorGUI.BeginChangeCheck(); for (int i = 0; i < widths.Length; i++) { var previewWidth = Mathf.Min(kMaxPreviewSize, widths[i]); var previewHeight = (int)((float)heights[i] * previewWidth / widths[i]); // take into account the aspect ratio if (namedBuildTarget == NamedBuildTarget.iOS) { // Spotlight icons begin with 120 but there are two in the list. // So check if the next one is 80. if (kinds[i] == IconKind.Spotlight && kinds[i - 1] != IconKind.Spotlight) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "Spotlight icons", EditorStyles.boldLabel); } if (kinds[i] == IconKind.Settings && kinds[i - 1] != IconKind.Settings) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "Settings icons", EditorStyles.boldLabel); } if (kinds[i] == IconKind.Notification && kinds[i - 1] != IconKind.Notification) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "Notification icons", EditorStyles.boldLabel); } if (kinds[i] == IconKind.Store && kinds[i - 1] != IconKind.Store) { var labelRect = GUILayoutUtility.GetRect(EditorGUIUtility.labelWidth, 20); GUI.Label(new Rect(labelRect.x, labelRect.y, EditorGUIUtility.labelWidth, 20), "App Store icons", EditorStyles.boldLabel); } } var rect = GUILayoutUtility.GetRect(kSlotSize, Mathf.Max(kSlotSize, previewHeight) + kIconSpacing); var width = Mathf.Min(rect.width, EditorGUIUtility.labelWidth + 4 + kSlotSize + kIconSpacing + kMaxPreviewSize); // Label var label = widths[i] + "x" + heights[i]; GUI.Label(new Rect(rect.x, rect.y, width - kMaxPreviewSize - kSlotSize - 2 * kIconSpacing, 20), label); // Texture slot if (overrideIcons) { var slotWidth = kSlotSize; var slotHeight = (int)((float)heights[i] / widths[i] * kSlotSize); // take into account the aspect ratio icons[i] = (Texture2D)EditorGUI.ObjectField( new Rect(rect.x + width - kMaxPreviewSize - kSlotSize - kIconSpacing, rect.y, slotWidth, slotHeight), icons[i], typeof(Texture2D), false); } // Preview var previewRect = new Rect(rect.x + width - kMaxPreviewSize, rect.y, previewWidth, previewHeight); var closestIcon = PlayerSettings.GetPlatformIconForSizeForTargetIcons(platformName, widths[i], heights[i], kinds[i], m_AllLegacyIcons); if (closestIcon != null) { GUI.DrawTexture(previewRect, closestIcon); } else { GUI.Box(previewRect, ""); } } // Save changes if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(m_Owner.targets, SettingsContent.undoChangedIconString); SetLegacyPlatformIcons(platformName, icons, IconKind.Any, ref m_AllLegacyIcons); } EditorGUI.EndDisabled(); if (namedBuildTarget == NamedBuildTarget.iOS || namedBuildTarget == NamedBuildTarget.tvOS) { EditorGUILayout.PropertyField(m_UIPrerenderedIcon, SettingsContent.UIPrerenderedIcon); EditorGUILayout.Space(); } } } } if (settingsExtension != null) { settingsExtension.IconSectionGUI(); } m_Owner.EndSettingsBox(); }
public static SerializedPropertyTreeView.Column[] CreateEmissivesColumns(out string[] propNames) { SerializedPropertyTreeView.Column[] expr_07 = new SerializedPropertyTreeView.Column[4]; int arg_9B_1 = 0; SerializedPropertyTreeView.Column column = new SerializedPropertyTreeView.Column(); column.headerContent = LightTableColumns.Styles.SelectObjects; column.headerTextAlignment = TextAlignment.Left; column.sortedAscending = true; column.sortingArrowAlignment = TextAlignment.Center; column.width = 20f; column.minWidth = 20f; column.maxWidth = 20f; column.autoResize = false; column.allowToggleVisibility = true; column.propertyName = "m_LightmapFlags"; column.dependencyIndices = null; column.compareDelegate = null; column.drawDelegate = delegate(Rect r, SerializedProperty prop, SerializedProperty[] dep) { if (GUI.Button(r, LightTableColumns.Styles.SelectObjectsButton, "label")) { SearchableEditorWindow.SearchForReferencesToInstanceID(prop.serializedObject.targetObject.GetInstanceID()); } }; expr_07[arg_9B_1] = column; expr_07[1] = new SerializedPropertyTreeView.Column { headerContent = LightTableColumns.Styles.Name, headerTextAlignment = TextAlignment.Left, sortedAscending = true, sortingArrowAlignment = TextAlignment.Center, width = 200f, minWidth = 100f, autoResize = false, allowToggleVisibility = true, propertyName = null, dependencyIndices = null, compareDelegate = SerializedPropertyTreeView.DefaultDelegates.s_CompareName, drawDelegate = SerializedPropertyTreeView.DefaultDelegates.s_DrawName, filter = new SerializedPropertyFilters.Name() }; int arg_1A6_1 = 2; column = new SerializedPropertyTreeView.Column(); column.headerContent = LightTableColumns.Styles.GlobalIllumination; column.headerTextAlignment = TextAlignment.Left; column.sortedAscending = true; column.sortingArrowAlignment = TextAlignment.Center; column.width = 120f; column.minWidth = 70f; column.autoResize = false; column.allowToggleVisibility = true; column.propertyName = "m_LightmapFlags"; column.dependencyIndices = null; column.compareDelegate = SerializedPropertyTreeView.DefaultDelegates.s_CompareInt; column.drawDelegate = delegate(Rect r, SerializedProperty prop, SerializedProperty[] dep) { if (prop.serializedObject.targetObject.GetType().Equals(typeof(Material))) { using (new EditorGUI.DisabledScope(!LightTableColumns.IsEditable(prop.serializedObject.targetObject))) { MaterialGlobalIlluminationFlags materialGlobalIlluminationFlags = ((prop.intValue & 2) == 0) ? MaterialGlobalIlluminationFlags.RealtimeEmissive : MaterialGlobalIlluminationFlags.BakedEmissive; int[] optionValues = new int[] { 1, 2 }; EditorGUI.BeginChangeCheck(); materialGlobalIlluminationFlags = (MaterialGlobalIlluminationFlags)EditorGUI.IntPopup(r, (int)materialGlobalIlluminationFlags, LightTableColumns.Styles.LightmapEmissiveStrings, optionValues); if (EditorGUI.EndChangeCheck()) { Material material = (Material)prop.serializedObject.targetObject; Undo.RecordObjects(new Material[] { material }, "Modify GI Settings of " + material.name); material.globalIlluminationFlags = materialGlobalIlluminationFlags; prop.serializedObject.Update(); } } } }; expr_07[arg_1A6_1] = column; int arg_26F_1 = 3; column = new SerializedPropertyTreeView.Column(); column.headerContent = LightTableColumns.Styles.Color; column.headerTextAlignment = TextAlignment.Left; column.sortedAscending = true; column.sortingArrowAlignment = TextAlignment.Center; column.width = 70f; column.minWidth = 40f; column.autoResize = false; column.allowToggleVisibility = true; column.propertyName = "m_Shader"; column.dependencyIndices = null; column.compareDelegate = delegate(SerializedProperty lhs, SerializedProperty rhs) { float num; float num2; float num3; Color.RGBToHSV(((Material)lhs.serializedObject.targetObject).GetColor("_EmissionColor"), out num, out num2, out num3); float num4; float num5; float value; Color.RGBToHSV(((Material)rhs.serializedObject.targetObject).GetColor("_EmissionColor"), out num4, out num5, out value); return(num3.CompareTo(value)); }; column.drawDelegate = delegate(Rect r, SerializedProperty prop, SerializedProperty[] dep) { if (prop.serializedObject.targetObject.GetType().Equals(typeof(Material))) { using (new EditorGUI.DisabledScope(!LightTableColumns.IsEditable(prop.serializedObject.targetObject))) { Material material = (Material)prop.serializedObject.targetObject; Color color = material.GetColor("_EmissionColor"); EditorGUI.BeginChangeCheck(); Color value = EditorGUI.ColorField(r, GUIContent.Temp(""), color, true, false, true); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new Material[] { material }, "Modify Emission Color of " + material.name); material.SetColor("_EmissionColor", value); } } } }; column.copyDelegate = delegate(SerializedProperty target, SerializedProperty source) { Material material = (Material)source.serializedObject.targetObject; Color color = material.GetColor("_EmissionColor"); Material material2 = (Material)target.serializedObject.targetObject; material2.SetColor("_EmissionColor", color); }; expr_07[arg_26F_1] = column; SerializedPropertyTreeView.Column[] columns = expr_07; return(LightTableColumns.FinalizeColumns(columns, out propNames)); }
void ResetEnvironmentSettings(object userData, string[] options, int selected) { Undo.RecordObjects(new[] { RenderSettings.GetRenderSettings() }, "Reset Environment Settings"); Unsupported.SmartReset(RenderSettings.GetRenderSettings()); }
/// <summary> /// Calls the methods in its invocation list when show the Inspector /// </summary> public override void OnInspectorGUI() { var camera = Camera.main; if (camera == null) { EditorGUILayout.HelpBox("Light Anchor: At least one camera must be tagged as MainCamera", MessageType.Error); return; } if (IsCacheInvalid(manipulator)) { manipulator.SynchronizeOnTransform(camera); UpdateCache(); } // anchor is cached for it cannot be changed from the inspector, // we have a dedicated editor tool to move the anchor var anchor = manipulator.anchorPosition; bool yawChanged = false; bool pitchChanged = false; bool rollChanged = false; bool distanceChanged = false; bool upChanged = false; using (var change = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.Space(); float widgetHeight = EditorGUIUtility.singleLineHeight * 5f; using (new EditorGUILayout.HorizontalScope()) { Color usedColor; EditorGUI.BeginChangeCheck(); { var localRect = EditorGUILayout.GetControlRect(false, widgetHeight); usedColor = Color.green; usedColor.a = 0.2f; m_Yaw = AngleField(localRect, "Yaw", m_Yaw, 90, usedColor, true); } yawChanged = EditorGUI.EndChangeCheck(); EditorGUI.BeginChangeCheck(); { var localRect = EditorGUILayout.GetControlRect(false, widgetHeight); usedColor = Color.blue; usedColor.a = 0.2f; m_Pitch = AngleField(localRect, "Pitch", m_Pitch, 180, usedColor, true); } pitchChanged = EditorGUI.EndChangeCheck(); EditorGUI.BeginChangeCheck(); { var localRect = EditorGUILayout.GetControlRect(false, widgetHeight); usedColor = Color.grey; usedColor.a = 0.2f; bool enabledKnob = true; m_Roll = AngleField(localRect, "Roll", m_Roll, -90, usedColor, enabledKnob); } rollChanged = EditorGUI.EndChangeCheck(); } EditorGUILayout.Space(); Rect angleRect = EditorGUILayout.GetControlRect(true, EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector3, EditorGUIUtility.TrTextContent(""))); float[] angles = new float[3] { m_Yaw, m_Pitch, m_Roll }; EditorGUI.BeginChangeCheck(); EditorGUI.MultiFloatField(angleRect, LightAnchorStyles.angleSubContent, angles); const float eps = 1e-4f; if (EditorGUI.EndChangeCheck()) { if (Mathf.Abs(angles[0] - m_Yaw) > eps) { m_Yaw = angles[0]; yawChanged = true; } if (Mathf.Abs(angles[1] - m_Pitch) > eps) { m_Pitch = angles[1]; pitchChanged = true; } if (Mathf.Abs(angles[2] - m_Roll) > eps) { m_Roll = angles[2]; rollChanged = true; } } EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); m_Distance = EditorGUILayout.FloatField(LightAnchorStyles.distanceProperty, manipulator.distance); distanceChanged = EditorGUI.EndChangeCheck(); EditorGUI.BeginChangeCheck(); var dropRect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight); m_FrameSpace = (LightAnchor.UpDirection)EditorGUI.EnumPopup(dropRect, LightAnchorStyles.upDirectionProperty, manipulator.frameSpace); upChanged = EditorGUI.EndChangeCheck(); if (m_FoldoutPreset = EditorGUILayout.Foldout(m_FoldoutPreset, "Common")) { Color cachedColor = GUI.backgroundColor; GUI.backgroundColor = LightAnchorStyles.BackgroundIconColor(); var inspectorWidth = EditorGUIUtility.currentViewWidth - LightAnchorStyles.inspectorWidthPadding; var presetButtonWidth = GUILayout.Width(inspectorWidth / LightAnchorStyles.presetButtonCount); var presetButtonHeight = GUILayout.Height(inspectorWidth / LightAnchorStyles.presetButtonCount); using (new EditorGUILayout.HorizontalScope()) { bool rectFound = false; Rect rect = new Rect(); if (GUILayout.Button(LightAnchorStyles.presetTextureRimLeft, presetButtonWidth, presetButtonHeight)) { m_Yaw = 135; m_Pitch = 0; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw - 135.0f) < eps && Mathf.Abs(m_Pitch - 0.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureKickLeft, presetButtonWidth, presetButtonHeight)) { m_Yaw = 100; m_Pitch = 10; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw - 100.0f) < eps && Mathf.Abs(m_Pitch - 10.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureBounceLeft, presetButtonWidth, presetButtonHeight)) { m_Yaw = 30; m_Pitch = -30; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw - 30.0f) < eps && Mathf.Abs(m_Pitch + 30.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureFillLeft, presetButtonWidth, presetButtonHeight)) { m_Yaw = 35; m_Pitch = 35; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw - 35.0f) < eps && Mathf.Abs(m_Pitch - 35.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureHair, presetButtonWidth, presetButtonHeight)) { m_Yaw = 0; m_Pitch = 110; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw - 0.0f) < eps && Mathf.Abs(m_Pitch - 110.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureFillRight, presetButtonWidth, presetButtonHeight)) { m_Yaw = -35; m_Pitch = 35; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw + 35.0f) < eps && Mathf.Abs(m_Pitch - 35.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureBounceRight, presetButtonWidth, presetButtonHeight)) { m_Yaw = -30; m_Pitch = -30; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw + 30.0f) < eps && Mathf.Abs(m_Pitch + 30.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureKickRight, presetButtonWidth, presetButtonHeight)) { m_Yaw = -100; m_Pitch = 10; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw + 100.0f) < eps && Mathf.Abs(m_Pitch - 10.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (GUILayout.Button(LightAnchorStyles.presetTextureRimRight, presetButtonWidth, presetButtonHeight)) { m_Yaw = -135; m_Pitch = 0; yawChanged = true; pitchChanged = true; } if (Mathf.Abs(m_Yaw + 135.0f) < eps && Mathf.Abs(m_Pitch - 0.0f) < eps) { rect = GUILayoutUtility.GetLastRect(); rectFound = true; } if (rectFound) { Handles.DrawSolidRectangleWithOutline(rect, LightAnchorStyles.totalTransparentColor, LightAnchorStyles.hoverColor); } GUILayout.FlexibleSpace(); } GUI.backgroundColor = cachedColor; } if (upChanged) { Undo.RecordObjects(new UnityEngine.Object[] { target, manipulator.transform }, "Light Anchor Change"); manipulator.frameSpace = m_FrameSpace; manipulator.SynchronizeOnTransform(camera); UpdateCache(); } if (yawChanged || pitchChanged || rollChanged || distanceChanged) { Undo.RecordObjects(new UnityEngine.Object[] { target, manipulator.transform }, "Light Anchor Change"); if (yawChanged) { manipulator.yaw = m_Yaw; } if (pitchChanged) { manipulator.pitch = m_Pitch; } if (rollChanged) { manipulator.roll = m_Roll; } if (distanceChanged) { manipulator.distance = m_Distance; } manipulator.UpdateTransform(camera, anchor); IsCacheInvalid(manipulator); } } }