void UseCompareDistance() { GameObject[] allObjects = FindObjectsOfType <GameObject>(); //get all game objects in the scene ArrayList objectList = new ArrayList(); //make an arrayList to copy all of the game objects to foreach (GameObject go in allObjects) { objectList.Add(go); } DistanceComparer comparer = new DistanceComparer(); // create a distance comparer comparer.Target = this.gameObject; // assign the comparer a target objectList.Sort(comparer); // sort the list with the comparer SortedByDistance = new GameObject[objectList.Count]; objectList.CopyTo(SortedByDistance, 0); // copy to Array we can observe in the Editor. }
void Start() { currentTimeBetweenFootsteps = timeBetweenFootsteps; items_to_carry = new List <GameObject>(); comparer = new DistanceComparer(); body = transform.GetChild(0); body_animator = body.GetComponent <Animator>(); body_renderer = body.GetComponent <SpriteRenderer>(); carrying_arm = transform.GetChild(1); repair_counter = timeToRepair; load_counter = timeToLoad; near_obj = false; repairing = false; loading_bullets = false; main_down = false; main_down_sustained = false; secondary_down = false; facing_left = false; obj = null; scenary = GameObject.FindGameObjectWithTag("scenary"); TilemapRenderer tr = scenary.GetComponent <TilemapRenderer>(); scenary_center = tr.bounds.center; scenary_half = tr.bounds.extents; footSteps.Init(); rechargeSound.Init(); grabBulletsSound.Init(); grabRepairKit.Init(); repairSound.Init(); }
private void Initialize() { _wayPoints = new SimpleQueue <Vector3>(); _groupCog = GetGroupCenterOfGravity(); _unitSortComparer = new DistanceComparer <IUnitFacade>(false); _stopped = true; var updateInterval = GameServices.navigationSettings.groupUpdateInterval; NavLoadBalancer.steering.Add(this, updateInterval, true); }
public void WhenComparingSmaller_ReturnsPostive() { //Prepare Node a = new Node { Distance = 2 }; Node b = new Node { Distance = 1 }; DistanceComparer<Node> target = new DistanceComparer<Node>(); //Act int result = target.Compare(a, b); //Verify Assert.IsTrue(result > 0); }
public void WhenComparingEqual_ReturnsZero() { //Prepare Node a = new Node { Distance = 1 }; Node b = new Node { Distance = 1 }; DistanceComparer<Node> target = new DistanceComparer<Node>(); //Act int result = target.Compare(a, b); //Verify Assert.AreEqual(0, result); }
static ColorComparer() { dc = new DistanceComparer(); nc = new NameComparer(); sc = new SaturationComparer(); hc = new HueComparer(); bc = new BrightnessComparer(); uc = new UnsortedComparer(); }
void Update() { ArrayList ObjectList = new ArrayList(); GameObject[] Objects = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[]; foreach (GameObject go in Objects) { ObjectList.Add(go); } DistanceComparer dComparer = new DistanceComparer(); dComparer.Target = this.gameObject; ObjectList.Sort(dComparer); SortedByDistance = new GameObject[ObjectList.Count]; ObjectList.CopyTo(SortedByDistance); }
// Use this for initialization void Start() { detectRadius = GetComponentInChildren <SphereCollider>(); targetableEnemies = new ArrayList(); distanceComparer = new DistanceComparer(); distanceComparer.originator = this.gameObject; agent = GetComponent <NavMeshAgent>(); if (_instances == null) { _instances = new List <CompanionAbilities>(); } _instances.Add(this); }
// Finds the GameObjects tagged tag, ranked by distance to self public GameObject[] FindAllTaggedByDistance(string tag) { var entities = GameObject.FindGameObjectsWithTag(tag); if (entities == null || entities.Length == 0) { return(new GameObject[0]); } var comparer = new DistanceComparer(this); Array.Sort(entities, comparer); return(entities); }
void Update() { ArrayList ObjectList = new ArrayList(); GameObject[] Objects = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[]; foreach (GameObject go in Objects) { ObjectList.Add(go); } DistanceComparer dComparer = new DistanceComparer(); dComparer.Target = this.gameObject; ObjectList.Sort(dComparer); SortedByDistance = new GameObject[ObjectList.Count]; ObjectList.CopyTo(SortedByDistance); }
/// <summary> /// Helper method to target mobs. This is used to handle targetting. /// Typically F8 will invoke this to target nearest mob (last = null) /// Typically Tab will invoke this to target closest mob (or last) /// </summary> /// <param name="last">last mob targetted</param> /// <param name="reverse">whether we are spiraling in instead of out</param> /// <param name="onlyAttackable"> /// whether we should exclude objects that are not attackable /// </param> public void TargetMobHelper(ObjectNode last, bool reverse, bool onlyAttackable) { // Get a copy of the list of mobs List <MobNode> mobNodes = new List <MobNode>(worldManager.GetMobNodes()); mobNodes.Remove(client.Player); IComparer <MobNode> comparer = new DistanceComparer(client.Player); mobNodes.Sort(comparer); if (reverse) { mobNodes.Reverse(); } // Ideally, I would set lastMob to be the last mob within // targetting range, but for now, I'll just consider all. bool lastFound = (last == null) ? true : false; ObjectNode target = null; int lastIndex = -1; if (last != null) { for (int i = 0; i < mobNodes.Count; ++i) { if (mobNodes[i] == last) { lastIndex = i; break; } } } // Now, starting at lastIndex + 1, loop around the list for (int i = 1; i < mobNodes.Count; ++i) { int index = (i + lastIndex) % mobNodes.Count; if (!onlyAttackable || IsAttackable(mobNodes[index])) { target = mobNodes[index]; break; } } // If we found the 'last' object, and found another object if (target != null) { client.Target = target; } }
// Use this for initialization void Start() { //creates an array of an undetermined size and type ArrayList aList = new ArrayList(); //create an array of all objects in the scene Object[] AllObjects = GameObject.FindObjectsOfType(typeof(Object)) as Object[]; //iterate through all objects foreach (Object o in AllObjects) { if (o.GetType() == typeof(GameObject)) { aList.Add(o); } } if (aList.Contains(SpecificObject)) { Debug.Log(aList.IndexOf(SpecificObject)); } if (aList.Contains(gameObject)) { aList.Remove(gameObject); } //initialize the AllGameObjects array AllGameObjects = new GameObject[aList.Count]; //copy the list to the array DistanceComparer dc = new DistanceComparer(); dc.Target = gameObject; aList.Sort(dc); aList.CopyTo(AllGameObjects); ArrayList sorted = new ArrayList(); sorted.AddRange(messyInts); sorted.Sort(); sorted.Reverse(); sorted.CopyTo(messyInts); }
// Use this for initialization void Start() { //creates an array of an undetermined size and type ArrayList aList = new ArrayList(); //create an array of all objects in the scene Object[] AllObjects = GameObject.FindObjectsOfType(typeof(Object)) as Object[]; //iterate through all objects foreach (Object o in AllObjects) { if (o.GetType() == typeof(GameObject)) { aList.Add(o); } } if (aList.Contains(SpecificObject)) { Debug.Log(aList.IndexOf(SpecificObject)); } if (aList.Contains(gameObject)) { aList.Remove(gameObject); } //initialize the AllGameObjects array AllGameObjects = new GameObject[aList.Count]; //copy the list to the array DistanceComparer dc = new DistanceComparer(); dc.Target = gameObject; aList.Sort(dc); aList.CopyTo(AllGameObjects); ArrayList sorted = new ArrayList(); sorted.AddRange(messyInts); sorted.Sort(); sorted.Reverse(); sorted.CopyTo(messyInts); }
void BeginAbility() { Collider[] hits = Physics.OverlapSphere(player.position, Mathf.Infinity); foreach (Collider hit in hits) { if (hit.tag == Globals.INTERACTABLE_ITEM) { // Set items to objects hit items = GameObject.FindGameObjectsWithTag(hit.tag); DistanceComparer dComp = new DistanceComparer(); dComp.SetTarget(player.gameObject); // Sort objects based on distance from player System.Array.Sort(items, dComp); } } // TODO: Possibly fix this to make it more dynamic...work with less than 4 objects if (items.Length > 0) { StartCoroutine("SpawnOrbitHolders"); } }
private void Initialize() { _wayPoints = new SimpleQueue<Vector3>(); _groupCog = GetGroupCenterOfGravity(); _unitSortComparer = new DistanceComparer<IUnitFacade>(false); _stopped = true; var updateInterval = GameServices.navigationSettings.groupUpdateInterval; NavLoadBalancer.steering.Add(this, updateInterval, true); }
/// <summary> /// Helper method to target mobs. This is used to handle targetting. /// Typically F8 will invoke this to target nearest mob (last = null) /// Typically Tab will invoke this to target closest mob (or last) /// </summary> /// <param name="last">last mob targetted</param> /// <param name="reverse">whether we are spiraling in instead of out</param> /// <param name="onlyAttackable"> /// whether we should exclude objects that are not attackable /// </param> public void TargetMobHelper(ObjectNode last, bool reverse, bool onlyAttackable) { // Get a copy of the list of mobs List<MobNode> mobNodes = new List<MobNode>(worldManager.GetMobNodes()); mobNodes.Remove(client.Player); IComparer<MobNode> comparer = new DistanceComparer(client.Player); mobNodes.Sort(comparer); if (reverse) mobNodes.Reverse(); // Ideally, I would set lastMob to be the last mob within // targetting range, but for now, I'll just consider all. bool lastFound = (last == null) ? true : false; ObjectNode target = null; int lastIndex = -1; if (last != null) { for (int i = 0; i < mobNodes.Count; ++i) if (mobNodes[i] == last) { lastIndex = i; break; } } // Now, starting at lastIndex + 1, loop around the list for (int i = 1; i < mobNodes.Count; ++i) { int index = (i + lastIndex) % mobNodes.Count; if (!onlyAttackable || IsAttackable(mobNodes[index])) { target = mobNodes[index]; break; } } // If we found the 'last' object, and found another object if (target != null) client.Target = target; }