Exemple #1
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();
				}
			}
		}
Exemple #2
0
		// 绘制编辑器 UI
		protected override void Editor_OnGUI(Rect rect, SerializedProperty property, GUIContent label)
		{
			UnityEngine.Object target = property.serializedObject.targetObject;
			rect.height = EditorGUIUtility.singleLineHeight;

			{
				// 材质类型

				EditorGUI.BeginChangeCheck();
				var newMaterialType = EditorGUI.EnumPopup(rect, "Material Type", _materialType);
				if (EditorGUI.EndChangeCheck())
				{
					Undo.RecordObject(target, "Material Type");
					materialType = (MaterialType)newMaterialType;
					EditorUtility.SetDirty(target);
				}
			}

			rect.y = rect.yMax + _lineInterval;

			if (_materialType == MaterialType.Specified)
			{
				// 指定材质

				EditorGUI.BeginChangeCheck();
				var newSpecifiedMaterial = EditorGUI.ObjectField(rect, "Specified Material", _specifiedMaterial, typeof(Material), false);
				if (EditorGUI.EndChangeCheck())
				{
					Undo.RecordObject(target, "Specified Material");
					specifiedMaterial = newSpecifiedMaterial as Material;
					EditorUtility.SetDirty(target);
				}
			}
			else
			{
				// 动态 GI

				EditorGUI.BeginChangeCheck();
				bool newUpdateDynamicGI = EditorGUI.Toggle(rect, "Update Dynamic GI", _updateDynamicGI);
				if (EditorGUI.EndChangeCheck())
				{
					Undo.RecordObject(target, "Update Dynamic GI");
					_updateDynamicGI = newUpdateDynamicGI;
					EditorUtility.SetDirty(target);
				}

				rect.y = rect.yMax + _lineInterval;

				// 渲染器

				EditorGUI.BeginChangeCheck();
				var newRenderer = EditorGUI.ObjectField(rect, "Renderer", _renderer, typeof(Renderer), !EditorUtility.IsPersistent(target));
				if (EditorGUI.EndChangeCheck())
				{
					Undo.RecordObject(target, "Renderer");
					renderer = newRenderer as Renderer;
					EditorUtility.SetDirty(target);
				}

				rect.y = rect.yMax + _lineInterval;

				// 材质索引

				EditorGUI.BeginChangeCheck();
				int newMaterialIndex = EditorGUI.IntField(rect, "Material Index", _materialIndex);
				if (EditorGUI.EndChangeCheck())
				{
					Undo.RecordObject(target, "Material Index");
					materialIndex = newMaterialIndex;
					EditorUtility.SetDirty(target);
				}
			}

			rect.y = rect.yMax + _lineInterval;

			{
				// Shader

				UpdateShader();
				EditorGUI.BeginDisabledGroup(true);
				EditorGUI.ObjectField(rect, "Shader", _shader, typeof(Shader), false);
				EditorGUI.EndDisabledGroup();

				Rect refreshRect = rect;
				refreshRect.xMin = refreshRect.xMax - refreshRect.height;

				// 刷新按钮

				EditorGUI.DrawRect(refreshRect, EditorKit.defaultBackgroundColor);
				EditorKit.RecordAndSetGUIContentColor(EditorKit.defaultContentColor);
                if (GUI.Button(refreshRect, EditorAssets.refreshTexture, GUIStyle.none))
				{
					UpdateMaterial();
					_shader = null;
					UpdateShader();
				}
				EditorKit.RestoreGUIContentColor();
            }

			rect.y = rect.yMax + _lineInterval;

			if (_shader && _propertyCount > 0)
			{
				// 属性列表

				if (_propertyIndexInMenu == -2)
				{
					_propertyIndexInMenu = Array.FindIndex(_propertyNames, value => value == _propertyName);
                }

				EditorGUI.BeginChangeCheck();
				_propertyIndexInMenu = EditorGUI.Popup(rect, "Property", _propertyIndexInMenu, _propertyDescriptions);
				if (EditorGUI.EndChangeCheck())
				{
					Undo.RecordObject(target, "Property");
					propertyName = _propertyNames[_propertyIndexInMenu];
					EditorUtility.SetDirty(target);
				}
			}
			else EditorGUI.LabelField(rect, "- No available property.");

			// 同步 Undo Redo 时的数据
			if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
			{
				_material = null;
				_propertyID = -1;
				_propertyIndexInMenu = -2;
			}
		}
Exemple #3
0
        protected sealed override void Editor_OnInspectorGUI()
        {
            // Edit Button

            _rect       = EditorGUILayout.GetControlRect(true, _editButtonHeight);
            _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 Path", middleLeftLabel);

            // Circular

            editor.DrawToggleLayout(circular, value => circular = value, "Circular");

            // World Scale

            EditorGUI.BeginChangeCheck();
            float scale = EditorGUILayout.FloatField(_worldScaleContent, worldScale);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this, editor.undoString);
                worldScale = scale;
                EditorUtility.SetDirty(this);
            }

            // Length Error

            editor.DrawFloatFieldLayout(lengthError, value => lengthError = value, "Length Error");

            // Length

            if (isSamplesValid)
            {
                EditorGUILayout.FloatField("Length", length);
            }
            else
            {
                _rect = EditorGUILayout.GetControlRect();
                EditorGUI.LabelField(_rect, "Length");
                _rect.xMin += EditorGUIUtility.labelWidth;

                // Calculate Button

                if (GUI.Button(_rect, "Calculate", EditorStyles.miniButton))
                {
                    Undo.RecordObject(this, editor.undoString);
                    ValidateSamples();
                    EditorUtility.SetDirty(this);
                }
            }

            // Always Visible Button
            _alwaysVisible = EditorKit.IndentedToggle("Always Visible", _alwaysVisible);
        }
Exemple #4
0
        void DrawSerializeFields(Type modelType)
        {
            var beforeSerializedValues = new Dictionary <string, ModelObjectBinder.SerializedBinder>();

            for (var i = 0; i < _bindersProperty.arraySize; i++)
            {
                var element = _bindersProperty.GetArrayElementAtIndex(i);
                var value   = new ModelObjectBinder.SerializedBinder()
                {
                    FieldName      = element.FindPropertyRelative("FieldName").stringValue,
                    ManualInput    = element.FindPropertyRelative("ManualInput").boolValue,
                    TokenType      = (MTokenType)element.FindPropertyRelative("TokenType").intValue,
                    BinderInstance = element.FindPropertyRelative("BinderInstance").objectReferenceValue
                };
                if (!string.IsNullOrEmpty(value.FieldName))
                {
                    beforeSerializedValues.Add(value.FieldName, value);
                }
            }

            var afterSerializedValues = new List <ModelObjectBinder.SerializedBinder>();
            //var afterSerializedValues = new Dictionary<string, UnityEngine.Object>();
            var toSerializeMembers = BinderUtil.GetRequireBinderInfoFromModelMembers(modelType);

            foreach (var member in toSerializeMembers)
            {
                var fieldName = member.Key;
                ModelObjectBinder.SerializedBinder binderInfo;
                if (!beforeSerializedValues.TryGetValue(fieldName, out binderInfo))
                {
                    binderInfo = new ModelObjectBinder.SerializedBinder()
                    {
                        FieldName   = fieldName,
                        ManualInput = false,
                        TokenType   = member.Value.BinderInfo.TokenType
                    };
                }

                if (member.Value.BinderInfo.TokenType == MTokenType.Dynamic)
                {
                    EditorGUILayout.LabelField(fieldName, member.Value.BinderInfo.ValueTypeName + "is not supported. Use float instead.");
                }
                else
                {
                    binderInfo.BinderInstance = EditorKit.DrawBinderField(
                        fieldName, member.Value.BinderInfo.ValueTypeName, binderInfo.BinderInstance, member.Value.BinderInfo.InterfaceType);
                }
                afterSerializedValues.Add(binderInfo);
            }

            for (var i = beforeSerializedValues.Count - 1; i >= afterSerializedValues.Count; i--)
            {
                _bindersProperty.DeleteArrayElementAtIndex(i);
            }

            for (var i = 0; i < afterSerializedValues.Count; i++)
            {
                if (i >= _bindersProperty.arraySize)
                {
                    _bindersProperty.InsertArrayElementAtIndex(i);
                }
                var data    = afterSerializedValues[i];
                var element = _bindersProperty.GetArrayElementAtIndex(i);
                element.FindPropertyRelative("FieldName").stringValue = data.FieldName;
                element.FindPropertyRelative("ManualInput").boolValue = data.ManualInput;
                element.FindPropertyRelative("TokenType").intValue    = (int)data.TokenType;
                element.FindPropertyRelative("BinderInstance").objectReferenceValue = data.BinderInstance;
            }
        }
Exemple #5
0
 /// <summary>
 /// Sets the currently installed kit for handling
 /// content.
 /// </summary>
 public void setEditorKit(EditorKit @kit)
 {
 }
Exemple #6
0
 /// <summary>
 /// Directly sets the editor kit to use for the given type.
 /// </summary>
 public void setEditorKitForContentType(string @type, EditorKit @k)
 {
 }
Exemple #7
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);
                    }
                }
            }
Exemple #8
0
        public override void OnInspectorGUI()
        {
            var specifyEnumTypeProp = serializedObject.FindProperty("_specifyEnumType");

            EditorGUILayout.PropertyField(specifyEnumTypeProp);

            Type enumType = null;

            if (specifyEnumTypeProp.boolValue)
            {
                var enumTypeStringProperty = serializedObject.FindProperty("_enumTypeString");
                var allEnumTypes           = TypeUtil.GetAllTypes(t => t.IsEnum && t.GetCustomAttributes(typeof(MvpModelAttribute), true).Length != 0)
                                             .Select(t => new EditorKit.SerializedType(t))
                                             .OrderBy(t => t.TypeString)
                                             .ToList();

                if (allEnumTypes.Count == 0)
                {
                    EditorGUILayout.HelpBox("No enum implement MvpModelAttribute", MessageType.Info);
                }
                else
                {
                    var type = EditorKit.DrawTypeSelector("Select Enum Type", enumTypeStringProperty.stringValue, allEnumTypes);
                    if (type != null)
                    {
                        enumTypeStringProperty.stringValue = type.Value.TypeString;
                        enumType = type.Value.Type;
                    }
                }
            }

            var settingsListProperty = serializedObject.FindProperty("_eventSettings");

            if (EditorGUILayout.PropertyField(settingsListProperty, false))
            {
                EditorGUI.indentLevel++;

                var size = EditorGUILayout.DelayedIntField("Size", settingsListProperty.arraySize);
                while (settingsListProperty.arraySize > size)
                {
                    settingsListProperty.DeleteArrayElementAtIndex(size);
                }

                for (var i = 0; i < size; i++)
                {
                    if (i >= settingsListProperty.arraySize)
                    {
                        settingsListProperty.InsertArrayElementAtIndex(i);
                    }

                    var elementProp = settingsListProperty.GetArrayElementAtIndex(i);

                    var valueProp = elementProp.FindPropertyRelative("Value");
                    var eventPorp = elementProp.FindPropertyRelative("Event");

                    if (enumType == null)
                    {
                        valueProp.intValue = EditorGUILayout.IntField("Element " + i, valueProp.intValue);
                    }
                    else
                    {
                        var enumNames  = Enum.GetNames(enumType);
                        var enumValues = (int[])Enum.GetValues(enumType);
                        var index      = enumValues.ToList().FindIndex(t => t == valueProp.intValue);
                        index = EditorGUILayout.Popup("Element " + i, index, enumNames);
                        valueProp.intValue = enumValues[index];
                    }

                    EditorGUI.indentLevel++;
                    var rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 5);
                    rect.x += 15;
                    EditorGUI.PropertyField(rect, eventPorp);
                    EditorGUI.indentLevel--;
                }

                EditorGUI.indentLevel--;
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemple #9
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();
        }
        //int _selectedPageIndex;
        public override void OnInspectorGUI()
        {
            //_selectedPageIndex = GUILayout.Toolbar(_selectedPageIndex, new string[] { "Settings", "Events" }, EditorStyles.miniButton);
            //EditorGUILayout.Space();
            //Rect rect = EditorGUILayout.GetControlRect(false, 1f);
            //EditorGUI.DrawRect(rect, EditorStyles.label.normal.textColor * 0.5f);
            //EditorGUILayout.Space();

            //if (_selectedPageIndex == 1)
            //{
            //	EditorGUILayout.PropertyField(serializedObject.FindProperty("_beforeReceiveEvent"));
            //	EditorGUILayout.PropertyField(serializedObject.FindProperty("_afterReceiveEvent"));
            //}
            //else
            {
                var typeProperty = serializedObject.FindProperty("_dataType");
                EditorGUILayout.PropertyField(typeProperty);

                Type binderInterfaceType = null;
                var  arrayElementType    = (ArrayElementTypeEnum)typeProperty.enumValueIndex;

                switch (arrayElementType)
                {
                case ArrayElementTypeEnum.Bool:
                    binderInterfaceType = typeof(IMvpBoolBinder);
                    break;

                case ArrayElementTypeEnum.String:
                    binderInterfaceType = typeof(IMvpStringBinder);
                    break;

                case ArrayElementTypeEnum.Float:
                    binderInterfaceType = typeof(IMvpFloatBinder);
                    break;

                case ArrayElementTypeEnum.Object:
                    binderInterfaceType = typeof(IMvpObjectBinder);
                    break;

                case ArrayElementTypeEnum.Custom:
                {
                    var customElementTypeStringProp = serializedObject.FindProperty("_customElementTypeString");
                    if (_allBinderValueTypes.Count == 0)
                    {
                        EditorGUILayout.HelpBox("No custom type binder implemented.", MessageType.Warning);
                    }
                    else
                    {
                        var returnType = EditorKit.DrawTypeSelector("Custom Element Type", customElementTypeStringProp.stringValue, _allBinderValueTypes);
                        if (returnType != null)
                        {
                            customElementTypeStringProp.stringValue = returnType.Value.TypeString;
                            binderInterfaceType = typeof(IMvpCustomTypeBinder <>).MakeGenericType(returnType.Value.Type);
                        }
                    }
                }
                break;
                }
                if (binderInterfaceType != null)
                {
                    var mainBinderProperty    = serializedObject.FindProperty("_mainBinder");
                    var extendBindersProperty = serializedObject.FindProperty("_extendBinders");

                    //EditorGUILayout.BeginHorizontal();
                    //EditorGUILayout.PrefixLabel("Array Element Template");
                    mainBinderProperty.objectReferenceValue = EditorKit.DrawBinderField("Main Binder", mainBinderProperty.objectReferenceValue, binderInterfaceType);

                    if (EditorGUILayout.PropertyField(extendBindersProperty, false))
                    {
                        EditorGUI.indentLevel++;

                        var size = EditorGUILayout.DelayedIntField("Size", extendBindersProperty.arraySize);
                        while (extendBindersProperty.arraySize > size)
                        {
                            extendBindersProperty.DeleteArrayElementAtIndex(size);
                        }

                        for (var i = 0; i < size; i++)
                        {
                            if (i >= extendBindersProperty.arraySize)
                            {
                                extendBindersProperty.InsertArrayElementAtIndex(i);
                            }

                            var elementProp = extendBindersProperty.GetArrayElementAtIndex(i);
                            elementProp.objectReferenceValue = EditorKit.DrawBinderField("Element " + i, elementProp.objectReferenceValue, binderInterfaceType);
                        }

                        EditorGUI.indentLevel--;
                    }

                    //EditorGUILayout.PropertyField(extendBindersProperty, true);
                    //for(var i = 0; i < extendBindersProperty.arraySize; i++)
                    //{
                    //	var exbp = extendBindersProperty.GetArrayElementAtIndex(i);

                    //}

                    //EditorGUILayout.EndHorizontal();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemple #11
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.Node:
                {
                    worldPoint = GetNodePosition(_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);
                    }
                }
            }
        }
Exemple #12
0
        // 绘制选中中控制点时的控件
        void DrawNodeUI(Rect rect)
        {
            // Position

            _lineRect.Set(rect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarLineHeight) * 0.5f, _positionWidth, _toolBarLineHeight);

            EditorGUI.BeginChangeCheck();
            _node = EditorGUI.Vector3Field(_lineRect, GUIContent.none, GetNodePosition(_selectedItem, Space.Self));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this, undoNode);
                SetNodePosition(_selectedItem, _node, Space.Self);
                EditorUtility.SetDirty(this);
            }

            // Insert Back

            rect.Set(_lineRect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarButtonHeight) * 0.5f, _toolBarButtonWidth, _toolBarButtonHeight);

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.insertNodeBackTexture, "Insert Back"), EditorKit.buttonLeftStyle))
            {
                Undo.RecordObject(this, "Insert Node");
                InsertNode(_selectedItem);
                EditorUtility.SetDirty(this);

                return;
            }

            // Insert Forward

            rect.x = rect.xMax;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.insertNodeForwardTexture, "Insert Forward"), EditorKit.buttonRightStyle))
            {
                Undo.RecordObject(this, "Insert Node");
                InsertNode(_selectedItem += 1);
                EditorUtility.SetDirty(this);

                return;
            }

            // Remove Node

            rect.x = rect.xMax + _toolBarHorizontalInterval;

            EditorGUI.BeginDisabledGroup(nodeCount <= 2);

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.removeNodeTexture, "Remove node"), EditorKit.buttonStyle))
            {
                Undo.RecordObject(this, "Remove Node");
                RemoveNode(_selectedItem);
                EditorUtility.SetDirty(this);

                return;
            }

            EditorGUI.EndDisabledGroup();

            // 前一个

            rect.x = rect.xMax + _toolBarHorizontalInterval;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.prevTexture, "Previous node"), EditorKit.buttonLeftStyle))
            {
                _selectedItem = (_selectedItem == 0) ? (nodeCount - 1) : (_selectedItem - 1);
            }

            // 后一个

            rect.x = rect.xMax;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.nextTexture, "Next node"), EditorKit.buttonRightStyle))
            {
                _selectedItem = (_selectedItem == nodeCount - 1) ? 0 : (_selectedItem + 1);
            }
        }
Exemple #13
0
        public override void OnInspectorGUI()
        {
            _selectedPageIndex = GUILayout.Toolbar(_selectedPageIndex, new string[] { "Settings", "Events" }, EditorStyles.miniButton);
            EditorGUILayout.Space();
            Rect rect = EditorGUILayout.GetControlRect(false, 1f);

            EditorGUI.DrawRect(rect, EditorStyles.label.normal.textColor * 0.5f);
            EditorGUILayout.Space();

            if (_selectedPageIndex == 1)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("_beforeReceiveEvent"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("_afterReceiveEvent"));
            }
            else
            {
                var typeProperty = serializedObject.FindProperty("_elementType");
                EditorGUILayout.PropertyField(typeProperty);

                var templateProperty = serializedObject.FindProperty("_elementBinder");

                Type templateInterfaceType = null;
                var  arrayElementType      = (ArrayElementTypeEnum)typeProperty.enumValueIndex;

                switch (arrayElementType)
                {
                case ArrayElementTypeEnum.Bool:
                    templateInterfaceType = typeof(IMvpBoolBinder);
                    break;

                case ArrayElementTypeEnum.String:
                    templateInterfaceType = typeof(IMvpStringBinder);
                    break;

                case ArrayElementTypeEnum.Float:
                    templateInterfaceType = typeof(IMvpFloatBinder);
                    break;

                case ArrayElementTypeEnum.Object:
                    templateInterfaceType = typeof(IMvpObjectBinder);
                    break;

                case ArrayElementTypeEnum.Custom:
                {
                    var customElementTypeStringProp = serializedObject.FindProperty("_customElementTypeString");
                    if (_allBinderValueTypes.Count == 0)
                    {
                        EditorGUILayout.HelpBox("No custom type binder implemented.", MessageType.Warning);
                    }
                    else
                    {
                        var returnType = EditorKit.DrawTypeSelector("Custom Element Type", customElementTypeStringProp.stringValue, _allBinderValueTypes);
                        if (returnType != null)
                        {
                            customElementTypeStringProp.stringValue = returnType.Value.TypeString;
                            templateInterfaceType = typeof(IMvpCustomTypeBinder <>).MakeGenericType(returnType.Value.Type);
                        }
                    }
                }
                break;
                }
                if (templateInterfaceType != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Element Binder");
                    templateProperty.objectReferenceValue = EditorKit.DrawBinderField("", templateProperty.objectReferenceValue, templateInterfaceType);
                    EditorGUILayout.EndHorizontal();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemple #14
0
        // 绘制顶部工具条内容
        protected override void DrawToolBar(Rect rect)
        {
            ValidateSelectedItem();
            EditorKit.RecordAndSetGUIContentColor(EditorKit.defaultContentColor);

            // 主工具栏
            rect.Set(rect.x + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarBigButtonHeight) * 0.5f, _toolBarBigButtonWidth * 4f, _toolBarBigButtonHeight);
            _selectedTool = GUI.Toolbar(rect, _selectedTool, toolBarContent);

            // 重置选择
            switch (_selectedTool)
            {
            case 0:
            {
                if (_selectionType != SelectionType.Spline)
                {
                    _selectionType = SelectionType.None;
                    _selectedItem  = -1;
                }
                break;
            }

            case 1:
            case 2:
            case 3:
            {
                if (_selectionType == SelectionType.Spline)
                {
                    _selectionType = SelectionType.None;
                    _selectedItem  = -1;
                }
                break;
            }
            }

            // 绘制其他控件
            switch (_selectionType)
            {
            case SelectionType.Spline:
            {
                DrawSplineUI(rect);
                break;
            }

            case SelectionType.MiddleControlPoint:
            {
                DrawMiddleControlPointUI(rect);
                break;
            }

            case SelectionType.ForwardControlPoint:
            {
                DrawForwardControlPointUI(rect);
                break;
            }

            case SelectionType.BackControlPoint:
            {
                DrawBackControlPointUI(rect);
                break;
            }
            }

            EditorKit.RestoreGUIContentColor();
        }
Exemple #15
0
        // 绘制 Node 控件
        void DrawNodeControls(bool edit)
        {
            _count = nodeCount;

            for (int i = 0; i < _count; i++)
            {
                // 获取控制点位置
                _back    = GetBackControlPoint(i);
                _forward = GetForwardControlPoint(i);
                _middle  = GetMiddleControlPoint(i);

                // 绘制切线
                Handles.color = _controlLineColor;
                EditorKit.HandlesDrawAALine(_back, _middle);
                EditorKit.HandlesDrawAALine(_forward, _middle);

                // 绘制后控制点

                EditorGUI.BeginChangeCheck();
                EditorKit.BeginHotControlChangeCheck();

                if (_selectionType == SelectionType.BackControlPoint && _selectedItem == i)
                {
                    Handles.color = _capSelectedColor;
                }
                else
                {
                    Handles.color = _capNormalColor;
                }

                _handleSize = HandleUtility.GetHandleSize(_back) * _controlPointCapSize;
                _back       = Handles.FreeMoveHandle(_back, _identityQuaternion, _handleSize, _zeroVector3, Handles.DotCap);

                // 更新选择
                if (EditorKit.EndHotControlChangeCheck() == HotControlEvent.MouseDown)
                {
                    _selectionType = SelectionType.BackControlPoint;
                    _selectedItem  = i;
                }

                // 修改后控制点
                if (EditorGUI.EndChangeCheck() && edit)
                {
                    Undo.RecordObject(this, undoBackControlPoint);
                    SetBackControlPoint(i, _back);
                    EditorUtility.SetDirty(this);
                }

                // 绘制中控制点

                EditorGUI.BeginChangeCheck();
                EditorKit.BeginHotControlChangeCheck();

                if (_selectionType == SelectionType.MiddleControlPoint && _selectedItem == i)
                {
                    Handles.color = _capSelectedColor;
                }
                else
                {
                    Handles.color = _capNormalColor;
                }

                _handleSize = HandleUtility.GetHandleSize(_middle) * _controlPointCapSize;
                _middle     = Handles.FreeMoveHandle(_middle, _identityQuaternion, _handleSize, _zeroVector3, Handles.DotCap);

                // 更新选择
                if (EditorKit.EndHotControlChangeCheck() == HotControlEvent.MouseDown)
                {
                    _selectionType = SelectionType.MiddleControlPoint;
                    _selectedItem  = i;
                }

                // 修改中控制点
                if (EditorGUI.EndChangeCheck() && edit)
                {
                    Undo.RecordObject(this, undoMiddleControlPoint);
                    SetMiddleControlPoint(i, _middle);
                    EditorUtility.SetDirty(this);
                }

                // 绘制前控制点

                EditorGUI.BeginChangeCheck();
                EditorKit.BeginHotControlChangeCheck();

                if (_selectionType == SelectionType.ForwardControlPoint && _selectedItem == i)
                {
                    Handles.color = _capSelectedColor;
                }
                else
                {
                    Handles.color = _capNormalColor;
                }

                _handleSize = HandleUtility.GetHandleSize(_forward) * _controlPointCapSize;
                _forward    = Handles.FreeMoveHandle(_forward, _identityQuaternion, _handleSize, _zeroVector3, Handles.DotCap);

                // 更新选择
                if (EditorKit.EndHotControlChangeCheck() == HotControlEvent.MouseDown)
                {
                    _selectionType = SelectionType.ForwardControlPoint;
                    _selectedItem  = i;
                }

                // 修改前控制点
                if (EditorGUI.EndChangeCheck() && edit)
                {
                    Undo.RecordObject(this, undoForwardControlPoint);
                    SetForwardControlPoint(i, _forward);
                    EditorUtility.SetDirty(this);
                }
            }
        }