Beispiel #1
0
 public static void _Add(this List <ISelectObject> os, ISelectObject o)
 {
     if (o != null)
     {
         os.Add(o);
     }
 }
Beispiel #2
0
 public static void _Remove(this List <ISelectObject> os, ISelectObject o)
 {
     if (o != null)
     {
         os.Remove(o);
     }
 }
Beispiel #3
0
        void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            ISelectObject so = ServiceHost.File.CurrentDocument.ActiveView as ISelectObject;

            if (so != null)
            {
                (so as Control).Refresh();
            }
        }
        /// <summary>
        /// When clicking selects the object clicked on.
        /// </summary>
        private void SelectObject()
        {
            RaycastHit hit;
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                ISelectObject selectedObject = hit.transform.GetComponent <ISelectObject>();


                if (hit.transform.tag == "FieldPlot")
                {
                    Debug.Log("Clicked on " + hit.transform.name);
                    towerBuilderController.TurnOnTowerMenu(hit.transform.GetComponent <FieldPlot>());
                }
            }
        }
Beispiel #5
0
        public void LateUpdate()
        {
            if (!Enable && !isDrawBox)
            {
                return;
            }
            if (Input.GetMouseButtonDown(0) && (EventSystem.current == null || !EventSystem.current.IsPointerOverGameObject()))
            {
                isDown = true;
                point  = Input.mousePosition;
            }
            if (!isDown)
            {
                return;
            }
            if (Input.GetMouseButtonUp(0))
            {
                isDown = false;
                if (HandlingEvent != null)
                {
                    HandlingEvent(false);
                }
                if (!isDrawBox)
                {
                    CalcTexture(0.5f, 0.5f);
                    Vector2       uv  = GetPointerUV();
                    Color         col = tex.GetPixelBilinear(uv.x, uv.y);
                    ISelectObject s   = GetSelectObject(col);
                    if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl))
                    {
                        if (results.Contains(s))
                        {
                            results._Remove(s);
                        }
                        else
                        {
                            results._Add(s);
                        }
                    }
                    else
                    {
                        results.Clear();
                        results._Add(s);
                    }
                    if (SelectingEvent != null)
                    {
                        SelectingEvent(results);
                    }
                }
                isDrawBox = false;
                if (SelectedEvent != null)
                {
                    SelectedEvent(results);
                }
            }
            if (!isDown)
            {
                return;
            }
            if (!isDrawBox)
            {
                if ((Input.mousePosition - point).sqrMagnitude > 100)
                {
                    if (HandlingEvent != null)
                    {
                        HandlingEvent(true);
                    }
                    CalcTexture(0.1f, 0.1f);
                    isDrawBox = true;
                }
            }
            else
            {
                Vector2 _min = GetPointerUV(min);
                Vector2 _max = GetPointerUV(max) - _min;
                int     x    = (int)(_min.x * w);
                int     y    = (int)(_min.y * h);
                int     sw   = (int)(_max.x * w);
                int     sh   = (int)(_max.y * h);
                Color[] cols = tex.GetPixels(x, y, sw, sh);

                List <Color> _cols = new List <Color>();
                foreach (var col in cols)
                {
                    if (!_cols.Contains(col))
                    {
                        _cols.Add(col);
                    }
                }
                selected.Clear();
                foreach (var col in _cols)
                {
                    ISelectObject ele = GetSelectObject(col);
                    if (ele != null)
                    {
                        selected._Add(ele);
                    }
                }
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    results.AddRange(from s in selected where !results.Contains(s) select s);
                }
                else if (Input.GetKey(KeyCode.LeftControl))
                {
                    results = (from r in results where !selected.Contains(r) select r).ToList();
                }
                else
                {
                    results = selected;
                }
                if (SelectingEvent != null)
                {
                    SelectingEvent(results);
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// Select the given objects using the given rayOrigin
 /// </summary>
 /// <param name="hoveredObjects">The hovered objects</param>
 /// <param name="rayOrigin">The rayOrigin used for selection</param>
 /// <param name="multiSelect">Whether to add the hovered object to the selection, or override the current selection</param>
 /// <param name="useGrouping">Use group selection</param>
 public static void SelectObjects(this ISelectObject obj, List <GameObject> hoveredObjects, Transform rayOrigin, bool multiSelect, bool useGrouping = false)
 {
     selectObjects(hoveredObjects, rayOrigin, multiSelect, useGrouping);
 }
Beispiel #7
0
 /// <summary>
 /// Given a hovered object, find what object would actually be selected
 /// </summary>
 /// <param name="hoveredObject">The hovered object that is being tested for selection</param>
 /// <param name="useGrouping">Use group selection</param>
 /// <returns>Returns what object would be selected by selectObject</returns>
 public static GameObject GetSelectionCandidate(this ISelectObject obj, GameObject hoveredObject, bool useGrouping = false)
 {
     return(getSelectionCandidate(hoveredObject, useGrouping));
 }