示例#1
0
        private void DrawText(UTinyObject tinyObject)
        {
            var textProperty = tinyObject.Properties.PropertyBag.FindProperty("text") as IProperty <UTinyObject.PropertiesContainer, string>;

            EditorGUI.BeginChangeCheck();
            var mixed = EditorGUI.showMixedValue;

            EditorGUI.showMixedValue = HasMixedValues <string>(tinyObject.Properties, textProperty);
            var isOverriden = (textProperty as IUTinyValueProperty)?.IsOverridden(tinyObject.Properties) ?? true;

            UTinyEditorUtility.SetEditorBoldDefault(isOverriden);
            try
            {
                var container = tinyObject.Properties;
                var newText   = EditorGUILayout.TextField(textProperty.Name, textProperty.GetValue(container));

                if (EditorGUI.EndChangeCheck())
                {
                    textProperty.SetValue(container, newText);
                    PushChange(container, textProperty);
                }
            }
            finally
            {
                UTinyEditorUtility.SetEditorBoldDefault(false);
                EditorGUI.showMixedValue = mixed;
            }
        }
        private void DrawCullingMask(UTinyObject tinyObject)
        {
            var cullingMask = tinyObject.Properties.PropertyBag.FindProperty("layerMask") as IProperty <UTinyObject.PropertiesContainer, int>;

            EditorGUI.BeginChangeCheck();
            var mixed = EditorGUI.showMixedValue;

            EditorGUI.showMixedValue = HasMixedValues <int>(tinyObject.Properties, cullingMask);
            var isOverriden = (cullingMask as IUTinyValueProperty)?.IsOverridden(tinyObject.Properties) ?? true;

            UTinyEditorUtility.SetEditorBoldDefault(isOverriden);
            try
            {
                var container  = tinyObject.Properties;
                var layerNames = GetLayerNames();
                var newLayer   = EditorGUILayout.MaskField("cullingMask", GetCurrentEditorLayer(layerNames, cullingMask.GetValue(container)), layerNames.ToArray());
                if (EditorGUI.EndChangeCheck())
                {
                    cullingMask.SetValue(container, GetLayers(layerNames, newLayer));
                    PushChange(container, cullingMask);
                }
            }
            finally
            {
                UTinyEditorUtility.SetEditorBoldDefault(false);
                EditorGUI.showMixedValue = mixed;
            }
        }
        protected bool DoField <TContainer, TValue>(ref TContainer container, ref VisitContext <TValue> context,
                                                    Func <GUIContent, TValue, TValue> onGUI)
            where TContainer : IPropertyContainer
        {
            var property = context.Property;

            // Well, we must be in a list.
            if (context.Index >= 0 && null != CurrentListProperty)
            {
                var label = ConstructLabel(CurrentListProperty);
                label.text = context.Index.ToString();

                EditorGUILayout.BeginHorizontal();
                context.Value = onGUI(label, context.Value);
                if (GUILayout.Button("x", GUILayout.Width(16.0f), GUILayout.Height(16.0f)))
                {
                    RemoveAtIndex = context.Index;
                }

                EditorGUILayout.EndHorizontal();
                return(true);
            }

            if (property == null || ShouldHide(property))
            {
                return(false);
            }

            PushEnabledState();
            var isReadOnly = IsReadOnly(property);

            GUI.enabled &= !isReadOnly;

            if (HasHeader(property))
            {
                DrawHeader(property);
            }

            var mixed = EditorGUI.showMixedValue;

            var isOverridden = (property as Tiny.IUTinyValueProperty)?.IsOverridden(container) ?? true;

            UTinyEditorUtility.SetEditorBoldDefault(isOverridden);

            try
            {
                EditorGUI.showMixedValue = HasMixedValues <TValue>(container, context.Property);
                context.Value            = onGUI(ConstructLabel(property), context.Value);
            }
            finally
            {
                EditorGUI.showMixedValue = mixed;
                UTinyEditorUtility.SetEditorBoldDefault(false);
            }

            PopEnabledState();
            return(true);
        }
示例#4
0
 private void Draw(UTinyObject.PropertiesContainer container, IProperty<UTinyObject.PropertiesContainer, float> property)
 {
     var isOverridden = (property as IUTinyValueProperty)?.IsOverridden(container) ?? true;
     UTinyEditorUtility.SetEditorBoldDefault(isOverridden);
     var current = property.GetValue(container);
     var value = EditorGUILayout.FloatField(property.Name, current);
     UTinyEditorUtility.SetEditorBoldDefault(false);
     if (value != current)
     {
         property.SetValue(container, value);
         PushChange(container, property);
     }
 }
        public override bool VisitStruct(UTinyObject tinyObject, GUIContent label)
        {
            var value = tinyObject.As <Color>();

            EditorGUI.BeginChangeCheck();

            UTinyEditorUtility.SetEditorBoldDefault(tinyObject.IsOverridden);
            value = EditorGUILayout.ColorField(string.IsNullOrEmpty(label.text) ? GUIContent.none : label, value);
            UTinyEditorUtility.SetEditorBoldDefault(false);
            if (EditorGUI.EndChangeCheck())
            {
                tinyObject.AssignFrom(value);
                foreach (var prop in tinyObject.Properties.PropertyBag.Properties)
                {
                    PushChange(tinyObject.Properties, prop);
                }
            }
            return(true);
        }
        public override bool VisitStruct(UTinyObject tinyObject, GUIContent label)
        {
            var properties = tinyObject.Properties;

            //For the rotation, we will offer Euler angles to the user.
            var tinyEuler = GetEulerAnglesObject(tinyObject);

            tinyEuler.Refresh();

            if (Screen.width < 400)
            {
                EditorGUIUtility.labelWidth = Mathf.Max(EditorGUIUtility.labelWidth - (400 - Screen.width), 70);
            }

            var mixed  = EditorGUI.showMixedValue;
            var indent = EditorGUI.indentLevel;

            UTinyEditorUtility.SetEditorBoldDefault(tinyObject.IsOverridden);
            try
            {
                EditorGUI.showMixedValue =
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("x")) ||
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("y")) ||
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("z")) ||
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("w"));


                EditorGUILayout.BeginHorizontal();
                if (!string.IsNullOrEmpty(label.text))
                {
                    EditorGUILayout.PrefixLabel(label);
                }

                EditorGUIUtility.labelWidth = 15;
                EditorGUIUtility.fieldWidth = 30;
                EditorGUI.indentLevel       = 0;

                EditorGUI.BeginChangeCheck();

                Draw(tinyEuler.Properties, tinyEuler.Properties.PropertyBag.FindProperty("x") as IProperty <UTinyObject.PropertiesContainer, float>);
                Draw(tinyEuler.Properties, tinyEuler.Properties.PropertyBag.FindProperty("y") as IProperty <UTinyObject.PropertiesContainer, float>);
                Draw(tinyEuler.Properties, tinyEuler.Properties.PropertyBag.FindProperty("z") as IProperty <UTinyObject.PropertiesContainer, float>);

                if (EditorGUI.EndChangeCheck())
                {
                    SetQuaternionFromEuler(tinyObject, tinyEuler);
                    PushChange(properties, properties.PropertyBag.FindProperty("x"));
                    PushChange(properties, properties.PropertyBag.FindProperty("y"));
                    PushChange(properties, properties.PropertyBag.FindProperty("z"));
                    PushChange(properties, properties.PropertyBag.FindProperty("w"));
                }
            }
            finally
            {
                UTinyEditorUtility.SetEditorBoldDefault(false);
                EditorGUILayout.EndHorizontal();
                EditorGUI.showMixedValue    = mixed;
                EditorGUI.indentLevel       = indent;
                EditorGUIUtility.fieldWidth = 0;
                EditorGUIUtility.labelWidth = 0;
            }
            return(true);
        }