// Token: 0x060024D3 RID: 9427 RVA: 0x0019D2FC File Offset: 0x0019B4FC
 public void Initialize(GraphTransform transform, float scale)
 {
     this.up                 = (transform.Transform(Vector3.up) - transform.Transform(Vector3.zero)).normalized;
     this.upheight           = this.up * this.height;
     this.finalRadius        = this.diameter * scale * 0.5f;
     this.finalRaycastRadius = this.thickRaycastDiameter * scale * 0.5f;
 }
Beispiel #2
0
 /** Sets up several variables using the specified matrix and scale.
  * \see GraphCollision.up
  * \see GraphCollision.upheight
  * \see GraphCollision.finalRadius
  * \see GraphCollision.finalRaycastRadius
  */
 public void Initialize(GraphTransform transform, float scale)
 {
     up                 = (transform.Transform(Vector3.up) - transform.Transform(Vector3.zero)).normalized;
     upheight           = up * height;
     finalRadius        = diameter * scale * 0.5F;
     finalRaycastRadius = thickRaycastDiameter * scale * 0.5F;
 }
Beispiel #3
0
 /// <summary>
 /// Sets up several variables using the specified matrix and scale.
 /// See: GraphCollision.up
 /// See: GraphCollision.upheight
 /// See: GraphCollision.finalRadius
 /// See: GraphCollision.finalRaycastRadius
 /// </summary>
 public void Initialize(GraphTransform transform, float scale)
 {
     up                 = (transform.Transform(Vector3.up) - transform.Transform(Vector3.zero)).normalized;
     upheight           = up * height;
     finalRadius        = diameter * scale * 0.5F;
     finalRaycastRadius = thickRaycastDiameter * scale * 0.5F;
     contactFilter      = new ContactFilter2D {
         layerMask = mask, useDepth = false, useLayerMask = true, useNormalAngle = false, useTriggers = false
     };
 }
        /** Draws some debug lines representing the rect */
        public void DebugDraw(GraphTransform transform, Color color)
        {
            Vector3 p1 = transform.Transform(new Vector3(xmin, 0, ymin));
            Vector3 p2 = transform.Transform(new Vector3(xmin, 0, ymax));
            Vector3 p3 = transform.Transform(new Vector3(xmax, 0, ymax));
            Vector3 p4 = transform.Transform(new Vector3(xmax, 0, ymin));

            Debug.DrawLine(p1, p2, color);
            Debug.DrawLine(p2, p3, color);
            Debug.DrawLine(p3, p4, color);
            Debug.DrawLine(p4, p1, color);
        }
        // Token: 0x0600246E RID: 9326 RVA: 0x0019C23C File Offset: 0x0019A43C
        public void DebugDraw(GraphTransform transform, Color color)
        {
            Vector3 vector  = transform.Transform(new Vector3((float)this.xmin, 0f, (float)this.ymin));
            Vector3 vector2 = transform.Transform(new Vector3((float)this.xmin, 0f, (float)this.ymax));
            Vector3 vector3 = transform.Transform(new Vector3((float)this.xmax, 0f, (float)this.ymax));
            Vector3 vector4 = transform.Transform(new Vector3((float)this.xmax, 0f, (float)this.ymin));

            Debug.DrawLine(vector, vector2, color);
            Debug.DrawLine(vector2, vector3, color);
            Debug.DrawLine(vector3, vector4, color);
            Debug.DrawLine(vector4, vector, color);
        }
Beispiel #6
0
        public static Bounds Transform(this GraphTransform self, Bounds bounds)
        {
            if (self.onlyTranslational)
            {
                return(new Bounds(bounds.center + self.translation.ToUnityV3(), bounds.size));
            }

            var corners = PF.ArrayPool <Vector3> .Claim(8);

            var extents = bounds.extents;

            corners[0] = self.Transform(bounds.center + new Vector3(extents.x, extents.y, extents.z));
            corners[1] = self.Transform(bounds.center + new Vector3(extents.x, extents.y, -extents.z));
            corners[2] = self.Transform(bounds.center + new Vector3(extents.x, -extents.y, extents.z));
            corners[3] = self.Transform(bounds.center + new Vector3(extents.x, -extents.y, -extents.z));
            corners[4] = self.Transform(bounds.center + new Vector3(-extents.x, extents.y, extents.z));
            corners[5] = self.Transform(bounds.center + new Vector3(-extents.x, extents.y, -extents.z));
            corners[6] = self.Transform(bounds.center + new Vector3(-extents.x, -extents.y, extents.z));
            corners[7] = self.Transform(bounds.center + new Vector3(-extents.x, -extents.y, -extents.z));

            var min = corners[0];
            var max = corners[0];

            for (int i = 1; i < 8; i++)
            {
                min = Vector3.Min(min, corners[i]);
                max = Vector3.Max(max, corners[i]);
            }
            PF.ArrayPool <Vector3> .Release(ref corners);

            return(new Bounds((min + max) * 0.5f, max - min));
        }
Beispiel #7
0
        public void DrawTransformGizmos(GraphTransform t, Vector3 pivotPoint, Vector3 forward, Vector3 up)
        {
            Vector3 pivotWorld = t.Transform(pivotPoint);
            Vector3 xWorld     = t.Transform(forward).normalized;
            Vector3 yWorld     = t.Transform(up).normalized;
            Vector3 zWorld     = Vector3.Cross(xWorld, yWorld);

            yWorld = Vector3.Cross(zWorld, xWorld);
            yWorld.Normalize();
            xWorld.Normalize();
            // Gizmos.color = Color.red;
            // Gizmos.DrawLine(pivotWorld, pivotWorld + xWorld);
            // Gizmos.color = Color.green;
            // Gizmos.DrawLine(pivotWorld, pivotWorld + yWorld);
            // Gizmos.color = Color.blue;
            // Gizmos.DrawLine(pivotWorld, pivotWorld + zWorld);
        }
Beispiel #8
0
        // Token: 0x06002696 RID: 9878 RVA: 0x001A8890 File Offset: 0x001A6A90
        public void OnDrawGizmosSelected()
        {
            List <List <Vector3> > list = ListPool <List <Vector3> > .Claim();

            this.GetContour(list);
            Color color = Color.Lerp(NavmeshCut.GizmoColor, Color.white, 0.5f);

            color.a     *= 0.5f;
            Gizmos.color = color;
            NavmeshBase    navmeshBase    = (AstarPath.active != null) ? (AstarPath.active.data.recastGraph ?? AstarPath.active.data.navmesh) : null;
            GraphTransform graphTransform = (navmeshBase != null) ? navmeshBase.transform : GraphTransform.identityTransform;
            float          y  = this.GetY(graphTransform);
            float          y2 = y - this.height * 0.5f;
            float          y3 = y + this.height * 0.5f;

            for (int i = 0; i < list.Count; i++)
            {
                List <Vector3> list2 = list[i];
                for (int j = 0; j < list2.Count; j++)
                {
                    Vector3 vector  = graphTransform.InverseTransform(list2[j]);
                    Vector3 vector2 = graphTransform.InverseTransform(list2[(j + 1) % list2.Count]);
                    Vector3 point   = vector;
                    Vector3 point2  = vector2;
                    Vector3 point3  = vector;
                    Vector3 point4  = vector2;
                    point.y  = (point2.y = y2);
                    point3.y = (point4.y = y3);
                    Gizmos.DrawLine(graphTransform.Transform(point), graphTransform.Transform(point2));
                    Gizmos.DrawLine(graphTransform.Transform(point3), graphTransform.Transform(point4));
                    Gizmos.DrawLine(graphTransform.Transform(point), graphTransform.Transform(point3));
                }
            }
            ListPool <List <Vector3> > .Release(ref list);
        }
        public override void OnSceneGUI(NavGraph target)
        {
            Event e = Event.current;

            var graph = target as GridGraph;

            graph.UpdateTransform();
            var currentTransform = graph.transform * Matrix4x4.Scale(new Vector3(graph.width, 1, graph.depth));

            if (e.type == EventType.MouseDown)
            {
                isMouseDown = true;
            }
            else if (e.type == EventType.MouseUp)
            {
                isMouseDown = false;
            }

            if (!isMouseDown)
            {
                savedTransform  = currentTransform;
                savedDimensions = new Vector2(graph.width, graph.depth);
                savedNodeSize   = graph.nodeSize;
            }

            Handles.matrix = Matrix4x4.identity;
            Handles.color  = AstarColor.BoundsHandles;
#if UNITY_5_5_OR_NEWER
            Handles.CapFunction cap = Handles.CylinderHandleCap;
#else
            Handles.DrawCapFunction cap = Handles.CylinderCap;
#endif

            var center = currentTransform.Transform(new Vector3(0.5f, 0, 0.5f));
            if (Tools.current == Tool.Scale)
            {
                const float HandleScale = 0.1f;

                Vector3 mn = Vector3.zero;
                Vector3 mx = Vector3.zero;
                EditorGUI.BeginChangeCheck();
                for (int i = 0; i < handlePoints.Length; i++)
                {
                    var     ps = currentTransform.Transform(handlePoints[i]);
                    Vector3 p  = savedTransform.InverseTransform(Handles.Slider(ps, ps - center, HandleScale * HandleUtility.GetHandleSize(ps), cap, 0));

                    // Snap to increments of whole nodes
                    p.x = Mathf.Round(p.x * savedDimensions.x) / savedDimensions.x;
                    p.z = Mathf.Round(p.z * savedDimensions.y) / savedDimensions.y;

                    if (i == 0)
                    {
                        mn = mx = p;
                    }
                    else
                    {
                        mn = Vector3.Min(mn, p);
                        mx = Vector3.Max(mx, p);
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    graph.center        = savedTransform.Transform((mn + mx) * 0.5f);
                    graph.unclampedSize = Vector2.Scale(new Vector2(mx.x - mn.x, mx.z - mn.z), savedDimensions) * savedNodeSize;
                }
            }
            else if (Tools.current == Tool.Move)
            {
                EditorGUI.BeginChangeCheck();
                center = Handles.PositionHandle(graph.center, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : Quaternion.Euler(graph.rotation));

                if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit)
                {
                    graph.center = center;
                }
            }
            else if (Tools.current == Tool.Rotate)
            {
                EditorGUI.BeginChangeCheck();
                var rot = Handles.RotationHandle(Quaternion.Euler(graph.rotation), graph.center);

                if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit)
                {
                    graph.rotation = rot.eulerAngles;
                }
            }

            Handles.matrix = Matrix4x4.identity;
        }
Beispiel #10
0
        private static void FindAllContours(GridGraph grid, Action <Vector3[], bool> callback, GridNodeBase[] nodes = null)
        {
            if (grid is LayerGridGraph)
            {
                nodes = (nodes ?? (grid as LayerGridGraph).nodes);
            }
            nodes = (nodes ?? grid.nodes);
            int[] neighbourXOffsets = grid.neighbourXOffsets;
            int[] neighbourZOffsets = grid.neighbourZOffsets;
            int[] array;
            if (grid.neighbours == NumNeighbours.Six)
            {
                array = GridGraph.hexagonNeighbourIndices;
            }
            else
            {
                RuntimeHelpers.InitializeArray(array = new int[4], fieldof(< PrivateImplementationDetails >.$field - 02E4414E7DFA0F3AA2387EE8EA7AB31431CB406A).FieldHandle);
            }
            int[] array2 = array;
            float num    = (grid.neighbours != NumNeighbours.Six) ? 0.5f : 0.333333343f;

            if (nodes != null)
            {
                Dictionary <Int3, int> dictionary  = new Dictionary <Int3, int>();
                Dictionary <int, int>  dictionary2 = new Dictionary <int, int>();
                HashSet <int>          hashSet     = new HashSet <int>();
                List <Vector3>         vertices    = ListPool <Vector3> .Claim();

                foreach (GridNodeBase gridNodeBase in nodes)
                {
                    if (gridNodeBase != null && gridNodeBase.Walkable && !gridNodeBase.HasConnectionsToAllEightNeighbours)
                    {
                        for (int j = 0; j < array2.Length; j++)
                        {
                            int num2 = array2[j];
                            if (gridNodeBase.GetNeighbourAlongDirection(num2) == null)
                            {
                                int     num3   = array2[(j - 1 + array2.Length) % array2.Length];
                                int     num4   = array2[(j + 1) % array2.Length];
                                Vector3 vector = new Vector3((float)gridNodeBase.XCoordinateInGrid + 0.5f, 0f, (float)gridNodeBase.ZCoordinateInGrid + 0.5f);
                                vector.x += (float)neighbourXOffsets[num2] * num;
                                vector.z += (float)neighbourZOffsets[num2] * num;
                                vector.y  = grid.transform.InverseTransform((Vector3)gridNodeBase.position).y;
                                Vector3 vector3;
                                Vector3 vector2 = vector3 = vector;
                                vector3.x += (float)neighbourXOffsets[num3] * num;
                                vector3.z += (float)neighbourZOffsets[num3] * num;
                                vector2.x += (float)neighbourXOffsets[num4] * num;
                                vector2.z += (float)neighbourZOffsets[num4] * num;
                                Int3 key  = (Int3)vector3;
                                Int3 key2 = (Int3)vector2;
                                int  key3;
                                if (dictionary.TryGetValue(key, out key3))
                                {
                                    dictionary.Remove(key);
                                }
                                else
                                {
                                    int count = vertices.Count;
                                    dictionary[key] = count;
                                    key3            = count;
                                    vertices.Add(vector3);
                                }
                                int num5;
                                if (dictionary.TryGetValue(key2, out num5))
                                {
                                    dictionary.Remove(key2);
                                }
                                else
                                {
                                    int count = vertices.Count;
                                    dictionary[key2] = count;
                                    num5             = count;
                                    vertices.Add(vector2);
                                }
                                dictionary2.Add(key3, num5);
                                hashSet.Add(num5);
                            }
                        }
                    }
                }
                GraphTransform transform    = grid.transform;
                List <Vector3> vertexBuffer = ListPool <Vector3> .Claim();

                RVONavmesh.CompressContour(dictionary2, hashSet, delegate(List <int> chain, bool cycle)
                {
                    vertexBuffer.Clear();
                    Vector3 vector4 = vertices[chain[0]];
                    vertexBuffer.Add(vector4);
                    for (int k = 1; k < chain.Count - 1; k++)
                    {
                        Vector3 vector5 = vertices[chain[k]];
                        Vector3 vector6 = vector5 - vector4;
                        Vector3 vector7 = vertices[chain[k + 1]] - vector4;
                        if (((Mathf.Abs(vector6.x) > 0.01f || Mathf.Abs(vector7.x) > 0.01f) && (Mathf.Abs(vector6.z) > 0.01f || Mathf.Abs(vector7.z) > 0.01f)) || Mathf.Abs(vector6.y) > 0.01f || Mathf.Abs(vector7.y) > 0.01f)
                        {
                            vertexBuffer.Add(vector5);
                        }
                        vector4 = vector5;
                    }
                    vertexBuffer.Add(vertices[chain[chain.Count - 1]]);
                    Vector3[] array3 = vertexBuffer.ToArray();
                    transform.Transform(array3);
                    callback(array3, cycle);
                });
                ListPool <Vector3> .Release(vertexBuffer);

                ListPool <Vector3> .Release(vertices);
            }
        }
Beispiel #11
0
            public void DrawWireCube(GraphTransform tr, Bounds bounds, Color color)
            {
                var min = bounds.min;
                var max = bounds.max;

                DrawLine(tr.Transform(new Vector3(min.x, min.y, min.z)), tr.Transform(new Vector3(max.x, min.y, min.z)), color);
                DrawLine(tr.Transform(new Vector3(max.x, min.y, min.z)), tr.Transform(new Vector3(max.x, min.y, max.z)), color);
                DrawLine(tr.Transform(new Vector3(max.x, min.y, max.z)), tr.Transform(new Vector3(min.x, min.y, max.z)), color);
                DrawLine(tr.Transform(new Vector3(min.x, min.y, max.z)), tr.Transform(new Vector3(min.x, min.y, min.z)), color);

                DrawLine(tr.Transform(new Vector3(min.x, max.y, min.z)), tr.Transform(new Vector3(max.x, max.y, min.z)), color);
                DrawLine(tr.Transform(new Vector3(max.x, max.y, min.z)), tr.Transform(new Vector3(max.x, max.y, max.z)), color);
                DrawLine(tr.Transform(new Vector3(max.x, max.y, max.z)), tr.Transform(new Vector3(min.x, max.y, max.z)), color);
                DrawLine(tr.Transform(new Vector3(min.x, max.y, max.z)), tr.Transform(new Vector3(min.x, max.y, min.z)), color);

                DrawLine(tr.Transform(new Vector3(min.x, min.y, min.z)), tr.Transform(new Vector3(min.x, max.y, min.z)), color);
                DrawLine(tr.Transform(new Vector3(max.x, min.y, min.z)), tr.Transform(new Vector3(max.x, max.y, min.z)), color);
                DrawLine(tr.Transform(new Vector3(max.x, min.y, max.z)), tr.Transform(new Vector3(max.x, max.y, max.z)), color);
                DrawLine(tr.Transform(new Vector3(min.x, min.y, max.z)), tr.Transform(new Vector3(min.x, max.y, max.z)), color);
            }