Example #1
0
    // Use this for initialization

    void Start()
    {
        nbAgents = GameObject.Find("AgentManager").transform.childCount;
        v_size   = 10;
        valuesA  = new int[v_size];
        valuesF  = new int[v_size];
        valuesW  = new int[v_size];

        LR1.SetVertexCount(0);
        LR2.SetVertexCount(0);
        LR3.SetVertexCount(0);

        LR1.SetColors(Color.green, Color.green);
        LR2.SetColors(Color.red, Color.red);
        LR3.SetColors(Color.blue, Color.blue);

        LR1.enabled = false;
        LR2.enabled = false;
        LR3.enabled = false;

        timeCurrent = Time.fixedTime;

        for (int i = 0; i < v_size; i++)
        {
            valuesA[i] = -1;
            valuesF[i] = -1;
            valuesW[i] = -1;
        }

        nbAgents = countAgents();
        nbWater  = countWater();
        nbFood   = countFood();

        yUp   = T1.position.y;
        yDown = T2.position.y;

        current = state.None;
    }
Example #2
0
    void draw(bool all)
    {
        /////////////////////////////////////////////////////////1
        int i = 0;

        while (i < v_size && valuesA[i] != -1 && !fullA)
        {
            i++;
        }

        if (i == v_size)
        {
            fullA = true;
        }

        if (fullA)
        {
            for (int j = 1; j < v_size; j++)
            {
                valuesA[j - 1] = valuesA[j];
            }

            valuesA[v_size - 1] = nbAgents;
            nbEA = v_size;
            LR1.SetVertexCount(v_size);
        }
        else
        {
            valuesA[i] = nbAgents;
            LR1.SetVertexCount(i);
            nbEA = i;
        }
        ////////////////////////////////////////////////////////2
        i = 0;

        while (i < v_size && valuesF[i] != -1 && !fullF)
        {
            i++;
        }

        if (i == v_size)
        {
            fullF = true;
        }

        if (fullF)
        {
            for (int j = 1; j < v_size; j++)
            {
                valuesF[j - 1] = valuesF[j];
            }

            valuesF[v_size - 1] = nbFood;
            LR2.SetVertexCount(v_size);
            nbEF = v_size;
        }
        else
        {
            valuesF[i] = nbFood;
            LR2.SetVertexCount(i);
            nbEF = i;
        }
        /////////////////////////////////////////////////////////3
        i = 0;

        while (i < v_size && valuesW[i] != -1 && !fullW)
        {
            i++;
        }

        if (i == v_size)
        {
            fullW = true;
        }

        if (fullW)
        {
            for (int j = 1; j < v_size; j++)
            {
                valuesW[j - 1] = valuesW[j];
            }

            valuesW[v_size - 1] = nbWater;
            LR3.SetVertexCount(v_size);
            nbEW = v_size;
        }
        else
        {
            valuesW[i] = nbWater;
            LR3.SetVertexCount(i);
            nbEW = i;
        }

        switch (current)
        {
        case state.All:
        {
            for (int j = 0; j < nbEA; j++)
            {
                lastYA = origin.position.y + yScaleA * valuesA[j];
                LR1.SetPosition(j, new Vector3(origin.position.x + j * xScaleA, origin.position.y + yScaleA * valuesA[j], origin.position.z));
            }
            for (int j = 0; j < nbEF; j++)
            {
                lastYF = origin.position.y + yScaleF * valuesF[j];
                LR2.SetPosition(j, new Vector3(origin.position.x + j * xScaleF, origin.position.y + yScaleF * valuesF[j], origin.position.z));
            }
            for (int j = 0; j < nbEW; j++)
            {
                lastYW = origin.position.y + yScaleW * valuesW[j];
                LR3.SetPosition(j, new Vector3(origin.position.x + j * xScaleW, origin.position.y + yScaleW * valuesW[j], origin.position.z));
            }
            break;
        }

        case state.Agents:
        {
            for (int j = 0; j < nbEA; j++)
            {
                lastYA = origin.position.y + yScaleA * valuesA[j];
                LR1.SetPosition(j, new Vector3(origin.position.x + j * xScaleA, origin.position.y + yScaleA * valuesA[j], origin.position.z));
            }
            break;
        }

        case state.Food:
        {
            for (int j = 0; j < nbEF; j++)
            {
                lastYF = origin.position.y + yScaleF * valuesF[j];
                LR2.SetPosition(j, new Vector3(origin.position.x + j * xScaleF, origin.position.y + yScaleF * valuesF[j], origin.position.z));
            }
            break;
        }

        case state.Water:
        {
            for (int j = 0; j < nbEW; j++)
            {
                lastYW = origin.position.y + yScaleW * valuesW[j];
                LR3.SetPosition(j, new Vector3(origin.position.x + j * xScaleW, origin.position.y + yScaleW * valuesW[j], origin.position.z));
            }
            break;
        }
        }
    }