示例#1
0
        public static void Add(IControllable target, int order)
        {
            var targets = Instance.orderedTargets;

            Debug.Assert(target != null, "Input target can't be null.");
            Debug.Assert(order >= 0, "Input order must be non-negative.");
            Debug.Assert(targets.All(t => t.Order != order), $"Duplicate input order ({order}).");

            InputTarget existingTarget = null;

            // This loop accounts for targets that registered input buffers before adding themselves properly (via
            // this function).
            for (int i = 0; i < targets.Count; i++)
            {
                var(orderValue, t) = targets[i];

                if (orderValue >= 0)
                {
                    break;
                }

                // If a temporary entry is found, that entry is removed (then re-inserted below with proper ordering).
                if (t.Target == target)
                {
                    existingTarget = t;
                    targets.RemoveAt(i);

                    break;
                }
            }

            Debug.Assert(targets.All(t => t.Target.Target != target), "Duplicate input target.");

            var index = 0;

            while (index < targets.Count && targets[index].Order < order)
            {
                index++;
            }

            targets.Insert(index, (order, existingTarget ?? new InputTarget(target)));
        }
示例#2
0
        public static InputBuffer RegisterBuffer(IControllable target, List <InputBind> binds, bool requiresHold,
                                                 float duration = 0)
        {
            var inputTarget = Instance.orderedTargets.FirstOrDefault(t => t.Target.Target == target).Target;

            // If untracked, the given target is temporarily tracked with an ordering of -1. This ordering is
            // overridden when the target is added normally (or else a debug assertion is thrown later). Doing this
            // allows targets to create input buffers before officially adding themselves to the processor.
            if (inputTarget == null)
            {
                inputTarget = new InputTarget(target);
                Instance.orderedTargets.Insert(0, (-1, inputTarget));
            }

            var buffer = new InputBuffer(binds, requiresHold, duration);

            inputTarget.Buffers.Add(buffer);

            return(buffer);
        }