Inheritance: UnityEngine.MonoBehaviour
コード例 #1
0
        // Token: 0x060022E7 RID: 8935 RVA: 0x001963F4 File Offset: 0x001945F4
        private void QueueGraphUpdatesInternal()
        {
            bool flag = false;

            while (this.graphUpdateQueue.Count > 0)
            {
                GraphUpdateObject graphUpdateObject = this.graphUpdateQueue.Dequeue();
                if (graphUpdateObject.requiresFloodFill)
                {
                    flag = true;
                }
                foreach (object obj in this.astar.data.GetUpdateableGraphs())
                {
                    IUpdatableGraph updatableGraph = (IUpdatableGraph)obj;
                    NavGraph        graph          = updatableGraph as NavGraph;
                    if (graphUpdateObject.nnConstraint == null || graphUpdateObject.nnConstraint.SuitableGraph(this.astar.data.GetGraphIndex(graph), graph))
                    {
                        GraphUpdateProcessor.GUOSingle item = default(GraphUpdateProcessor.GUOSingle);
                        item.order = GraphUpdateProcessor.GraphUpdateOrder.GraphUpdate;
                        item.obj   = graphUpdateObject;
                        item.graph = updatableGraph;
                        this.graphUpdateQueueRegular.Enqueue(item);
                    }
                }
            }
            if (flag)
            {
                GraphUpdateProcessor.GUOSingle item2 = default(GraphUpdateProcessor.GUOSingle);
                item2.order = GraphUpdateProcessor.GraphUpdateOrder.FloodFill;
                this.graphUpdateQueueRegular.Enqueue(item2);
            }
            GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate);
            this.anyGraphUpdateInProgress = true;
        }
コード例 #2
0
        /** Triggers an event for all active graph modifiers */
        public static void TriggerEvent(GraphModifier.EventType type)
        {
            List<GraphModifier> mods = GetActiveModifiers();

            switch (type){
            case EventType.PreScan:
                    for (int i=0;i<mods.Count;i++) mods[i].OnPreScan();
                    break;
            case EventType.PostScan:
                    for (int i=0;i<mods.Count;i++) mods[i].OnPostScan();
                    break;
            case EventType.LatePostScan:
                    lastLateScanEvent = Time.frameCount;
                    for (int i=0;i<mods.Count;i++) mods[i].OnLatePostScan();
                    break;
            case EventType.PreUpdate:
                    for (int i=0;i<mods.Count;i++) mods[i].OnGraphsPreUpdate();
                    break;
            case EventType.PostUpdate:
                    for (int i=0;i<mods.Count;i++) mods[i].OnGraphsPostUpdate();
                    break;
            case EventType.PostCacheLoad:
                    lastPostCacheEvent = Time.frameCount;
                    for (int i=0;i<mods.Count;i++) mods[i].OnPostCacheLoad ();
                    break;
            }
        }
コード例 #3
0
        /// <summary>Schedules graph updates internally</summary>
        void QueueGraphUpdatesInternal()
        {
            while (graphUpdateQueue.Count > 0)
            {
                GraphUpdateObject ob = graphUpdateQueue.Dequeue();
                if (ob.internalStage != GraphUpdateObject.STAGE_PENDING)
                {
                    Debug.LogError("Expected remaining graph updates to be pending");
                    continue;
                }
                ob.internalStage = 0;

                foreach (IUpdatableGraph g in astar.data.GetUpdateableGraphs())
                {
                    NavGraph gr = g as NavGraph;
                    if (ob.nnConstraint == null || ob.nnConstraint.SuitableGraph(astar.data.GetGraphIndex(gr), gr))
                    {
                        var guo = new GUOSingle();
                        guo.order         = GraphUpdateOrder.GraphUpdate;
                        guo.obj           = ob;
                        guo.graph         = g;
                        ob.internalStage += 1;
                        graphUpdateQueueRegular.Enqueue(guo);
                    }
                }
            }

            GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate);
            anyGraphUpdateInProgress = true;
        }
コード例 #4
0
        private void RemoveFromLinkedList()
        {
            if (root == this)
            {
                root = next;
                if (root != null)
                {
                    root.prev = null;
                }
            }
            else
            {
                if (prev != null)
                {
                    prev.next = next;
                }
                if (next != null)
                {
                    next.prev = prev;
                }
            }

            prev = null;
            next = null;
        }
コード例 #5
0
        /// <summary>
        /// Deserializes graphs from the specified byte array additively.
        /// An error will be logged if deserialization fails.
        /// This function will add loaded graphs to the current ones.
        /// </summary>
        public void DeserializeGraphsAdditive(byte[] bytes)
        {
            var graphLock = AssertSafe();

            try {
                if (bytes != null)
                {
                    var sr = new AstarSerializer(this, active.gameObject);

                    if (sr.OpenDeserialize(bytes))
                    {
                        DeserializeGraphsPartAdditive(sr);
                        sr.CloseDeserialize();
                    }
                    else
                    {
                        Debug.Log("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
                    }
                }
                else
                {
                    throw new System.ArgumentNullException(nameof(bytes));
                }
                active.VerifyIntegrity();
            } catch (System.Exception e) {
                Debug.LogError("Caught exception while deserializing data.\n" + e);
                graphs = new NavGraph[0];
            }

            UpdateShortcuts();
            GraphModifier.TriggerEvent(GraphModifier.EventType.PostGraphLoad);
            graphLock.Release();
        }
コード例 #6
0
ファイル: GraphModifier.cs プロジェクト: Bjeck/BM-RTS-game
		/** Triggers an event for all active graph modifiers */
		public static void TriggerEvent (GraphModifier.EventType type) {
			
			if (!Application.isPlaying) {
				FindAllModifiers ();
			}
			
			GraphModifier c = root;
			switch (type){
			case EventType.PreScan:
					while (c != null) { c.OnPreScan(); c = c.next; }
					break;
			case EventType.PostScan:
					while (c != null) { c.OnPostScan(); c = c.next; }
					break;
			case EventType.LatePostScan:
					while (c != null) { c.OnLatePostScan(); c = c.next; }
					break;
			case EventType.PreUpdate:
					while (c != null) { c.OnGraphsPreUpdate(); c = c.next; }
					break;
			case EventType.PostUpdate:
					while (c != null) { c.OnGraphsPostUpdate(); c = c.next; }
					break;
			case EventType.PostCacheLoad:
					while (c != null) { c.OnPostCacheLoad(); c = c.next; }
					break;
			}
		}
コード例 #7
0
        public static void TriggerEvent(EventType type)
        {
            if (!Application.isPlaying)
            {
                FindAllModifiers();
            }
            GraphModifier root = GraphModifier.root;

            switch (type)
            {
            case EventType.PostScan:
                while (root != null)
                {
                    root.OnPostScan();
                    root = root.next;
                }
                return;

            case EventType.PreScan:
                while (root != null)
                {
                    root.OnPreScan();
                    root = root.next;
                }
                return;

            case EventType.LatePostScan:
                while (root != null)
                {
                    root.OnLatePostScan();
                    root = root.next;
                }
                return;

            case EventType.PreUpdate:
                while (root != null)
                {
                    root.OnGraphsPreUpdate();
                    root = root.next;
                }
                return;

            case EventType.PostUpdate:
                while (root != null)
                {
                    root.OnGraphsPostUpdate();
                    root = root.next;
                }
                break;

            case EventType.PostCacheLoad:
                while (root != null)
                {
                    root.OnPostCacheLoad();
                    root = root.next;
                }
                break;
            }
        }
コード例 #8
0
 void IWorkItemContext.PreUpdate()
 {
     if (!preUpdateEventSent && !astar.isScanning)
     {
         preUpdateEventSent = true;
         GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate);
     }
 }
コード例 #9
0
ファイル: GraphModifier.cs プロジェクト: Bjeck/BM-RTS-game
		/** Adds this modifier to list of active modifiers.
		 */
		protected virtual void OnEnable () {
			OnDisable();

			if (root == null) {
				root = this;
			} else {
				this.next = root;
				root.prev = this;
				root = this;
			}
		}
コード例 #10
0
ファイル: GraphModifier.cs プロジェクト: Bjeck/BM-RTS-game
		/** Removes this modifier from list of active modifiers */
		protected virtual void OnDisable () {
			if (root == this) {
				root = this.next;
				if (root != null) root.prev = null;
			} else {
				if (prev != null) prev.next = next;
				if (next != null) next.prev = prev;
			}
			prev = null;
			next = null;
		}
コード例 #11
0
		/** Load from data from #file_cachedStartup */
		public void LoadFromCache () {
			AstarPath.active.BlockUntilPathQueueBlocked();
			if (file_cachedStartup != null) {
				var bytes = file_cachedStartup.bytes;
				DeserializeGraphs(bytes);

				GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad);
			} else {
				Debug.LogError("Can't load from cache since the cache is empty");
			}
		}
コード例 #12
0
ファイル: AstarData.cs プロジェクト: TonyDongGuaPi/joework
 public void LoadFromCache()
 {
     AstarPath.active.BlockUntilPathQueueBlocked();
     if (this.data_cachedStartup != null && this.data_cachedStartup.Length > 0)
     {
         this.DeserializeGraphs(this.data_cachedStartup);
         GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad);
     }
     else
     {
         Debug.LogError("Can't load from cache since the cache is empty");
     }
 }
コード例 #13
0
 void AddToLinkedList()
 {
     if (root == null)
     {
         root = this;
     }
     else
     {
         next      = root;
         root.prev = this;
         root      = this;
     }
 }
コード例 #14
0
 protected virtual void OnEnable()
 {
     this.OnDisable();
     if (root == null)
     {
         root = this;
     }
     else
     {
         this.next = root;
         root.prev = this;
         root      = this;
     }
 }
コード例 #15
0
 protected virtual void OnEnable()
 {
     this.OnDisable();
     if (GraphModifier.root == null)
     {
         GraphModifier.root = this;
     }
     else
     {
         this.next = GraphModifier.root;
         GraphModifier.root.prev = this;
         GraphModifier.root      = this;
     }
 }
コード例 #16
0
ファイル: AstarData.cs プロジェクト: stjordanis/gridworld
        public void LoadFromCache()
        {
            if (data_cachedStartup != null && data_cachedStartup.Length > 0)
            {
                //AstarSerializer serializer = new AstarSerializer (active);
                //DeserializeGraphs (serializer,data_cachedStartup);
                DeserializeGraphs(data_cachedStartup);

                GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad);
            }
            else
            {
                Debug.LogError("Can't load from cache since the cache is empty");
            }
        }
コード例 #17
0
 public void LoadFromCache()
 {
     PathProcessor.GraphUpdateLock graphUpdateLock = this.AssertSafe(false);
     if (this.file_cachedStartup != null)
     {
         byte[] bytes = this.file_cachedStartup.bytes;
         this.DeserializeGraphs(bytes);
         GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad);
     }
     else
     {
         Debug.LogError("Can't load from cache since the cache is empty");
     }
     graphUpdateLock.Release();
 }
コード例 #18
0
ファイル: GraphModifier.cs プロジェクト: DevZhav/The-Forest
        protected static List <T> GetModifiersOfType <T>() where T : GraphModifier
        {
            GraphModifier graphModifier = GraphModifier.root;
            List <T>      list          = new List <T>();

            while (graphModifier != null)
            {
                T t = graphModifier as T;
                if (t != null)
                {
                    list.Add(t);
                }
                graphModifier = graphModifier.next;
            }
            return(list);
        }
コード例 #19
0
		internal static void SerializeReferences(GraphSerializationContext ctx)
		{
			List<NodeLink2> modifiersOfType = GraphModifier.GetModifiersOfType<NodeLink2>();
			ctx.writer.Write(modifiersOfType.Count);
			foreach (NodeLink2 nodeLink in modifiersOfType)
			{
				ctx.writer.Write(nodeLink.uniqueID);
				ctx.SerializeNodeReference(nodeLink.startNode);
				ctx.SerializeNodeReference(nodeLink.endNode);
				ctx.SerializeNodeReference(nodeLink.connectedNode1);
				ctx.SerializeNodeReference(nodeLink.connectedNode2);
				ctx.SerializeVector3(nodeLink.clamped1);
				ctx.SerializeVector3(nodeLink.clamped2);
				ctx.writer.Write(nodeLink.postScanCalled);
			}
		}
コード例 #20
0
        protected static List <T> GetModifiersOfType <T>() where T : GraphModifier
        {
            GraphModifier root = GraphModifier.root;
            List <T>      list = new List <T>();

            while (root != null)
            {
                T item = root as T;
                if (item != null)
                {
                    list.Add(item);
                }
                root = root.next;
            }
            return(list);
        }
コード例 #21
0
        private void QueueGraphUpdatesInternal()
        {
            bool flag = false;

            while (this.graphUpdateQueue.Count > 0)
            {
                GraphUpdateObject graphUpdateObject = this.graphUpdateQueue.Dequeue();
                if (graphUpdateObject.requiresFloodFill)
                {
                    flag = true;
                }
                IEnumerator enumerator = this.astar.astarData.GetUpdateableGraphs().GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object          obj            = enumerator.Current;
                        IUpdatableGraph updatableGraph = (IUpdatableGraph)obj;
                        NavGraph        graph          = updatableGraph as NavGraph;
                        if (graphUpdateObject.nnConstraint == null || graphUpdateObject.nnConstraint.SuitableGraph(this.astar.astarData.GetGraphIndex(graph), graph))
                        {
                            GraphUpdateProcessor.GUOSingle item = default(GraphUpdateProcessor.GUOSingle);
                            item.order = GraphUpdateProcessor.GraphUpdateOrder.GraphUpdate;
                            item.obj   = graphUpdateObject;
                            item.graph = updatableGraph;
                            this.graphUpdateQueueRegular.Enqueue(item);
                        }
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (flag)
            {
                GraphUpdateProcessor.GUOSingle item2 = default(GraphUpdateProcessor.GUOSingle);
                item2.order = GraphUpdateProcessor.GraphUpdateOrder.FloodFill;
                this.graphUpdateQueueRegular.Enqueue(item2);
            }
            GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate);
            this.anyGraphUpdateInProgress = true;
        }
コード例 #22
0
ファイル: AstarData.cs プロジェクト: araya/ET-Plus
        /** Load from data from #file_cachedStartup */
        public void LoadFromCache()
        {
            var graphLock = AssertSafe();

            if (file_cachedStartup != null)
            {
                var bytes = file_cachedStartup.bytes;
                DeserializeGraphs(bytes);

                GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad);
            }
            else
            {
                Debug.LogError("Can't load from cache since the cache is empty");
            }
            graphLock.Release();
        }
コード例 #23
0
        /** Schedules graph updates internally */
        void QueueGraphUpdatesInternal()
        {
            bool anyRequiresFloodFill = false;

            while (graphUpdateQueue.Count > 0)
            {
                GraphUpdateObject ob = graphUpdateQueue.Dequeue();

                if (ob.requiresFloodFill)
                {
                    anyRequiresFloodFill = true;
                }

                foreach (IUpdatableGraph g in astar.data.GetUpdateableGraphs())
                {
                    NavGraph gr = g as NavGraph;
                    if (ob.nnConstraint == null || ob.nnConstraint.SuitableGraph(astar.data.GetGraphIndex(gr), gr))
                    {
                        var guo = new GUOSingle
                        {
                            order = GraphUpdateOrder.GraphUpdate,
                            obj   = ob,
                            graph = g
                        };
                        graphUpdateQueueRegular.Enqueue(guo);
                    }
                }
            }

            if (anyRequiresFloodFill)
            {
                var guo = new GUOSingle
                {
                    order = GraphUpdateOrder.FloodFill
                };
                graphUpdateQueueRegular.Enqueue(guo);
            }

            GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate);
            anyGraphUpdateInProgress = true;
        }
コード例 #24
0
        /// <summary>
        /// Updates graphs.
        /// Will do some graph updates, possibly signal another thread to do them.
        /// Will only process graph updates added by QueueGraphUpdatesInternal
        ///
        /// Returns: True if all graph updates have been done and pathfinding (or other tasks) may resume.
        /// False if there are still graph updates being processed or waiting in the queue.
        /// </summary>
        /// <param name="force">If true, all graph updates will be processed before this function returns. The return value
        /// will be True.</param>
        private bool ProcessGraphUpdates(bool force)
        {
            Assert.IsTrue(anyGraphUpdateInProgress);

            if (force)
            {
                asyncGraphUpdatesComplete.WaitOne();
            }
            else
            {
#if !UNITY_WEBGL
                if (!asyncGraphUpdatesComplete.WaitOne(0))
                {
                    return(false);
                }
#endif
            }

            Assert.AreEqual(graphUpdateQueueAsync.Count, 0, "Queue should be empty at this stage");

            ProcessPostUpdates();
            if (!ProcessRegularUpdates(force))
            {
                return(false);
            }

            GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
            if (OnGraphsUpdated != null)
            {
                OnGraphsUpdated();
            }

            Assert.AreEqual(graphUpdateQueueRegular.Count, 0, "QueueRegular should be empty at this stage");
            Assert.AreEqual(graphUpdateQueueAsync.Count, 0, "QueueAsync should be empty at this stage");
            Assert.AreEqual(graphUpdateQueuePost.Count, 0, "QueuePost should be empty at this stage");

            anyGraphUpdateInProgress = false;
            return(true);
        }
コード例 #25
0
        /// <summary>Schedules graph updates internally</summary>
        private void QueueGraphUpdatesInternal()
        {
            while (graphUpdateQueue.Count > 0)
            {
                GraphUpdateObject ob = graphUpdateQueue.Dequeue();

                foreach (IUpdatableGraph g in astar.data.GetUpdateableGraphs())
                {
                    NavGraph gr = g as NavGraph;
                    if (ob.nnConstraint == null || ob.nnConstraint.SuitableGraph(astar.data.GetGraphIndex(gr), gr))
                    {
                        var guo = new GUOSingle();
                        guo.order = GraphUpdateOrder.GraphUpdate;
                        guo.obj   = ob;
                        guo.graph = g;
                        graphUpdateQueueRegular.Enqueue(guo);
                    }
                }
            }

            GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate);
            anyGraphUpdateInProgress = true;
        }
コード例 #26
0
 // Token: 0x060022E8 RID: 8936 RVA: 0x0019650C File Offset: 0x0019470C
 private bool ProcessGraphUpdates(bool force)
 {
     if (force)
     {
         this.asyncGraphUpdatesComplete.WaitOne();
     }
     else if (!this.asyncGraphUpdatesComplete.WaitOne(0))
     {
         return(false);
     }
     this.ProcessPostUpdates();
     if (!this.ProcessRegularUpdates(force))
     {
         return(false);
     }
     GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
     if (this.OnGraphsUpdated != null)
     {
         this.OnGraphsUpdated();
     }
     this.anyGraphUpdateInProgress = false;
     return(true);
 }
コード例 #27
0
 /** Removes this modifier from list of active modifiers */
 protected virtual void OnDisable()
 {
     if (root == this)
     {
         root = this.next;
         if (root != null)
         {
             root.prev = null;
         }
     }
     else
     {
         if (prev != null)
         {
             prev.next = next;
         }
         if (next != null)
         {
             next.prev = prev;
         }
     }
     prev = null;
     next = null;
 }
コード例 #28
0
 private void RemoveFromLinkedList()
 {
     if (root == this)
     {
         root = this.next;
         if (root != null)
         {
             root.prev = null;
         }
     }
     else
     {
         if (this.prev != null)
         {
             this.prev.next = this.next;
         }
         if (this.next != null)
         {
             this.next.prev = this.prev;
         }
     }
     this.prev = null;
     this.next = null;
 }
コード例 #29
0
 protected virtual void OnDisable()
 {
     if (GraphModifier.root == this)
     {
         GraphModifier.root = this.next;
         if (GraphModifier.root != null)
         {
             GraphModifier.root.prev = null;
         }
     }
     else
     {
         if (this.prev != null)
         {
             this.prev.next = this.next;
         }
         if (this.next != null)
         {
             this.next.prev = this.prev;
         }
     }
     this.prev = null;
     this.next = null;
 }
コード例 #30
0
        /** Process graph updating work items.
         * Process all queued work items, e.g graph updates and the likes.
         *
         * \returns
         * - false if there are still items to be processed.
         * - true if the last work items was processed and pathfinding threads are ready to be resumed.
         *
         * \see AddWorkItem
         * \see threadSafeUpdateState
         * \see Update
         */
        public bool ProcessWorkItems(bool force)
        {
            if (workItemsInProgressRightNow)
            {
                throw new System.Exception("Processing work items recursively. Please do not wait for other work items to be completed inside work items. " +
                                           "If you think this is not caused by any of your scripts, this might be a bug.");
            }

            workItemsInProgressRightNow = true;
            astar.data.LockGraphStructure(true);
            while (workItems.Count > 0)
            {
                // Working on a new batch
                if (!workItemsInProgress)
                {
                    workItemsInProgress     = true;
                    queuedWorkItemFloodFill = false;
                }

                // Peek at first item in the queue
                AstarWorkItem itm = workItems[0];
                bool          status;

                try {
                    // Call init the first time the item is seen
                    if (itm.init != null)
                    {
                        itm.init();
                        itm.init = null;
                    }

                    if (itm.initWithContext != null)
                    {
                        itm.initWithContext(this);
                        itm.initWithContext = null;
                    }

                    // Make sure the item in the queue is up to date
                    workItems[0] = itm;

                    if (itm.update != null)
                    {
                        status = itm.update(force);
                    }
                    else if (itm.updateWithContext != null)
                    {
                        status = itm.updateWithContext(this, force);
                    }
                    else
                    {
                        status = true;
                    }
                } catch {
                    workItems.Dequeue();
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    throw;
                }

                if (!status)
                {
                    if (force)
                    {
                        Debug.LogError("Misbehaving WorkItem. 'force'=true but the work item did not complete.\nIf force=true is passed to a WorkItem it should always return true.");
                    }

                    // Still work items to process
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    return(false);
                }
                else
                {
                    workItems.Dequeue();
                }
            }

            EnsureValidFloodFill();
            Profiler.BeginSample("PostUpdate");
            if (anyGraphsDirty)
            {
                GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
            }
            Profiler.EndSample();

            anyGraphsDirty = false;
            workItemsInProgressRightNow = false;
            workItemsInProgress         = false;
            astar.data.UnlockGraphStructure();
            return(true);
        }
コード例 #31
0
        bool ProcessWorkItems(bool force, bool sendEvents)
        {
            if (workItemsInProgressRightNow)
            {
                throw new System.Exception("Processing work items recursively. Please do not wait for other work items to be completed inside work items. " +
                                           "If you think this is not caused by any of your scripts, this might be a bug.");
            }

            // Make sure the physics engine data is up to date.
            // Graph updates may use physics methods and it is very confusing if they
            // do not always pick up the latest changes made to the scene.
            UnityEngine.Physics.SyncTransforms();
            UnityEngine.Physics2D.SyncTransforms();

            workItemsInProgressRightNow = true;
            astar.data.LockGraphStructure(true);
            while (workItems.Count > 0)
            {
                // Working on a new batch
                if (!workItemsInProgress)
                {
                    workItemsInProgress = true;
                }

                // Peek at first item in the queue
                AstarWorkItem itm = workItems[0];
                bool          status;

                try {
                    // Call init the first time the item is seen
                    if (itm.init != null)
                    {
                        itm.init();
                        itm.init = null;
                    }

                    if (itm.initWithContext != null)
                    {
                        itm.initWithContext(this);
                        itm.initWithContext = null;
                    }

                    // Make sure the item in the queue is up to date
                    workItems[0] = itm;

                    if (itm.update != null)
                    {
                        status = itm.update(force);
                    }
                    else if (itm.updateWithContext != null)
                    {
                        status = itm.updateWithContext(this, force);
                    }
                    else
                    {
                        status = true;
                    }
                } catch {
                    workItems.Dequeue();
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    throw;
                }

                if (!status)
                {
                    if (force)
                    {
                        Debug.LogError("Misbehaving WorkItem. 'force'=true but the work item did not complete.\nIf force=true is passed to a WorkItem it should always return true.");
                    }

                    // Still work items to process
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    return(false);
                }
                else
                {
                    workItems.Dequeue();
                }
            }

            if (sendEvents)
            {
                Profiler.BeginSample("PostUpdate");
                if (anyGraphsDirty)
                {
                    GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdateBeforeAreaRecalculation);
                }
                Profiler.EndSample();

                EnsureValidFloodFill();

                Profiler.BeginSample("PostUpdate");
                if (anyGraphsDirty)
                {
                    GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
                    if (OnGraphsUpdated != null)
                    {
                        OnGraphsUpdated();
                    }
                }
                Profiler.EndSample();
            }

            // Reset flags at the end
            anyGraphsDirty     = false;
            preUpdateEventSent = false;

            workItemsInProgressRightNow = false;
            workItemsInProgress         = false;
            astar.data.UnlockGraphStructure();
            return(true);
        }
コード例 #32
0
        public static void TriggerEvent(GraphModifier.EventType type)
        {
            if (!Application.isPlaying)
            {
                GraphModifier.FindAllModifiers();
            }
            GraphModifier graphModifier = GraphModifier.root;

            switch (type)
            {
            case GraphModifier.EventType.PostScan:
                while (graphModifier != null)
                {
                    graphModifier.OnPostScan();
                    graphModifier = graphModifier.next;
                }
                return;

            case GraphModifier.EventType.PreScan:
                while (graphModifier != null)
                {
                    graphModifier.OnPreScan();
                    graphModifier = graphModifier.next;
                }
                return;

            case (GraphModifier.EventType) 3:
            case (GraphModifier.EventType) 5:
            case (GraphModifier.EventType) 6:
            case (GraphModifier.EventType) 7:
IL_3F:
                if (type == GraphModifier.EventType.PostUpdate)
                {
                    while (graphModifier != null)
                    {
                        graphModifier.OnGraphsPostUpdate();
                        graphModifier = graphModifier.next;
                    }
                    return;
                }
                if (type != GraphModifier.EventType.PostCacheLoad)
                {
                    return;
                }
                while (graphModifier != null)
                {
                    graphModifier.OnPostCacheLoad();
                    graphModifier = graphModifier.next;
                }
                return;

            case GraphModifier.EventType.LatePostScan:
                while (graphModifier != null)
                {
                    graphModifier.OnLatePostScan();
                    graphModifier = graphModifier.next;
                }
                return;

            case GraphModifier.EventType.PreUpdate:
                while (graphModifier != null)
                {
                    graphModifier.OnGraphsPreUpdate();
                    graphModifier = graphModifier.next;
                }
                return;
            }
            goto IL_3F;
        }
コード例 #33
0
        /// <summary>Triggers an event for all active graph modifiers</summary>
        public static void TriggerEvent(GraphModifier.EventType type)
        {
            if (!Application.isPlaying)
            {
                FindAllModifiers();
            }

            try {
                GraphModifier c = root;
                switch (type)
                {
                case EventType.PreScan:
                    while (c != null)
                    {
                        c.OnPreScan(); c = c.next;
                    }
                    break;

                case EventType.PostScan:
                    while (c != null)
                    {
                        c.OnPostScan(); c = c.next;
                    }
                    break;

                case EventType.LatePostScan:
                    while (c != null)
                    {
                        c.OnLatePostScan(); c = c.next;
                    }
                    break;

                case EventType.PreUpdate:
                    while (c != null)
                    {
                        c.OnGraphsPreUpdate(); c = c.next;
                    }
                    break;

                case EventType.PostUpdate:
                    while (c != null)
                    {
                        c.OnGraphsPostUpdate(); c = c.next;
                    }
                    break;

                case EventType.PostUpdateBeforeAreaRecalculation:
                    while (c != null)
                    {
                        c.OnGraphsPostUpdateBeforeAreaRecalculation(); c = c.next;
                    }
                    break;

                case EventType.PostCacheLoad:
                    while (c != null)
                    {
                        c.OnPostCacheLoad(); c = c.next;
                    }
                    break;

                case EventType.PostGraphLoad:
                    while (c != null)
                    {
                        c.OnPostGraphLoad(); c = c.next;
                    }
                    break;
                }
            } catch (System.Exception e) {
                Debug.LogException(e);
            }
        }
コード例 #34
0
ファイル: GraphModifier.cs プロジェクト: DevZhav/The-Forest
        public static void TriggerEvent(GraphModifier.EventType type)
        {
            if (!Application.isPlaying)
            {
                GraphModifier.FindAllModifiers();
            }
            GraphModifier graphModifier = GraphModifier.root;

            switch (type)
            {
            case GraphModifier.EventType.PostScan:
                while (graphModifier != null)
                {
                    graphModifier.OnPostScan();
                    graphModifier = graphModifier.next;
                }
                break;

            case GraphModifier.EventType.PreScan:
                while (graphModifier != null)
                {
                    graphModifier.OnPreScan();
                    graphModifier = graphModifier.next;
                }
                break;

            default:
                if (type != GraphModifier.EventType.PostUpdate)
                {
                    if (type == GraphModifier.EventType.PostCacheLoad)
                    {
                        while (graphModifier != null)
                        {
                            graphModifier.OnPostCacheLoad();
                            graphModifier = graphModifier.next;
                        }
                    }
                }
                else
                {
                    while (graphModifier != null)
                    {
                        graphModifier.OnGraphsPostUpdate();
                        graphModifier = graphModifier.next;
                    }
                }
                break;

            case GraphModifier.EventType.LatePostScan:
                while (graphModifier != null)
                {
                    graphModifier.OnLatePostScan();
                    graphModifier = graphModifier.next;
                }
                break;

            case GraphModifier.EventType.PreUpdate:
                while (graphModifier != null)
                {
                    graphModifier.OnGraphsPreUpdate();
                    graphModifier = graphModifier.next;
                }
                break;
            }
        }