예제 #1
0
 public void OnDrawGizmos()
 {
     if (this.points.Length >= 3)
     {
         for (int i = 0; i < this.points.Length; i++)
         {
             if (this.points[i] == null)
             {
                 return;
             }
         }
         for (int j = 0; j < this.points.Length; j++)
         {
             int     num         = this.points.Length;
             Vector3 normalized  = ((this.points[(j + 1) % num].position - this.points[j].position).normalized - (this.points[(j - 1 + num) % num].position - this.points[j].position).normalized).normalized;
             Vector3 normalized2 = ((this.points[(j + 2) % num].position - this.points[(j + 1) % num].position).normalized - (this.points[(j + num) % num].position - this.points[(j + 1) % num].position).normalized).normalized;
             Vector3 from        = this.points[j].position;
             for (int k = 1; k <= 100; k++)
             {
                 Vector3 vector = AstarSplines.CubicBezier(this.points[j].position, this.points[j].position + normalized * this.tangentLengths, this.points[(j + 1) % num].position - normalized2 * this.tangentLengths, this.points[(j + 1) % num].position, (float)k / 100f);
                 Gizmos.DrawLine(from, vector);
                 from = vector;
             }
         }
     }
 }
예제 #2
0
        public void Bezier(Vector3 a, Vector3 b, Color color)
        {
            Vector3 dir = b - a;

            if (dir == Vector3.zero)
            {
                return;
            }

            Vector3 normal   = Vector3.Cross(Vector3.up, dir);
            Vector3 normalUp = Vector3.Cross(dir, normal);

            normalUp  = normalUp.normalized;
            normalUp *= dir.magnitude * 0.1f;

            Vector3 p1c = a + normalUp;
            Vector3 p2c = b + normalUp;

            Vector3 prev = a;

            for (int i = 1; i <= 20; i++)
            {
                float   t = i / 20.0f;
                Vector3 p = AstarSplines.CubicBezier(a, p1c, p2c, b, t);
                Line(prev, p, color);
                prev = p;
            }
        }
예제 #3
0
        Vector3 Position(float t)
        {
            int c  = points.Length;
            int pt = Mathf.FloorToInt(t) % c;

            return(AstarSplines.CatmullRom(points[(pt - 1 + c) % c].position, points[pt].position, points[(pt + 1) % c].position, points[(pt + 2) % c].position, t - Mathf.FloorToInt(t)));
        }
예제 #4
0
    public void OnDrawGizmos()
    {
        if (points.Length >= 3)
        {
            for (int i = 0; i < points.Length; i++)
            {
                if (points[i] == null)
                {
                    return;
                }
            }

            for (int pt = 0; pt < points.Length; pt++)
            {
                int     c      = points.Length;
                Vector3 inTang = ((points[(pt + 1) % c].position - points[pt + 0].position).normalized - (points[(pt - 1 + c) % c].position - points[pt + 0].position).normalized).normalized;

                Vector3 outTang = ((points[(pt + 2) % c].position - points[(pt + 1) % c].position).normalized - (points[(pt - 0 + c) % c].position - points[(pt + 1) % c].position).normalized).normalized;

                Vector3 pp = points[pt].position;

                for (int i = 1; i <= 100; i++)
                {
                    Vector3 p = AstarSplines.CubicBezier(points[pt].position, points[pt].position + inTang * tangentLengths, points[(pt + 1) % c].position - outTang * tangentLengths, points[(pt + 1) % c].position, i / 100.0f);
                    Gizmos.DrawLine(pp, p);
                    pp = p;
                }
            }
        }
    }
예제 #5
0
        /// <summary>Interpolates the unit along the path</summary>
        static IEnumerator MoveAlongPath(TurnBasedAI unit, ABPath path, float speed)
        {
            if (path.error || path.vectorPath.Count == 0)
            {
                throw new System.ArgumentException("Cannot follow an empty path");
            }

            // Very simple movement, just interpolate using a catmull rom spline
            float distanceAlongSegment = 0;

            for (int i = 0; i < path.vectorPath.Count - 1; i++)
            {
                var p0 = path.vectorPath[Mathf.Max(i - 1, 0)];
                // Start of current segment
                var p1 = path.vectorPath[i];
                // End of current segment
                var p2 = path.vectorPath[i + 1];
                var p3 = path.vectorPath[Mathf.Min(i + 2, path.vectorPath.Count - 1)];

                var segmentLength = Vector3.Distance(p1, p2);

                while (distanceAlongSegment < segmentLength)
                {
                    var interpolatedPoint = AstarSplines.CatmullRom(p0, p1, p2, p3, distanceAlongSegment / segmentLength);
                    unit.transform.position = interpolatedPoint;
                    yield return(null);

                    distanceAlongSegment += Time.deltaTime * speed;
                }

                distanceAlongSegment -= segmentLength;
            }

            unit.transform.position = path.vectorPath[path.vectorPath.Count - 1];
        }
        // Token: 0x06002A2E RID: 10798 RVA: 0x001C739F File Offset: 0x001C559F
        private static IEnumerator MoveAlongPath(TurnBasedAI unit, ABPath path, float speed)
        {
            if (path.error || path.vectorPath.Count == 0)
            {
                throw new ArgumentException("Cannot follow an empty path");
            }
            float distanceAlongSegment = 0f;
            int   num;

            for (int i = 0; i < path.vectorPath.Count - 1; i = num + 1)
            {
                Vector3 p0            = path.vectorPath[Mathf.Max(i - 1, 0)];
                Vector3 p             = path.vectorPath[i];
                Vector3 p2            = path.vectorPath[i + 1];
                Vector3 p3            = path.vectorPath[Mathf.Min(i + 2, path.vectorPath.Count - 1)];
                float   segmentLength = Vector3.Distance(p, p2);
                while (distanceAlongSegment < segmentLength)
                {
                    Vector3 position = AstarSplines.CatmullRom(p0, p, p2, p3, distanceAlongSegment / segmentLength);
                    unit.transform.position = position;
                    yield return(null);

                    distanceAlongSegment += Time.deltaTime * speed;
                }
                distanceAlongSegment -= segmentLength;
                p0  = default(Vector3);
                p   = default(Vector3);
                p2  = default(Vector3);
                p3  = default(Vector3);
                num = i;
            }
            unit.transform.position = path.vectorPath[path.vectorPath.Count - 1];
            yield break;
        }
예제 #7
0
        // Token: 0x06002A11 RID: 10769 RVA: 0x001C6DC0 File Offset: 0x001C4FC0
        private Vector3 Position(float t)
        {
            int num  = this.points.Length;
            int num2 = Mathf.FloorToInt(t) % num;

            return(AstarSplines.CatmullRom(this.points[(num2 - 1 + num) % num].position, this.points[num2].position, this.points[(num2 + 1) % num].position, this.points[(num2 + 2) % num].position, t - (float)Mathf.FloorToInt(t)));
        }
예제 #8
0
 public void OnDrawGizmos()
 {
     if (this.points.Length >= 3)
     {
         for (int i = 0; i < this.points.Length; i++)
         {
             if (this.points[i] == null)
             {
                 return;
             }
         }
         for (int j = 0; j < this.points.Length; j++)
         {
             int     length     = this.points.Length;
             Vector3 vector5    = this.points[(j + 1) % length].position - this.points[j].position;
             Vector3 vector6    = this.points[((j - 1) + length) % length].position - this.points[j].position;
             Vector3 vector7    = vector5.normalized - vector6.normalized;
             Vector3 normalized = vector7.normalized;
             Vector3 vector8    = this.points[(j + 2) % length].position - this.points[(j + 1) % length].position;
             Vector3 vector9    = this.points[(j + length) % length].position - this.points[(j + 1) % length].position;
             Vector3 vector10   = vector8.normalized - vector9.normalized;
             Vector3 vector2    = vector10.normalized;
             Vector3 position   = this.points[j].position;
             for (int k = 1; k <= 100; k++)
             {
                 Vector3 to = AstarSplines.CubicBezier(this.points[j].position, this.points[j].position + ((Vector3)(normalized * this.tangentLengths)), this.points[(j + 1) % length].position - ((Vector3)(vector2 * this.tangentLengths)), this.points[(j + 1) % length].position, ((float)k) / 100f);
                 Gizmos.DrawLine(position, to);
                 position = to;
             }
         }
     }
 }
예제 #9
0
		private Vector3 Plot(float t)
		{
			int num = this.points.Length;
			int num2 = Mathf.FloorToInt(t);
			Vector3 normalized = ((this.points[(num2 + 1) % num].position - this.points[num2 % num].position).normalized - (this.points[(num2 - 1 + num) % num].position - this.points[num2 % num].position).normalized).normalized;
			Vector3 normalized2 = ((this.points[(num2 + 2) % num].position - this.points[(num2 + 1) % num].position).normalized - (this.points[(num2 + num) % num].position - this.points[(num2 + 1) % num].position).normalized).normalized;
			Debug.DrawLine(this.points[num2 % num].position, this.points[num2 % num].position + normalized * this.tangentLengths, Color.red);
			Debug.DrawLine(this.points[(num2 + 1) % num].position - normalized2 * this.tangentLengths, this.points[(num2 + 1) % num].position, Color.green);
			return AstarSplines.CubicBezier(this.points[num2 % num].position, this.points[num2 % num].position + normalized * this.tangentLengths, this.points[(num2 + 1) % num].position - normalized2 * this.tangentLengths, this.points[(num2 + 1) % num].position, t - (float)num2);
		}
예제 #10
0
    Vector3 Plot(float t)
    {
        Vector3 inTang, outTang;


        int c  = points.Length;
        int pt = Mathf.FloorToInt(t);

        inTang = ((points[(pt + 1) % c].position - points[(pt + 0) % c].position).normalized - (points[(pt - 1 + c) % c].position - points[(pt + 0) % c].position).normalized).normalized;

        outTang = ((points[(pt + 2) % c].position - points[(pt + 1) % c].position).normalized - (points[(pt - 0 + c) % c].position - points[(pt + 1) % c].position).normalized).normalized;

        Debug.DrawLine(points[pt % c].position, points[pt % c].position + inTang * tangentLengths, Color.red);
        Debug.DrawLine(points[(pt + 1) % c].position - outTang * tangentLengths, points[(pt + 1) % c].position, Color.green);

        return(AstarSplines.CubicBezier(points[pt % c].position, points[pt % c].position + inTang * tangentLengths, points[(pt + 1) % c].position - outTang * tangentLengths, points[(pt + 1) % c].position, t - pt));
    }
예제 #11
0
        private Vector3 Plot(float t)
        {
            int     length     = this.points.Length;
            int     num2       = Mathf.FloorToInt(t);
            Vector3 vector3    = this.points[(num2 + 1) % length].position - this.points[num2 % length].position;
            Vector3 vector4    = this.points[((num2 - 1) + length) % length].position - this.points[num2 % length].position;
            Vector3 vector5    = vector3.normalized - vector4.normalized;
            Vector3 normalized = vector5.normalized;
            Vector3 vector6    = this.points[(num2 + 2) % length].position - this.points[(num2 + 1) % length].position;
            Vector3 vector7    = this.points[(num2 + length) % length].position - this.points[(num2 + 1) % length].position;
            Vector3 vector8    = vector6.normalized - vector7.normalized;
            Vector3 vector2    = vector8.normalized;

            Debug.DrawLine(this.points[num2 % length].position, this.points[num2 % length].position + ((Vector3)(normalized * this.tangentLengths)), Color.red);
            Debug.DrawLine(this.points[(num2 + 1) % length].position - ((Vector3)(vector2 * this.tangentLengths)), this.points[(num2 + 1) % length].position, Color.green);
            return(AstarSplines.CubicBezier(this.points[num2 % length].position, this.points[num2 % length].position + ((Vector3)(normalized * this.tangentLengths)), this.points[(num2 + 1) % length].position - ((Vector3)(vector2 * this.tangentLengths)), this.points[(num2 + 1) % length].position, t - num2));
        }
예제 #12
0
    /// <summary>
    /// This method is called when the player clicks on an available pathnode and start moving the unit on the calculated path.
    /// </summary>
    /// <param name="unit"></param>
    /// <param name="path"></param>
    /// <param name="speed"></param>
    /// <returns></returns>

    private IEnumerator MoveAlongPath(Unit unit, ABPath path, float speed)
    {
        if (path.error || path.vectorPath.Count == 0)
        {
            throw new System.ArgumentException("Cannot follow an empty path");
        }

        unit.RemoveAP(movementCost);

        float distanceAlongSegment = 0;

        for (int i = 0; i < path.vectorPath.Count - 1; i++)
        {
            Vector3 p0 = path.vectorPath[Mathf.Max(i - 1, 0)];
            Vector3 p1 = path.vectorPath[i];
            Vector3 p2 = path.vectorPath[i + 1];
            Vector3 p3 = path.vectorPath[Mathf.Min(i + 2, path.vectorPath.Count - 1)];

            float segmentLength = Vector3.Distance(p1, p2);
            ///rotate before move
            unit.positionGrid = GridManager.GetWorldToCellFromTile(unit.transform.position);
            if (unit.positionGrid.Equals(GridManager.GetWorldToCellFromTile(p1)) && i < path.vectorPath.Count - 2)
            {
                Vector3Int pos = GridManager.GetWorldToCellFromTile(p2);
                unit.SetSpriteOrientation(pos);
            }
            while (distanceAlongSegment < segmentLength)
            {
                Vector3 interpolatedPoint = AstarSplines.CatmullRom(p0, p1, p2, p3, distanceAlongSegment / segmentLength);
                unit.transform.position = interpolatedPoint;
                yield return(null);

                distanceAlongSegment += Time.deltaTime * speed;
            }

            distanceAlongSegment -= segmentLength;
        }

        unit.transform.position = path.vectorPath[path.vectorPath.Count - 1];
        unit.positionGrid       = GridManager.GetWorldToCellFromTile(unit.transform.position);

        unit.blocker.BlockAtCurrentPosition();
        unit.animationManager.Animate(false, AnimationManager.moveTrigger);
    }
예제 #13
0
        // Token: 0x06002903 RID: 10499 RVA: 0x001BACF8 File Offset: 0x001B8EF8
        public void Bezier(Vector3 a, Vector3 b, Color color)
        {
            Vector3 vector = b - a;

            if (vector == Vector3.zero)
            {
                return;
            }
            Vector3 rhs     = Vector3.Cross(Vector3.up, vector);
            Vector3 vector2 = Vector3.Cross(vector, rhs).normalized;

            vector2 *= vector.magnitude * 0.1f;
            Vector3 p  = a + vector2;
            Vector3 p2 = b + vector2;
            Vector3 a2 = a;

            for (int i = 1; i <= 20; i++)
            {
                float   t       = (float)i / 20f;
                Vector3 vector3 = AstarSplines.CubicBezier(a, p, p2, b, t);
                this.Line(a2, vector3, color);
                a2 = vector3;
            }
        }