Пример #1
0
            public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref Entity value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, Entity>
            {
                if (s_EntityStyle == null)
                {
                    s_EntityStyle = new GUIStyle(EditorStyles.label)
                    {
                        normal =
                        {
                            textColor = new Color(0.5f, 0.5f, 0.5f)
                        },
                        onHover =
                        {
                            textColor = new Color(0.0f, 0.7f, 0.7f)
                        }
                    };
                }

                GUI.enabled = true;

                var pos = EditorGUILayout.GetControlRect();

                EditorGUI.LabelField(pos, $"{property.GetName()} Index: {value.Index}, Version: {value.Version}", s_EntityStyle);

                if (Event.current.type == EventType.MouseDown && pos.Contains(Event.current.mousePosition))
                {
                    if (Event.current.clickCount == 2)
                    {
                        Event.current.Use();
                        m_Callback?.Invoke(value);
                    }
                }

                GUI.enabled = false;
                return(VisitStatus.Handled);
            }
Пример #2
0
        private void RenderEntityView <TValue>(VisitContext <TValue> context)
            where TValue : IPropertyContainer
        {
            if (m_EntityStyle == null)
            {
                m_EntityStyle = new GUIStyle(EditorStyles.label);
                m_EntityStyle.normal.textColor  = new Color(0.2f, 0.2f, 0.2f);
                m_EntityStyle.onHover.textColor = new Color(0.0f, 0.7f, 0.7f);
            }

            // @TODO register a TypeConverter

            string index = string.Empty;
            var    f     = context.Value?.PropertyBag?.FindProperty(s_EntityIdFieldName);

            if (f != null)
            {
                index = (f as IValueProperty).GetObjectValue(context.Value).ToString();
            }

            string version = string.Empty;

            f = context.Value?.PropertyBag?.FindProperty(s_EntityVersionFieldName);
            if (f != null)
            {
                version = (f as IValueProperty).GetObjectValue(context.Value).ToString();
            }

            {
                GUI.enabled = true;

                Rect pos = EditorGUILayout.GetControlRect();
                EditorGUI.LabelField(
                    pos,
                    string.Format("Entity - Index: {0}, Version: {1}", index, version),
                    m_EntityStyle);

                if (Event.current.type == EventType.MouseDown && pos.Contains(Event.current.mousePosition))
                {
                    if (Event.current.clickCount == 2)
                    {
                        Event.current.Use();
                        m_entityDoubleClickCallback?.Invoke(
                            new Entity {
                            Index = int.Parse(index), Version = int.Parse(version)
                        });
                    }
                }

                GUI.enabled = false;
            }
        }
            public VisitStatus Visit<TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref Entity value, ref ChangeTracker changeTracker) where TProperty : IProperty<TContainer, Entity>
            {
                InitStyles();

                GUI.enabled = true;

                var pos = EditorGUILayout.GetControlRect();

                EditorGUI.LabelField(pos, $"{property.GetName()} Index: {value.Index}, Version: {value.Version}", Styles.EntityStyle);

                if (Event.current.type == EventType.MouseDown && pos.Contains(Event.current.mousePosition))
                {
                    if (Event.current.clickCount == 2)
                    {
                        Event.current.Use();
                        m_Callback?.Invoke(value);
                    }
                }

                GUI.enabled = false;
                return VisitStatus.Handled;
            }