Beispiel #1
0
 public TrailPoint(ITrailOwner owner)
 {
     Owner    = owner;
     Strength = owner.Strength;
     Position = Util.GetGroundPos(owner.Position, offset);
     Hash     = GetHash(Position);
 }
Beispiel #2
0
    public TrailPoint AddPoint(ITrailOwner owner)
    {
        TrailPoint point = new TrailPoint(owner);

        queue.Enqueue(point);
        return(point);
    }
Beispiel #3
0
 public void OrphanTrail(ITrailOwner owner)
 {
     if (owner != null && activeTrails.ContainsKey(owner))
     {
         activeTrails[owner].Owner = null;
         activeTrails.Remove(owner);
     }
 }
Beispiel #4
0
    public Vector4 SearchVicinity(int radius,
                                  ITrailOwner owner,
                                  bool ignoreOwnerTrail = true,
                                  bool skipOnPowerUp    = true)
    {
        Vector3 pos      = owner.Position;
        int     xMin     = Mathf.RoundToInt(pos.x) - radius;
        int     zMin     = Mathf.RoundToInt(pos.z) - radius;
        int     xMax     = Mathf.RoundToInt(pos.x) + radius;
        int     zMax     = Mathf.RoundToInt(pos.z) + radius;
        Vector3 centroid = Vector3.zero;
        float   strength = 0f;
        int     i        = 0;

        for (int x = xMin; x <= xMax; x++)
        {
            for (int z = zMin; z <= zMax; z++)
            {
                int hash = Point.GetHash(x, z);
                if (pointLists.ContainsKey(hash))
                {
                    List <Point> list = pointLists[hash];
                    foreach (Point point in list)
                    {
                        if (ignoreOwnerTrail && point.Owner == owner)
                        {
                            continue;
                        }

                        if (Vector3.Distance(point.Position, pos) <= radius)
                        {
                            if (skipOnPowerUp && point is PowerUpLocation)
                            {
                                Vector4 resultPowerUp = point.Position;
                                resultPowerUp.w = 1f;
                                // Debug.DrawLine(pos, resultPowerUp, Color.white);
                                return(resultPowerUp);
                            }
                            strength += point.Strength;
                            centroid += (point.Position - pos) * point.Strength;
                            i++;
                            // Debug.DrawLine(pos, point.Position, Color.magenta * point.Strength);
                        }
                    }
                }
            }
        }

        i = Mathf.Max(1, i);
        Vector4 result = pos + centroid / i;

        result.w = strength / i;
        // Debug.DrawLine(pos, result, Color.white);
        return(result);
    }
Beispiel #5
0
    public void AddTrailPoint(ITrailOwner owner)
    {
        Trail trail;

        if (activeTrails.ContainsKey(owner))
        {
            trail = activeTrails[owner];
        }
        else
        {
            trail = new Trail(owner, RemovePoint, color0, color1, thickness);
            trail.SetParent(transform);
            activeTrails.Add(owner, trail);
            allTrails.Add(trail);
        }

        AddPoint(trail.AddPoint(owner));
    }
Beispiel #6
0
    public Trail(ITrailOwner owner,
                 Action <TrailPoint> onRemovePoint,
                 Color color0,
                 Color color1,
                 float thickness)
    {
        Owner = owner;
        queue = new Queue <TrailPoint>();
        this.onRemovePoint = onRemovePoint;

        CreateLineRenderer(thickness);

        colorKeys = new GradientColorKey[] {
            new GradientColorKey(color0, 0f),
            new GradientColorKey(color1, 1f)
        };
        alphaKeys = new GradientAlphaKey[] {
            new GradientAlphaKey(1f, 0f),
            new GradientAlphaKey(1f, 1f)
        };
    }