Example #1
0
			protected override void Editor_OnGUI(Rect rect, SerializedProperty property, GUIContent label)
			{
				var target = property.serializedObject.targetObject as TweenAnimation;

				// 绘制 Tweener 引用

				rect.width -= rect.height + 4;

				EditorGUI.BeginChangeCheck();

				var tweener = EditorGUI.ObjectField(rect, "Tweener", target.tweener,
					typeof(Tweener), !EditorUtility.IsPersistent(target)) as Tweener;

				if (EditorGUI.EndChangeCheck())
				{
					Undo.RecordObject(target, "Set Tweener");
					target.tweener = tweener;
					EditorUtility.SetDirty(target);
				}

				rect.x = rect.xMax + 4f;
				rect.width = rect.height;

				if (target.tweener)
				{
					// 绘制个性化颜色块

					EditorKit.RecordAndSetGUIColor(EditorKit.defaultContentColor);
					GUI.DrawTexture(rect, EditorAssets.bigDiamondTexture);
					EditorKit.RestoreGUIColor();

					EditorKit.RecordAndSetGUIColor(target.tweener._personalizedColor);
					GUI.DrawTexture(rect, EditorAssets.smallDiamondTexture);
					EditorKit.RestoreGUIColor();
				}
				else
				{
					// 绘制 + 按钮

					EditorKit.RecordAndSetGUIContentColor(EditorKit.defaultContentColor);

					if (GUI.Button(rect, EditorAssets.addTexture, GUIStyle.none))
					{
						tweener = Undo.AddComponent<Tweener>(target.gameObject);
						Undo.IncrementCurrentGroup();
						Undo.RecordObject(target, "Set Tweener");
						target.tweener = tweener;
						EditorUtility.SetDirty(target);
					}

					EditorKit.RestoreGUIContentColor();
				}
			}
Example #2
0
        protected override void Editor_OnInspectorGUI()
        {
            Color foregroundColor = EditorKit.defaultContentColor;

            EditorGUILayout.Space();
            _selectedPageIndex = GUILayout.Toolbar(_selectedPageIndex, pageTitles, EditorStyles.miniButton);
            EditorGUILayout.Space();
            Rect rect = EditorGUILayout.GetControlRect(false, 1f);

            EditorGUI.DrawRect(rect, foregroundColor * 0.5f);
            EditorGUILayout.Space();

            editor.serializedObject.Update();

            switch (_selectedPageIndex)
            {
            case 0:                             // Interpolator
            {
                EditorGUILayout.PropertyField(_interpolatorProp);
                break;
            }

            case 1:                             // Animation
            {
                EditorGUILayout.PropertyField(_startDelayProp);
                EditorGUILayout.PropertyField(_durationProp);
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(_wrapModeProp);
                EditorGUILayout.PropertyField(_playModeProp);
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(_updateModeProp);
                EditorGUI.BeginDisabledGroup(_updateMode == UpdateMode.FixedUpdate);
                EditorGUILayout.PropertyField(_timeModeProp);
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.Space();

                rect = EditorGUILayout.GetControlRect();
                EditorGUI.LabelField(rect, " ", _animations.Count.ToString());
                _showAnimations = EditorGUI.Foldout(rect, _showAnimations, "Animations", true);
                if (_showAnimations)
                {
                    EditorGUI.indentLevel++;
                    EditorGUI.BeginDisabledGroup(true);
                    for (int i = 0; i < _animations.Count; i++)
                    {
                        stringBuilder.Length = 8;
                        EditorGUILayout.ObjectField(stringBuilder.Append(i).ToString(), _animations[i], typeof(TweenAnimation), false);
                    }
                    EditorGUI.EndDisabledGroup();
                    EditorGUI.indentLevel--;
                }
                break;
            }

            case 2:                             // Event
            {
                EditorGUILayout.PropertyField(_onForwardToEndingProp);
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(_onBackToBeginningProp);
                break;
            }
            }

            editor.serializedObject.ApplyModifiedProperties();

            EditorGUILayout.Space();
            rect = EditorGUILayout.GetControlRect(true, 1f);
            EditorGUI.DrawRect(rect, foregroundColor * 0.5f);

            EditorGUILayout.Space();
            rect = EditorGUILayout.GetControlRect(true);

            // 绘制预览按钮
            Rect previewRect = rect;

            previewRect.width = 54f;
            rect.xMin         = rect.xMax - rect.height;

            if (Application.isPlaying)
            {
                EditorKit.RecordAndSetGUIBackgroundColor(enabled ? _personalizedColor : GUI.backgroundColor);
                enabled = GUI.Toggle(previewRect, enabled, "Play", EditorStyles.miniButton);
                EditorKit.RestoreGUIBackgroundColor();
            }
            else
            {
                EditorKit.RecordAndSetGUIBackgroundColor(_isPreviewInEditor ? _personalizedColor : GUI.backgroundColor);
                previewInEditor = GUI.Toggle(previewRect, _isPreviewInEditor, "Preview", EditorStyles.miniButton);
                EditorKit.RestoreGUIBackgroundColor();
            }

            // 进度条
            previewRect.x    = previewRect.xMax + 8f;
            previewRect.xMax = rect.xMin - 8f;

            // 鼠标开始拖动
            if (Event.current.type == EventType.MouseDown)
            {
                if (previewRect.Contains(Event.current.mousePosition))
                {
                    draggingInEditor = true;
                }
            }

            // 鼠标结束拖动
            if (Event.current.rawType == EventType.MouseUp)
            {
                if (_isDraggingInEditor)
                {
                    draggingInEditor = false;
                    editor.Repaint();
                }
            }

            // 绘制进度条
            EditorGUI.BeginChangeCheck();
            float time01 = EditorKit.ProgressBar(previewRect, _normalizedTime, progressBackground, _personalizedColor, foregroundColor, true);

            if (EditorGUI.EndChangeCheck() && _isDraggingInEditor)
            {
                normalizedTime = time01;
            }

            // 绘制个性化颜色按钮
            if (GUI.Button(rect, GUIContent.none))
            {
                Undo.RecordObject(this, "Change Color");
                _personalizedColor = EditorKit.randomColor;
                EditorUtility.SetDirty(this);
            }

            // 绘制颜色块
            EditorKit.RecordAndSetGUIColor(foregroundColor);
            GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture);
            EditorKit.RestoreGUIColor();

            EditorKit.RecordAndSetGUIColor(_personalizedColor);
            previewRect.Set(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f);
            GUI.DrawTexture(previewRect, EditorGUIUtility.whiteTexture);
            EditorKit.RestoreGUIColor();

            EditorGUILayout.Space();
        }
Example #3
0
        // 在场景里绘制编辑控件
        protected override void DrawSceneControls()
        {
            ValidateSelectedItem();

            // 绘制控件

            switch (_selectedTool)
            {
            case 0: DrawSplineControls(); break;

            case 1: DrawNodeControls(false); break;

            case 2: DrawNodeControls(true); break;

            case 3: DrawNodeControls(false); DrawMoveHandle(); break;
            }

            if (_selectionType != SelectionType.None)
            {
                // 获取选择元素的世界位置

                Vector3 worldPoint;

                switch (_selectionType)
                {
                case SelectionType.Spline:
                {
                    _location.Set(_selectedItem, 0.5f);
                    worldPoint = GetPoint(_location);
                    break;
                }

                case SelectionType.MiddleControlPoint:
                {
                    worldPoint = GetMiddleControlPoint(_selectedItem);
                    break;
                }

                case SelectionType.ForwardControlPoint:
                {
                    worldPoint = GetForwardControlPoint(_selectedItem);
                    break;
                }

                case SelectionType.BackControlPoint:
                {
                    worldPoint = GetBackControlPoint(_selectedItem);
                    break;
                }

                default:
                {
                    worldPoint = Vector3.zero;
                    break;
                }
                }

                // 绘制光晕

                Vector2 guiPoint = HandleUtility.WorldToGUIPoint(worldPoint);
                _lineRect = new Rect(guiPoint.x - 32f, guiPoint.y - 34f, 64f, 64f);

                Handles.BeginGUI();
                EditorKit.RecordAndSetGUIColor(_haloColor);
                GUI.DrawTexture(_lineRect, EditorAssets.roundGradientTexture);
                EditorKit.RestoreGUIColor();
                Handles.EndGUI();

                // 居中元素
                if (Event.current.type == EventType.keyDown)
                {
                    if (Event.current.character == 'f' || Event.current.character == 'F')
                    {
                        Event.current.Use();
                        SceneView.lastActiveSceneView.LookAt(worldPoint);
                    }
                }
            }
        }
Example #4
0
            protected sealed override void Editor_OnInspectorGUI()
            {
                // Check Path

                if (!path)
                {
                    EditorGUILayout.HelpBox("Require Path Component!", MessageType.Error, true);
                    if (_currentEditing == this)
                    {
                        SetCurrentEditing(null);
                    }
                    return;
                }

                // personalized Color

                _rect = EditorGUILayout.GetControlRect(true, _editButtonHeight);
                var rect2 = new Rect(_rect.x + 3f, _rect.y + 3f, _rect.height - 6f, _rect.height - 6f);

                if (GUI.Button(rect2, GUIContent.none))
                {
                    Undo.RecordObject(this, "Change Color");
                    personalizedColor = EditorKit.randomColor;
                    EditorUtility.SetDirty(this);
                }

                EditorKit.RecordAndSetGUIColor(EditorKit.defaultContentColor);
                GUI.DrawTexture(rect2, EditorGUIUtility.whiteTexture);
                EditorKit.RestoreGUIColor();

                EditorKit.RecordAndSetGUIColor(personalizedColor);
                rect2.Set(rect2.x + 1f, rect2.y + 1f, rect2.width - 2f, rect2.height - 2f);
                GUI.DrawTexture(rect2, EditorGUIUtility.whiteTexture);
                EditorKit.RestoreGUIColor();

                // Edit Button

                _rect.x    += EditorGUIUtility.labelWidth;
                _rect.width = _editButtonWidth;

                EditorGUI.BeginChangeCheck();
                EditorKit.RecordAndSetGUIContentColor(EditorKit.defaultContentColor);
                bool edit = GUI.Toggle(_rect, _currentEditing == this, EditorAssets.editTexture, EditorKit.buttonStyle);

                EditorKit.RestoreGUIContentColor();
                if (EditorGUI.EndChangeCheck())
                {
                    SetCurrentEditing(edit ? this : null);
                }

                // Edit Label

                _rect.x     = _rect.xMax + _horizontalInterval;
                _rect.width = 128f;
                EditorGUI.LabelField(_rect, "Edit Keys", middleLeftLabel);

                // DrawExtraInspector

                DrawExtraInspector();

                // Sort Button

                if (!isSorted)
                {
                    if (EditorKit.IndentedButton("Sort"))
                    {
                        Undo.RecordObject(this, editor.undoString);
                        Sort();
                        EditorUtility.SetDirty(this);
                    }
                }
            }
Example #5
0
		protected sealed override void Editor_OnInspectorGUI()
		{
			// path
			editor.DrawObjectFieldLayout(_path, value => path = value, "Path");

			// distance
			EditorGUI.BeginChangeCheck();
			var distance = EditorGUILayout.FloatField("Distance", _distance);
			if (EditorGUI.EndChangeCheck())
			{
				Undo.RecordObject(transform, editor.undoString);
				Undo.RecordObject(this, editor.undoString);
				this.distance = distance;
				EditorUtility.SetDirty(transform);
				EditorUtility.SetDirty(this);
			}

			Editor_OnExtraInspectorGUI();

			// sync button
			Rect rect = EditorGUILayout.GetControlRect(true);
			rect.xMin += EditorGUIUtility.labelWidth;
			if (GUI.Button(rect, _buttonContent, EditorStyles.miniButton))
			{
				Undo.RecordObject(transform, editor.undoString);
				Undo.RecordObject(this, editor.undoString);
				Sync();
				EditorUtility.SetDirty(transform);
				EditorUtility.SetDirty(this);
			}

			// keyframe list
			if (_path)
			{
				_keyframeLists.Clear();
				_path.GetComponents(_keyframeLists);

				if (_keyframeLists.Count > 0)
				{
					// 计算表格大小

					EditorGUILayout.Space();
					float lineHeight = EditorGUIUtility.singleLineHeight;
					rect = EditorGUILayout.GetControlRect(true, (lineHeight + 1f) * (_keyframeLists.Count + 1) + 4f);
					Rect left = new Rect(rect.x, rect.y, rect.width * 0.5f, lineHeight);
					Rect right = new Rect(left.xMax, left.y, left.width, lineHeight);

					// 绘制背景和线条

					EditorGUI.DrawRect(rect, _tableBackgroundColor);
					float yMax = rect.yMax;
					rect.height = 1f;
					Color lineColor = EditorKit.defaultContentColor * 0.5f;
					EditorGUI.DrawRect(rect, lineColor);
					rect.y += lineHeight + 1f;
					EditorGUI.DrawRect(rect, lineColor);
					rect.y = yMax;
					EditorGUI.DrawRect(rect, lineColor);

					// 绘制标题

					EditorGUI.LabelField(left, "Keyframe List", EditorKit.centeredBoldLabelStyle);
					EditorGUI.LabelField(right, "Target Component", EditorKit.centeredBoldLabelStyle);

					left.y += 3f;
					right.y += 3f;

					// 计算左列宽度

					rect = left;
					rect.width = lineHeight;
					left.xMin += lineHeight + 2f;

					// 绘制行元素

					Path.KeyframeList keyframeList;
					KeyframeListTargetComponentPair pair;

					for (int i = 0; i < _keyframeLists.Count; i++)
					{
						rect.y += lineHeight + 1f;
						left.y += lineHeight + 1f;
						right.y += lineHeight + 1f;

						keyframeList = _keyframeLists[i];

						// 绘制个性色

						EditorKit.RecordAndSetGUIColor(EditorKit.defaultContentColor);
						GUI.DrawTexture(rect, EditorAssets.bigDiamondTexture);
						EditorKit.RestoreGUIColor();

						EditorKit.RecordAndSetGUIColor(keyframeList.personalizedColor);
						GUI.DrawTexture(rect, EditorAssets.smallDiamondTexture);
						EditorKit.RestoreGUIColor();

						// 绘制关键帧列表名

						EditorGUI.LabelField(left, keyframeList.targetPropertyName);

						// 绘制目标组件引用

						pair = _pairs.Find(item => item.keyframeList == keyframeList);

						if (pair == null)
						{
							EditorGUI.BeginChangeCheck();
							var target = EditorGUI.ObjectField(right, null, keyframeList.targetComponentType, !EditorUtility.IsPersistent(this));
							if (EditorGUI.EndChangeCheck())
							{
								if (target)
								{
									Undo.RecordObject(this, editor.undoString);
									AddMovingObject(keyframeList, target as Component);
									EditorUtility.SetDirty(this);
									editor.Repaint();
									break;
								}
							}
						}
						else
						{
							EditorGUI.BeginChangeCheck();
							var target = EditorGUI.ObjectField(right, pair.targetComponent, keyframeList.targetComponentType, !EditorUtility.IsPersistent(this));
							if (EditorGUI.EndChangeCheck())
							{
								Undo.RecordObject(this, editor.undoString);

								if (target) pair.targetComponent = target as Component;
								else _pairs.Remove(pair);

								EditorUtility.SetDirty(this);
								editor.Repaint();
								break;
							}
						}
					}

					EditorGUILayout.Space();
				}
			}
		}