void OnGUI() { EditorGUILayout.Space(); var rect = EditorGUILayout.GetControlRect(); if (Application.isPlaying) { rect = EditorGUI.PrefixLabel(rect, EditorGUIKit.TempContent("Language")); string desc = string.Empty; if (LocalizationManager.languageIndex >= 0) { desc = string.Format("{0} ({1})", LocalizationManager.languageName, LocalizationManager.languageType); } if (GUI.Button(rect, desc, EditorStyles.layerMaskField)) { GenericMenu menu = new GenericMenu(); for (int i = 0; i < LocalizationManager.languageCount; i++) { string text = string.Format("{0} ({1})", LocalizationManager.GetLanguageName(i), LocalizationManager.GetLanguageType(i)); int index = i; menu.AddItem(new GUIContent(text), i == LocalizationManager.languageIndex, () => LocalizationManager.languageIndex = index); } menu.DropDown(rect); } } else { EditorGUI.LabelField(rect, "Can't set language in edit-mode"); } }
// 绘制曲线 void DrawCurve(Rect rect, bool drawStrength) { EditorGUI.DrawRect(rect, new Color(0.3f, 0.3f, 0.3f)); if (drawStrength) { EditorGUI.DrawRect(new Rect(rect.x + (rect.width - 1) * _lastStrength, rect.y, 1, rect.height), new Color(1, 0.33f, 0)); } Vector2 origin = new Vector2(rect.x + 1, rect.y + 1); Vector2 scale = new Vector2(rect.width - 2, (rect.height - 2) / (_maxValue - _minValue)); //if (_maxValue > 0f && _minValue < 1f) //{ // float yMin = origin.y + (_maxValue - Mathf.Min(_maxValue, 1f)) * scale.y; // float yMax = origin.y + (_maxValue - Mathf.Max(_minValue, 0f)) * scale.y; // Rect rect01 = new Rect(rect.x, yMin, rect.width, yMax - yMin); // EditorGUI.DrawRect(rect01, new Color(0.4f, 0.4f, 0.4f)); //} Vector3 last = _samples[0]; last.x = origin.x + last.x * scale.x; last.y = origin.y + (_maxValue - last.y) * scale.y; using (new HandlesColorScope(new Color(1f, 1f, 1f, 0.8f))) { Vector3 point; for (int i = 1; i < _samples.Count; i++) { point = _samples[i]; point.x = origin.x + point.x * scale.x; point.y = origin.y + (_maxValue - point.y) * scale.y; HandlesKit.DrawAALine(last, point); last = point; } } EditorGUIKit.DrawWireRect(rect, new Color(0, 0, 0, 0.4f)); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position = EditorGUI.PrefixLabel(position, label); var typeProp = property.FindPropertyRelative("type"); int type = typeProp.intValue; var strengthProp = property.FindPropertyRelative("strength"); var buttonRect = new Rect(position.x + 1, position.y + 2, EditorGUIKit.paneOptionsIconDark.width, EditorGUIKit.paneOptionsIconDark.height); using (var scope = new ChangeCheckScope(null)) { EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Arrow); System.Enum newType; if (fieldInfo.FieldType == typeof(CustomizableInterpolator)) { newType = EditorGUI.EnumPopup(buttonRect, GUIContent.none, (CustomizableInterpolator.Type)type, buttonStyle); } else { newType = EditorGUI.EnumPopup(buttonRect, GUIContent.none, (Interpolator.Type)type, buttonStyle); } if (scope.changed) { typeProp.intValue = type = (int)(CustomizableInterpolator.Type)newType; strengthProp.floatValue = 0.5f; } } if ((CustomizableInterpolator.Type)type == CustomizableInterpolator.Type.CustomCurve) { EditorGUIUtility.AddCursorRect(position, MouseCursor.Zoom); EditorGUI.PropertyField(position, property.FindPropertyRelative("customCurve"), GUIContent.none); } else { bool drawStrength; switch ((CustomizableInterpolator.Type)type) { case CustomizableInterpolator.Type.Linear: case CustomizableInterpolator.Type.Parabolic: case CustomizableInterpolator.Type.Sine: drawStrength = false; break; default: strengthProp.floatValue = Mathf.Clamp01(EditorGUIKit.DragValue(position, strengthProp.floatValue, 0.01f)); drawStrength = true; break; } if (Event.current.type == EventType.Repaint) { Sample(type, strengthProp.floatValue, Mathf.Min((int)position.width, 256), 0.002f); DrawCurve(position, drawStrength); } } EditorGUI.LabelField(buttonRect, EditorGUIKit.TempContent(image: EditorGUIKit.paneOptionsIconDark), GUIStyle.none); }
void OnGUI() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Start", EditorStyles.boldLabel); using (var scope = new ChangeCheckScope(d)) { var rect = EditorGUILayout.GetControlRect(); rect.width -= 8 + rect.height * 3; var startTrans = EditorGUI.ObjectField(rect, GUIContent.none, d.startTrans, typeof(Transform), true) as Transform; rect.x = rect.xMax + 8; rect.width = rect.height * 1.5f; if (GUI.Button(rect, EditorGUIKit.TempContent("S", null, "Use selection"), EditorStyles.miniButtonLeft)) { startTrans = Selection.activeTransform; } rect.x = rect.xMax; if (GUI.Button(rect, EditorGUIKit.TempContent("C", null, "Clear reference"), EditorStyles.miniButtonRight)) { startTrans = null; } if (scope.changed) { d.startTrans = startTrans; } } if (d.startTrans) { using (var scope = new ChangeCheckScope(d.startTrans)) { d.startPos = EditorGUILayout.Vector3Field(GUIContent.none, d.startTrans.position); if (scope.changed) { d.startTrans.position = d.startPos; } } } else { using (var scope = new ChangeCheckScope(d)) { var startPos = EditorGUILayout.Vector3Field(GUIContent.none, d.startPos); if (scope.changed) { d.startPos = startPos; } } } EditorGUILayout.Space(); EditorGUILayout.LabelField("End", EditorStyles.boldLabel); using (var scope = new ChangeCheckScope(d)) { var rect = EditorGUILayout.GetControlRect(); rect.width -= 8 + rect.height * 3; var endTrans = EditorGUI.ObjectField(rect, GUIContent.none, d.endTrans, typeof(Transform), true) as Transform; rect.x = rect.xMax + 8; rect.width = rect.height * 1.5f; if (GUI.Button(rect, EditorGUIKit.TempContent("S", null, "Use selection"), EditorStyles.miniButtonLeft)) { endTrans = Selection.activeTransform; } rect.x = rect.xMax; if (GUI.Button(rect, EditorGUIKit.TempContent("C", null, "Clear reference"), EditorStyles.miniButtonRight)) { endTrans = null; } if (scope.changed) { d.endTrans = endTrans; } } if (d.endTrans) { using (var scope = new ChangeCheckScope(d.endTrans)) { d.endPos = EditorGUILayout.Vector3Field(GUIContent.none, d.endTrans.position); if (scope.changed) { d.endTrans.position = d.endPos; } } } else { using (var scope = new ChangeCheckScope(d)) { var endPos = EditorGUILayout.Vector3Field(GUIContent.none, d.endPos); if (scope.changed) { d.endPos = endPos; } } } Vector3 distance = d.endPos - d.startPos; EditorGUILayout.Space(); EditorGUILayout.LabelField("Distance", EditorStyles.boldLabel); EditorGUILayout.FloatField(GUIContent.none, distance.magnitude); using (new HorizontalLayoutScope(0)) { using (new VerticalLayoutScope(0)) { using (new LabelWidthScope(20)) { EditorGUILayout.FloatField("YZ", distance.yz().magnitude); EditorGUILayout.FloatField("XZ", distance.xz().magnitude); EditorGUILayout.FloatField("XY", distance.xy().magnitude); } } EditorGUILayout.Space(); using (new VerticalLayoutScope(0)) { using (new LabelWidthScope(14)) { EditorGUILayout.FloatField("X", distance.x); EditorGUILayout.FloatField("Y", distance.y); EditorGUILayout.FloatField("Z", distance.z); } } } EditorGUILayout.Space(); EditorGUILayout.LabelField("Visualization", EditorStyles.boldLabel); d.showXYZ = GUILayout.Toggle(d.showXYZ, "Show XYZ 3D", EditorStyles.miniButton); d.showYZ = GUILayout.Toggle(d.showYZ, "Show YZ Plane", EditorStyles.miniButton); d.showXZ = GUILayout.Toggle(d.showXZ, "Show XZ Plane", EditorStyles.miniButton); d.showXY = GUILayout.Toggle(d.showXY, "Show XY Plane", EditorStyles.miniButton); EditorGUILayout.Space(); d.showMoveTools = GUILayout.Toggle(d.showMoveTools, "Show Move Tools", EditorStyles.miniButton); Tools.hidden = !GUILayout.Toggle(!Tools.hidden, "Show Unity Tools", EditorStyles.miniButton); }