protected virtual void AwakeObj() { player = GetComponent<Player>(); hud = player.GetComponentInChildren<HUD>(); dialogManager = player.GetComponentInChildren<DialogManager>(); formationManager = player.GetComponentInChildren<FormationManager>(); targetManager = player.GetComponentInChildren<TargetManager>(); }
public LaissezUnAvisViewModel(string nomseo) { Formation formation = null; if (FormationManager.ObtenirFormation(nomseo, out formation)) { this.Formation = formation; } }
// Use this for initialization void Start() { int squad_size = 0; level_generator = gameObject.GetComponent <LevelGenerator>(); squad_generator = gameObject.GetComponent <SquadGenerator>(); enemy_generator = gameObject.GetComponent <EnemyGenerator>(); cover_manager = gameObject.GetComponent <CoverManager>(); formation_manager = gameObject.GetComponent <FormationManager>(); squadies = new List <GameObject>(); enemies = new List <GameObject>(); // Generate Squad if (no_of_squadies > 8) { no_of_squadies = 8; } //no_of_enemies = no_of_squadies * 2; level_generator.GenerateNewLevel(level_height, level_width, grid_section_size); Vector3 level_size = new Vector3(level_width * grid_section_size, 0.0f, level_height * grid_section_size); // This is to stop duplicate cover spots spawning! if (cover_spacing <= 0) { cover_spacing = 1; } cover_manager.GenerateCoverPoints(level_size, no_cover_passes_across, no_cover_passes_up, cover_spacing); // Set Player position player.transform.position = new Vector3(player.transform.position.x, 1.0f, player.transform.position.z); // Position ID's cover_manager.SetSquads(no_of_squadies); squad_generator.GenerateSquad(no_of_squadies, cover_manager.StartupCover(no_of_squadies, player.transform.position), ref squadies); if (no_of_squadies % 2 == 1) // If we have a remainder ie Squad sizes are not even { squad_size = no_of_squadies / 2 + 1; // We use the biggest squad size } if (no_of_squadies % 2 == 0) // If they are even all good { squad_size = no_of_squadies / 2; } // Tell the formation manager about the largest squad size formation_manager.GenerateFormations(player, squad_size); //enemy_generator.GenerateEnemies(no_of_enemies, cover_manager.GetEnemyPositions(no_of_enemies, enemy_generator.GetSpawnPoints()), ref enemies); }
public FlockFormation(List<Vector3> vertices) { formationManagers = new Dictionary<Entity, FormationManager>(); updateTimer = new System.Diagnostics.Stopwatch(); var pattern = new ModelFormation(null, vertices); var formationManager = new FormationManager(pattern); generalManager = formationManager; }
// Use this for initialization void Start() { player = transform.root.GetComponent <Player>(); targetManager = transform.root.GetComponentInChildren <TargetManager>(); formationManager = transform.root.GetComponentInChildren <FormationManager>(); dialogManager = transform.root.GetComponentInChildren <DialogManager>(); hud = transform.root.GetComponentInChildren <HUD>(); mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>(); ground = FindObjectOfType <Ground>(); }
void Awake() { if (current == null) { current = this; } if (agentsNum == 0) { Debug.Log("YOU MUST SELECT THE TAG OF THE AGENTS IN THE FORMATION MANAGER GAME OBJECT"); } }
//***************************************************************************** // AI can change it's formation to a new one after it deliver or receive a goal. //***************************************************************************** public IEnumerator changeFormation(int _formationIndex, float _speed) { //cache the initial position of all units List <Vector3> unitsSartingPosition = new List <Vector3>(); foreach (var unit in myTeam) { unitsSartingPosition.Add(unit.transform.position); //get the initial postion of this unit for later use. unit.GetComponent <MeshCollider>().enabled = false; //no collision for this unit till we are done with re positioning. } float t = 0; while (t < 1) { t += Time.deltaTime * _speed; for (int cnt = 0; cnt < myTeam.Length; cnt++) { myTeam[cnt].transform.position = new Vector3(Mathf.SmoothStep(unitsSartingPosition[cnt].x, FormationManager.getPositionInFormation(_formationIndex, cnt).x * -1, t), Mathf.SmoothStep(unitsSartingPosition[cnt].y, FormationManager.getPositionInFormation(_formationIndex, cnt).y, t), FormationManager.fixedZ); /* * myTeam[cnt].transform.position.x = Mathf.SmoothStep( unitsSartingPosition[cnt].x, * FormationManager.getPositionInFormation(_formationIndex, cnt).x * -1, * t); * myTeam[cnt].transform.position.y = Mathf.SmoothStep( unitsSartingPosition[cnt].y, * FormationManager.getPositionInFormation(_formationIndex, cnt).y, * t); * myTeam[cnt].transform.position.z = FormationManager.fixedZ; */ } yield return(0); } if (t >= 1) { canChangeFormation = true; foreach (var unit in myTeam) { unit.GetComponent <MeshCollider>().enabled = true; //collision is now enabled. } } }
public static void SwitchFormationType(FormationManager formationManager) { if (!formationManager) { return; } if (formationManager.CurrentFormationType == FormationType.Auto) { formationManager.CurrentFormationType = FormationType.Manual; } else if (formationManager.CurrentFormationType == FormationType.Manual) { formationManager.CurrentFormationType = FormationType.Auto; } }
// Use this for initialization IEnumerator Start() { playerUnitPanels = new List <PlayerUnitPanel>(); canvas = GetComponentInChildren <Canvas>(); player = transform.root.GetComponent <Player>(); targetManager = player.GetComponentInChildren <TargetManager>(); formationManager = player.GetComponentInChildren <FormationManager>(); dialogManager = player.GetComponentInChildren <DialogManager>(); playerUnitBar = GetComponentInChildren <PlayerUnitBar>(); enemyUnitBar = GetComponentInChildren <EnemyUnitBar>(); selectionIndicator = GetComponentInChildren <SelectionIndicator>(); abilityBar = GetComponentInChildren <AbilityBar>(); // upperBar = GetComponentInChildren<UpperBar>(); generalIndicatorBar = GetComponentInChildren <GeneralIndicatorBar>(); enemyCountBar = GetComponentInChildren <EnemyCountBar>(); unitPanelWrapper = GetComponentInChildren <UnitPanelWrapper>(); animator = GetComponent <Animator>(); if (player && player.human) { while (!animator || !player || !targetManager || !formationManager) { yield return(new WaitForSeconds(0.1f)); } } ResourceManager.StoreSelectBoxItems(selectBoxSkin, healthy, damaged, critical); SetCursorState(CursorState.Select); buildAreaHeight = Screen.height - RESOURCE_BAR_HEIGHT - SELECTION_NAME_HEIGHT - 2 * BUTTON_SPACING; List <AudioClip> sounds = new List <AudioClip>(); List <float> volumes = new List <float>(); sounds.Add(clickSound); volumes.Add(clickVolume); audioElement = new AudioElement(sounds, volumes, "HUD", null); Cursor.lockState = CursorLockMode.Locked; cursorPosition = new Vector3(Screen.width / 2, Screen.height / 2); lastCursorPosition = new Vector3(Screen.width / 2, Screen.height / 2); }
public static void UpdateMovePosition(Vector3 position) { if (_selectedShips.Count == 0) { return; } List <Vector3> formation = FormationManager.Get(position, _selectedShips[0].transform.forward, _selectedShips.Count).ToList(); //move to closest position in formation for (int i = 0; i < _selectedShips.Count; i++) { Vector3 np = formation .OrderByDescending(v => Vector3.Distance(v, _selectedShips[i].transform.position)) .First(); formation.Remove(np); _selectedShips[i].UpdateMovePosition(np); } }
// //transform.position = dest; // // seek towards dest // /* // rb.AddForce((dest - (Vector2)transform.position).normalized * acceleration); // if (rb.velocity.magnitude > max_speed) // rb.velocity = (dest - (Vector2)transform.position).normalized * max_speed; // */ // // rotate if we are far enough away // if(((Vector2)transform.position - dest).magnitude > 0.25f) // { // Vector2 _direction = (dest - (Vector2)transform.position).normalized; // float angle = Mathf.Atan2(_direction.y, _direction.x) * Mathf.Rad2Deg; // float lerp_angle = Mathf.LerpAngle(transform.eulerAngles.z, angle, Time.deltaTime * rotational_speed); // transform.rotation = Quaternion.Euler(0f, 0f, lerp_angle); // } // if(Vector2.Dot((Vector2)transform.position - dest, transform.right) < 0) // { // // accelerate // rb.AddForce(transform.right * acceleration); // if (rb.velocity.magnitude > max_speed) // { // rb.velocity = rb.velocity.normalized * max_speed; // } // } //} private void OnCollisionEnter2D(Collision2D collision) { //print("collision start!"); if (collision.gameObject.GetComponent <BlackBird>()) { FormationManager f_manager = FindObjectOfType <FormationManager>(); if (f_manager) { f_manager.RemoveAgent(this); } else { TwoLevelManager tlm = FindObjectOfType <TwoLevelManager>(); if (tlm) { tlm.RemoveAgent(this); } } Destroy(this.gameObject); } }
public static void AddMove(Vector3?position, bool clearQueue) { if (_selectedShips.Count == 0) { return; } List <Vector3> formation = FormationManager.Get((Vector3)position, _selectedShips[0].transform.forward, _selectedShips.Count).ToList(); //need to map the closest ship to the closest point for (int i = 0; i < _selectedShips.Count; i++) { if (position != null) { int closestIndex = -1; float distance = Mathf.Infinity; for (int j = 0; j < formation.Count; j++) { float d = Vector3.Distance(_selectedShips[i].transform.position, formation[j]); if (closestIndex == -1 || d < distance) { closestIndex = j; } } _selectedShips[i].AddMove(new Move(formation[closestIndex], _selectedShips[i]), clearQueue); formation.RemoveAt(closestIndex); } else { _selectedShips[i].AddMove(new Move(position, _selectedShips[i]), clearQueue); } } }
void Awake() { INSTANCE = this; }
public override void OnInspectorGUI() { FormationManager _target = (FormationManager)target; EditorGUILayout.BeginVertical("box"); _target.target = (GameObject)EditorGUILayout.ObjectField("Target", _target.target, typeof(GameObject), true); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("box"); // EditorGUILayout.FloatField("Agents In Formation", _target.agentsNum); _target.zLookAhead = EditorGUILayout.FloatField("Look Ahead", _target.zLookAhead); _target.formationSpeed = EditorGUILayout.FloatField("Formation Speed", _target.formationSpeed); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("box"); FormationManager.Formations newValue = (FormationManager.Formations)EditorGUILayout.EnumPopup("Formation Type:", _target.formation); switch (newValue) { case FormationManager.Formations.SemiCircle: _target.radius = EditorGUILayout.FloatField(new GUIContent("Radius", "The radius of the semicircle"), _target.radius); _target.concave = EditorGUILayout.Toggle(new GUIContent("Concave", "If you want that the semicircle will be concave"), _target.concave); break; case FormationManager.Formations.Circle: _target.radius = EditorGUILayout.FloatField(new GUIContent("Radius", "The radius of the semicircle"), _target.radius); break; case FormationManager.Formations.V: _target._separation = EditorGUILayout.FloatField(new GUIContent("Separation", "The separation between agents in the formation."), _target._separation); break; case FormationManager.Formations.Triangle: _target.length = EditorGUILayout.FloatField(new GUIContent("Length", "The separation between agents in the formation."), _target.length); break; case FormationManager.Formations.Wedge: _target._separation = EditorGUILayout.FloatField(new GUIContent("Separation", "The separation between agents in the formation."), _target._separation); _target.fill = EditorGUILayout.Toggle(new GUIContent("Fill", "If you want that the agents fill the formation"), _target.fill); break; case FormationManager.Formations.Column: _target._separation = EditorGUILayout.FloatField(new GUIContent("Separation", "The separation between agents in the formation."), _target._separation); _target.columns = EditorGUILayout.IntSlider(new GUIContent("Columns", "The number of columns to form"), _target.columns, 1, 100); break; case FormationManager.Formations.Diamond: _target.backPositionOffset = EditorGUILayout.Toggle(new GUIContent("backPositionOffset", "Should the back agents have a left and right offset?"), _target.backPositionOffset); _target._separation = EditorGUILayout.FloatField(new GUIContent("Separation", "The separation between agents in the formation."), _target._separation); break; case FormationManager.Formations.Diagonal: _target.right = EditorGUILayout.Toggle(new GUIContent("Right", "Should the formation be to the right of the leader?"), _target.right); _target._separation = EditorGUILayout.FloatField(new GUIContent("Separation", "The separation between agents in the formation."), _target._separation); break; case FormationManager.Formations.Grid: _target.columns = EditorGUILayout.IntSlider(new GUIContent("Columns", "The number of columns to form"), _target.columns, 1, 100); _target._separation = EditorGUILayout.FloatField(new GUIContent("Separation", "The separation between agents in the formation."), _target._separation); break; case FormationManager.Formations.Line: _target._separation = EditorGUILayout.FloatField(new GUIContent("Separation", "The separation between agents in the formation."), _target._separation); _target.right = EditorGUILayout.Toggle(new GUIContent("Right", "Should the formation be to the right of the leader?"), _target.right); break; default: break; } if (newValue != _target.formation) { _target.formation = newValue; EditorUtility.SetDirty(target); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal("box"); EditorGUILayout.BeginVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Select the tag of the Agents", EditorStyles.boldLabel); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); _target.selectedTag = EditorGUILayout.TagField("Tag of Agents:", _target.selectedTag); if (_target.agentes != null && _target.agentes.Length == 0) { GUI.color = Color.red; } else { GUI.color = Color.green; if (_target.leaderAgent == null && _target.agentsNum > 1) { _target.leaderAgent = _target.agentes [_target.agentsNum - 1]; } } if (GUILayout.Button("Load Agents from tag")) { _target.loadFromTags(); _target.LoadAgentList(); Debug.Log(_target.agentsNum); GUI.color = Color.white; } //if (GUILayout.Button("Test")) //{ //} EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorUtility.SetDirty(target); }
void OnSceneGUI() { FormationManager _target = (FormationManager)target; if (_target.leaderAgent != null) { Handles.color = Color.red; Handles.ArrowCap(0, _target.leaderAgent.transform.position, _target.leaderAgent.transform.rotation, 4f); } switch (_target.formation) { case FormationManager.Formations.SemiCircle: _target.theta = Mathf.PI / (_target.agentsNum * 2); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetSemiCirclePos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Circle: _target.theta = Mathf.PI / (_target.agentsNum); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetCirclePos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.V: _target.separation = new Vector2(_target._separation, _target._separation); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetVPosition(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Triangle: for (int i = 0; i < 3; ++i) { _target.agentsPerSide [i] = _target.agentsNum / 3 + (_target.agentsNum % 3 > i ? 1 : 0); } for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetTrianglePos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Wedge: _target.separation = new Vector2(_target._separation, _target._separation); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetWedgePos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Column: _target.separation = new Vector2(_target._separation, _target._separation); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetColumnPos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Diamond: _target.separation = new Vector2(_target._separation, _target._separation); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetDiamondPos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Diagonal: _target.separation = new Vector2(_target._separation, _target._separation); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetDiagonalPos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Grid: _target.separation = new Vector2(_target._separation, _target._separation); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetGridPos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; case FormationManager.Formations.Line: _target.separation = new Vector2(_target._separation, _target._separation); for (int i = 0; i < _target.agentsNum; i++) { var pos = _target.GetLinePos(i, _target.zLookAhead); if (_target.leaderAgent != null) { pos = pos + _target.leaderAgent.transform.position; } Handles.color = Color.red; Handles.SphereCap(i, pos, Quaternion.identity, 0.5f); } break; default: break; } }
public void setup() { formationManager = new FormationManager(); }
void Awake() { manager = Object.FindObjectOfType <FormationManager>(); }
Steering getDefaultSteering(Entry e, FormationManager generalManager, Flock flock) { var pattSteering = new PatternSteering(e.bird, generalManager); var separation = new Separation(e.bird, flock, 5.0f, -1f); separation.aknnApproxVal = 1.0; var obstacleAvoidance = new ObstacleAvoidance(e.bird, 20f, new string[]{"Ground"}); var blended = new BlendedSteering[3]; blended[0] = new BlendedSteering(e.bird, new BehaviorAndWeight(obstacleAvoidance, 1f)); blended[1] = new BlendedSteering(e.bird, new BehaviorAndWeight(separation, 1f)); blended[2] = new BlendedSteering(e.bird, new BehaviorAndWeight(pattSteering, 1f)); return new PrioritySteering(1f, blended); }