Beispiel #1
0
        public State CheckState()
        {
            var buttons = Object.FindObjectsOfType <Button>();

            _targetButton = buttons.Shuffle().FirstOrDefault(x => ApeUtil.CheckButtonClickable(x, _condition));
            return(_targetButton != null ? State.Execute : State.DontExecute);
        }
Beispiel #2
0
        public State CheckState()
        {
            var buttons    = Object.FindObjectsOfType <Button>();
            var maxNum     = 0;
            var clickables = buttons.Where(x => ApeUtil.CheckButtonClickable(x, _condition)).Select(x =>
            {
                var fullName = ApeUtil.GetFullName(x.gameObject);
                if (!PushNum.ContainsKey(fullName))
                {
                    PushNum.Add(fullName, 0);
                }
                var num = PushNum[fullName] + 1;
                maxNum  = Mathf.Max(maxNum, num * 2);
                return(x, num);
            }).ToArray();

            if (clickables.Length == 0)
            {
                return(State.DontExecute);
            }

            var lot   = clickables.Select(x => (x.x, maxNum - x.num)).ToArray();
            var total = lot.Sum(x => x.Item2);

            var r     = UnityEngine.Random.Range(0, total);
            var index = -1;

            while (r >= 0)
            {
                index++;
                r -= lot[index].Item2;
            }
            _targetButton = lot[index].x;
            PushNum[ApeUtil.GetFullName(lot[index].x.gameObject)]++;

            return(State.Execute);
        }