Example #1
0
 public void SetEditorPrefs <T>(string key, T value)
 {
     DT.SetEditorPrefs <T>(Identifier + "." + key, value);
 }
Example #2
0
 public T GetEditorPrefs <T>(string key, T defaultValue)
 {
     return(DT.GetEditorPrefs <T>(Identifier + "." + key, defaultValue));
 }
Example #3
0
        public static void DoGUI(Rect position, SerializedProperty property, DTPropertyAttribute attribute, GUIContent label, AttributeOptionsFlags flags, VectorExPropertyDrawer drawer = null)
        {
            if (property.propertyType != SerializedPropertyType.Vector2 && property.propertyType != SerializedPropertyType.Vector3 && property.propertyType != SerializedPropertyType.Quaternion)
            {
                Debug.LogError("DevTools: [VectorEx] only valid for Vector and Quaternion fields!");
            }
            else
            {
                Rect posb = position.WithoutLabel();
                posb.height = EditorGUIUtility.singleLineHeight;

                int buttons = 0;
                if (flags.HasFlag(AttributeOptionsFlags.Clipboard))
                {
                    buttons += 2;
                }
                if (flags.HasFlag(AttributeOptionsFlags.One))
                {
                    buttons++;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Zero))
                {
                    buttons++;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Negate))
                {
                    buttons++;
                }

                Rect r = position.WithoutLabel();
                r.width -= buttons * 20;

                if (flags.HasFlag(AttributeOptionsFlags.Compact) || EditorGUIUtility.wideMode)
                {
                    if (drawer != null)
                    {
                        drawer.PushCustomColors();
                    }
                    EditorGUI.PrefixLabel(position, label);

                    if (property.propertyType == SerializedPropertyType.Vector2)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector2 v = DTGUI.CompactVector2Field(r, property.vector2Value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            property.vector2Value = DT._UseSnapValuePrecision ? DTMath.SnapPrecision(v, attribute.Precision) : v;
                        }
                    }
                    else if (property.propertyType == SerializedPropertyType.Vector3)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 v = DTGUI.CompactVector3Field(r, property.vector3Value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            property.vector3Value = DT._UseSnapValuePrecision ? DTMath.SnapPrecision(v, attribute.Precision) : v;
                        }
                    }
                    else if (property.propertyType == SerializedPropertyType.Quaternion)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 v = DTGUI.CompactVector3Field(r, DT._UseSnapValuePrecision ? DTMath.SnapPrecision(property.quaternionValue.eulerAngles, attribute.Precision) : property.quaternionValue.eulerAngles);
                        if (EditorGUI.EndChangeCheck())
                        {
                            property.quaternionValue = Quaternion.Euler(v);
                        }
                    }
                    if (drawer != null)
                    {
                        drawer.PopCustomColors();
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    if (drawer != null)
                    {
                        drawer.PushCustomColors();
                    }
                    EditorGUI.PropertyField(position, property, label);
                    if (drawer != null)
                    {
                        drawer.PopCustomColors();
                    }
                    if (EditorGUI.EndChangeCheck() && DT._UseSnapValuePrecision)
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = DTMath.SnapPrecision(property.vector2Value, attribute.Precision);
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = DTMath.SnapPrecision(property.vector3Value, attribute.Precision);
                        }
                    }
                }

                // Buttons
                posb       = posb.ShiftXBy(r.width);
                posb.width = 19;
                if (flags.HasFlag(AttributeOptionsFlags.Clipboard))
                {
                    if (GUI.Button(posb, new GUIContent("C", "Copy"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            DT.ClipboardCopy(property.vector2Value);
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            DT.ClipboardCopy(property.vector3Value);
                        }
                    }
                    posb.x += 20;
                    // Can Paste?
                    if (property.propertyType == SerializedPropertyType.Vector2)
                    {
                        GUI.enabled = DT.ClipboardCanPasteTo <Vector2>();
                    }
                    else if (property.propertyType == SerializedPropertyType.Vector3)
                    {
                        GUI.enabled = DT.ClipboardCanPasteTo <Vector3>();
                    }

                    if (GUI.Button(posb, new GUIContent("P", "Pastge"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = DT.ClipboardPaste <Vector2>();
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = DT.ClipboardPaste <Vector3>();
                        }
                    }
                    GUI.enabled = true;
                    posb.x     += 20;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Zero))
                {
                    if (GUI.Button(posb, new GUIContent("0", "Set to zero"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = Vector2.zero;
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = Vector3.zero;
                        }
                    }
                    posb.x += 20;
                }
                if (flags.HasFlag(AttributeOptionsFlags.One))
                {
                    if (GUI.Button(posb, new GUIContent("1", "Set to one"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = Vector2.one;
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = Vector3.one;
                        }
                    }
                    posb.x += 20;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Negate))
                {
                    if (GUI.Button(posb, new GUIContent("~", "Negate"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value *= -1;
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value *= -1;
                        }
                    }
                    posb.x += 20;
                }
            }
        }