예제 #1
0
        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;
                }
            }
        }
예제 #2
0
 public override void OnRightClick(SelectableView view)
 {
     if (view is BuildingTemplateView)
     {
         Orders.AttachAsBuilder(((BuildingTemplateView)view).Info.ID);
     }
 }
예제 #3
0
        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;
        }
예제 #4
0
 private void ControlledFactoryOnViewCreated(SelectableView selectableView)
 {
     selectableView.IsControlable = true;
 }
예제 #5
0
 private void EnemyFactoryOnViewCreated(SelectableView obj)
 {
     obj.IsControlable = false;
 }
예제 #6
0
 void Awake()
 {
     _selectableView = GetComponent <SelectableView>();
     _selectableView.OnViewClicked = HandleViewClicked;
     OnAwake();
 }