public void InitializeGame() { Game game = new Game(); game.player1 = new Player(Vector2.left * 4, PlayerTag.One); game.player2 = new Player(Vector2.right * 4, PlayerTag.Two); game.ball = new Ball( Constants.BALL_DEFAULT_POS, Constants.BALL_DEFAULT_RADIUS, Constants.BALL_MIN_SPEED ); Vector2 horizontalPos = new Vector2(0, 5); Vector2 verticalPos = new Vector2(10, 0); Vector2 horizontalScale = new Vector2(1, 10); Vector2 verticalScale = new Vector2(20, 1); game.walls = new Box[4] { new Box(horizontalPos, verticalScale), new Box(-horizontalPos, verticalScale), new Box(verticalPos, horizontalScale), new Box(-verticalPos, horizontalScale) }; player1Transform.position = game.player1.box.position; player1Transform.localScale = new Vector3(game.player1.box.scale.x, game.player1.box.scale.y, 1); strikeHitbox1Transform.localScale = new Vector3( game.player1.strikeHitbox.box.scale.x, game.player1.strikeHitbox.box.scale.y, 1); player2Transform.position = game.player2.box.position; player2Transform.localScale = new Vector3(game.player2.box.scale.x, game.player2.box.scale.y, 1); strikeHitbox2Transform.localScale = new Vector3( game.player2.strikeHitbox.box.scale.x, game.player2.strikeHitbox.box.scale.y, 1); ballTransform.position = game.ball.circle.position; ballTransform.localScale = new Vector2(game.ball.circle.radius, game.ball.circle.radius); for (int i = 0; i < 4; i++) { wallsTransform[i].position = game.walls[i].position; wallsTransform[i].localScale = new Vector3(game.walls[i].scale.x, game.walls[i].scale.y, 1); } this.game = game; isRunning = true; uiManager.OnGameStart(game); agent1 = AAgent.CreateAgent(agentType1, game, PlayerTag.One); agent2 = AAgent.CreateAgent(agentType2, game, PlayerTag.Two); }
void OnTriggerEnter(Collider c) { print(c.name); PedestrianWalkBehavior pwb = c.GetComponent <PedestrianWalkBehavior> (); if (pwb) { AAgent a = pwb.GetComponent <AAgent> (); a.World.ResignAgent(a); } }
public override void Initialize() { int radius = 10; for (float i = 0; i < 360; i += 360 / 100f) { AAgent a = CreateAgent(AttachedWorld, toriPref.AttachedAgent); a.transform.position = new Vector3(Mathf.Cos(i) * radius, 0, Mathf.Sin(i) * radius); a.transform.LookAt(Vector3.zero); a.GetComponent <SpeedDirectionBehavior>().Direction = a.transform.forward; } }
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]; } }
void ChangeCharacter(int n) { if (currentCharacter == n) { return; } if (factory == null || !factory.HasAWalker(n)) { return; } currentCharacter = n; Animator current = GetComponentInChildren <Animator> (); Debug.Log(current); Transform parent = transform; Quaternion orgRot = transform.localRotation; if (current != null) { parent = current.transform.parent; orgRot = current.transform.localRotation; DestroyImmediate(current.gameObject); } AAgent agent2 = factory.GetAWalker(n); Animator nAnim = agent2.GetComponentInChildren <Animator> (); nAnim.runtimeAnimatorController = controller; nAnim.transform.SetParent(parent); nAnim.transform.localPosition = Vector3.zero; nAnim.transform.localRotation = orgRot; DestroyImmediate(agent2.gameObject); AnimatorDelegate ad = nAnim.gameObject.AddComponent <AnimatorDelegate> (); ad.target = gameObject; MonoBehaviour[] monos = gameObject.GetComponents <MonoBehaviour> (); foreach (MonoBehaviour mono in monos) { mono.SendMessage("OnModelChanged", nAnim, SendMessageOptions.DontRequireReceiver); } }
public void AddSensorToAgent(string typeSensor, string nom, AAgent agent) { GameObject sensor = new GameObject(); sensor.transform.parent = agent.transform; sensor.transform.position = agent.transform.position; if (typeSensor == "Lidar") { Lidar lidar = Lidar.CreateComponent(sensor, nom); agent.Sensors.Add(lidar); agent.AddLidarListner(lidar); } if (typeSensor == "RFID") { RFID rfid = RFID.CreateComponent(sensor, nom); rfid.RfidTag = RFID_Tags.Agent; agent.Sensors.Add(rfid); agent.AddRFIDListner(rfid); } }
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); } } } } }
void Start() { agent = GetComponent<AAgent> (); cc = GetComponent<CharacterController>(); }
private static bool IsInRange(AAgent a, AAgent b, int d) { return(Mathf.Abs(a.transform.position.x - b.transform.position.x) <= d && Mathf.Abs(a.transform.position.y - b.transform.position.y) <= d && Mathf.Abs(a.transform.position.z - b.transform.position.z) <= d); }
private static bool IsInRange(AAgent a, AAgent b, int d) { return (a.transform.position - b.transform.position).sqrMagnitude <= d*d; /* return Mathf.Abs(a.transform.position.x - b.transform.position.x) <= d && Mathf.Abs(a.transform.position.y - b.transform.position.y) <= d && Mathf.Abs(a.transform.position.z - b.transform.position.z) <= d; */ }
public void Initialized(AAgent agent) { }
void Start() { agent = GetComponent <AAgent> (); cc = GetComponent <CharacterController>(); }
public void Subscribe(AAgent agent) { // Debug.Log("Subscribe : " + agent.name); _agents.Add(agent); }
public void Ended(AAgent agent) { }
/// <summary> /// Register an agent to the world<br> /// The agent will be registered and started in {@link World#commit()} after running every ohter exsisting agents. /// </summary> public void RegisterAgent (AAgent agent) { foreach (IWorldEventListener l in listeners) { l.AgentAdded (this, agent); } agent.World = this; }
public virtual void AgentRemoved(World world, AAgent agent) { }
public void Began(AAgent agent) { }
public void Committed(AAgent agent) { }
public void Stepped(AAgent agent) { }
public virtual void AgentAdded(World world, AAgent agent) { }
void Initialize() { int num = 8; float rateToRemove = 0.25f; int numToRemove = (int)(num * num * rateToRemove); Camera.main.transform.position = new Vector3(0, num, 0); float offset = num / 2 + (num % 2 == 0 ? -.5f : 0); int[,] map = new int[num, num]; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { map [i, j] = 0; if (i == 0 && j == 0) { continue; } if (i == num - 1 && j == 0) { continue; } if (i == 0 && j == num - 1) { continue; } if (i == num - 1 && j == num - 1) { continue; } map [i, j] = ((i + j) % 2) + 1; } } int counter = 0; while (counter <= numToRemove) { int i = Random.Range(0, num); int j = Random.Range(0, num); if (map [i, j] == 1 || map [i, j] == 2) { map [i, j] = -1; counter++; } } for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { int type = map [i, j]; if (type == -1) { AAgent a = CreateAgent(AttachedWorld, emptyPrefab); a.transform.position = new Vector3(i - offset, 0, j - offset); } else if (type == 1) { AAgent a = CreateAgent(AttachedWorld, pennyPrefab); a.transform.position = new Vector3(i - offset, 0, j - offset); } else if (type == 2) { AAgent a = CreateAgent(AttachedWorld, dimePrefab); a.transform.position = new Vector3(i - offset, 0, j - offset); } } } if (AriscoChart.Instance) { AriscoChart.Instance.AddChart("satisfied", "Satisfied Rate", AriscoChart.ChartType.Line, 100, 50); AriscoChart.Instance.AddChart("satisfied_pie", "Satisfied Rate", AriscoChart.ChartType.Pie, 100, 50); } }
/// <summary> /// Remove an agent from the world /// The agent will be removed in {@link World#commit()} after commiting every ohter exsisting agents. /// </summary> public void ResignAgent (AAgent agent) { foreach (IWorldEventListener l in listeners) { l.AgentRemoved (this, agent); } }
public void Disposed(AAgent agent) { }