示例#1
0
        public void TestSubMenuTransition()
        {
            var config = new HashSet <BubbleMenuItem> {
                BubbleMenuItem.Branch("System", 0, new HashSet <BubbleMenuItem> {
                    BubbleMenuItem.Leaf("Reset", 0),
                    BubbleMenuItem.Leaf("Suspend", 1),
                    BubbleMenuItem.Leaf("Options", 2),
                    BubbleMenuItem.Leaf("Tips", 3)
                }),
                BubbleMenuItem.Leaf("Tactical", 1),
                BubbleMenuItem.Leaf("Units", 2),
                BubbleMenuItem.Branch("Range", 3, new HashSet <BubbleMenuItem> {
                    BubbleMenuItem.Leaf("Off", 0),
                    BubbleMenuItem.Leaf("Attack", 1),
                    BubbleMenuItem.Leaf("Absolute", 2)
                }),
                BubbleMenuItem.Leaf("End Turn", 4)
            };

            var machine      = BubbleMenuUtils.CreateStateMachine(config);
            var initialState = machine.State;

            machine.Fire("System");
            Assert.AreEqual("System", machine.State);

            machine.GoBack();
            Assert.AreEqual(initialState, machine.State);

            machine.Fire("System");
            machine.Fire("Reset");

            Assert.AreEqual("dispatch", machine.State);
        }
示例#2
0
        private void ShowActionMenu(Vector3 unitPosition)
        {
            View.transform.localPosition = unitPosition;

            var characterName = BattleModel.SelectedCombatant.Name;
            var config        = BubbleMenuUtils.CreateFromActions(BattleModel.AvailableActions, characterName);

            View.Show(config);
        }
示例#3
0
        public void Show(HashSet <BubbleMenuItem> config)
        {
            _hidden       = false;
            _config       = config;
            _stateMachine = BubbleMenuUtils.CreateStateMachine(config);
            _stateMachine.SelectSignal.AddListener(Select);
            _stateMachine.ChangeLevelSignal.AddListener(ShowLevel);
            _stateMachine.CloseSignal.AddListener(DismissSignal.Dispatch);
            var count        = config.Count;
            var copiedConfig = new HashSet <BubbleMenuItem>().Concat(config).ToHashSet();

            copiedConfig.Add(BubbleMenuItem.Leaf("Back", int.MaxValue));
            var configItems = Flatten(copiedConfig);

            foreach (var item in configItems)
            {
                var buttonName = item.Name;
                var path       = item.ResourcePath == null ? "MenuBubbles/" + buttonName : item.ResourcePath;
                var prefab     = Resources.Load(path) as GameObject;
                if (prefab == null)
                {
                    throw new ArgumentException("Could not find menu item at path: " + path);
                }

                var child = Instantiate(prefab);
                child.name = prefab.name;
                child.transform.SetParent(transform);
                child.SetActive(false);

                var eventTrigger = child.GetComponent <EventTrigger>();
                if (eventTrigger == null)
                {
                    eventTrigger = child.AddComponent <EventTrigger>();
                }

                var entry = new EventTrigger.Entry {
                    eventID = EventTriggerType.PointerClick
                };

                var nameCopy = buttonName;
                entry.callback.AddListener(eventData => ClickItem(nameCopy));
                eventTrigger.triggers.Add(entry);

                _bubbles[buttonName] = child;
            }
            var positions = GetPoints(count);
            var bubbles   = GetGameObjectsForBubbles(copiedConfig);

            ScaleInBubbles(positions, bubbles);
        }