public void Update(Vector3 mouse) { mSelectionBox.gameObject.SetActive(mSelectionInProgress); if (mSelectionInProgress) { mSelectionBox.position = new Vector3(Mathf.Min(mouse.x, mSelectionStartPosition.x), Mathf.Max(mouse.y, mSelectionStartPosition.y)); mSelectionBox.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Abs(mouse.x - mSelectionStartPosition.x)); mSelectionBox.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Mathf.Abs(mouse.y - mSelectionStartPosition.y)); } if (mLastMouseOver != null) { mLastMouseOver.IsMouseOver = false; } if (!mSelectionInProgress) { var hit = mRaycaster.Raycast <SelectableView>(mouse); if (!hit.IsEmpty()) { hit.Object.IsMouseOver = true; mLastMouseOver = hit.Object; } } }
public override void OnRightClick(SelectableView view) { if (view is BuildingTemplateView) { Orders.AttachAsBuilder(((BuildingTemplateView)view).Info.ID); } }
public void FinishBoxSelection(bool union, Vector3 mouse) { if (!mSelectionInProgress) { return; } var selectionRect = new Rect(mSelectionStartPosition, mouse - mSelectionStartPosition); if (selectionRect.size.magnitude > 0.1f) { var toSelect = new List <SelectableView>(); for (int i = 0; i < mUserInterface.Root.MapView.ChildContainer.transform.childCount; i++) { var child = mUserInterface.Root.MapView.ChildContainer.transform.GetChild(i); var selectableView = child.GetComponent <SelectableView>(); if (selectableView == null) { continue; } if (!selectableView.IsControlable) { continue; } var projected = Camera.main.WorldToScreenPoint(child.position); if (selectionRect.Contains((Vector2)projected, true)) { toSelect.Add(selectableView); } } IEnumerable <SelectableView> filtered = new SelectableView[0]; if (toSelect.Count > 0) { filtered = toSelect.GroupBy(view => view.SelectionPriority).OrderByDescending(g => g.Key).First(); } SelectInner(filtered, union); } mSelectionInProgress = false; }
private void ControlledFactoryOnViewCreated(SelectableView selectableView) { selectableView.IsControlable = true; }
private void EnemyFactoryOnViewCreated(SelectableView obj) { obj.IsControlable = false; }
void Awake() { _selectableView = GetComponent <SelectableView>(); _selectableView.OnViewClicked = HandleViewClicked; OnAwake(); }