Exemple #1
0
        // -----------------------  Public API ------------------------------------------------


        // ------------------------------------------------------------------------------------------------
        /// <summary>
        /// Called most of the time the sim is running to highlight whatever is under the mouse currently.
        /// If it's part of set, then highlight is updated on selected set. I.e. if we have mouse-dragged
        /// to select a bunch of stuff, subsequently doing a mouse-over one of them will highlight all of them
        /// </summary>
        /// <returns></returns>
        public void UpdateHilight(UN_Camera cam)
        // ------------------------------------------------------------------------------------------------
        {
            SM_ISelectable obj = CheckForObjectUnderMouse(cam);

            if (obj == null)
            {
                UnHilightAll();
            }
            else if (obj.IsHilighted == false) // the object wasn't hilighted before
            {
                UnHilightAll();                // clear out old set

                // if this object is a member of a set, then hilight all of them
                if (obj.IsSelected && _selected.Count > 1)
                {
                    foreach (var v in _selected)
                    {
                        SetHilighted(v);
                    }
                }
                else
                {
                    SetHilighted(obj);
                }
            }
            // otherwise we were already hilighted and have nothing to do.
        }
Exemple #2
0
        /// <summary>
        /// Sets object to be selected. Returns true if something changed
        /// </summary>
        /// <param name="obj"></param>
        bool SetSelected(SM_ISelectable obj)
        {
            if (obj != null && obj.IsSelected == false)
            {
                SM_SelectionChangedEvent ev = new SM_SelectionChangedEvent();

                if (_selected.Count != 0)
                {
                    for (int i = 0; i < _selected.Count; i++)
                    {
                        ev.Who.Add(_selected[i]);
                        _selected[i].SetSelected(false);
                    }
                    _selected.Clear();
                }

                _selected.Add(obj);
                obj.SetSelected(true);

                ev.NewWho.AddRange(_selected);
                Events.SendGlobal(ev);

                return(true);
            }
            return(false);
        }
Exemple #3
0
 /// <summary>
 /// Sets object to be selected
 /// </summary>
 /// <param name="obj"></param>
 void SetHilighted(SM_ISelectable obj)
 {
     if (obj != null && obj.IsHilighted == false)
     {
         _hilighted.Add(obj);
         obj.SetHilighted(true);
     }
 }
 void SetTarget(SM_ISelectable sel)
 {
     _target = sel;
     if (_target != null)
     {
         _selectionProjector.transform.SetParent(_target.gameObject.transform);
         _selectionProjector.transform.localPosition = Vector3.zero;
         _selectionProjector.transform.localRotation = Quaternion.identity;
         Refresh();
     }
     else
     {
         UN.SetActive(_selectionProjector, false);
     }
 }
Exemple #5
0
        protected bool CheckParentsForSelectable(Transform trans, ref SM_ISelectable select)
        {
            SM_ISelectable sel = trans.gameObject.GetComponent <SM_ISelectable>();

            if (sel != null && CanSelect(sel))
            {
                select = sel;
                return(true);
            }

            for (int i = 0; i < trans.childCount; i++)
            {
                Transform newT = trans.GetChild(i);
                if (CheckParentsForSelectable(newT, ref select))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #6
0
        // ------------------------------------------------------------------------------------------------
        /// <summary>
        /// Simply returns the 'best' ISelectable under the mouse
        /// </summary>
        /// <returns></returns>
        protected SM_ISelectable CheckForObjectUnderMouse(UN_Camera cam)
        // ------------------------------------------------------------------------------------------------
        {
            if (Dbg.Assert(cam != null))
            {
                return(null);
            }

            Ray ray = cam.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] hits = Physics.RaycastAll(ray);
            if (hits == null)
            {
                return(null);
            }

            int            bestNdx    = -1;
            float          bestDst    = float.MaxValue;
            SM_ISelectable bestSelect = null;

            for (int i = 0; i < hits.Length; i++)
            {
                if (hits[i].distance < bestDst)
                {
                    if (CheckParentsForSelectable(hits[i].transform, ref bestSelect))
                    {
                        bestNdx = i;
                    }
                }
            }

            if (bestNdx < 0)
            {
                return(null);
            }

            return(bestSelect);
        }
Exemple #7
0
        //protected override void OnSelectionChanged(SM_SelectionChangedEvent ev)
        //{
        //    //### TODO check to see if this is someone that the local player can muck with
        //    //bool isHumanTeam = false;

        //    //// if we are de-selecting, or selecting non-human team then we don't care
        //    //if (ev.NewWho.Count == 0 && isHumanTeam == false)
        //    //{
        //    //    _inputMgr.QueueInputMode<MT_InputModeBase>();
        //    //}
        //}

        public override bool Update()
        {
            // returns true if we're done with update this frame
            if (base.Update())
            {
                return(true);
            }

            UpdateHilight(PT_Game.Match.MainCamera);

            if (Input.GetMouseButtonDown(0))
            {
                SM_ISelectable sel = CheckForObjectUnderMouse(PT_Game.Match.MainCamera);
                if (sel != null)
                {
                }
            }

            MT_Combatant c = PT_Game.UI.Match.SelectedPCCombatant;

            Dbg.Assert(c != null);

            if (c.IsOut == false)
            {
                int numKeyDown = GetNumberKeyDown();
                if (numKeyDown >= 0)
                {
                    if (c.Base.Actions != null && numKeyDown <= c.Base.Actions.Count)
                    {
                        PT_Game.Match.StartAction(c.Base.Actions[numKeyDown - 1], c); // TODO : replace with event?
                        return(true);
                    }
                }
            }

            return(false);
        }
 private void Awake()
 {
     _target = GetComponentInParent <SM_ISelectable>();
     Refresh();
     UN.SetActive(this, false);
 }
Exemple #9
0
 protected virtual bool CanSelect(SM_ISelectable sel)
 {
     return(true);
 }