예제 #1
0
        public void Add(GridGraphRule.Pass rule, System.Action <Context> action)
        {
            var index = (int)rule;

            if (callbacks[index] == null)
            {
                callbacks[index] = new List <System.Action <Context> >();
            }
            callbacks[index].Add(action);
        }
예제 #2
0
        /// <summary>
        /// Adds a pass callback that runs in the main thread.
        /// The callback may access and modify any data in the context.
        /// You do not need to schedule jobs in order to access the data.
        ///
        /// Warning: Not all data in the Context is valid for every pass. For example you cannot access node connections in the BeforeConnections pass
        /// since they haven't been calculated yet.
        ///
        /// This is a bit slower than <see cref="AddJobSystemPass"/> since parallelism and the burst compiler cannot be used.
        /// But if you need to use non-thread-safe APIs or data then this is a good choice.
        /// </summary>
        public void AddMainThreadPass(GridGraphRule.Pass pass, System.Action <Context> action)
        {
            var index = (int)pass;

            if (mainThreadCallbacks[index] == null)
            {
                mainThreadCallbacks[index] = new List <System.Action <Context> >();
            }
            mainThreadCallbacks[index].Add(action);
        }
예제 #3
0
        /// <summary>
        /// Adds a pass callback that uses the job system.
        /// This rule should only schedule jobs using the `Context.tracker` dependency tracker. Data is not safe to access directly in the callback
        /// </summary>
        public void AddJobSystemPass(GridGraphRule.Pass pass, System.Action <Context> action)
        {
            var index = (int)pass;

            if (jobSystemCallbacks[index] == null)
            {
                jobSystemCallbacks[index] = new List <System.Action <Context> >();
            }
            jobSystemCallbacks[index].Add(action);
        }
예제 #4
0
        /// <summary>
        /// Executes the rules for the given pass.
        /// Call handle.Complete on, or wait for, all yielded job handles.
        /// </summary>
        public IEnumerator <JobHandle> ExecuteRule(GridGraphRule.Pass rule, Context context)
        {
            if (jobSystemCallbacks == null)
            {
                Rebuild();
            }
            CallActions(jobSystemCallbacks[(int)rule], context);

            if (mainThreadCallbacks[(int)rule] != null && mainThreadCallbacks[(int)rule].Count > 0)
            {
                if (!context.tracker.forceLinearDependencies)
                {
                    yield return(context.tracker.AllWritesDependency);
                }
                CallActions(mainThreadCallbacks[(int)rule], context);
            }
        }
예제 #5
0
        public bool ExecuteRule(GridGraphRule.Pass rule, Context context)
        {
            if (callbacks == null)
            {
                Rebuild();
            }
            var actions = callbacks[(int)rule];

            if (actions != null)
            {
                try {
                    for (int i = 0; i < actions.Count; i++)
                    {
                        actions[i](context);
                    }
                } catch (System.Exception e) {
                    UnityEngine.Debug.LogException(e);
                    return(false);
                }
                return(true);
            }
            return(false);
        }
예제 #6
0
 public void Add(GridGraphRule.Pass pass, System.Action <Context> action)
 {
     AddJobSystemPass(pass, action);
 }