Example #1
0
        private static void DrawStoreConstraint(Rect rect, ref VariableConstraint constraint)
        {
            if (!(constraint is StoreVariableConstraint storeConstraint))
            {
                storeConstraint = new StoreVariableConstraint {
                    Schema = null
                };
                constraint = storeConstraint;
            }

            storeConstraint.Schema = AssetDisplayDrawer.Draw(rect, GUIContent.none, storeConstraint.Schema, false, false, AssetLocation.None, null);
        }
Example #2
0
        public static float GetStoreHeight(VariableValue value, StoreVariableConstraint constraint, bool drawStores)
        {
            var height = EditorGUIUtility.singleLineHeight;

            if (drawStores)
            {
                var index = 0;
                var names = value.Store.GetVariableNames();

                foreach (var name in names)
                {
                    var variable       = value.Store.GetVariable(name);
                    var itemDefinition = constraint?.Schema != null ? constraint.Schema[index].Definition : ValueDefinition.Create(VariableType.Empty);

                    height += RectHelper.VerticalSpace;
                    height += GetHeight(variable, itemDefinition, true);
                    index++;
                }
            }

            return(height);
        }
Example #3
0
        private static VariableValue DrawStore(Rect rect, VariableValue value, StoreVariableConstraint constraint, bool drawStores)
        {
            if (drawStores)
            {
                var names  = value.Store.GetVariableNames();
                var remove = string.Empty;
                var first  = true;
                var empty  = ValueDefinition.Create(VariableType.Empty);

                foreach (var name in names)
                {
                    if (!first)
                    {
                        RectHelper.TakeVerticalSpace(ref rect);
                    }

                    var index = constraint?.Schema != null?constraint.Schema.GetIndex(name) : -1;

                    var definition = index >= 0 ? constraint.Schema[index].Definition : empty;

                    var item      = value.Store.GetVariable(name);
                    var height    = GetHeight(item, definition, true);
                    var itemRect  = RectHelper.TakeHeight(ref rect, height);
                    var labelRect = RectHelper.TakeWidth(ref itemRect, _storeLabelWidth);
                    labelRect = RectHelper.TakeLine(ref labelRect);

                    EditorGUI.LabelField(labelRect, name);

                    if (constraint?.Schema == null && value.Store is VariableStore)
                    {
                        var removeRect = RectHelper.TakeTrailingIcon(ref itemRect);

                        if (GUI.Button(removeRect, _removeStoreButton.Content, GUIStyle.none))
                        {
                            remove = name;
                        }
                    }

                    item = Draw(itemRect, GUIContent.none, item, definition, true);
                    value.Store.SetVariable(name, item);

                    first = false;
                }

                if (constraint?.Schema == null && value.Store is VariableStore store)
                {
                    var addRect = RectHelper.TakeTrailingIcon(ref rect);

                    if (GUI.Button(addRect, _addStoreButton.Content, GUIStyle.none))
                    {
                        AddToStorePopup.Store = store;
                        AddToStorePopup.Name  = "";
                        PopupWindow.Show(addRect, AddToStorePopup.Instance);
                    }

                    if (!string.IsNullOrEmpty(remove))
                    {
                        (value.Store as VariableStore).RemoveVariable(remove);
                    }
                }
            }
            else
            {
                EditorGUI.LabelField(rect, value.Store.ToString());
            }

            return(value);
        }