Normal2D() public méthode

public Normal2D ( ) : Int3
Résultat Int3
Exemple #1
0
        public void Apply(bool forceNewCheck)
        {
            NNConstraint none = NNConstraint.None;

            none.distanceXZ = true;
            int graphIndex = (int)this.startNode.GraphIndex;

            none.graphMask = ~(((int)1) << graphIndex);
            bool   flag    = true;
            NNInfo nearest = AstarPath.active.GetNearest(this.StartTransform.position, none);

            flag &= (nearest.node == this.connectedNode1) && (nearest.node != null);
            this.connectedNode1 = nearest.node as MeshNode;
            this.clamped1       = nearest.position;
            if (this.connectedNode1 != null)
            {
                Debug.DrawRay((Vector3)this.connectedNode1.position, (Vector3)(Vector3.up * 5f), Color.red);
            }
            NNInfo info2 = AstarPath.active.GetNearest(this.EndTransform.position, none);

            flag &= (info2.node == this.connectedNode2) && (info2.node != null);
            this.connectedNode2 = info2.node as MeshNode;
            this.clamped2       = info2.position;
            if (this.connectedNode2 != null)
            {
                Debug.DrawRay((Vector3)this.connectedNode2.position, (Vector3)(Vector3.up * 5f), Color.cyan);
            }
            if ((this.connectedNode2 != null) && (this.connectedNode1 != null))
            {
                this.startNode.SetPosition((Int3)this.StartTransform.position);
                this.endNode.SetPosition((Int3)this.EndTransform.position);
                if (!flag || forceNewCheck)
                {
                    this.RemoveConnections(this.startNode);
                    this.RemoveConnections(this.endNode);
                    Int3 num12 = (Int3)(this.StartTransform.position - this.EndTransform.position);
                    uint cost  = (uint)Mathf.RoundToInt(num12.costMagnitude * this.costFactor);
                    this.startNode.AddConnection(this.endNode, cost);
                    this.endNode.AddConnection(this.startNode, cost);
                    Int3 rhs = this.connectedNode2.position - this.connectedNode1.position;
                    for (int i = 0; i < this.connectedNode1.GetVertexCount(); i++)
                    {
                        Int3 vertex  = this.connectedNode1.GetVertex(i);
                        Int3 lineEnd = this.connectedNode1.GetVertex((i + 1) % this.connectedNode1.GetVertexCount());
                        Int3 num13   = lineEnd - vertex;
                        if (Int3.DotLong(num13.Normal2D(), rhs) <= 0L)
                        {
                            for (int j = 0; j < this.connectedNode2.GetVertexCount(); j++)
                            {
                                Int3 point = this.connectedNode2.GetVertex(j);
                                Int3 num9  = this.connectedNode2.GetVertex((j + 1) % this.connectedNode2.GetVertexCount());
                                Int3 num14 = num9 - point;
                                if ((Int3.DotLong(num14.Normal2D(), rhs) >= 0L) && (Int3.Angle(num9 - point, lineEnd - vertex) > 2.9670598109563189))
                                {
                                    float num10 = 0f;
                                    float num11 = 1f;
                                    num11 = Math.Min(num11, VectorMath.ClosestPointOnLineFactor(vertex, lineEnd, point));
                                    num10 = Math.Max(num10, VectorMath.ClosestPointOnLineFactor(vertex, lineEnd, num9));
                                    if (num11 >= num10)
                                    {
                                        Vector3 vector  = ((Vector3)(((Vector3)(lineEnd - vertex)) * num10)) + ((Vector3)vertex);
                                        Vector3 vector2 = ((Vector3)(((Vector3)(lineEnd - vertex)) * num11)) + ((Vector3)vertex);
                                        this.startNode.portalA = vector;
                                        this.startNode.portalB = vector2;
                                        this.endNode.portalA   = vector2;
                                        this.endNode.portalB   = vector;
                                        Int3 num15 = (Int3)(this.clamped1 - this.StartTransform.position);
                                        this.connectedNode1.AddConnection(this.startNode, (uint)Mathf.RoundToInt(num15.costMagnitude * this.costFactor));
                                        Int3 num16 = (Int3)(this.clamped2 - this.EndTransform.position);
                                        this.connectedNode2.AddConnection(this.endNode, (uint)Mathf.RoundToInt(num16.costMagnitude * this.costFactor));
                                        Int3 num17 = (Int3)(this.clamped1 - this.StartTransform.position);
                                        this.startNode.AddConnection(this.connectedNode1, (uint)Mathf.RoundToInt(num17.costMagnitude * this.costFactor));
                                        Int3 num18 = (Int3)(this.clamped2 - this.EndTransform.position);
                                        this.endNode.AddConnection(this.connectedNode2, (uint)Mathf.RoundToInt(num18.costMagnitude * this.costFactor));
                                        return;
                                    }
                                    Debug.LogError(string.Concat(new object[] { "Wait wut!? ", num10, " ", num11, " ", vertex, " ", lineEnd, " ", point, " ", num9, "\nTODO, fix this error" }));
                                }
                            }
                        }
                    }
                }
            }
        }