public override void Initialize ()
	{	

		//int num = AriscoGUI.Instance.Get<int> ("num", 20);
		//bool torus = AriscoGUI.Instance.Get<bool>("torus", true);
		//Camera.main.transform.position = new Vector3 (0,  0, -num);
        int num = 20;
        bool torus = true;

		if(GetComponent<LimitedWorld>()){
			GetComponent<LimitedWorld>().size = new Vector3(num, 1, num);
		}
		
		float offset = num / 2;
		
		for (int i=0; i<num; i++) {
			for (int j=0; j<num; j++) {
                AAgent a = CreateAgent (AttachedWorld, lifePrefab, new Vector2 (i - offset+0.5f, j - offset+0.5f));
			}
		}

		
		LimitedWorld tw = GetComponent<LimitedWorld>();
        if (tw)
        {
            tw.size = Vector3.one * num;
            tw.AdjustMainCamera();
            tw.offset = Vector3.one * (num%2 == 0 ? -.5f : 0);
        }
	}
    public override void Initialize()
    {
        print("AgentCreateWorldBehavior#Initialize");

        LimitedWorld lw = GetComponent <LimitedWorld>();

        List <Vector3> points = new List <Vector3>();

        for (int i = 0; i < num; i++)
        {
            AAgent a = CreateAgent(AttachedWorld, target);
            if (randomInTheWorld && lw)
            {
                Vector3 vec = Vector3.zero;
                do
                {
                    vec = new Vector3(Random.Range(lw.size.x / -2 + 1, lw.size.x / 2), 0, Random.Range(-lw.size.z / 2 + 1, lw.size.z / 2));
                    if (lw.grid)
                    {
                        vec = ToGrid(vec);
                    }
                }while(notTogether && points.Contains(vec));
                points.Add(vec);
                a.transform.position = vec;
            }
        }
    }
Beispiel #3
0
    public void MoveToSpaceCell(int d)
    {
        AAgent        a    = AttachedAgent;
        List <AAgent> list = a.World.AllAgents.Where(x => IsInRange(a, x, d)).ToList();
        LimitedWorld  lw   = a.World.GetComponent <LimitedWorld>();
        Bounds        b    = new Bounds();

        if (lw)
        {
            b = lw.Bound;
        }

        List <Vector3> candidates = new List <Vector3>();

        for (int x = -d; x <= d; x++)
        {
            for (int y = -d; y <= d; y++)
            {
                for (int z = -d; z <= d; z++)
                {
                    Vector3 v = ToGrid(new Vector3(x, y, z) + transform.position);
                    if (lw)
                    {
                        if (b.Contains(v))
                        {
                            candidates.Add(v);
                        }
                    }
                    else
                    {
                        candidates.Add(v);
                    }
                }
            }
        }
        foreach (AAgent agent in list)
        {
            Vector3 p = ToGrid(agent.transform.position);
            candidates.Remove(p);
        }
        candidates.Remove(transform.position);
        candidates = candidates.OrderBy(x => Vector3.Distance(transform.position, x)).ToList();

        if (candidates.Count > 0)
        {
            a.transform.position = candidates[0];
        }
    }
Beispiel #4
0
    public override void Initialize()
    {
        AAgent aa = prefab.GetComponent <AAgent>();

        Vector3 offset = Vector3.zero;

        LimitedWorld lw = GetComponent <LimitedWorld>();

        if (useLimitedWorld && lw)
        {
            size   = lw.size;
            offset = lw.offset;
        }

        if (offsetCenter)
        {
            offset = new Vector3((int)(-size.x / 2), (int)(-size.y / 2), (int)(-size.z / 2));
        }

        for (int i = 0; i < (int)size.x; i++)
        {
            for (int j = 0; j < (int)size.y; j++)
            {
                for (int k = 0; k < (int)size.z; k++)
                {
                    if (aa)
                    {
                        AAgent a = CreateAgent(AttachedWorld, aa);
                        a.transform.position = new Vector3(offset.x + i * step.x, offset.y + j * step.y, offset.z + k * step.z);
                    }
                    else
                    {
                        Instantiate(prefab, new Vector3(offset.x + i * step.x, offset.y + j * step.y, offset.z + k * step.z) + transform.position, Quaternion.identity);
                    }
                }
            }
        }
    }