Exemplo n.º 1
0
 private static void HandleWindowsGUI(SceneView sceneView)
 {
     SceneViewWindow.OnSceneView(sceneView);
 }
Exemplo n.º 2
0
        private static void UpdateMouseOverPrimitives(Event current)
        {
            // Can't perform picking during repaint event.
            if (current == null || !(current.isMouse || current.isKey))
            {
                return;
            }

            // Update mouse over before we reveal the VisualPrimitives.
            // NOTE: We're putting our "visual primitives" in the ignore list.
            if (current.isMouse)
            {
                List <GameObject> ignoreList = new List <GameObject>();
                foreach (var primitive in m_visualPrimitives)
                {
                    if (!primitive.Visible)
                    {
                        continue;
                    }

                    MeshFilter[] primitiveFilters = primitive.Node.GetComponentsInChildren <MeshFilter>();
                    ignoreList.AddRange(primitiveFilters.Select(pf => { return(pf.gameObject); }));
                }

                // If the mouse is hovering a scene view window - MouseOverObject should be null.
                if (SceneViewWindow.GetMouseOverWindow(current.mousePosition) != null)
                {
                    MouseOverObject = null;
                }
                else
                {
                    MouseOverObject = RouteObject(HandleUtility.PickGameObject(current.mousePosition,
                                                                               false,
                                                                               ignoreList.ToArray())) as GameObject;
                }
            }

            // Early exit if we haven't any active visual primitives.
            if (m_visualPrimitives.Count == 0)
            {
                return;
            }

            var primitiveHitList = new[] { new { Primitive = (Utils.VisualPrimitive)null, RaycastResult = Raycast.Hit.Invalid } }.ToList();

            primitiveHitList.Clear();

            Ray mouseRay = HandleUtility.GUIPointToWorldRay(current.mousePosition);

            foreach (var primitive in m_visualPrimitives)
            {
                primitive.MouseOver = false;

                if (!primitive.Pickable)
                {
                    continue;
                }

                Raycast.Hit hit = Raycast.Test(primitive.Node, mouseRay, 500f, true);
                if (hit.Triangle.Valid)
                {
                    primitiveHitList.Add(new { Primitive = primitive, RaycastResult = hit });
                }
            }

            if (primitiveHitList.Count == 0)
            {
                return;
            }

            var bestResult = primitiveHitList[0];

            for (int i = 1; i < primitiveHitList.Count; ++i)
            {
                if (primitiveHitList[i].RaycastResult.Triangle.Distance < bestResult.RaycastResult.Triangle.Distance)
                {
                    bestResult = primitiveHitList[i];
                }
            }

            bestResult.Primitive.MouseOver = true;
            if (HijackLeftMouseClick())
            {
                bestResult.Primitive.OnMouseClick(bestResult.RaycastResult, bestResult.Primitive);
            }
        }