protected static void FromToFieldLayout(string label, ref float from, ref float to, out bool fromChanged, out bool toChanged) { var rect = EditorGUILayout.GetControlRect(); float labelWidth = EditorGUIUtility.labelWidth; var fromRect = new Rect(rect.x + labelWidth, rect.y, (rect.width - labelWidth) / 2 - 2, rect.height); var toRect = new Rect(rect.xMax - fromRect.width, fromRect.y, fromRect.width, fromRect.height); rect.width = labelWidth - 8; var content = EditorGUIKit.TempContent(label); EditorGUI.LabelField(rect, content); rect.width = EditorStyles.label.CalcSize(content).x; float delta = EditorGUIKit.DragValue(rect, 0, 0.01f); using (new LabelWidthScope(14)) { float newFrom = EditorGUI.FloatField(fromRect, "F", from + delta); float newTo = EditorGUI.FloatField(toRect, "T", to + delta); fromChanged = from != newFrom; from = newFrom; toChanged = to != newTo; to = newTo; } }
protected override void OnPropertiesGUI(Tween tween) { EditorGUILayout.Space(); EditorGUILayout.PropertyField(_useGradientProp); if (target.useGradient) { var rect = EditorGUILayout.GetControlRect(); var rect2 = rect; rect.width = rect.height + EditorStyles.label.CalcSize(EditorGUIKit.TempContent("RGB")).x; _toggleRGBProp.boolValue = EditorGUI.ToggleLeft(rect, "RGB", _toggleRGBProp.boolValue); rect.x = rect.xMax + rect.height; rect.width = rect.height + EditorStyles.label.CalcSize(EditorGUIKit.TempContent("A")).x; _toggleAlphaProp.boolValue = EditorGUI.ToggleLeft(rect, "A", _toggleAlphaProp.boolValue); using (new DisabledScope(!target.toggleRGB && !target.toggleAlpha)) { rect2.xMin += EditorGUIUtility.labelWidth; EditorGUI.PropertyField(rect2, _gradientProp, GUIContent.none); } } else { var rect = EditorGUILayout.GetControlRect(); float labelWidth = EditorGUIUtility.labelWidth; var fromRect = new Rect(rect.x + labelWidth, rect.y, (rect.width - labelWidth) / 2 - 2, rect.height); var toRect = new Rect(rect.xMax - fromRect.width, fromRect.y, fromRect.width, fromRect.height); rect.width = labelWidth - 8; _toggleRGBProp.boolValue = EditorGUI.ToggleLeft(rect, "RGB", _toggleRGBProp.boolValue); using (new DisabledScope(!target.toggleRGB)) { using (new LabelWidthScope(14)) { _fromProp.colorValue = EditorGUI.ColorField(fromRect, EditorGUIKit.TempContent("F"), _fromProp.colorValue, false, false, hdr); _toProp.colorValue = EditorGUI.ColorField(toRect, EditorGUIKit.TempContent("T"), _toProp.colorValue, false, false, hdr); } } FromToFieldLayout("A", _fromAProp, _toAProp, _toggleAlphaProp); } }
protected override void OnPropertiesGUI(Tween tween) { EditorGUILayout.Space(); EditorGUILayout.PropertyField(_targetRendererProp); int materialCount = target.GetMaterials(); DrawMaterialMask(materialCount); DrawProperty(materialCount); EditorGUILayout.Space(); switch (target.propertyType) { case Type.Float: case Type.Range: FromToFieldLayout("Value", _fromXProp, _toXProp); break; case Type.Vector: FromToFieldLayout("X", _fromXProp, _toXProp); FromToFieldLayout("Y", _fromYProp, _toYProp); FromToFieldLayout("Z", _fromZProp, _toZProp); FromToFieldLayout("W", _fromWProp, _toWProp); break; case Type.Color: var rect = EditorGUILayout.GetControlRect(); float labelWidth = EditorGUIUtility.labelWidth; var fromRect = new Rect(rect.x + labelWidth, rect.y, (rect.width - labelWidth) / 2 - 2, rect.height); var toRect = new Rect(rect.xMax - fromRect.width, fromRect.y, fromRect.width, fromRect.height); rect.width = labelWidth - 8; EditorGUI.LabelField(rect, "Color"); using (new LabelWidthScope(14)) { _fromProp.vector4Value = EditorGUI.ColorField(fromRect, EditorGUIKit.TempContent("F"), _fromProp.vector4Value, false, true, true); _toProp.vector4Value = EditorGUI.ColorField(toRect, EditorGUIKit.TempContent("T"), _toProp.vector4Value, false, true, true); } break; } }
void DrawProperty(int materialCount) { var rect = EditorGUILayout.GetControlRect(); rect = EditorGUI.PrefixLabel(rect, EditorGUIKit.TempContent("Property")); if (!string.IsNullOrEmpty(target.propertyName)) { _builder.Append(target.propertyName); _builder.Append(" ("); _builder.Append(target._propertyType); _builder.Append(')'); } if (GUI.Button(rect, _builder.ToString(), EditorStyles.layerMaskField)) { var properties = new HashSet<Property>(); var menu = new GenericMenu(); for (int i = 0; i < materialCount; i++) { if (target.IsMaterialSelected(i) && _materials[i] && _materials[i].shader) { var shader = _materials[i].shader; int count = ShaderUtil.GetPropertyCount(shader); for (int idx = 0; idx < count; idx++) { if (!ShaderUtil.IsShaderPropertyHidden(shader, idx)) { var prop = new Property { name = ShaderUtil.GetPropertyName(shader, idx), type = ShaderUtil.GetPropertyType(shader, idx) }; if (properties.Contains(prop)) continue; properties.Add(prop); string description = ShaderUtil.GetPropertyDescription(shader, idx); if (prop.type == ShaderUtil.ShaderPropertyType.TexEnv) { prop.name += "_ST"; prop.type = ShaderUtil.ShaderPropertyType.Vector; description += " Scale and Offest"; } _builder.Clear(); _builder.Append(prop.name); _builder.Append(" (\""); _builder.Append(description); _builder.Append("\", "); _builder.Append(prop.type); _builder.Append(')'); menu.AddItem(new GUIContent(_builder.ToString()), target._propertyName == prop.name && target._propertyType == (Type)(int)prop.type, () => { Undo.RecordObject(target, "Select Property"); Type oldType = target.propertyType; target.SetProperty(prop.name, (Type)(int)prop.type); if (oldType != target.propertyType) { if (target.propertyType == Type.Color) target.from = target.to = Color.white; if (target.propertyType == Type.Float || target.propertyType == Type.Range) target.from.x = target.to.x = 1f; if (target.propertyType == Type.Vector) { if (prop.name.EndsWith("_ST")) target.from = target.to = new Vector4(1, 1, 0, 0); else target.from = target.to = new Vector4(1, 1, 1, 1); } } }); _builder.Clear(); } } } } if (properties.Count == 0) menu.AddItem(new GUIContent("(No Valid Property)"), false, () => { }); menu.DropDown(rect); } _builder.Clear(); }
void DrawMaterialMask(int materialCount) { int count = 0; if (target.allMaterialSelected) _builder.Append("All (Apply to Renderer)"); else if (target.noneMaterialSelected) _builder.Append("None"); else { for (int i = 0; i < materialCount; i++) { if (target.IsMaterialSelected(i)) { count++; if (count > 1) { _builder.Append(", "); if (count == 4) { _builder.Append("..."); break; } } _builder.Append(i); _builder.Append(": "); _builder.Append(_materials[i] ? _materials[i].name : "(None)"); } } } var rect = EditorGUILayout.GetControlRect(); rect = EditorGUI.PrefixLabel(rect, EditorGUIKit.TempContent("Materials")); if (GUI.Button(rect, _builder.ToString(), EditorStyles.layerMaskField)) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("All (Apply to Renderer)"), target.allMaterialSelected, () => { Undo.RecordObject(target, "Select Material"); target.SelectAllMaterials(); }); menu.AddItem(new GUIContent("None"), target.noneMaterialSelected, () => { Undo.RecordObject(target, "Select Material"); target.DeselectAllMaterials(); }); if (materialCount > 0) menu.AddSeparator(string.Empty); for (int i = 0; i < materialCount; i++) { int index = i; menu.AddItem(new GUIContent(index + ": " + (_materials[index] ? _materials[index].name : "(None)")), target.IsMaterialSelected(index), () => { Undo.RecordObject(target, "Select Material"); target.SetMaterialSelected(index, !target.IsMaterialSelected(index)); }); } menu.DropDown(rect); } _builder.Clear(); }
public override void OnInspectorGUI() { // Edit Button var rect = EditorGUILayout.GetControlRect(true, 23); rect.x += EditorGUIUtility.labelWidth; rect.width = 33; using (var scope = new ChangeCheckScope(null)) { bool edit = GUI.Toggle(rect, FloatingWindow.target == target, EditorGUIUtility.IconContent("EditCollider"), EditorGUIKit.buttonStyle); rect.x = rect.xMax + 5; rect.width = 140; EditorGUI.LabelField(rect, "Edit Path", EditorGUIKit.middleLeftLabelStyle); if (scope.changed) { FloatingWindow.target = edit ? target : null; } } // circular using (var scope = new ChangeCheckScope(target)) { bool circular = EditorGUILayout.Toggle("Circular", target.circular); if (scope.changed) { target.circular = circular; } } // World Scale using (var scope = new ChangeCheckScope(target)) { float value = EditorGUILayout.FloatField( EditorGUIKit.TempContent("World Scale", null, "Use \"World Scale\" to scale the path instead of scales of transform."), target.worldScale); if (scope.changed) { target.worldScale = value; } } // Length Error using (var scope = new ChangeCheckScope(target)) { float value = EditorGUILayout.FloatField("Length Error", target.lengthError); if (scope.changed) { target.lengthError = value; } } // Length if (target.isSamplesValid) { EditorGUILayout.FloatField("Length", target.length); } else { rect = EditorGUILayout.GetControlRect(); EditorGUI.LabelField(rect, "Length"); rect.xMin += EditorGUIUtility.labelWidth; // Calculate Button if (GUI.Button(rect, "Calculate", EditorStyles.miniButton)) { Undo.RecordObject(target, "Calculate"); target.ValidateSamples(); } } // Visible using (var scope = new ChangeCheckScope(target)) { bool value = EditorGUIKit.IndentedToggleButton("Always Visible", target._alwaysVisible); if (scope.changed) { target._alwaysVisible = value; } } }
void OnGUI() { var path = target; if (path) { selectedNode = Mathf.Clamp(selectedNode, 0, path.nodeCount - 1); EditorGUILayout.LabelField("Tools", EditorStyles.centeredGreyMiniLabel); using (new GUIContentColorScope(EditorGUIKit.defaultTextColor)) { var rect = EditorGUILayout.GetControlRect(false, 25); rect.width /= 3; if (GUI.Toggle(rect, selectedTool == 0, EditorGUIKit.TempContent(null, EditorAsset.instance.moveToolPan, "Pan Move Tool"), EditorGUIKit.buttonLeftStyle)) { selectedTool = 0; } rect.x = rect.xMax; if (GUI.Toggle(rect, selectedTool == 1, EditorGUIKit.TempContent(null, EditorAsset.instance.moveTool3D, "3D Move Tool"), EditorGUIKit.buttonMiddleStyle)) { selectedTool = 1; } using (new DisabledScope(disableRotateTool)) { rect.x = rect.xMax; if (GUI.Toggle(rect, selectedTool == 2, EditorGUIKit.TempContent(null, EditorAsset.instance.RotateTool, "Rotate Tool"), EditorGUIKit.buttonRightStyle)) { selectedTool = 2; } } EditorGUILayout.GetControlRect(false, 0); rect = EditorGUILayout.GetControlRect(false, 25); rect.width /= 3; if (GUI.Button(rect, EditorGUIKit.TempContent(null, EditorAsset.instance.addNodeBack, "Add Node Back"), EditorGUIKit.buttonLeftStyle)) { Undo.RecordObject(path, "Add Node Back"); path.InsertNode(selectedNode); } using (new DisabledScope(path.nodeCount == 2)) { rect.x = rect.xMax; if (GUI.Button(rect, EditorGUIKit.TempContent(null, EditorAsset.instance.removeNode, "Remove Node"), EditorGUIKit.buttonMiddleStyle)) { Undo.RecordObject(path, "Remove Node"); path.RemoveNode(selectedNode); selectedNode = Mathf.Clamp(selectedNode - 1, 0, path.nodeCount - 1); } } rect.x = rect.xMax; if (GUI.Button(rect, EditorGUIKit.TempContent(null, EditorAsset.instance.addNodeForward, "Add Node Forward"), EditorGUIKit.buttonRightStyle)) { Undo.RecordObject(path, "Add Node Forward"); selectedNode++; path.InsertNode(selectedNode); } } OnWindowGUI(path); } else { Close(); } }
public override void OnInspectorGUI() { EditorGUILayout.BeginVertical(EditorStyles.helpBox); var rect = EditorGUILayout.GetControlRect(); var rect2 = rect; // controller foldout using (var scope = new ChangeCheckScope(target)) { rect2.width = rect2.height; var result = GUI.Toggle(rect2, target._foldoutController, GUIContent.none, EditorStyles.foldout); if (scope.changed) { target._foldoutController = result; } } // controller label rect.xMin = rect2.xMax; EditorGUI.LabelField(rect, "Controller", EditorStyles.boldLabel); serializedObject.Update(); // controller settings if (target._foldoutController) { EditorGUILayout.PropertyField(_durationProp); EditorGUILayout.PropertyField(_updateModeProp); EditorGUILayout.PropertyField(_timeModeProp); EditorGUILayout.PropertyField(_wrapModeProp); EditorGUILayout.PropertyField(_arrivedActionProp); GUILayout.Space(4); } EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), EditorStyles.centeredGreyMiniLabel.normal.textColor); GUILayout.Space(4); rect = EditorGUILayout.GetControlRect(); rect2 = rect; // play button rect2.width = EditorGUIUtility.singleLineHeight * 2 - 4; using (new GUIContentColorScope(target.playing ? progressForegroundValid : EditorGUIKit.defaultTextColor)) { target.playing = GUI.Toggle(rect2, target.playing, EditorGUIKit.TempContent(image: EditorAsset.instance.play), imageButtonStyle); } // direction button rect2.x = rect.xMax - rect2.width; using (new DisabledScope(!target.playing)) { using (new GUIContentColorScope(EditorGUIKit.defaultTextColor)) { if (GUI.Button(rect2, EditorGUIKit.TempContent(image: target.direction == PlayDirection.Forward ? EditorAsset.instance.rightArrow : EditorAsset.instance.leftArrow), imageButtonStyle)) { target.ReverseDirection(); } } } rect.xMin += EditorGUIUtility.singleLineHeight * 2; rect.xMax -= EditorGUIUtility.singleLineHeight * 2; // 鼠标开始拖动 if (Event.current.type == EventType.MouseDown) { if (rect.Contains(Event.current.mousePosition)) { target.dragging = true; } } // 鼠标结束拖动 if (Event.current.rawType == EventType.MouseUp) { if (target.dragging) { target.dragging = false; Repaint(); } } // progress bar using (var scope = new ChangeCheckScope(null)) { float progress = EditorGUIKit.ProgressBar(rect, target._normalizedTime, progressBackgroundInvalid, progressForegroundValid); if (scope.changed && target.dragging) { target.normalizedTime = progress; } } GUILayout.Space(4); EditorGUILayout.EndVertical(); GUILayout.Space(4); EditorGUILayout.BeginVertical(EditorStyles.helpBox); rect = EditorGUILayout.GetControlRect(); rect2 = rect; // events foldout using (var scope = new ChangeCheckScope(target)) { rect2.width = rect2.height; var result = GUI.Toggle(rect2, target._foldoutEvents, GUIContent.none, EditorStyles.foldout); if (scope.changed) { target._foldoutEvents = result; } } // events label rect.xMin = rect2.xMax; EditorGUI.LabelField(rect, "Events", EditorStyles.boldLabel); // events if (target._foldoutEvents) { EditorGUILayout.PropertyField(_onForwardArrivedProp); GUILayout.Space(2); EditorGUILayout.PropertyField(_onBackArrivedProp); GUILayout.Space(2); } serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndVertical(); GUILayout.Space(4); EditorGUILayout.BeginVertical(EditorStyles.helpBox); // 绘制 Animation 列表。为了正确处理各种意外情况(比如其他代码增删了列表),因此处理比较复杂 :-/ if (!GeneralKit.IsNullOrEmpty(target._animations)) { int editorIndex = 0; for (int i = 0; i < target._animations.Count; i++) { var anim = target._animations[i]; if (anim) { if (_editors.Count <= editorIndex) { _editors.Add(null); } if (!_editors[editorIndex] || _editors[editorIndex].target != anim) { GeneralKit.DestroySafely(_editors[editorIndex]); _editors[editorIndex] = CreateEditor(anim); } (_editors[editorIndex] as TweenAnimation.Editor).OnInspectorGUI(target); editorIndex++; } else { target._animations.RemoveAt(i--); } } for (; editorIndex < _editors.Count; editorIndex++) { GeneralKit.DestroySafely(_editors[editorIndex]); _editors.RemoveAt(editorIndex--); } } // add button GUILayout.Space(4); var buttonRect = EditorGUILayout.GetControlRect(); if (GUI.Button(buttonRect, "Add Animation...", EditorStyles.miniButton)) { ShowAddMenu(buttonRect); } GUILayout.Space(4); EditorGUILayout.EndVertical(); }