Exemplo n.º 1
0
        private void Update()
        {
            if (m_DynamicColumn == null)
            {
                m_DynamicColumn = new DynamicValue <int>(columnGetter, m_SerializedProperty, column);
            }
            m_DynamicColumn.Update(m_SerializedProperty);
            if (columnGetter != null)
            {
                column = m_DynamicColumn.GetValue();
            }
            column = Mathf.Max(1, column);

            if (m_DynamicSize == null)
            {
                m_DynamicSize = new DynamicValue <Vector2>(cellSizeGetter, m_SerializedProperty, new Vector2(cellWidth, cellHeight));
            }
            m_DynamicSize.Update(m_SerializedProperty);
            if (cellSizeGetter != null)
            {
                var size = m_DynamicSize.GetValue();
                cellWidth  = size.x;
                cellHeight = size.y;
            }

            if (m_DynamicMaxHeight == null)
            {
                m_DynamicMaxHeight = new DynamicValue <float>(maxHeightGetter, m_SerializedProperty, maxHeight);
            }
            m_DynamicMaxHeight.Update(m_SerializedProperty);
            if (maxHeightGetter != null)
            {
                maxHeight = m_DynamicMaxHeight.GetValue();
            }
        }
Exemplo n.º 2
0
        private Texture GetImage()
        {
            if (m_Image == null)
            {
                m_Image   = new DynamicValue <string>(image, m_SerializedProperty);
                m_Texture = new DynamicValue <UnityEngine.Object>(texture, m_SerializedProperty);
            }
            m_Image.Update(m_SerializedProperty);
            m_Texture.Update(m_SerializedProperty);

            var obj = m_Texture.GetValue();

            if (obj != null && obj is Texture)
            {
                return(obj as Texture);
            }

            var img = m_Image.GetValue();

            if (!string.IsNullOrEmpty(img))
            {
                var tex = GUID ? img.GUIDToImage() : img.GetImage();
                if (tex != null)
                {
                    return(tex);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
 private string GetMessage()
 {
     if (m_DynamicMessage == null)
     {
         m_DynamicMessage = new DynamicValue <string>(m_Message, m_SerializedProperty);
     }
     m_DynamicMessage.Update(m_SerializedProperty);
     return(m_DynamicMessage.GetValue());
 }
 public virtual string GetMessage(SerializedProperty property)
 {
     if (m_DynamicMessage == null)
     {
         m_DynamicMessage = new DynamicValue <string>(m_Message, property);
     }
     m_DynamicMessage.Update(property);
     return(m_DynamicMessage.GetValue());
 }
Exemplo n.º 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            if (property.propertyType != SerializedPropertyType.Enum)
            {
                EditorGUI.LabelField(position, label.text, "Use with Enum.");
                return;
            }

            if (s_Style == null)
            {
                s_Style = new GUIStyle(EditorStyles.popup);
                s_Style.normal.background = null;
            }

            m_DynamicNames.UpdateAndCheckInitial(names, property);

            if (m_Names == null)
            {
                var exclude = this.exclude.Split(',');
                m_Indexs = new List <int>();
                for (int i = 0; i < property.enumNames.Length; i++)
                {
                    if (!exclude.Contains(property.enumNames[i]))
                    {
                        m_Indexs.Add(i);
                    }
                }

                if (names == null)
                {
                    m_Names = property.enumDisplayNames.Except(exclude).ToArray();
                }
                else
                {
                    var array = m_DynamicNames.GetValue();
                    m_Names = array == null?names.Split(',') : array;
                }
            }

            int selected = m_Indexs.IndexOf(property.enumValueIndex);

            label = EditorGUI.BeginProperty(position, label, property);
            var value = EditorGUI.Popup(position, label.text, selected, m_Names);

            if (value < 0 || value >= m_Names.Length)
            {
                if (!property.hasMultipleDifferentValues)
                {
                    EditorGUI.LabelField(position, " ", placeHolder, s_Style);
                }
            }
            else if (value != selected)
            {
                property.enumValueIndex = m_Indexs[value];
            }
            EditorGUI.EndProperty();
        }
Exemplo n.º 6
0
 private void Update()
 {
     if (m_DynamicMaxHeight == null)
     {
         m_DynamicMaxHeight = new DynamicValue <float>(maxHeightGetter, m_SerializedProperty, maxHeight);
     }
     m_DynamicMaxHeight.Update(m_SerializedProperty);
     if (maxHeightGetter != null)
     {
         maxHeight = m_DynamicMaxHeight.GetValue();
     }
 }
 public bool IsVisible()
 {
     if (m_ByPass == null)
     {
         m_ByPass = new DynamicValue <bool>(byPass, m_SerializedProperty);
     }
     m_ByPass.Update(m_SerializedProperty);
     if (!string.IsNullOrEmpty(byPass))
     {
         if (m_ByPass.GetValue())
         {
             return(false);
         }
     }
     return(visible);
 }
Exemplo n.º 8
0
        private void Update()
        {
            if (sizeGetter == null)
            {
                return;
            }
            if (m_DynamicSize == null)
            {
                m_DynamicSize = new DynamicValue <Vector2>(sizeGetter, m_SerializedProperty, new Vector2(width, height));
            }
            m_DynamicSize.Update(m_SerializedProperty);
            var size = m_DynamicSize.GetValue();

            width  = size.x;
            height = size.y;
        }
Exemplo n.º 9
0
        private void HandleEvent(Rect position)
        {
            var id  = GUIUtility.GetControlID(s_HashCode, FocusType.Passive, position);
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (position.Contains(evt.mousePosition) && evt.button == button)
                {
                    GUIUtility.hotControl = id;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && evt.button == button)
                {
                    GUIUtility.hotControl = 0;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id && position.Contains(evt.mousePosition) && evt.button == button)
                {
                    if (autoDrag && m_SerializedProperty.propertyType == SerializedPropertyType.ObjectReference && m_SerializedProperty.objectReferenceValue != null)
                    {
                        DragAndDrop.PrepareStartDrag();
                        DragAndDrop.objectReferences = new[] { m_SerializedProperty.objectReferenceValue };
                        if (EditorUtility.IsPersistent(m_SerializedProperty.objectReferenceValue))
                        {
                            var path = AssetDatabase.GetAssetPath(m_SerializedProperty.objectReferenceValue);
                            DragAndDrop.paths = new[] { path };
                        }
                        DragAndDrop.StartDrag(m_SerializedProperty.displayName);
                    }
                    else
                    {
                        m_DragAction.DoAction();
                    }
                    if (use)
                    {
                        evt.Use();
                    }
                }
                break;

            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (position.Contains(evt.mousePosition) && evt.button == button)
                {
                    if (autoDrop && m_SerializedProperty.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        foreach (var obj in DragAndDrop.objectReferences)
                        {
                            if (m_FieldInfo.FieldType.IsAssignableFrom(obj.GetType()))
                            {
                                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                                if (evt.type == EventType.DragPerform)
                                {
                                    DragAndDrop.AcceptDrag();
                                    m_SerializedProperty.objectReferenceValue = obj;
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (m_DropAccept.GetValue())
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        }
                        if (evt.type == EventType.DragPerform)
                        {
                            DragAndDrop.AcceptDrag();
                            m_DropAction.DoAction();
                        }
                    }
                    if (use)
                    {
                        evt.Use();
                    }
                }
                break;
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            switch (property.propertyType)
            {
            case SerializedPropertyType.Generic:
            case SerializedPropertyType.Enum:
            case SerializedPropertyType.LayerMask:
            case SerializedPropertyType.ArraySize:
            case SerializedPropertyType.Gradient:
#if UNITY_5_6_OR_NEWER
            case SerializedPropertyType.ExposedReference:
#endif
#if UNITY_2017_1_OR_NEWER
            case SerializedPropertyType.FixedBufferSize:
#endif
                EditorGUI.LabelField(position, label.text, "Not supported.");
                return;
            }

            if (s_Style == null)
            {
                s_Style = new GUIStyle(EditorStyles.popup);
                s_Style.normal.background = null;
            }

            if (m_TargetType == null)
            {
                m_TargetType = m_FieldInfo.FieldType;
                if (m_TargetType.IsArrayOrList())
                {
                    m_TargetType = m_TargetType.GetArrayOrListElementType();
                }
                m_TargetType = m_TargetType.MakeArrayType();
            }

            m_DynamicNames.UpdateAndCheckInitial(names, property);
            m_DynamicValues.UpdateAndCheckInitial(m_ValuesGetter, property, m_TargetType);

            if (m_Names == null)
            {
                var values = (Array)m_DynamicValues.GetValue();
                if (values == null)
                {
                    EditorGUI.LabelField(position, label.text, "Getter not correct.");
                    return;
                }

                m_Values = values.Cast <object>().ToArray();
                if (names == null)
                {
                    m_Names = m_Values.Select(v => v.ToString()).ToArray();
                }
                else
                {
                    var array = m_DynamicNames.GetValue();
                    m_Names = array == null?names.Split(',') : array;
                }

                var length = Mathf.Min(m_Names.Length, m_Values.Length);
                m_Names  = m_Names.Take(length).ToArray();
                m_Values = m_Values.Take(length).ToArray();
            }

            if (m_Values == null)
            {
                EditorGUI.LabelField(position, label.text, "Getter not correct.");
                return;
            }

            var propertyValue = property.GetValueAsObject();
            int selected      = Array.IndexOf(m_Values, propertyValue);

            label = EditorGUI.BeginProperty(position, label, property);
            var value = EditorGUI.Popup(position, label.text, selected, m_Names);
            if (value < 0 || value >= m_Names.Length)
            {
                if (!property.hasMultipleDifferentValues)
                {
                    EditorGUI.LabelField(position, " ", placeHolder, s_Style);
                }
            }
            else if (value != selected)
            {
                property.SetObjectToValue(m_Values[value]);
            }
            EditorGUI.EndProperty();
        }
Exemplo n.º 11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
#if !UNITY_5_6_OR_NEWER
            EditorGUI.LabelField(position, label.text, "Use with Unity 5.6 or above.");
            return;
#else
            if (property.propertyType != SerializedPropertyType.Enum)
            {
                EditorGUI.LabelField(position, label.text, "Use with Enum.");
                return;
            }

            m_DynamicNames.UpdateAndCheckInitial(names, property);

            if (m_Names == null)
            {
                var exclude = this.exclude.Split(',');
                var type    = m_FieldInfo.FieldType;
                type     = type.IsArrayOrList() ? type.GetArrayOrListElementType() : type;
                m_Values = Enum.GetNames(type).Except(exclude).Select(n => Convert.ToInt64(Enum.Parse(type, n))).ToList();

                if (names == null)
                {
                    m_Names = Enum.GetNames(type).Except(exclude).ToList();
                }
                else
                {
                    var array = m_DynamicNames.GetValue();
                    m_Names = array == null?names.Split(',').ToList() : array.ToList();
                }

                int index;
                while ((index = m_Values.IndexOf(0)) >= 0)
                {
                    if (names == null)
                    {
                        m_Names.RemoveAt(index);
                    }
                    m_Values.RemoveAt(index);
                }

                var length = Mathf.Min(m_Names.Count, m_Values.Count);
                m_Names  = m_Names.Take(length).ToList();
                m_Values = m_Values.Take(length).ToList();
            }

            long selected = property.longValue;
            long allmask  = 0;
            foreach (var mask in m_Values)
            {
                allmask |= mask;
            }
            var id = GUIUtility.GetControlID(s_HashCode, FocusType.Passive, position);

            label    = EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, label);

            s_Content.tooltip = string.Empty;
            if (selected == 0)
            {
                s_Content.text = placeHolder == string.Empty ? "None" : placeHolder;
            }
            else if (showAll && selected == allmask)
            {
                s_Content.text = "All";
            }
            else
            {
                s_StringBuilder.Length = 0;
                for (int i = 0; i < m_Names.Count; i++)
                {
                    if ((selected & m_Values[i]) == m_Values[i])
                    {
                        if ((!sortCombined && showCombined) || m_Values[i].IsPowerOfTwo())
                        {
                            s_StringBuilder.Append(m_Names[i]).Append(", ");
                        }
                    }
                }
                if (sortCombined)
                {
                    for (int i = 0; i < m_Names.Count; i++)
                    {
                        if ((selected & m_Values[i]) == m_Values[i])
                        {
                            if (showCombined && !m_Values[i].IsPowerOfTwo())
                            {
                                s_StringBuilder.Append(m_Names[i]).Append(", ");
                            }
                        }
                    }
                }
                if (s_StringBuilder.Length > 0)
                {
                    s_StringBuilder.Length -= 2;
                }
                s_Content.text = s_StringBuilder.ToString();
                if (EditorStyles.popup.CalcSize(s_Content).x > position.width)
                {
                    s_Content.tooltip = s_Content.text;
                }
            }

            if (property.hasMultipleDifferentValues)
            {
                selected = 0;
            }
            if (EditorGUI.DropdownButton(position, s_Content, FocusType.Keyboard, EditorStyles.popup))
            {
                MaskPopupList.Popup(position, selected, m_Names, m_Values, sortCombined, id);
            }
            if (MaskPopupList.IsSelectionChanged(id))
            {
                property.longValue = MaskPopupList.GetLastSelectedValue();
            }
            EditorGUI.EndProperty();
#endif
        }