LookAtDirect() public method

public LookAtDirect ( Vector3 pos, Quaternion rot ) : void
pos Vector3
rot UnityEngine.Quaternion
return void
示例#1
1
    public void OnSceneGUI(SceneView scene)
    {
        if(setPerspective){
            /* Selection.transforms	*/
            setPerspective = false;
            float angle = 30;
            Texture baseTile = IsoSettingsManager.getInstance().getIsoSettings().defautTextureScale;
            if(baseTile != null){
                float angulo = Mathf.Rad2Deg * Mathf.Acos(baseTile.height / (baseTile.width*1f));
                angle = 90f - angulo;
            }
            scene.LookAtDirect(scene.pivot,Quaternion.Euler(angle, 45, 0));
            scene.orthographic = true;

            if(fixView)
                fixedRotation = Quaternion.Euler(angle, 45, 0);

            scene.Repaint();
        }

        if(fixView)
            scene.LookAtDirect(scene.pivot,fixedRotation);

        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        if(Event.current.isMouse){
            if(Event.current.button == 0){
                if(Event.current.type == EventType.MouseDown)		startCreatingCells();
                else if(Event.current.type == EventType.MouseUp)	endCreatingCells();
                else												createCell();
            }
            else if(Event.current.button == 1){
                if(Event.current.type == EventType.MouseDown)		startMovingGrid();
                else if(Event.current.type == EventType.MouseUp)	endMovingGrid();
                else												moveGrid();
            }
            scene.Repaint();
        }

        Vector3 centerGridPoint = map.getMousePositionOverMap(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), Mathf.RoundToInt(gridHeight*2f)/2f);

        map.ghostCell(centerGridPoint, 0.5f);

        Vector3[] puntos = new Vector3[4];
        puntos[0] = new Vector3(centerGridPoint.x - cellSize/2.0f,centerGridPoint.y,centerGridPoint.z - cellSize/2.0f);
        puntos[1] = new Vector3(centerGridPoint.x - cellSize/2.0f,centerGridPoint.y,centerGridPoint.z + cellSize/2.0f);
        puntos[2] = new Vector3(centerGridPoint.x + cellSize/2.0f,centerGridPoint.y,centerGridPoint.z + cellSize/2.0f);
        puntos[3] = new Vector3(centerGridPoint.x + cellSize/2.0f,centerGridPoint.y,centerGridPoint.z - cellSize/2.0f);
        Handles.DrawSolidRectangleWithOutline(puntos, Color.yellow, Color.white);
    }
示例#2
0
    void Follow()
    {
        sceneViews = UnityEditor.SceneView.sceneViews;
        if (sceneViewFollowers == null || !on || sceneViews.Count == 0)
        {
            return;
        }

        foreach (SceneViewFollower svf in sceneViewFollowers)
        {
            if (!svf.enable)
            {
                continue;
            }
            UnityEditor.SceneView sceneView = (UnityEditor.SceneView)sceneViews[svf.sceneViewIndex];
            if (sceneView != null)
            {
                if ((Application.isPlaying && onlyInPlayMode) || !onlyInPlayMode)
                {
                    sceneView.orthographic = svf.orthographic;
                    sceneView.LookAtDirect(svf.targetTransform.position + svf.positionOffset, (svf.enableFixedRotation) ? Quaternion.Euler(svf.fixedRotation) : svf.targetTransform.rotation, svf.size);
                }
            }
        }
    }
示例#3
0
        public static void ArrowKeys(SceneView sv)
        {
            Event current   = Event.current;
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (GUIUtility.hotControl == 0 || GUIUtility.hotControl == controlID)
            {
                if (!EditorGUI.actionKey)
                {
                    EventType typeForControl = current.GetTypeForControl(controlID);
                    if (typeForControl != EventType.KeyDown)
                    {
                        if (typeForControl != EventType.KeyUp)
                        {
                            if (typeForControl == EventType.Layout)
                            {
                                if (GUIUtility.hotControl == controlID)
                                {
                                    Vector3 forward;
                                    if (!sv.m_Ortho.value)
                                    {
                                        forward   = Camera.current.transform.forward + Camera.current.transform.up * 0.3f;
                                        forward.y = 0f;
                                        forward.Normalize();
                                    }
                                    else
                                    {
                                        forward = Camera.current.transform.forward;
                                    }
                                    Vector3 movementDirection = SceneViewMotion.GetMovementDirection();
                                    sv.LookAtDirect(sv.pivot + Quaternion.LookRotation(forward) * movementDirection, sv.rotation);
                                    if (SceneViewMotion.s_Motion.sqrMagnitude == 0f)
                                    {
                                        sv.pivot = sv.pivot;
                                        SceneViewMotion.s_FlySpeed = 0f;
                                        GUIUtility.hotControl      = 0;
                                    }
                                    else
                                    {
                                        sv.Repaint();
                                    }
                                }
                            }
                        }
                        else if (GUIUtility.hotControl == controlID)
                        {
                            switch (current.keyCode)
                            {
                            case KeyCode.UpArrow:
                            case KeyCode.DownArrow:
                                SceneViewMotion.s_Motion.z = 0f;
                                SceneViewMotion.s_Motion.y = 0f;
                                current.Use();
                                break;

                            case KeyCode.RightArrow:
                            case KeyCode.LeftArrow:
                                SceneViewMotion.s_Motion.x = 0f;
                                current.Use();
                                break;
                            }
                        }
                    }
                    else
                    {
                        switch (current.keyCode)
                        {
                        case KeyCode.UpArrow:
                            sv.viewIsLockedToObject = false;
                            if (sv.m_Ortho.value)
                            {
                                SceneViewMotion.s_Motion.y = 1f;
                            }
                            else
                            {
                                SceneViewMotion.s_Motion.z = 1f;
                            }
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            break;

                        case KeyCode.DownArrow:
                            sv.viewIsLockedToObject = false;
                            if (sv.m_Ortho.value)
                            {
                                SceneViewMotion.s_Motion.y = -1f;
                            }
                            else
                            {
                                SceneViewMotion.s_Motion.z = -1f;
                            }
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            break;

                        case KeyCode.RightArrow:
                            sv.viewIsLockedToObject    = false;
                            SceneViewMotion.s_Motion.x = 1f;
                            GUIUtility.hotControl      = controlID;
                            current.Use();
                            break;

                        case KeyCode.LeftArrow:
                            sv.viewIsLockedToObject    = false;
                            SceneViewMotion.s_Motion.x = -1f;
                            GUIUtility.hotControl      = controlID;
                            current.Use();
                            break;
                        }
                    }
                }
            }
        }
示例#4
0
    public void OnSceneGUI()
    {
        current = Event.current;

        if (!current.isKey || current.type != EventType.KeyDown)
        {
            return;
        }

        sceneView   = UnityEditor.SceneView.lastActiveSceneView;
        eulerAngles = sceneView.camera.transform.rotation.eulerAngles;
        rotHelper   = sceneView.camera.transform.rotation;

        switch (current.keyCode)
        {
        case KeyCode.Keypad1:
            if (current.control == false)
            {
                sceneView.LookAtDirect(
                    SceneView.lastActiveSceneView.pivot,
                    Quaternion.Euler(new Vector3(0f, 360f, 0f)));
            }
            else
            {
                sceneView.LookAtDirect(
                    SceneView.lastActiveSceneView.pivot,
                    Quaternion.Euler(new Vector3(0f, 180f, 0f)));
            }
            break;

        case KeyCode.Keypad2:
            sceneView.LookAtDirect(
                SceneView.lastActiveSceneView.pivot,
                rotHelper * Quaternion.Euler(new Vector3(-15f, 0f, 0f)));
            break;

        case KeyCode.Keypad3:
            if (current.control == false)
            {
                sceneView.LookAtDirect(
                    SceneView.lastActiveSceneView.pivot,
                    Quaternion.Euler(new Vector3(0f, 270f, 0f)));
            }
            else
            {
                sceneView.LookAtDirect(
                    SceneView.lastActiveSceneView.pivot,
                    Quaternion.Euler(new Vector3(0f, 90f, 0f)));
            }
            break;

        case KeyCode.Keypad4:
            sceneView.LookAtDirect(
                SceneView.lastActiveSceneView.pivot,
                Quaternion.Euler(new Vector3(eulerAngles.x, eulerAngles.y + 15f, eulerAngles.z)));
            break;

        case KeyCode.Keypad5:
            sceneView.orthographic = !sceneView.orthographic;
            break;

        case KeyCode.Keypad6:
            sceneView.LookAtDirect(
                SceneView.lastActiveSceneView.pivot,
                Quaternion.Euler(new Vector3(eulerAngles.x, eulerAngles.y - 15f, eulerAngles.z)));
            break;

        case KeyCode.Keypad7:
            if (current.control == false)
            {
                sceneView.LookAtDirect(
                    SceneView.lastActiveSceneView.pivot,
                    Quaternion.Euler(new Vector3(90f, 0f, 0f)));
            }
            else
            {
                sceneView.LookAtDirect(
                    SceneView.lastActiveSceneView.pivot,
                    Quaternion.Euler(new Vector3(270f, 0f, 0f)));
            }
            break;

        case KeyCode.Keypad8:
            sceneView.LookAtDirect(
                SceneView.lastActiveSceneView.pivot,
                rotHelper * Quaternion.Euler(new Vector3(15f, 0f, 0f)));
            break;

        case KeyCode.KeypadPeriod:
            if (Selection.transforms.Length == 1)
            {
                sceneView.LookAtDirect(Selection.activeTransform.position, sceneView.camera.transform.rotation);
            }
            else if (Selection.transforms.Length > 1)
            {
                Vector3 tempVec = new Vector3();
                for (int i = 0; i < Selection.transforms.Length; i++)
                {
                    tempVec += Selection.transforms[i].position;
                }
                sceneView.LookAtDirect((tempVec / Selection.transforms.Length), sceneView.camera.transform.rotation);
            }
            break;

        case KeyCode.KeypadMinus:
            SceneView.RepaintAll();
            sceneView.size *= 1.1f;
            break;

        case KeyCode.KeypadPlus:
            SceneView.RepaintAll();
            sceneView.size /= 1.1f;
            break;

        case KeyCode.Keypad0:
            sceneView.FrameSelected();
            break;
        }
    }
 public static void ArrowKeys(SceneView sv)
 {
   Event current = Event.current;
   int controlId = GUIUtility.GetControlID(FocusType.Passive);
   if (GUIUtility.hotControl != 0 && GUIUtility.hotControl != controlId || EditorGUI.actionKey)
     return;
   switch (current.GetTypeForControl(controlId))
   {
     case EventType.KeyDown:
       switch (current.keyCode)
       {
         case KeyCode.UpArrow:
           sv.viewIsLockedToObject = false;
           if (sv.m_Ortho.value)
             SceneViewMotion.s_Motion.y = 1f;
           else
             SceneViewMotion.s_Motion.z = 1f;
           GUIUtility.hotControl = controlId;
           current.Use();
           return;
         case KeyCode.DownArrow:
           sv.viewIsLockedToObject = false;
           if (sv.m_Ortho.value)
             SceneViewMotion.s_Motion.y = -1f;
           else
             SceneViewMotion.s_Motion.z = -1f;
           GUIUtility.hotControl = controlId;
           current.Use();
           return;
         case KeyCode.RightArrow:
           sv.viewIsLockedToObject = false;
           SceneViewMotion.s_Motion.x = 1f;
           GUIUtility.hotControl = controlId;
           current.Use();
           return;
         case KeyCode.LeftArrow:
           sv.viewIsLockedToObject = false;
           SceneViewMotion.s_Motion.x = -1f;
           GUIUtility.hotControl = controlId;
           current.Use();
           return;
         default:
           return;
       }
     case EventType.KeyUp:
       if (GUIUtility.hotControl != controlId)
         break;
       switch (current.keyCode)
       {
         case KeyCode.UpArrow:
         case KeyCode.DownArrow:
           SceneViewMotion.s_Motion.z = 0.0f;
           SceneViewMotion.s_Motion.y = 0.0f;
           current.Use();
           return;
         case KeyCode.RightArrow:
         case KeyCode.LeftArrow:
           SceneViewMotion.s_Motion.x = 0.0f;
           current.Use();
           return;
         default:
           return;
       }
     case EventType.Layout:
       if (GUIUtility.hotControl != controlId)
         break;
       Vector3 forward;
       if (!sv.m_Ortho.value)
       {
         forward = Camera.current.transform.forward + Camera.current.transform.up * 0.3f;
         forward.y = 0.0f;
         forward.Normalize();
       }
       else
         forward = Camera.current.transform.forward;
       Vector3 movementDirection = SceneViewMotion.GetMovementDirection();
       sv.LookAtDirect(sv.pivot + Quaternion.LookRotation(forward) * movementDirection, sv.rotation);
       if ((double) SceneViewMotion.s_Motion.sqrMagnitude == 0.0)
       {
         sv.pivot = sv.pivot;
         SceneViewMotion.s_FlySpeed = 0.0f;
         GUIUtility.hotControl = 0;
         break;
       }
       sv.Repaint();
       break;
   }
 }
        public static void ArrowKeys(SceneView sv)
        {
            Event current = Event.current;
            int controlID = GUIUtility.GetControlID(FocusType.Passive);
            if (((GUIUtility.hotControl == 0) || (GUIUtility.hotControl == controlID)) && !EditorGUI.actionKey)
            {
                EventType typeForControl = current.GetTypeForControl(controlID);
                if (typeForControl == EventType.KeyDown)
                {
                    switch (current.keyCode)
                    {
                        case KeyCode.UpArrow:
                            sv.viewIsLockedToObject = false;
                            if (!sv.m_Ortho.value)
                            {
                                s_Motion.z = 1f;
                            }
                            else
                            {
                                s_Motion.y = 1f;
                            }
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            return;

                        case KeyCode.DownArrow:
                            sv.viewIsLockedToObject = false;
                            if (!sv.m_Ortho.value)
                            {
                                s_Motion.z = -1f;
                            }
                            else
                            {
                                s_Motion.y = -1f;
                            }
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            return;

                        case KeyCode.RightArrow:
                            sv.viewIsLockedToObject = false;
                            s_Motion.x = 1f;
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            break;

                        case KeyCode.LeftArrow:
                            sv.viewIsLockedToObject = false;
                            s_Motion.x = -1f;
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            break;
                    }
                }
                else if (typeForControl == EventType.KeyUp)
                {
                    if (GUIUtility.hotControl == controlID)
                    {
                        switch (current.keyCode)
                        {
                            case KeyCode.UpArrow:
                            case KeyCode.DownArrow:
                                s_Motion.z = 0f;
                                s_Motion.y = 0f;
                                current.Use();
                                break;

                            case KeyCode.RightArrow:
                            case KeyCode.LeftArrow:
                                s_Motion.x = 0f;
                                current.Use();
                                break;
                        }
                    }
                }
                else if ((typeForControl == EventType.Layout) && (GUIUtility.hotControl == controlID))
                {
                    Vector3 forward;
                    if (!sv.m_Ortho.value)
                    {
                        forward = Camera.current.transform.forward + ((Vector3) (Camera.current.transform.up * 0.3f));
                        forward.y = 0f;
                        forward.Normalize();
                    }
                    else
                    {
                        forward = Camera.current.transform.forward;
                    }
                    Vector3 movementDirection = GetMovementDirection();
                    sv.LookAtDirect(sv.pivot + (Quaternion.LookRotation(forward) * movementDirection), sv.rotation);
                    if (s_Motion.sqrMagnitude == 0f)
                    {
                        sv.pivot = sv.pivot;
                        s_FlySpeed = 0f;
                        GUIUtility.hotControl = 0;
                    }
                    else
                    {
                        sv.Repaint();
                    }
                }
            }
        }
示例#7
0
        // CURSOR KEYS
        public static void ArrowKeys(SceneView sv)
        {
            Event evt = Event.current;
            int   id  = GUIUtility.GetControlID(FocusType.Passive);

            if (GUIUtility.hotControl == 0 || GUIUtility.hotControl == id)
            {
                if (EditorGUI.actionKey)
                {
                    return;
                }
                switch (evt.GetTypeForControl(id))
                {
                case EventType.KeyDown:
                    switch (evt.keyCode)
                    {
                    case KeyCode.UpArrow:
                        sv.viewIsLockedToObject = false;
                        if (sv.m_Ortho.value)
                        {
                            s_Motion.y = 1;
                        }
                        else
                        {
                            s_Motion.z = 1;
                        }
                        GUIUtility.hotControl = id;
                        evt.Use();
                        break;

                    case KeyCode.DownArrow:
                        sv.viewIsLockedToObject = false;
                        if (sv.m_Ortho.value)
                        {
                            s_Motion.y = -1;
                        }
                        else
                        {
                            s_Motion.z = -1;
                        }
                        GUIUtility.hotControl = id;
                        evt.Use();
                        break;

                    case KeyCode.LeftArrow:
                        sv.viewIsLockedToObject = false;
                        s_Motion.x            = -1;
                        GUIUtility.hotControl = id;
                        evt.Use();
                        break;

                    case KeyCode.RightArrow:
                        sv.viewIsLockedToObject = false;
                        s_Motion.x            = 1;
                        GUIUtility.hotControl = id;
                        evt.Use();
                        break;
                    }
                    break;

                case EventType.KeyUp:
                    if (GUIUtility.hotControl == id)
                    {
                        switch (evt.keyCode)
                        {
                        case KeyCode.UpArrow:
                        case KeyCode.DownArrow:
                            s_Motion.z = 0;
                            s_Motion.y = 0;
                            evt.Use();
                            break;

                        case KeyCode.LeftArrow:
                        case KeyCode.RightArrow:
                            s_Motion.x = 0;
                            evt.Use();
                            break;
                        }
                    }

                    break;

                case EventType.Layout:
                    if (GUIUtility.hotControl == id)
                    {
                        Vector3 fwd;
                        if (!sv.m_Ortho.value)
                        {
                            fwd   = Camera.current.transform.forward + Camera.current.transform.up * .3f;
                            fwd.y = 0;
                            fwd.Normalize();
                        }
                        else
                        {
                            fwd = Camera.current.transform.forward;
                        }
                        Vector3 motion = GetMovementDirection();
                        sv.LookAtDirect(sv.pivot + Quaternion.LookRotation(fwd) * motion, sv.rotation);

                        // If we're done, stop animating
                        if (s_Motion.sqrMagnitude == 0)
                        {
                            sv.pivot              = sv.pivot;
                            s_FlySpeed            = 0;
                            GUIUtility.hotControl = 0;
                        }
                        else
                        {
                            sv.Repaint();
                        }
                    }
                    break;
                }
            }
        }
    public void OnSceneGUI()
    {

        current = Event.current;

        if (!current.isKey || current.type != EventType.keyDown)
            return;

        sceneView = UnityEditor.SceneView.lastActiveSceneView;
        eulerAngles = sceneView.camera.transform.rotation.eulerAngles;
        rotHelper = sceneView.camera.transform.rotation;

        switch (current.keyCode)
        {
            case KeyCode.Keypad1:
                if (current.control == false)
                    sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 360f, 0f)));
                else
                    sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 180f, 0f)));
                break;
            case KeyCode.Keypad2:
                sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, rotHelper * Quaternion.Euler(new Vector3(-15f, 0f, 0f)));
                break;
            case KeyCode.Keypad3:
                if (current.control == false)
                    sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 270f, 0f)));
                else
                    sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 90f, 0f)));
                break;
            case KeyCode.Keypad4:
                sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(eulerAngles.x, eulerAngles.y + 15f, eulerAngles.z)));
                break;
            case KeyCode.Keypad5:
                sceneView.orthographic = !sceneView.orthographic;
                break;
            case KeyCode.Keypad6:
                sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(eulerAngles.x, eulerAngles.y - 15f, eulerAngles.z)));
                break;
            case KeyCode.Keypad7:
                if (current.control == false)
                    sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(90f, 0f, 0f)));
                else
                    sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(270f, 0f, 0f)));
                break;
            case KeyCode.Keypad8:
                sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, rotHelper * Quaternion.Euler(new Vector3(15f, 0f, 0f)));
                break;
            case KeyCode.KeypadPeriod:
                if (Selection.transforms.Length == 1)
                    sceneView.LookAtDirect(Selection.activeTransform.position, sceneView.camera.transform.rotation);
                else if (Selection.transforms.Length > 1)
                {
                    Vector3 tempVec = new Vector3();
                    for (int i = 0; i < Selection.transforms.Length; i++)
                    {
                        tempVec += Selection.transforms[i].position;
                    }
                    sceneView.LookAtDirect((tempVec / Selection.transforms.Length), sceneView.camera.transform.rotation);
                }
                break;
            case KeyCode.KeypadMinus:
                SceneView.RepaintAll();
                sceneView.size *= 1.1f;
                break;
            case KeyCode.KeypadPlus:
                SceneView.RepaintAll();
                sceneView.size /= 1.1f;
                break;
        }
    }
示例#9
0
    public void OnSceneGUI(SceneView scene)
    {
        if(fixView)
            scene.LookAtDirect(scene.pivot, fixedRotation);

        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        if(Event.current.isMouse){
            if(Event.current.button == 0){
                if(Event.current.type == EventType.MouseDown)		startCreatingCells();
                else if(Event.current.type == EventType.MouseUp)	endCreatingCells();
                else												createCell();
            }
            else if(Event.current.button == 1){
                if(Event.current.type == EventType.MouseDown)		startMovingGrid();
                else if(Event.current.type == EventType.MouseUp)	endMovingGrid();
                else												moveGrid();
            }
            scene.Repaint();
        }

        Vector3 centerGridPoint = map.getMousePositionOverMap(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), Mathf.RoundToInt(gridHeight*2f)/2f);

        map.ghostCell(centerGridPoint, 0.5f);

        Vector3[] puntos = new Vector3[4];
        puntos[0] = new Vector3(centerGridPoint.x - cellSize/2.0f,centerGridPoint.y,centerGridPoint.z - cellSize/2.0f);
        puntos[1] = new Vector3(centerGridPoint.x - cellSize/2.0f,centerGridPoint.y,centerGridPoint.z + cellSize/2.0f);
        puntos[2] = new Vector3(centerGridPoint.x + cellSize/2.0f,centerGridPoint.y,centerGridPoint.z + cellSize/2.0f);
        puntos[3] = new Vector3(centerGridPoint.x + cellSize/2.0f,centerGridPoint.y,centerGridPoint.z - cellSize/2.0f);
        Handles.DrawSolidRectangleWithOutline(puntos, Color.yellow, Color.white);
    }