LookAt() public method

public LookAt ( Vector3 pos ) : void
pos Vector3
return void
Exemplo n.º 1
0
        private void ContextMenuDelegate(object userData, string[] options, int selected)
        {
            SceneView view = userData as SceneView;

            if (view != null)
            {
                if (selected == 0)
                {
                    this.ViewFromNiceAngle(view, false);
                }
                else if ((selected >= 1) && (selected <= 6))
                {
                    int dir = selected - 1;
                    this.ViewAxisDirection(view, dir);
                }
                else if (selected == 8)
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
                else if (selected == 10)
                {
                    view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(-1f, -0.7f, -1f)), view.size, view.orthographic);
                }
                else if (selected == 11)
                {
                    view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(1f, -0.7f, -1f)), view.size, view.orthographic);
                }
                else if (selected == 12)
                {
                    view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(1f, -0.7f, 1f)), view.size, view.orthographic);
                }
            }
        }
        private static void HandleMouseUp(SceneView view, int id, int button, int clickCount)
        {
            if (GUIUtility.hotControl == id && (shortcutKey == KeyCode.None || shortcutKey == (Event.current.keyCode == KeyCode.None ? KeyCode.Mouse0 + Event.current.button : Event.current.keyCode)))
            {
                // Move pivot to clicked point.
                if (Tools.s_LockedViewTool == ViewTool.Pan && !s_Drag)
                {
                    RaycastHit hit;
                    if (RaycastWorld(Event.current.mousePosition, out hit))
                    {
                        Vector3 currentPosition = view.pivot - view.rotation * Vector3.forward * view.cameraDistance;
                        float   targetSize      = view.size;
                        if (!view.orthographic)
                        {
                            targetSize = view.size * Vector3.Dot(hit.point - currentPosition, view.rotation * Vector3.forward) / view.cameraDistance;
                        }
                        view.LookAt(hit.point, view.rotation, targetSize);
                    }
                }

                Tools.viewTool         = ViewTool.Pan;
                Tools.s_LockedViewTool = ViewTool.None;
                shortcutKey            = KeyCode.None;
                ResetDragState();
                viewToolActiveChanged?.Invoke();
            }
        }
Exemplo n.º 3
0
        private void ViewFromNiceAngle(SceneView view, bool forcePerspective)
        {
            // Use dir that's the same as the current one in the x-z plane, but placed a bit above middle vertically.
            // (Same as old dir except it had the x-z dir fixed.)
            Vector3 dir = view.rotation * Vector3.forward;

            dir.y = 0;
            if (dir == Vector3.zero)
            {
                // When the view is top or bottom, the closest nice view is to look approx. towards z.
                dir = Vector3.forward;
            }
            else
            {
                // Otherwise pick dir based on existing dir.
                dir = dir.normalized;
            }
            // Look at object a bit from above.
            dir.y = -0.5f;

            bool ortho = forcePerspective ? false : view.orthographic;

            view.LookAt(view.pivot, Quaternion.LookRotation(dir), view.size, ortho);
            SwitchDirNameVisible(ortho ? 6 : 7);
        }
Exemplo n.º 4
0
        private static void HandleMouseUp(SceneView view, int id, int button, int clickCount)
        {
            if (GUIUtility.hotControl == id)
            {
                GUIUtility.hotControl = 0;

                // Move pivot to clicked point.
                if (button == 2 && s_CurrentState != MotionState.kDragging)
                {
                    RaycastHit hit;
                    if (RaycastWorld(Event.current.mousePosition, out hit))
                    {
                        Vector3 currentPosition = view.pivot - view.rotation * Vector3.forward * view.cameraDistance;
                        float   targetSize      = view.size;
                        if (!view.orthographic)
                        {
                            targetSize = view.size * Vector3.Dot(hit.point - currentPosition, view.rotation * Vector3.forward) / view.cameraDistance;
                        }
                        view.LookAt(hit.point, view.rotation, targetSize);
                    }
                }

                ResetDragState();

                Event.current.Use();
            }
        }
Exemplo n.º 5
0
        private void ViewAxisDirection(SceneView view, int dir)
        {
            bool orthographic = view.orthographic;

            if ((Event.current != null) && (Event.current.shift || (Event.current.button == 2)))
            {
                orthographic = true;
            }
            view.LookAt(view.pivot, kDirectionRotations[dir], view.size, orthographic);
            this.SwitchDirNameVisible(dir);
        }
Exemplo n.º 6
0
        private void ContextMenuDelegate(object userData, string[] options, int selected)
        {
            SceneView view = userData as SceneView;

            if (view == null)
            {
                return;
            }

            if (selected == 0)
            {
                // "free" selected
                ViewFromNiceAngle(view, false);
            }
            else if (selected >= 1 && selected <= 6)
            {
                // one of axes was selected
                int axis = selected - 1;
                ViewAxisDirection(view, axis);
            }
            else if (selected == 8)
            {
                // perspective / ortho toggled
                ViewSetOrtho(view, !view.orthographic);
            }
            else if (selected == 10)
            {
                // Unity default point of view
                view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(-1, -.7f, -1)), view.size, view.orthographic);
            }
            else if (selected == 11)
            {
                // Maya default point of view
                view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(1, -.7f, -1)), view.size, view.orthographic);
            }
            else if (selected == 12)
            {
                // 3DSMax default point of view
                view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(1, -.7f, 1)), view.size, view.orthographic);
            }
        }
Exemplo n.º 7
0
        private void ViewFromNiceAngle(SceneView view, bool forcePerspective)
        {
            Vector3 forward = view.rotation * Vector3.forward;

            forward.y = 0.0f;
            forward   = !(forward == Vector3.zero) ? forward.normalized : Vector3.forward;
            forward.y = -0.5f;
            bool ortho = !forcePerspective && view.orthographic;

            view.LookAt(view.pivot, Quaternion.LookRotation(forward), view.size, ortho);
            this.SwitchDirNameVisible(!ortho ? 7 : 6);
        }
Exemplo n.º 8
0
        private void ViewAxisDirection(SceneView view, int dir)
        {
            // If holding shift or clicking with middle mouse button, orthographic is enforced, otherwise not altered.
            // Note: This function can also be called from a context menu where Event.current is null.
            bool ortho = view.orthographic;

            if (Event.current != null && (Event.current.shift || Event.current.button == 2))
            {
                ortho = true;
            }

            view.LookAt(view.pivot, kDirectionRotations[dir], view.size, ortho);
            // Set label to according direction
            SwitchDirNameVisible(dir);
        }
        static void PastePlacement(SceneView view)
        {
            var tr        = view.camera.transform;
            var placement = Clipboard.GetCustomValue <TransformWorldPlacement>();

            tr.position   = placement.position;
            tr.rotation   = placement.rotation;
            tr.localScale = placement.scale;

            // Similar to what AlignViewToObject does, except we need to do that instantly
            // in case the shortcut key was pressed while FPS camera controls (right click drag)
            // were active.
            view.size = 10;
            view.LookAt(tr.position + tr.forward * view.cameraDistance, tr.rotation, view.size, view.orthographic, true);

            view.Repaint();
        }
Exemplo n.º 10
0
        private void ViewFromNiceAngle(SceneView view, bool forcePerspective)
        {
            Vector3 vector = view.rotation * Vector3.forward;

            vector.y = 0f;
            if (vector == Vector3.zero)
            {
                vector = Vector3.forward;
            }
            else
            {
                vector = vector.normalized;
            }
            vector.y = -0.5f;
            bool flag = !forcePerspective && view.orthographic;

            view.LookAt(view.pivot, Quaternion.LookRotation(vector), view.size, flag);
            this.SwitchDirNameVisible((!flag) ? 7 : 6);
        }
Exemplo n.º 11
0
 private static void HandleMouseUp(SceneView view, int id, int button, int clickCount)
 {
     if (GUIUtility.hotControl == id)
     {
         SceneViewMotion.ResetDragState();
         RaycastHit raycastHit;
         if (button == 2 && !SceneViewMotion.s_Dragged && SceneViewMotion.RaycastWorld(Event.current.mousePosition, out raycastHit))
         {
             Vector3 b       = view.pivot - view.rotation * Vector3.forward * view.cameraDistance;
             float   newSize = view.size;
             if (!view.orthographic)
             {
                 newSize = view.size * Vector3.Dot(raycastHit.point - b, view.rotation * Vector3.forward) / view.cameraDistance;
             }
             view.LookAt(raycastHit.point, view.rotation, newSize);
         }
         Event.current.Use();
     }
 }
Exemplo n.º 12
0
        private void ViewFromNiceAngle(SceneView view, bool forcePerspective)
        {
            Vector3 forward = (Vector3)(view.rotation * Vector3.forward);

            forward.y = 0f;
            if (forward == Vector3.zero)
            {
                forward = Vector3.forward;
            }
            else
            {
                forward = forward.normalized;
            }
            forward.y = -0.5f;
            bool ortho = !forcePerspective ? view.orthographic : false;

            view.LookAt(view.pivot, Quaternion.LookRotation(forward), view.size, ortho);
            this.SwitchDirNameVisible(!ortho ? 7 : 6);
        }
Exemplo n.º 13
0
 private static void HandleMouseUp(SceneView view, int id, int button, int clickCount)
 {
     if (GUIUtility.hotControl == id)
     {
         RaycastHit hit;
         ResetDragState();
         if (((button == 2) && !s_Dragged) && RaycastWorld(Event.current.mousePosition, out hit))
         {
             Vector3 vector = view.pivot - ((Vector3)((view.rotation * Vector3.forward) * view.cameraDistance));
             float   size   = view.size;
             if (!view.orthographic)
             {
                 size = (view.size * Vector3.Dot(hit.point - vector, (Vector3)(view.rotation * Vector3.forward))) / view.cameraDistance;
             }
             view.LookAt(hit.point, view.rotation, size);
         }
         Event.current.Use();
     }
 }
Exemplo n.º 14
0
    private void UpdateSetCam(SceneView scene)
    {
        if (SetCam)
        {

            if (EditorApplication.isPlaying && !EditorApplication.isPaused)
            {
                var t = Camera.main.transform;
                scene.LookAt(t.position, t.rotation, 3);
                //Camera.main.GetComponent<GUILayer>().enabled = true;
            }
            else
            {
                var t = Camera.main.transform;
                t.position = scene.camera.transform.position;
                t.rotation = scene.camera.transform.rotation;
                //Camera.main.GetComponent<GUILayer>().enabled = false;
            }
        }
    }
Exemplo n.º 15
0
 private void ViewSetOrtho(SceneView view, bool ortho)
 {
     view.LookAt(view.pivot, view.rotation, view.size, ortho);
 }
Exemplo n.º 16
0
 private static void HandleMouseUp(SceneView view, int id, int button, int clickCount)
 {
   if (GUIUtility.hotControl != id)
     return;
   SceneViewMotion.ResetDragState();
   RaycastHit hit;
   if (button == 2 && !SceneViewMotion.s_Dragged && SceneViewMotion.RaycastWorld(Event.current.mousePosition, out hit))
   {
     Vector3 vector3 = view.pivot - view.rotation * Vector3.forward * view.cameraDistance;
     float newSize = view.size;
     if (!view.orthographic)
       newSize = view.size * Vector3.Dot(hit.point - vector3, view.rotation * Vector3.forward) / view.cameraDistance;
     view.LookAt(hit.point, view.rotation, newSize);
   }
   Event.current.Use();
 }
Exemplo n.º 17
0
 internal void ViewAxisDirection(SceneView view, int dir, bool ortho)
 {
     view.LookAt(view.pivot, kDirectionRotations[dir], view.size, ortho);
     // Set label to according direction
     SwitchDirNameVisible(dir);
 }
 private void UpdateSetCam(SceneView scene)
 {
     if (SetCam)
     {
         if (EditorApplication.isPlaying && !EditorApplication.isPaused && Camera.main != null)
         {
             var t = Camera.main.transform;
             scene.LookAt(t.position, t.rotation, 3);
         }
     }
 }
Exemplo n.º 19
0
 internal void ViewSetMaxDefault(SceneView view)
 {
     // 3DSMax default point of view
     view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(1, -.7f, 1)), view.size, view.orthographic);
 }
Exemplo n.º 20
0
 internal void ViewSetUnityDefault(SceneView view)
 {
     // Unity default point of view
     view.LookAt(view.pivot, Quaternion.LookRotation(new Vector3(-1, -.7f, -1)), view.size, view.orthographic);
 }
Exemplo n.º 21
0
 private static void HandleMouseUp(SceneView view, int id, int button, int clickCount)
 {
     if (GUIUtility.hotControl == id)
     {
         RaycastHit hit;
         ResetDragState();
         if (((button == 2) && !s_Dragged) && RaycastWorld(Event.current.mousePosition, out hit))
         {
             Vector3 vector = view.pivot - ((Vector3) ((view.rotation * Vector3.forward) * view.cameraDistance));
             float size = view.size;
             if (!view.orthographic)
             {
                 size = (view.size * Vector3.Dot(hit.point - vector, (Vector3) (view.rotation * Vector3.forward))) / view.cameraDistance;
             }
             view.LookAt(hit.point, view.rotation, size);
         }
         Event.current.Use();
     }
 }
Exemplo n.º 22
0
    private void OnSceneUpdate(SceneView scene)
    {
        if (Event.current.isMouse) idletime = DateTime.Now;
        var ago = Selection.activeGameObject;
        if (SetPivot)
        {
            var move = oldpos - ago.transform.position;
            foreach (Transform t in ago.transform)
            {
                t.position += move;
            }
        }
        if (ago != null)
            oldpos = ago.transform.position;
        var scenecam = scene.camera;
        if (SetCam)
        {
            if (EditorApplication.isPlaying && !EditorApplication.isPaused)
            {
                var t = Camera.main.transform;
                scene.LookAt(t.position,t.rotation,3);
                Camera.main.GetComponent<GUILayer>().enabled = true;
            }
            else
            {
                var t = Camera.main.transform;
                t.position = scene.camera.transform.position;
                t.rotation = scene.camera.transform.rotation;
                Camera.main.GetComponent<GUILayer>().enabled = false;
            }
        }
        var e = Event.current;
        var p = e.mousePosition;
        if (e.keyCode == KeyCode.G && e.type == EventType.KeyUp)
        {

            Ray r = HandleUtility.GUIPointToWorldRay(new Vector2(p.x, p.y));
            RaycastHit h;
            if (Physics.Raycast(r, out h))
                scene.LookAt(h.point - 5 * r.direction, scenecam.transform.rotation, 5);
            if (e.modifiers == EventModifiers.Control && Selection.activeGameObject != null)
            {
                Undo.RegisterSceneUndo("rtools");
                var o = (GameObject)EditorUtility.InstantiatePrefab(Selection.activeGameObject);
                o.transform.localPosition = Vector3.zero;
                o.transform.position = h.point;
                o.transform.rotation = Quaternion.AngleAxis(90, Vector3.up) * Quaternion.LookRotation(h.normal);
                    //* Quaternion.LookRotation(h.point - SceneView.lastActiveSceneView.camera.transform.position);
            }
        }
    }
Exemplo n.º 23
0
		private void ViewFromNiceAngle(SceneView view, bool forcePerspective)
		{
			Vector3 vector = view.rotation * Vector3.forward;
			vector.y = 0f;
			if (vector == Vector3.zero)
			{
				vector = Vector3.forward;
			}
			else
			{
				vector = vector.normalized;
			}
			vector.y = -0.5f;
			bool flag = !forcePerspective && view.orthographic;
			view.LookAt(view.pivot, Quaternion.LookRotation(vector), view.size, flag);
			this.SwitchDirNameVisible((!flag) ? 7 : 6);
		}
        private void DrawSceneGUI(SceneView view)
        {
            isMouseOverGoID = -1;
            isMouseOverCompID = -1;
            Rect isMouseOverRect = default(Rect);

            if (currentFrameData != null && currentFrameData.particleSystems != null) {
                //--------------- GUI --------------------

                foreach (SGenericParticleSystem system in currentFrameData.particleSystems) {
                    if (system == null || !system.emit || !system.enabled || system.particles == null || system.particles.positions == null || !representors.ContainsKey(system.instanceID))
                        continue;

                    Bounds bounds = new Bounds(system.position, Vector3.zero);
                    if (system.particles.positions.Length > 0)
                        bounds = GetBoundsFromParticlePositions(system.instanceID, system.particles);

                    if (Vector3.Dot(view.camera.transform.forward, bounds.center - view.camera.transform.position) > 0) {
                        Rect bbRect = SceneVisualsHelper.GetRectFromBounds(bounds);

                        if (isMouseOverCompID != -1 && isMouseOverRect.Contains(bbRect.center))
                            continue;

                        Rect iconRect = VisualResources.DrawIcon(EditorIcon.playbackToggles, 1, bbRect.center, 1f, true);
                        if (iconRect.Contains(Event.current.mousePosition)) {

                            isMouseOverCompID = system.instanceID;
                            isMouseOverGoID = system.goInstanceID;

                            //--------------- Arrow & BB Rect --------------------
                            SceneVisualsHelper.DrawBBArrow(bbRect);
                            //SceneVisualsHelper.DrawBBRect(bbRect);
                            //--------------- Arrow & BB Rect --------------------

                            //--------------- Layout init --------------------
                            float width = 200f;
                            float infoHeight = 70f;
                            float left = bbRect.xMax + 16;
                            float top = bbRect.y + (bbRect.height / 2f) - (infoHeight / 2f);

                            GUI.contentColor = Color.white;
                            EditorHelper.styleLabelSceneVisuals.fontSize = 12;
                            //--------------- Layout init --------------------

                            //--------------- Label --------------------
                            Rect labelRect = new Rect(left, top, width, 20);
                            VisualResources.DrawTexture(labelRect, VisualResources.proConsoleLineDark);
                            GUI.Label(labelRect, !string.IsNullOrEmpty(system.name) ? system.name : "N/A", EditorHelper.styleLabelSceneVisuals);
                            //--------------- Label --------------------

                            //--------------- Particle Info --------------------
                            GUI.contentColor = Color.black;
                            EditorHelper.styleLabelSceneVisuals.fontSize = 9;
                            Rect contentRect = new Rect(left, top + 20, width, infoHeight - 20);
                            isMouseOverRect = contentRect;

                            VisualResources.DrawTexture(contentRect, VisualResources.gray);
                            string infoLabel =
                                (system.isLegacy ? "[LEGACY]\n" : "[SHURIKEN]\n") +
                                "Particle count : " + (system.particles.positions.Length / 3) + "\n" +
                                "Rendermode : " + system.renderer.renderMode + "\n" +
                                "Simulation space : " + (system.isWorldSpace ? "world" : "local") + "\n";

                            GUI.Label(new Rect(left, top + 15, width, infoHeight), infoLabel, EditorHelper.styleLabelSceneVisuals);
                            //--------------- Particle Info --------------------

                            //--------------- Navigation --------------------
                            //if (Event.current.type == EventType.MouseDown) {
                            if (Handles.Button(bounds.center, Quaternion.identity, 10, 10, Handles.CubeCap)) {
                                if (isMouseTapID == isMouseOverCompID) { //already selected
                                    Transform camTrans = view.camera.transform;
                                    view.LookAt(bounds.center, Quaternion.LookRotation(bounds.center - camTrans.position, Vector3.up), Mathf.Max(1, bounds.extents.magnitude * 2f));

                                    if (vBugBaseWindow.CheckIfOpen(typeof(vBugHierarchyWindow))) {
                                        vBugHierarchyWindow hierarchyWin = EditorWindow.GetWindow<vBugHierarchyWindow>();
                                        if (hierarchyWin != null)
                                            hierarchyWin.NavigateToID(isMouseOverGoID);
                                    }
                                }
                                isMouseTapID = isMouseOverCompID;
                            }
                            //--------------- Navigation --------------------
                        }
                    }
                }
                //--------------- GUI --------------------
                GUI.contentColor = Color.white;
            }

            if (isMouseOverCompID == -1)
                isMouseTapID = -1;
        }
 private void ViewFromNiceAngle(SceneView view, bool forcePerspective)
 {
   Vector3 forward = view.rotation * Vector3.forward;
   forward.y = 0.0f;
   forward = !(forward == Vector3.zero) ? forward.normalized : Vector3.forward;
   forward.y = -0.5f;
   bool ortho = !forcePerspective && view.orthographic;
   view.LookAt(view.pivot, Quaternion.LookRotation(forward), view.size, ortho);
   this.SwitchDirNameVisible(!ortho ? 7 : 6);
 }
 private void ViewSetOrtho(SceneView view, bool ortho)
 {
   view.LookAt(view.pivot, view.rotation, view.size, ortho);
 }
 private void ViewAxisDirection(SceneView view, int dir)
 {
   bool ortho = view.orthographic;
   if (Event.current != null && (Event.current.shift || Event.current.button == 2))
     ortho = true;
   view.LookAt(view.pivot, SceneViewRotation.kDirectionRotations[dir], view.size, ortho);
   this.SwitchDirNameVisible(dir);
 }
Exemplo n.º 28
0
 private void ViewFromNiceAngle(SceneView view, bool forcePerspective)
 {
     Vector3 forward = (Vector3) (view.rotation * Vector3.forward);
     forward.y = 0f;
     if (forward == Vector3.zero)
     {
         forward = Vector3.forward;
     }
     else
     {
         forward = forward.normalized;
     }
     forward.y = -0.5f;
     bool ortho = !forcePerspective ? view.orthographic : false;
     view.LookAt(view.pivot, Quaternion.LookRotation(forward), view.size, ortho);
     this.SwitchDirNameVisible(!ortho ? 7 : 6);
 }
Exemplo n.º 29
0
 static void ToggleBetweenViewDirections(SceneView view, Quaternion primaryDirection, Quaternion alternativeDirection)
 {
     Vector3 direction = primaryDirection * Vector3.forward;
     float dot = Vector3.Dot(view.camera.transform.forward, direction);
     if (dot < 1.0f - kCompareEpsilon) { view.LookAt(view.pivot, primaryDirection,     view.size, view.orthographic); }
     else                              { view.LookAt(view.pivot, alternativeDirection, view.size, view.orthographic); }
 }