Esempio n. 1
0
        private bool DrawStore(Rect rect, string name, object obj)
        {
            var selected = false;
            var unity    = obj as Object;
            var store    = obj as IVariableStore;

            var viewRect = store != null?RectHelper.TakeTrailingIcon(ref rect) : rect;

            var editRect = unity != null?RectHelper.TakeTrailingIcon(ref rect) : rect;

            GUI.Label(rect, name);

            if (unity != null)
            {
                if (GUI.Button(editRect, VariableStoreControl.EditButton.Content, GUIStyle.none))
                {
                    Selection.activeObject = unity;
                }
            }

            if (store != null)
            {
                if (GUI.Button(rect, VariableStoreControl.ViewButton.Content, GUIStyle.none))
                {
                    selected = true;
                }
            }

            return(selected);
        }
Esempio n. 2
0
        public override void Draw(Rect position, GUIContent label)
        {
            if (Creature.Species != null)
            {
                var speciesHeight = _instructionCaller.GetHeight(null);
                var speciesRect   = RectHelper.TakeHeight(ref position, speciesHeight);

                RectHelper.TakeVerticalSpace(ref position);

                var labelRect = RectHelper.TakeWidth(ref speciesRect, speciesRect.width * 0.25f);
                var editRect  = RectHelper.AdjustHeight(RectHelper.TakeTrailingIcon(ref speciesRect), EditorGUIUtility.singleLineHeight, RectVerticalAlignment.Top);

                EditorGUI.LabelField(labelRect, Creature.Species.Name);
                _instructionCaller.Draw(speciesRect, GUIContent.none);

                if (GUI.Button(editRect, _editSpeciesButton.Content, GUIStyle.none))
                {
                    Selection.activeObject = Creature.Species;
                }
            }

            if (Creature.Creature != null)
            {
                var editRect = RectHelper.TakeTrailingIcon(ref position);
                EditorGUI.LabelField(position, Creature.Creature.Name);

                if (GUI.Button(editRect, _editCreatureButton.Content, GUIStyle.none))
                {
                    Selection.activeObject = Creature.Creature;
                }
            }
        }
Esempio n. 3
0
        public static Instruction Draw(Rect position, GUIContent label, Instruction instruction)
        {
            var popup = AssetHelper.GetAssetList(typeof(Instruction), true, true);
            var index = popup.GetIndex(instruction);

            var buttonRect    = instruction == null ? position : RectHelper.TakeTrailingIcon(ref position);
            var selectedIndex = EditorGUI.Popup(position, label, index, popup.Names);

            if (selectedIndex != index)
            {
                instruction = popup.GetAsset(selectedIndex) as Instruction;

                if (instruction == null)
                {
                    var type = popup.GetType(selectedIndex);

                    if (type != null)
                    {
                        instruction = AssetHelper.CreateAsset(type.Name, type) as Instruction;
                    }
                }
            }

            if (instruction != null)
            {
                if (GUI.Button(buttonRect, _editButton.Content, GUIStyle.none))
                {
                    Selection.activeObject = instruction;
                }
            }

            return(instruction);
        }
        public static void Draw(Rect rect, GUIContent label, InstructionGraphNode target)
        {
            var editRect    = RectHelper.TakeTrailingIcon(ref rect);
            var targetLabel = target ? target.Name : "Unconnected";

            EditorGUI.LabelField(rect, label, new GUIContent(targetLabel));

            if (target)
            {
                if (GUI.Button(editRect, _editIcon.Content, GUIStyle.none))
                {
                    InstructionGraphEditor.SelectNode(target);
                }
            }
        }
Esempio n. 5
0
        private static VariableValue DrawList(Rect rect, VariableValue value, ListVariableConstraint constraint, bool drawStores)
        {
            var itemDefinition = constraint != null
                                ? ValueDefinition.Create(constraint.ItemType, constraint.ItemConstraint)
                                : ValueDefinition.Create(VariableType.Empty);

            var remove = -1;

            for (var i = 0; i < value.List.Count; i++)
            {
                if (i != 0)
                {
                    RectHelper.TakeVerticalSpace(ref rect);
                }

                var item       = value.List.GetVariable(i);
                var height     = GetHeight(item, itemDefinition, drawStores);
                var itemRect   = RectHelper.TakeHeight(ref rect, height);
                var removeRect = RectHelper.TakeTrailingIcon(ref itemRect);

                item = Draw(itemRect, GUIContent.none, item, itemDefinition, drawStores);
                value.List.SetVariable(i, item);

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

            var addRect = RectHelper.TakeTrailingIcon(ref rect);

            if (GUI.Button(addRect, _addListButton.Content, GUIStyle.none))
            {
                value.List.AddVariable(itemDefinition.Generate(null));
            }

            if (remove >= 0)
            {
                value.List.RemoveVariable(remove);
            }

            return(value);
        }
Esempio n. 6
0
        private static void DrawStringConstraint(Rect rect, ref VariableConstraint constraint)
        {
            if (!(constraint is StringVariableConstraint stringConstraint))
            {
                stringConstraint = new StringVariableConstraint {
                    Values = new string[] { }
                };
                constraint = stringConstraint;
            }

            var remove = -1;

            for (var i = 0; i < stringConstraint.Values.Length; i++)
            {
                if (i != 0)
                {
                    RectHelper.TakeVerticalSpace(ref rect);
                }

                var item       = stringConstraint.Values[i];
                var itemRect   = RectHelper.TakeLine(ref rect);
                var removeRect = RectHelper.TakeTrailingIcon(ref itemRect);

                stringConstraint.Values[i] = EditorGUI.TextField(itemRect, item);

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

            var addRect = RectHelper.TakeTrailingIcon(ref rect);

            if (GUI.Button(addRect, _addButton.Content, GUIStyle.none))
            {
                ArrayUtility.Add(ref stringConstraint.Values, string.Empty);
            }

            if (remove >= 0)
            {
                ArrayUtility.RemoveAt(ref stringConstraint.Values, remove);
            }
        }
Esempio n. 7
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);
        }
        public static bool DrawStoreView(ref Rect rect)
        {
            var viewRect = RectHelper.TakeTrailingIcon(ref rect);

            return(GUI.Button(viewRect, ViewButton.Content, GUIStyle.none));
        }