// selection type void SingleLeftClick() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, playerMask)) { Entitas entity = hit.collider.GetComponent <Entitas>(); entity.OnSelected(); selectedEntities.Add(entity.instanceID, entity); if (entity is Building) { Building b = (Building)entity; if (b.currentState != BuildingState.Complete) { UIController.instance.commandController.Create("Incomplete Building"); } else { UIController.instance.commandController.Create(b.entityName); } } else { UIController.instance.commandController.Create(entity.entityName); } } }
// unit selection void AddWithinBounds() { bound = GetViewportBounds(Camera.main, positionPressed, positionReleased); // foreach(ISelectable entity in visibleEntities.Values) // { // if(IsWithinBounds(Camera.main, bound, entity.ISelectTransform.localPosition)) // { // if(!selectableEntities.Contains(entity)) // { // selectableEntities.Add(entity); // entity.OnSelected(); // } // } // } // first phase - select all foreach (KeyValuePair <int, Entitas> entitas in OnScreenEntities) { if (IsWithinBounds(Camera.main, bound, entitas.Value.transform.localPosition)) { if (!selectedEntities.ContainsKey(entitas.Key)) { selectedEntities.Add(entitas.Key, entitas.Value); //entitas.Value.OnSelected(); } } } // second phase - filtering if (selectedEntities.Count == 0) { return; } else if (selectedEntities.Count == 1) { Entitas entity = selectedEntities.Values.First(); entity.OnSelected(); if (entity is Building) { Building b = (Building)entity; if (b.currentState != BuildingState.Complete) { UIController.instance.commandController.Create("Incomplete Building"); } else { UIController.instance.commandController.Create(b.entityName); } } else { UIController.instance.commandController.Create(entity.entityName); } } else { // check if any building mixed with units List <int> toRemove = selectedEntities.Where(pair => pair.Value.entityType == EntitasType.Building).Select(pair => pair.Key).ToList(); foreach (int i in toRemove) { selectedEntities.Remove(i); } foreach (KeyValuePair <int, Entitas> pair in selectedEntities) { pair.Value.OnSelected(); } if (selectedEntities.Count == 1) { UIController.instance.commandController.Create(selectedEntities.Values.First().entityName); } else { UIController.instance.commandController.Create("Generic"); } } }