Inheritance: UnityEngine.MonoBehaviour
示例#1
0
            public void OnDrawGismos(Transform tr)
            {
                List <IntPoint> list = ListPool <IntPoint> .Claim();

                Bounds bounds;

                if (this.type == NavmeshCut.MeshType.Circle)
                {
                    NavmeshCut.GetContour_Circle(list, tr, this.circleResolution, this.circleRadius, this.center, this.useRotation);
                    bounds = NavmeshCut.GetBounds_Circle(tr, this.center, this.circleRadius, this.height, this.useRotation);
                }
                else
                {
                    NavmeshCut.GetContour_Rectangle(list, tr, this.rectangleSize, this.center, this.useRotation);
                    bounds = NavmeshCut.GetBounds_Rectangle(tr, this.center, this.rectangleSize, this.height, this.useRotation);
                }
                float   y = bounds.min.y;
                Vector3 b = Vector3.up * (bounds.max.y - y);

                for (int i = 0; i < list.get_Count(); i++)
                {
                    Vector3 vector = NavmeshCut.IntPointToV3(list.get_Item(i));
                    vector.y = y;
                    Vector3 vector2 = NavmeshCut.IntPointToV3(list.get_Item((i + 1) % list.get_Count()));
                    vector2.y = y;
                    Gizmos.DrawLine(vector, vector2);
                    Gizmos.DrawLine(vector + b, vector2 + b);
                    Gizmos.DrawLine(vector, vector + b);
                    Gizmos.DrawLine(vector2, vector2 + b);
                }
                ListPool <IntPoint> .Release(list);
            }
示例#2
0
        public void OnDrawGizmos()
        {
            if (this.tr == null)
            {
                this.tr = base.transform;
            }
            List <List <IntPoint> > list = ListPool <List <IntPoint> > .Claim();

            this.GetContour(list);
            Gizmos.color = NavmeshCut.GizmoColor;
            Bounds  bounds = this.GetBounds();
            float   y      = bounds.min.y;
            Vector3 b      = Vector3.up * (bounds.max.y - y);

            for (int i = 0; i < list.get_Count(); i++)
            {
                List <IntPoint> list2 = list.get_Item(i);
                for (int j = 0; j < list2.get_Count(); j++)
                {
                    Vector3 vector = NavmeshCut.IntPointToV3(list2.get_Item(j));
                    vector.y = y;
                    Vector3 vector2 = NavmeshCut.IntPointToV3(list2.get_Item((j + 1) % list2.get_Count()));
                    vector2.y = y;
                    Gizmos.DrawLine(vector, vector2);
                    Gizmos.DrawLine(vector + b, vector2 + b);
                    Gizmos.DrawLine(vector, vector + b);
                    Gizmos.DrawLine(vector2, vector2 + b);
                }
            }
            ListPool <List <IntPoint> > .Release(list);
        }
示例#3
0
            public void OnDrawGismos(Transform tr)
            {
                Bounds          bounds;
                List <IntPoint> buffer = ListPool <IntPoint> .Claim();

                if (this.type == NavmeshCut.MeshType.Circle)
                {
                    NavmeshCut.GetContour_Circle(buffer, tr, this.circleResolution, this.circleRadius, this.center, this.useRotation);
                    bounds = NavmeshCut.GetBounds_Circle(tr, this.center, this.circleRadius, this.height, this.useRotation);
                }
                else
                {
                    NavmeshCut.GetContour_Rectangle(buffer, tr, this.rectangleSize, this.center, this.useRotation);
                    bounds = NavmeshCut.GetBounds_Rectangle(tr, this.center, this.rectangleSize, this.height, this.useRotation);
                }
                float   y      = bounds.min.y;
                Vector3 vector = (Vector3)(Vector3.up * (bounds.max.y - y));

                for (int i = 0; i < buffer.Count; i++)
                {
                    Vector3 from = NavmeshCut.IntPointToV3(buffer[i]);
                    from.y = y;
                    Vector3 to = NavmeshCut.IntPointToV3(buffer[(i + 1) % buffer.Count]);
                    to.y = y;
                    Gizmos.DrawLine(from, to);
                    Gizmos.DrawLine(from + vector, to + vector);
                    Gizmos.DrawLine(from, from + vector);
                    Gizmos.DrawLine(to, to + vector);
                }
                ListPool <IntPoint> .Release(buffer);
            }
示例#4
0
        // Token: 0x06000730 RID: 1840 RVA: 0x000465B0 File Offset: 0x000449B0
        public void ForceUpdate()
        {
            if (this.handler == null)
            {
                throw new Exception("Cannot update graphs. No TileHandler. Do not call this method in Awake.");
            }
            this.lastUpdateTime = Time.realtimeSinceStartup;
            List <NavmeshCut> all = NavmeshCut.GetAll();

            if (this.forcedReloadBounds.Count == 0)
            {
                int num = 0;
                for (int i = 0; i < all.Count; i++)
                {
                    if (all[i].RequiresUpdate())
                    {
                        num++;
                        break;
                    }
                }
                if (num == 0)
                {
                    return;
                }
            }
            bool flag = this.handler.StartBatchLoad();

            for (int j = 0; j < this.forcedReloadBounds.Count; j++)
            {
                this.handler.ReloadInBounds(this.forcedReloadBounds[j]);
            }
            this.forcedReloadBounds.Clear();
            for (int k = 0; k < all.Count; k++)
            {
                if (all[k].enabled)
                {
                    if (all[k].RequiresUpdate())
                    {
                        this.handler.ReloadInBounds(all[k].LastBounds);
                        this.handler.ReloadInBounds(all[k].GetBounds());
                    }
                }
                else if (all[k].RequiresUpdate())
                {
                    this.handler.ReloadInBounds(all[k].LastBounds);
                }
            }
            for (int l = 0; l < all.Count; l++)
            {
                if (all[l].RequiresUpdate())
                {
                    all[l].NotifyUpdated();
                }
            }
            if (flag)
            {
                this.handler.EndBatchLoad();
            }
        }
示例#5
0
 public void OnDestroy()
 {
     if (NavmeshCut.OnDestroyCallback != null)
     {
         NavmeshCut.OnDestroyCallback.Invoke(this);
     }
     NavmeshCut.RemoveCut(this);
 }
示例#6
0
		public void DiscardPending()
		{
			List<NavmeshCut> all = NavmeshCut.GetAll();
			for (int i = 0; i < all.Count; i++)
			{
				if (all[i].RequiresUpdate())
				{
					all[i].NotifyUpdated();
				}
			}
		}
示例#7
0
		public static List<NavmeshCut> GetAllInRange(Bounds b)
		{
			List<NavmeshCut> list = ListPool<NavmeshCut>.Claim();
			for (int i = 0; i < NavmeshCut.allCuts.Count; i++)
			{
				if (NavmeshCut.allCuts[i].enabled && NavmeshCut.Intersects(b, NavmeshCut.allCuts[i].GetBounds()))
				{
					list.Add(NavmeshCut.allCuts[i]);
				}
			}
			return list;
		}
示例#8
0
        public void DiscardPending()
        {
            List <NavmeshCut> cuts = NavmeshCut.GetAll();

            for (int i = 0; i < cuts.Count; i++)
            {
                if (cuts[i].RequiresUpdate())
                {
                    cuts[i].NotifyUpdated();
                }
            }
        }
示例#9
0
        public static ListView <NavmeshCut> GetAllInRange(Bounds b)
        {
            ListView <NavmeshCut> listView = new ListView <NavmeshCut>();

            for (int i = 0; i < NavmeshCut.allCuts.Count; i++)
            {
                if (NavmeshCut.allCuts[i].enabled && NavmeshCut.Intersects(b, NavmeshCut.allCuts[i].GetBounds()))
                {
                    listView.Add(NavmeshCut.allCuts[i]);
                }
            }
            return(listView);
        }
示例#10
0
            public void OnDrawGizmosSelected(Transform tr)
            {
                Bounds bounds;

                Gizmos.color = Color.Lerp(NavmeshCut.GizmoColor, new Color(1f, 1f, 1f, 0.2f), 0.9f);
                if (this.type == NavmeshCut.MeshType.Circle)
                {
                    bounds = NavmeshCut.GetBounds_Circle(tr, this.center, this.circleRadius, this.height, this.useRotation);
                }
                else
                {
                    bounds = NavmeshCut.GetBounds_Rectangle(tr, this.center, this.rectangleSize, this.height, this.useRotation);
                }
                Gizmos.DrawCube(bounds.center, bounds.size);
                Gizmos.DrawWireCube(bounds.center, bounds.size);
            }
示例#11
0
        public Bounds GetBounds()
        {
            switch (this.type)
            {
            case NavmeshCut.MeshType.Rectangle:
                this.bounds = NavmeshCut.GetBounds_Rectangle(this.tr, this.center, this.rectangleSize, this.height, this.useRotation);
                break;

            case NavmeshCut.MeshType.Circle:
                this.bounds = NavmeshCut.GetBounds_Circle(this.tr, this.center, this.circleRadius, this.height, this.useRotation);
                break;

            case NavmeshCut.MeshType.CustomMesh:
                if (!(this.mesh == null))
                {
                    Bounds bounds = this.mesh.bounds;
                    if (this.useRotation)
                    {
                        Matrix4x4 localToWorldMatrix = this.tr.localToWorldMatrix;
                        bounds.center *= this.meshScale;
                        bounds.size   *= this.meshScale;
                        this.bounds    = new Bounds(localToWorldMatrix.MultiplyPoint3x4(this.center + bounds.center), Vector3.zero);
                        Vector3 max = bounds.max;
                        Vector3 min = bounds.min;
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(max.x, max.y, max.z)));
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(min.x, max.y, max.z)));
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(min.x, max.y, min.z)));
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(max.x, max.y, min.z)));
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(max.x, min.y, max.z)));
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(min.x, min.y, max.z)));
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(min.x, min.y, min.z)));
                        this.bounds.Encapsulate(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(max.x, min.y, min.z)));
                        Vector3 size = this.bounds.size;
                        size.y           = Mathf.Max(size.y, this.height * this.tr.lossyScale.y);
                        this.bounds.size = size;
                    }
                    else
                    {
                        Vector3 size2 = bounds.size * this.meshScale;
                        size2.y     = Mathf.Max(size2.y, this.height);
                        this.bounds = new Bounds(base.transform.position + this.center + bounds.center * this.meshScale, size2);
                    }
                }
                break;
            }
            return(this.bounds);
        }
        private bool ShouldRebuild()
        {
            List <NavmeshCut> all = NavmeshCut.GetAll();

            if (this.forcedReloadBounds.Count != 0)
            {
                return(true);
            }
            for (int i = 0; i < all.Count; i++)
            {
                if (all[i].RequiresUpdate())
                {
                    return(true);
                }
            }
            return(false);
        }
示例#13
0
        public static void GetContour_Rectangle(List <IntPoint> buffer, Transform tr, Vector2 rectangleSize, Vector3 center, bool useRotation)
        {
            Vector3 a = tr.position;

            if (useRotation)
            {
                Matrix4x4 localToWorldMatrix = tr.localToWorldMatrix;
                buffer.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(center + new Vector3(-rectangleSize.x, 0f, -rectangleSize.y) * 0.5f)));
                buffer.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(center + new Vector3(rectangleSize.x, 0f, -rectangleSize.y) * 0.5f)));
                buffer.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(center + new Vector3(rectangleSize.x, 0f, rectangleSize.y) * 0.5f)));
                buffer.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(center + new Vector3(-rectangleSize.x, 0f, rectangleSize.y) * 0.5f)));
            }
            else
            {
                float num  = rectangleSize.x * tr.lossyScale.x;
                float num2 = rectangleSize.y * tr.lossyScale.y;
                a += center.Mul(tr.lossyScale);
                buffer.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(-num, 0f, -num2) * 0.5f));
                buffer.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(num, 0f, -num2) * 0.5f));
                buffer.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(num, 0f, num2) * 0.5f));
                buffer.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(-num, 0f, num2) * 0.5f));
            }
        }
        public void Rebuild()
        {
            List <NavmeshCut> all      = NavmeshCut.GetAll();
            List <NavmeshCut> listView = new List <NavmeshCut>();

            this.CreateHandlers(all);
            if (this.handler == null)
            {
                return;
            }
            AstarPath active = AstarPath.active;
            int       num    = active.astarData.graphs.Length + 1;

            for (int i = 0; i < all.Count; i++)
            {
                all[i].Check();
            }

            listView.Clear();
            for (int k = 0; k < all.Count; k++)
            {
                NavmeshCut navmeshCut = all[k];
                listView.Add(navmeshCut);
            }

            this.handler.ReloadTiles(listView);
            AstarPath.active.astarData.InitRasterizer();

            for (int l = 0; l < all.Count; l++)
            {
                if (all[l].RequiresUpdate())
                {
                    all[l].NotifyUpdated();
                }
            }
            this.forcedReloadBounds.Clear();
        }
示例#15
0
        public static void GetContour_Circle(List <IntPoint> buffer, Transform tr, int circleResolution, float circleRadius, Vector3 center, bool useRotation)
        {
            Vector3 a = tr.position;

            if (useRotation)
            {
                Matrix4x4 localToWorldMatrix = tr.localToWorldMatrix;
                for (int i = 0; i < circleResolution; i++)
                {
                    buffer.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(center + new Vector3(Mathf.Cos((float)(i * 2) * 3.14159274f / (float)circleResolution), 0f, Mathf.Sin((float)(i * 2) * 3.14159274f / (float)circleResolution)) * circleRadius)));
                }
            }
            else
            {
                Vector3 zero = Vector3.zero;
                a += center.Mul(tr.lossyScale);
                for (int j = 0; j < circleResolution; j++)
                {
                    zero.x = Mathf.Cos((float)(j * 2) * 3.14159274f / (float)circleResolution) * circleRadius * tr.lossyScale.x;
                    zero.z = Mathf.Sin((float)(j * 2) * 3.14159274f / (float)circleResolution) * circleRadius * tr.lossyScale.z;
                    buffer.Add(NavmeshCut.V3ToIntPoint(a + zero));
                }
            }
        }
示例#16
0
 private static void RemoveCut(NavmeshCut obj)
 {
     allCuts.Remove(obj);
 }
示例#17
0
 private static void AddCut(NavmeshCut obj)
 {
     allCuts.Add(obj);
 }
 /** Called when a NavmeshCut is destroyed */
 void HandleOnDestroyCallback(NavmeshCut obj)
 {
     forcedReloadBounds.Add(obj.LastBounds);
 }
示例#19
0
        public void GetContour(List <List <IntPoint> > buffer)
        {
            if (this.circleResolution < 3)
            {
                this.circleResolution = 3;
            }
            Vector3 a = this.tr.position;

            switch (this.type)
            {
            case NavmeshCut.MeshType.Rectangle:
            {
                List <IntPoint> list = ListPool <IntPoint> .Claim();

                NavmeshCut.GetContour_Rectangle(list, this.tr, this.rectangleSize, this.center, this.useRotation);
                buffer.Add(list);
                break;
            }

            case NavmeshCut.MeshType.Circle:
            {
                List <IntPoint> list2 = ListPool <IntPoint> .Claim(this.circleResolution);

                NavmeshCut.GetContour_Circle(list2, this.tr, this.circleResolution, this.circleRadius, this.center, this.useRotation);
                buffer.Add(list2);
                break;
            }

            case NavmeshCut.MeshType.CustomMesh:
                if (this.mesh != this.lastMesh || this.contours == null)
                {
                    this.CalculateMeshContour();
                    this.lastMesh = this.mesh;
                }
                if (this.contours != null)
                {
                    a += this.center;
                    bool flag = Vector3.Dot(this.tr.up, Vector3.up) < 0f;
                    for (int i = 0; i < this.contours.Length; i++)
                    {
                        Vector3[]       array = this.contours[i];
                        List <IntPoint> list3 = ListPool <IntPoint> .Claim(array.Length);

                        if (this.useRotation)
                        {
                            Matrix4x4 localToWorldMatrix = this.tr.localToWorldMatrix;
                            for (int j = 0; j < array.Length; j++)
                            {
                                list3.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(this.center + array[j] * this.meshScale)));
                            }
                        }
                        else
                        {
                            for (int k = 0; k < array.Length; k++)
                            {
                                list3.Add(NavmeshCut.V3ToIntPoint(a + array[k] * this.meshScale));
                            }
                        }
                        if (flag)
                        {
                            list3.Reverse();
                        }
                        buffer.Add(list3);
                    }
                }
                break;
            }
        }
示例#20
0
 /** Called when a NavmeshCut is destroyed */
 void HandleOnDestroyCallback(NavmeshCut obj)
 {
     forcedReloadBounds.Add(obj.LastBounds);
     lastUpdateTime = -999;
 }
示例#21
0
        /** Checks all NavmeshCut instances and updates graphs if needed */
        public void ForceUpdate()
        {
            if (handler == null)
            {
                throw new System.Exception("Cannot update graphs. No TileHandler. Do not call this method in Awake.");
            }

            lastUpdateTime = Time.realtimeSinceStartup;

            List <NavmeshCut> cuts = NavmeshCut.GetAll();

            if (forcedReloadBounds.Count == 0)
            {
                int any = 0;

                for (int i = 0; i < cuts.Count; i++)
                {
                    if (cuts[i].RequiresUpdate())
                    {
                        any++;
                        break;
                    }
                }

                // Nothing needs to be done for now
                if (any == 0)
                {
                    return;
                }
            }

            bool end = handler.StartBatchLoad();

            //Debug.Log ("Updating...");

            for (int i = 0; i < forcedReloadBounds.Count; i++)
            {
                handler.ReloadInBounds(forcedReloadBounds[i]);
            }
            forcedReloadBounds.Clear();

            for (int i = 0; i < cuts.Count; i++)
            {
                if (cuts[i].enabled)
                {
                    if (cuts[i].RequiresUpdate())
                    {
                        handler.ReloadInBounds(cuts[i].LastBounds);
                        handler.ReloadInBounds(cuts[i].GetBounds());
                    }
                }
                else if (cuts[i].RequiresUpdate())
                {
                    handler.ReloadInBounds(cuts[i].LastBounds);
                }
            }

            for (int i = 0; i < cuts.Count; i++)
            {
                if (cuts[i].RequiresUpdate())
                {
                    cuts[i].NotifyUpdated();
                }
            }

            if (end)
            {
                handler.EndBatchLoad();
            }
        }
示例#22
0
		public void Awake()
		{
			this.tr = base.transform;
			NavmeshCut.AddCut(this);
		}
示例#23
0
		private static void AddCut (NavmeshCut obj) {
			allCuts.Add (obj);
		}
示例#24
0
 public void Awake()
 {
     NavmeshCut.AddCut(this);
 }
示例#25
0
		/** Called when a NavmeshCut is destroyed */
		void HandleOnDestroyCallback ( NavmeshCut obj ) {
			forcedReloadBounds.Add (obj.LastBounds);
			lastUpdateTime = -999;
		}
示例#26
0
		public void GetContour(List<List<IntPoint>> buffer)
		{
			if (this.circleResolution < 3)
			{
				this.circleResolution = 3;
			}
			Vector3 a = this.tr.position;
			Matrix4x4 matrix = Matrix4x4.identity;
			bool flag = false;
			if (this.useRotation)
			{
				matrix = this.tr.localToWorldMatrix;
				flag = VectorMath.ReversesFaceOrientationsXZ(matrix);
			}
			NavmeshCut.MeshType meshType = this.type;
			if (meshType != NavmeshCut.MeshType.Rectangle)
			{
				if (meshType != NavmeshCut.MeshType.Circle)
				{
					if (meshType == NavmeshCut.MeshType.CustomMesh)
					{
						if (this.mesh != this.lastMesh || this.contours == null)
						{
							this.CalculateMeshContour();
							this.lastMesh = this.mesh;
						}
						if (this.contours != null)
						{
							a += this.center;
							flag ^= (this.meshScale < 0f);
							for (int i = 0; i < this.contours.Length; i++)
							{
								Vector3[] array = this.contours[i];
								List<IntPoint> list = ListPool<IntPoint>.Claim(array.Length);
								if (this.useRotation)
								{
									for (int j = 0; j < array.Length; j++)
									{
										list.Add(NavmeshCut.V3ToIntPoint(matrix.MultiplyPoint3x4(this.center + array[j] * this.meshScale)));
									}
								}
								else
								{
									for (int k = 0; k < array.Length; k++)
									{
										list.Add(NavmeshCut.V3ToIntPoint(a + array[k] * this.meshScale));
									}
								}
								if (flag)
								{
									list.Reverse();
								}
								buffer.Add(list);
							}
						}
					}
				}
				else
				{
					List<IntPoint> list = ListPool<IntPoint>.Claim(this.circleResolution);
					flag ^= (this.circleRadius < 0f);
					if (this.useRotation)
					{
						for (int l = 0; l < this.circleResolution; l++)
						{
							list.Add(NavmeshCut.V3ToIntPoint(matrix.MultiplyPoint3x4(this.center + new Vector3(Mathf.Cos((float)(l * 2) * 3.14159274f / (float)this.circleResolution), 0f, Mathf.Sin((float)(l * 2) * 3.14159274f / (float)this.circleResolution)) * this.circleRadius)));
						}
					}
					else
					{
						a += this.center;
						for (int m = 0; m < this.circleResolution; m++)
						{
							list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(Mathf.Cos((float)(m * 2) * 3.14159274f / (float)this.circleResolution), 0f, Mathf.Sin((float)(m * 2) * 3.14159274f / (float)this.circleResolution)) * this.circleRadius));
						}
					}
					if (flag)
					{
						list.Reverse();
					}
					buffer.Add(list);
				}
			}
			else
			{
				List<IntPoint> list = ListPool<IntPoint>.Claim();
				flag ^= (this.rectangleSize.x < 0f ^ this.rectangleSize.y < 0f);
				if (this.useRotation)
				{
					list.Add(NavmeshCut.V3ToIntPoint(matrix.MultiplyPoint3x4(this.center + new Vector3(-this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f)));
					list.Add(NavmeshCut.V3ToIntPoint(matrix.MultiplyPoint3x4(this.center + new Vector3(this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f)));
					list.Add(NavmeshCut.V3ToIntPoint(matrix.MultiplyPoint3x4(this.center + new Vector3(this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f)));
					list.Add(NavmeshCut.V3ToIntPoint(matrix.MultiplyPoint3x4(this.center + new Vector3(-this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f)));
				}
				else
				{
					a += this.center;
					list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(-this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f));
					list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f));
					list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f));
					list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(-this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f));
				}
				if (flag)
				{
					list.Reverse();
				}
				buffer.Add(list);
			}
		}
示例#27
0
 // Token: 0x06000736 RID: 1846 RVA: 0x0004687D File Offset: 0x00044C7D
 private void HandleOnDestroyCallback(NavmeshCut obj)
 {
     this.forcedReloadBounds.Add(obj.LastBounds);
     this.lastUpdateTime = -999f;
 }
示例#28
0
        public void GetContour(List <List <IntPoint> > buffer)
        {
            if (this.circleResolution < 3)
            {
                this.circleResolution = 3;
            }
            Vector3 a = this.tr.position;

            switch (this.type)
            {
            case NavmeshCut.MeshType.Rectangle:
            {
                List <IntPoint> list = ListPool <IntPoint> .Claim();

                if (this.useRotation)
                {
                    Matrix4x4 localToWorldMatrix = this.tr.localToWorldMatrix;
                    list.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(-this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f)));
                    list.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f)));
                    list.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f)));
                    list.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix.MultiplyPoint3x4(this.center + new Vector3(-this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f)));
                }
                else
                {
                    a += this.center;
                    list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(-this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f));
                    list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(this.rectangleSize.x, 0f, -this.rectangleSize.y) * 0.5f));
                    list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f));
                    list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(-this.rectangleSize.x, 0f, this.rectangleSize.y) * 0.5f));
                }
                buffer.Add(list);
                break;
            }

            case NavmeshCut.MeshType.Circle:
            {
                List <IntPoint> list = ListPool <IntPoint> .Claim(this.circleResolution);

                if (this.useRotation)
                {
                    Matrix4x4 localToWorldMatrix2 = this.tr.localToWorldMatrix;
                    for (int i = 0; i < this.circleResolution; i++)
                    {
                        list.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix2.MultiplyPoint3x4(this.center + new Vector3(Mathf.Cos((float)(i * 2) * 3.14159274f / (float)this.circleResolution), 0f, Mathf.Sin((float)(i * 2) * 3.14159274f / (float)this.circleResolution)) * this.circleRadius)));
                    }
                }
                else
                {
                    a += this.center;
                    for (int j = 0; j < this.circleResolution; j++)
                    {
                        list.Add(NavmeshCut.V3ToIntPoint(a + new Vector3(Mathf.Cos((float)(j * 2) * 3.14159274f / (float)this.circleResolution), 0f, Mathf.Sin((float)(j * 2) * 3.14159274f / (float)this.circleResolution)) * this.circleRadius));
                    }
                }
                buffer.Add(list);
                break;
            }

            case NavmeshCut.MeshType.CustomMesh:
                if (this.mesh != this.lastMesh || this.contours == null)
                {
                    this.CalculateMeshContour();
                    this.lastMesh = this.mesh;
                }
                if (this.contours != null)
                {
                    a += this.center;
                    bool flag = Vector3.Dot(this.tr.up, Vector3.up) < 0f;
                    for (int k = 0; k < this.contours.Length; k++)
                    {
                        Vector3[]       array = this.contours[k];
                        List <IntPoint> list  = ListPool <IntPoint> .Claim(array.Length);

                        if (this.useRotation)
                        {
                            Matrix4x4 localToWorldMatrix3 = this.tr.localToWorldMatrix;
                            for (int l = 0; l < array.Length; l++)
                            {
                                list.Add(NavmeshCut.V3ToIntPoint(localToWorldMatrix3.MultiplyPoint3x4(this.center + array[l] * this.meshScale)));
                            }
                        }
                        else
                        {
                            for (int m = 0; m < array.Length; m++)
                            {
                                list.Add(NavmeshCut.V3ToIntPoint(a + array[m] * this.meshScale));
                            }
                        }
                        if (flag)
                        {
                            list.Reverse();
                        }
                        buffer.Add(list);
                    }
                }
                break;
            }
        }
示例#29
0
        public void ForceUpdate()
        {
            if (this.handler == null)
            {
                throw new Exception("Cannot update graphs. No TileHandler. Do not call this method in Awake.");
            }
            this.lastUpdateTime = Time.realtimeSinceStartup;
            List <NavmeshCut> all = NavmeshCut.GetAll();

            if (!this.handler.isValid)
            {
                Debug.Log("TileHandler no longer matched the underlaying RecastGraph (possibly because of a graph scan). Recreating TileHandler...");
                this.handler = new TileHandler(this.handler.graph);
                this.handler.CreateTileTypesFromGraph();
                this.forcedReloadBounds.Add(new Bounds(Vector3.zero, new Vector3(1E+07f, 1E+07f, 1E+07f)));
            }
            if (this.forcedReloadBounds.Count == 0)
            {
                int num = 0;
                for (int m = 0; m < all.Count; m++)
                {
                    if (all[m].RequiresUpdate())
                    {
                        num++;
                        break;
                    }
                }
                if (num == 0)
                {
                    return;
                }
            }
            bool flag = this.handler.StartBatchLoad();

            for (int i = 0; i < this.forcedReloadBounds.Count; i++)
            {
                this.handler.ReloadInBounds(this.forcedReloadBounds[i]);
            }
            this.forcedReloadBounds.Clear();
            for (int j = 0; j < all.Count; j++)
            {
                if (all[j].enabled)
                {
                    if (all[j].RequiresUpdate())
                    {
                        this.handler.ReloadInBounds(all[j].LastBounds);
                        this.handler.ReloadInBounds(all[j].GetBounds());
                    }
                }
                else if (all[j].RequiresUpdate())
                {
                    this.handler.ReloadInBounds(all[j].LastBounds);
                }
            }
            for (int k = 0; k < all.Count; k++)
            {
                if (all[k].RequiresUpdate())
                {
                    all[k].NotifyUpdated();
                }
            }
            if (flag)
            {
                this.handler.EndBatchLoad();
            }
        }
示例#30
0
		private static void RemoveCut (NavmeshCut obj) {
			allCuts.Remove (obj);
		}
示例#31
0
        // Token: 0x06000738 RID: 1848 RVA: 0x000468DC File Offset: 0x00044CDC
        public void ForceUpdate()
        {
            if (this.handlers.Count == 0)
            {
                throw new Exception("Cannot update graphs. No TileHandler. Do not call this method in Awake.");
            }
            if (this.updateIndex >= this.handlers.Count - 1)
            {
                this.updateIndex = -1;
            }
            this.updateIndex++;
            this.lastUpdateTime = Time.realtimeSinceStartup;
            TileHandler       tileHandler = this.handlers[this.updateIndex];
            List <NavmeshCut> allInRange  = NavmeshCut.GetAllInRange(tileHandler.graph.forcedBounds);

            if (this.forcedReloadBounds.Count == 0)
            {
                int num = 0;
                for (int i = 0; i < allInRange.Count; i++)
                {
                    if (allInRange[i].RequiresUpdate())
                    {
                        num++;
                        break;
                    }
                }
                if (num == 0)
                {
                    ListPool <NavmeshCut> .Release(allInRange);

                    return;
                }
            }
            bool flag = tileHandler.StartBatchLoad();

            for (int j = 0; j < this.forcedReloadBounds.Count; j++)
            {
                tileHandler.ReloadInBounds(this.forcedReloadBounds[j]);
            }
            for (int k = 0; k < allInRange.Count; k++)
            {
                if (allInRange[k].enabled)
                {
                    if (allInRange[k].RequiresUpdate())
                    {
                        tileHandler.ReloadInBounds(allInRange[k].LastBounds);
                        tileHandler.ReloadInBounds(allInRange[k].GetBounds());
                    }
                }
                else if (allInRange[k].RequiresUpdate())
                {
                    tileHandler.ReloadInBounds(allInRange[k].LastBounds);
                }
            }
            for (int l = 0; l < allInRange.Count; l++)
            {
                if (allInRange[l].RequiresUpdate())
                {
                    allInRange[l].NotifyUpdated();
                }
            }
            ListPool <NavmeshCut> .Release(allInRange);

            if (flag)
            {
                tileHandler.EndBatchLoad();
            }
            this.forcedReloadBounds.Clear();
        }
示例#32
0
        /** Checks all NavmeshCut instances and updates graphs if needed.
         * \note This schedules updates for all necessary tiles to happen as soon as possible.
         * The pathfinding threads will continue to calculate the paths that they were calculating when this function
         * was called and then they will be paused and the graph updates will be carried out (this may be several frames into the
         * future and the graph updates themselves may take several frames to complete).
         * If you want to force all navmesh cutting to be completed in a single frame call this method
         * and immediately after call AstarPath.FlushWorkItems.
         */
        public void ForceUpdate()
        {
            if (handler == null)
            {
                throw new System.Exception("Cannot update graphs. No TileHandler. Do not call this method in Awake.");
            }

            lastUpdateTime = Time.realtimeSinceStartup;

            // Get all navmesh cuts in the scene
            List <NavmeshCut> cuts = NavmeshCut.GetAll();

            if (!handler.isValid)
            {
                Debug.Log("TileHandler no longer matched the underlaying RecastGraph (possibly because of a graph scan). Recreating TileHandler...");
                handler = new TileHandler(handler.graph);
                handler.CreateTileTypesFromGraph();

                // Reload in huge bounds. Cannot use infinity because that will not convert well to integers
                // This will cause all tiles to be updated
                forcedReloadBounds.Add(new Bounds(Vector3.zero, new Vector3(10000000, 10000000, 10000000)));
            }

            if (forcedReloadBounds.Count == 0)
            {
                int any = 0;

                // Check if any navmesh cuts need updating
                for (int i = 0; i < cuts.Count; i++)
                {
                    if (cuts[i].RequiresUpdate())
                    {
                        any++;
                        break;
                    }
                }

                // Nothing needs to be done for now
                if (any == 0)
                {
                    return;
                }
            }

            // Start batching tile updates which is good for performance
            // if we are updating a lot of them
            bool end = handler.StartBatchLoad();

            // Reload all tiles which touch the bounds in the forcedReloadBounds list
            for (int i = 0; i < forcedReloadBounds.Count; i++)
            {
                handler.ReloadInBounds(forcedReloadBounds[i]);
            }
            forcedReloadBounds.Clear();

            // Reload all bounds touching the previous bounds and current bounds
            // of navmesh cuts that have moved or changed in some other way
            for (int i = 0; i < cuts.Count; i++)
            {
                if (cuts[i].enabled)
                {
                    if (cuts[i].RequiresUpdate())
                    {
                        handler.ReloadInBounds(cuts[i].LastBounds);
                        handler.ReloadInBounds(cuts[i].GetBounds());
                    }
                }
                else if (cuts[i].RequiresUpdate())
                {
                    // The navmesh cut has been disabled
                    // Make sure the tile where it was is updated
                    handler.ReloadInBounds(cuts[i].LastBounds);
                }
            }

            // Notify navmesh cuts that they have been updated
            // This will cause RequiresUpdate to return false
            // until it is changed again
            for (int i = 0; i < cuts.Count; i++)
            {
                if (cuts[i].RequiresUpdate())
                {
                    cuts[i].NotifyUpdated();
                }
            }

            if (end)
            {
                handler.EndBatchLoad();
            }
        }