示例#1
0
 /** Color from an angle */
 public Color GetColor(float angle)
 {
     return(AstarMath.HSVToRGB(angle * rad2Deg, 0.8f, 0.6f));
 }
示例#2
0
        /// <summary>Create a number of agents in circle and restart simulation</summary>
        public void CreateAgents(int num)
        {
            this.agentCount = num;

            agents = new List <IAgent>(agentCount);
            goals  = new List <Vector3>(agentCount);
            colors = new List <Color>(agentCount);

            sim.ClearAgents();

            if (type == RVOExampleType.Circle)
            {
                float circleRad = Mathf.Sqrt(agentCount * radius * radius * 4 / Mathf.PI) * exampleScale * 0.05f;

                for (int i = 0; i < agentCount; i++)
                {
                    Vector3 pos   = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / agentCount)) * circleRad * (1 + Random.value * 0.01f);
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals.Add(-pos);
                    colors.Add(AstarMath.HSVToRGB(i * 360.0f / agentCount, 0.8f, 0.6f));
                }
            }
            else if (type == RVOExampleType.Line)
            {
                for (int i = 0; i < agentCount; i++)
                {
                    Vector3 pos   = new Vector3((i % 2 == 0 ? 1 : -1) * exampleScale, 0, (i / 2) * radius * 2.5f);
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals.Add(new Vector3(-pos.x, pos.y, pos.z));
                    colors.Add(i % 2 == 0 ? Color.red : Color.blue);
                }
            }
            else if (type == RVOExampleType.Point)
            {
                for (int i = 0; i < agentCount; i++)
                {
                    Vector3 pos   = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / agentCount)) * exampleScale;
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals.Add(new Vector3(0, pos.y, 0));
                    colors.Add(AstarMath.HSVToRGB(i * 360.0f / agentCount, 0.8f, 0.6f));
                }
            }
            else if (type == RVOExampleType.RandomStreams)
            {
                float circleRad = Mathf.Sqrt(agentCount * radius * radius * 4 / Mathf.PI) * exampleScale * 0.05f;

                for (int i = 0; i < agentCount; i++)
                {
                    float   angle       = Random.value * Mathf.PI * 2.0f;
                    float   targetAngle = Random.value * Mathf.PI * 2.0f;
                    Vector3 pos         = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * uniformDistance(circleRad);
                    IAgent  agent       = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals.Add(new Vector3(Mathf.Cos(targetAngle), 0, Mathf.Sin(targetAngle)) * uniformDistance(circleRad));
                    colors.Add(AstarMath.HSVToRGB(targetAngle * Mathf.Rad2Deg, 0.8f, 0.6f));
                }
            }
            else if (type == RVOExampleType.Crossing)
            {
                float distanceBetweenGroups = exampleScale * radius * 0.5f;
                int   directions            = (int)Mathf.Sqrt(agentCount / 25f);
                directions = Mathf.Max(directions, 2);

                const int AgentsPerDistance = 10;
                for (int i = 0; i < agentCount; i++)
                {
                    float   angle = ((i % directions) / (float)directions) * Mathf.PI * 2.0f;
                    var     dist  = distanceBetweenGroups * ((i / (directions * AgentsPerDistance) + 1) + 0.3f * Random.value);
                    Vector3 pos   = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * dist;
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agent.Priority = (i % directions) == 0 ? 1 : 0.01f;
                    agents.Add(agent);
                    goals.Add(-pos.normalized * distanceBetweenGroups * 3);
                    colors.Add(AstarMath.HSVToRGB(angle * Mathf.Rad2Deg, 0.8f, 0.6f));
                }
            }

            SetAgentSettings();

            verts      = new Vector3[4 * agents.Count];
            uv         = new Vector2[verts.Length];
            tris       = new int[agents.Count * 2 * 3];
            meshColors = new Color[verts.Length];
        }
 // Token: 0x060029FF RID: 10751 RVA: 0x001C57F4 File Offset: 0x001C39F4
 public void CreateAgents(int num)
 {
     this.agentCount = num;
     this.agents     = new List <IAgent>(this.agentCount);
     this.goals      = new List <Vector3>(this.agentCount);
     this.colors     = new List <Color>(this.agentCount);
     this.sim.ClearAgents();
     if (this.type == LightweightRVO.RVOExampleType.Circle)
     {
         float d = Mathf.Sqrt((float)this.agentCount * this.radius * this.radius * 4f / 3.14159274f) * this.exampleScale * 0.05f;
         for (int i = 0; i < this.agentCount; i++)
         {
             Vector3 vector = new Vector3(Mathf.Cos((float)i * 3.14159274f * 2f / (float)this.agentCount), 0f, Mathf.Sin((float)i * 3.14159274f * 2f / (float)this.agentCount)) * d * (1f + UnityEngine.Random.value * 0.01f);
             IAgent  item   = this.sim.AddAgent(new Vector2(vector.x, vector.z), vector.y);
             this.agents.Add(item);
             this.goals.Add(-vector);
             this.colors.Add(AstarMath.HSVToRGB((float)i * 360f / (float)this.agentCount, 0.8f, 0.6f));
         }
     }
     else if (this.type == LightweightRVO.RVOExampleType.Line)
     {
         for (int j = 0; j < this.agentCount; j++)
         {
             Vector3 vector2 = new Vector3((float)((j % 2 == 0) ? 1 : -1) * this.exampleScale, 0f, (float)(j / 2) * this.radius * 2.5f);
             IAgent  item2   = this.sim.AddAgent(new Vector2(vector2.x, vector2.z), vector2.y);
             this.agents.Add(item2);
             this.goals.Add(new Vector3(-vector2.x, vector2.y, vector2.z));
             this.colors.Add((j % 2 == 0) ? Color.red : Color.blue);
         }
     }
     else if (this.type == LightweightRVO.RVOExampleType.Point)
     {
         for (int k = 0; k < this.agentCount; k++)
         {
             Vector3 vector3 = new Vector3(Mathf.Cos((float)k * 3.14159274f * 2f / (float)this.agentCount), 0f, Mathf.Sin((float)k * 3.14159274f * 2f / (float)this.agentCount)) * this.exampleScale;
             IAgent  item3   = this.sim.AddAgent(new Vector2(vector3.x, vector3.z), vector3.y);
             this.agents.Add(item3);
             this.goals.Add(new Vector3(0f, vector3.y, 0f));
             this.colors.Add(AstarMath.HSVToRGB((float)k * 360f / (float)this.agentCount, 0.8f, 0.6f));
         }
     }
     else if (this.type == LightweightRVO.RVOExampleType.RandomStreams)
     {
         float num2 = Mathf.Sqrt((float)this.agentCount * this.radius * this.radius * 4f / 3.14159274f) * this.exampleScale * 0.05f;
         for (int l = 0; l < this.agentCount; l++)
         {
             float   f       = UnityEngine.Random.value * 3.14159274f * 2f;
             float   num3    = UnityEngine.Random.value * 3.14159274f * 2f;
             Vector3 vector4 = new Vector3(Mathf.Cos(f), 0f, Mathf.Sin(f)) * this.uniformDistance(num2);
             IAgent  item4   = this.sim.AddAgent(new Vector2(vector4.x, vector4.z), vector4.y);
             this.agents.Add(item4);
             this.goals.Add(new Vector3(Mathf.Cos(num3), 0f, Mathf.Sin(num3)) * this.uniformDistance(num2));
             this.colors.Add(AstarMath.HSVToRGB(num3 * 57.29578f, 0.8f, 0.6f));
         }
     }
     else if (this.type == LightweightRVO.RVOExampleType.Crossing)
     {
         float num4 = this.exampleScale * this.radius * 0.5f;
         int   num5 = (int)Mathf.Sqrt((float)this.agentCount / 25f);
         num5 = Mathf.Max(num5, 2);
         for (int m = 0; m < this.agentCount; m++)
         {
             float   num6    = (float)(m % num5) / (float)num5 * 3.14159274f * 2f;
             float   d2      = num4 * ((float)(m / (num5 * 10) + 1) + 0.3f * UnityEngine.Random.value);
             Vector3 vector5 = new Vector3(Mathf.Cos(num6), 0f, Mathf.Sin(num6)) * d2;
             IAgent  agent   = this.sim.AddAgent(new Vector2(vector5.x, vector5.z), vector5.y);
             agent.Priority = ((m % num5 == 0) ? 1f : 0.01f);
             this.agents.Add(agent);
             this.goals.Add(-vector5.normalized * num4 * 3f);
             this.colors.Add(AstarMath.HSVToRGB(num6 * 57.29578f, 0.8f, 0.6f));
         }
     }
     this.SetAgentSettings();
     this.verts      = new Vector3[4 * this.agents.Count];
     this.uv         = new Vector2[this.verts.Length];
     this.tris       = new int[this.agents.Count * 2 * 3];
     this.meshColors = new Color[this.verts.Length];
 }
示例#4
0
 public void CreateAgents(int num)
 {
     this.agentCount = num;
     this.agents     = new List <IAgent>(this.agentCount);
     this.goals      = new List <Vector3>(this.agentCount);
     this.colors     = new List <Color>(this.agentCount);
     this.sim.ClearAgents();
     if (this.type == RVOExampleType.Circle)
     {
         float num2 = (Mathf.Sqrt((((this.agentCount * this.radius) * this.radius) * 4f) / 3.141593f) * this.exampleScale) * 0.05f;
         for (int j = 0; j < this.agentCount; j++)
         {
             Vector3 position = (Vector3)(new Vector3(Mathf.Cos(((j * 3.141593f) * 2f) / ((float)this.agentCount)), 0f, Mathf.Sin(((j * 3.141593f) * 2f) / ((float)this.agentCount))) * num2);
             IAgent  item     = this.sim.AddAgent(position);
             this.agents.Add(item);
             this.goals.Add(-position);
             this.colors.Add(AstarMath.HSVToRGB((j * 360f) / ((float)this.agentCount), 0.8f, 0.6f));
         }
     }
     else if (this.type == RVOExampleType.Line)
     {
         for (int k = 0; k < this.agentCount; k++)
         {
             Vector3 vector2 = new Vector3((((k % 2) != 0) ? ((float)(-1)) : ((float)1)) * this.exampleScale, 0f, ((k / 2) * this.radius) * 2.5f);
             IAgent  agent2  = this.sim.AddAgent(vector2);
             this.agents.Add(agent2);
             this.goals.Add(new Vector3(-vector2.x, vector2.y, vector2.z));
             this.colors.Add(((k % 2) != 0) ? Color.blue : Color.red);
         }
     }
     else if (this.type == RVOExampleType.Point)
     {
         for (int m = 0; m < this.agentCount; m++)
         {
             Vector3 vector3 = (Vector3)(new Vector3(Mathf.Cos(((m * 3.141593f) * 2f) / ((float)this.agentCount)), 0f, Mathf.Sin(((m * 3.141593f) * 2f) / ((float)this.agentCount))) * this.exampleScale);
             IAgent  agent3  = this.sim.AddAgent(vector3);
             this.agents.Add(agent3);
             this.goals.Add(new Vector3(0f, vector3.y, 0f));
             this.colors.Add(AstarMath.HSVToRGB((m * 360f) / ((float)this.agentCount), 0.8f, 0.6f));
         }
     }
     else if (this.type == RVOExampleType.RandomStreams)
     {
         float radius = (Mathf.Sqrt((((this.agentCount * this.radius) * this.radius) * 4f) / 3.141593f) * this.exampleScale) * 0.05f;
         for (int n = 0; n < this.agentCount; n++)
         {
             float   f       = (UnityEngine.Random.value * 3.141593f) * 2f;
             float   num9    = (UnityEngine.Random.value * 3.141593f) * 2f;
             Vector3 vector4 = (Vector3)(new Vector3(Mathf.Cos(f), 0f, Mathf.Sin(f)) * this.uniformDistance(radius));
             IAgent  agent4  = this.sim.AddAgent(vector4);
             this.agents.Add(agent4);
             this.goals.Add((Vector3)(new Vector3(Mathf.Cos(num9), 0f, Mathf.Sin(num9)) * this.uniformDistance(radius)));
             this.colors.Add(AstarMath.HSVToRGB(num9 * 57.29578f, 0.8f, 0.6f));
         }
     }
     for (int i = 0; i < this.agents.Count; i++)
     {
         IAgent agent5 = this.agents[i];
         agent5.Radius              = this.radius;
         agent5.MaxSpeed            = this.maxSpeed;
         agent5.AgentTimeHorizon    = this.agentTimeHorizon;
         agent5.ObstacleTimeHorizon = this.obstacleTimeHorizon;
         agent5.MaxNeighbours       = this.maxNeighbours;
         agent5.NeighbourDist       = this.neighbourDist;
         agent5.DebugDraw           = (i == 0) && this.debug;
     }
     this.verts      = new Vector3[4 * this.agents.Count];
     this.uv         = new Vector2[this.verts.Length];
     this.tris       = new int[(this.agents.Count * 2) * 3];
     this.meshColors = new Color[this.verts.Length];
 }
 public Color GetColor(float angle)
 {
     return(AstarMath.HSVToRGB(angle * 57.29578f, 0.8f, 0.6f));
 }
示例#6
0
        /// <summary>Create a number of agents in circle and restart simulation</summary>
        public void CreateAgents(int num)
        {
            this.agentCount = num;

            agents = new List <IAgent>(agentCount);
            Util.Memory.Realloc(ref goals, agentCount, Allocator.Persistent);
            Util.Memory.Realloc(ref agentColors, agentCount, Allocator.Persistent);

            sim.ClearAgents();

            if (type == RVOExampleType.Circle)
            {
                float       agentArea         = agentCount * radius * radius * Mathf.PI;
                const float EmptyFraction     = 0.7f;
                const float PackingDensity    = 0.9f;
                float       innerCircleRadius = Mathf.Sqrt(agentArea / (Mathf.PI * (1 - EmptyFraction * EmptyFraction)));
                float       outerCircleRadius = Mathf.Sqrt(innerCircleRadius * innerCircleRadius + agentCount * radius * radius / PackingDensity);
                //float circleRad = Mathf.Sqrt(Mathf.Sqrt(agentCount * radius * radius * 4 / Mathf.PI)) * 0.05 * exampleScale;

                for (int i = 0; i < agentCount; i++)
                {
                    Vector3 pos   = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / agentCount)) * math.lerp(innerCircleRadius, outerCircleRadius, UnityEngine.Random.value);
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals[i]       = new float3(-pos.x, 0, -pos.z);
                    agentColors[i] = AstarMath.HSVToRGB(i * 360.0f / agentCount, 0.8f, 0.6f);
                }
            }
            else if (type == RVOExampleType.Line)
            {
                for (int i = 0; i < agentCount; i++)
                {
                    Vector3 pos   = new Vector3((i % 2 == 0 ? 1 : -1) * exampleScale, 0, (i / 2) * radius * 2.5f);
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals[i]       = new float3(-pos.x, 0, pos.z);
                    agentColors[i] = i % 2 == 0 ? Color.red : Color.blue;
                }
            }
            else if (type == RVOExampleType.Point)
            {
                for (int i = 0; i < agentCount; i++)
                {
                    Vector3 pos   = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / agentCount)) * exampleScale;
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals[i]       = new float3(0, 0, 0);
                    agentColors[i] = AstarMath.HSVToRGB(i * 360.0f / agentCount, 0.8f, 0.6f);
                }
            }
            else if (type == RVOExampleType.RandomStreams)
            {
                float circleRad = Mathf.Sqrt(agentCount * radius * radius * 4 / Mathf.PI) * exampleScale * 0.05f;

                for (int i = 0; i < agentCount; i++)
                {
                    float   angle       = UnityEngine.Random.value * Mathf.PI * 2.0f;
                    float   targetAngle = UnityEngine.Random.value * Mathf.PI * 2.0f;
                    Vector3 pos         = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * uniformDistance(circleRad);
                    IAgent  agent       = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agents.Add(agent);
                    goals[i]       = new float3(math.cos(targetAngle), 0, math.sin(targetAngle)) * uniformDistance(circleRad);
                    agentColors[i] = AstarMath.HSVToRGB(targetAngle * Mathf.Rad2Deg, 0.8f, 0.6f);
                }
            }
            else if (type == RVOExampleType.Crossing)
            {
                float distanceBetweenGroups = exampleScale * radius * 0.5f;
                int   directions            = (int)Mathf.Sqrt(agentCount / 25f);
                directions = Mathf.Max(directions, 2);

                const int AgentsPerDistance = 10;
                for (int i = 0; i < agentCount; i++)
                {
                    float   angle = ((i % directions) / (float)directions) * Mathf.PI * 2.0f;
                    var     dist  = distanceBetweenGroups * ((i / (directions * AgentsPerDistance) + 1) + 0.3f * UnityEngine.Random.value);
                    Vector3 pos   = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * dist;
                    IAgent  agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
                    agent.Priority = (i % directions) == 0 ? 1 : 0.01f;
                    agents.Add(agent);
                    goals[i]       = math.normalizesafe(new float3(-pos.x, 0, -pos.z)) * distanceBetweenGroups * 3;
                    agentColors[i] = AstarMath.HSVToRGB(angle * Mathf.Rad2Deg, 0.8f, 0.6f);
                }
            }

            Update();
        }