Jump to content
Unity Insider Forum

Sich (In Game) wie im Editor umsehen ?


w0rks

Recommended Posts

Geht mit einem entsprechden Kameraskript an der Kamera, welches deine Eingaben entsprechend umsetzt. Ich müsste jetzt aber auch Suchen, ein entsprechendes Skript zu finden. Folgendes würde das Skript aber machen:

  • eine Art  "Rotate-Around" der Kamera und verwendet dabei die Inputs der Maus
  • bei A und D wird wir Position der Kamera entlang der "Left-Achse" der Kamera verschoben
  • W und S bewegt die Kamera entlang der Vorwärtsachse
Link zu diesem Kommentar
Auf anderen Seiten teilen

Hier ein Skript das zumindest in die Richtung geht:
http://wiki.unity3d.com/index.php?title=MouseOrbitZoom

Arbeitet mit:
- Taste LeftAlt
- Taste LeftControl
und mittlere Maustaste

// Control and Alt and Middle => ZOOM
// middle mouse and left alt => ORBIT
// middle mouse => PANNING
// scroll wheel => Zoom distance

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Eine neues C#-Skript erstellen mit Namen "maxCamera".
Inhalt hineinkopieren.

Dann auf deine Kamera in der Szene gehen und "Add Component". Hier sollte dann folgendes auftauchen:
"Camera-Control/3dsMax Camera Style"

Diese Komponente fügst du deiner Szenenkamera hinzu.

PS: 
Das Skript auf deine Kamera ziehen sollte auch gehen.
 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Ist alles "hart codiert". Für unterschiedliche Maustasten oder Keys musst du alle Codestellen der Klasse austauschen, wo der entsprechende Eintrag vorkommt:

Input.GetMouseButton(2)

= mittlere Maustaste.

0 wäre linke und 1 rechte Maustaste.
 

Input.GetAxis("Mouse ScrollWheel")

= Maus-Scrollrad.

Bei den Tasten:

Input.GetKey(KeyCode.LeftAlt)

und 

Input.GetKey(KeyCode.LeftControl)

Die KeyCodes für Alternativtasten musst du in der Unityhilfe nachschauen...

Link zu diesem Kommentar
Auf anderen Seiten teilen

Habs mal fix umgeschrieben auf deine geforderten Tasten. Verhält sich nun quasi fast so wie im Editor. Linke Maustaste gedrückt halten ..

//
//Filename: maxCamera.cs
//
// original: http://www.unifycommunity.com/wiki/index.php?title=MouseOrbitZoom
//
// --01-18-2010 - create temporary target, if none supplied at start

using UnityEngine;
using System.Collections;


[AddComponentMenu("Camera-Control/3dsMax Camera Style")]
public class maxCamera : MonoBehaviour
{
    public Transform target;
    public Vector3 targetOffset;
    public float distance = 5.0f;
    public float maxDistance = 20;
    public float minDistance = .6f;
    public float xSpeed = 200.0f;
    public float ySpeed = 200.0f;
    public int yMinLimit = -80;
    public int yMaxLimit = 80;
    public int zoomRate = 40;
    public float panSpeed = 0.3f;
    public float zoomDampening = 5.0f;

    private float xDeg = 0.0f;
    private float yDeg = 0.0f;
    private float currentDistance;
    private float desiredDistance;
    private Quaternion currentRotation;
    private Quaternion desiredRotation;
    private Quaternion rotation;
    private Vector3 position;

    void Start() { Init(); }
    void OnEnable() { Init(); }

    public void Init()
    {
        //If there is no target, create a temporary target at 'distance' from the cameras current viewpoint
        if (!target)
        {
            GameObject go = new GameObject("Cam Target");
            go.transform.position = transform.position + (transform.forward * distance);
            target = go.transform;
        }

        distance = Vector3.Distance(transform.position, target.position);
        currentDistance = distance;
        desiredDistance = distance;

        //be sure to grab the current rotations as starting points.
        position = transform.position;
        rotation = transform.rotation;
        currentRotation = transform.rotation;
        desiredRotation = transform.rotation;

        xDeg = Vector3.Angle(Vector3.right, transform.right);
        yDeg = Vector3.Angle(Vector3.up, transform.up);
    }

    /*
     * Camera logic on LateUpdate to only update after all character movement logic has been handled. 
     */
    void LateUpdate()
    {
        // If Control and Alt and Middle button? ZOOM!
        //if (Input.GetMouseButton(2) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftControl))
        if (Input.GetMouseButton(1) && (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)))
        {
            //desiredDistance -= Input.GetAxis("Vertical") * Time.deltaTime * zoomRate * 0.125f * Mathf.Abs(desiredDistance);
            target.Translate(Vector3.forward * Input.GetAxis("Vertical") * panSpeed);
        }
        // If middle mouse and left alt are selected? ORBIT
        else if (Input.GetMouseButton(1))
        {
            xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
            yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

            ////////OrbitAngle

            //Clamp the vertical axis for the orbit
            yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
            // set camera rotation 
            desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
            currentRotation = transform.rotation;

            rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
            transform.rotation = rotation;
        }
        // otherwise if middle mouse is selected, we pan by way of transforming the target in screenspace
        //else if (Input.GetMouseButton(2))
        if (Input.GetMouseButton(1) && (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)))
        {
            //grab the rotation of the camera so we can move in a psuedo local XY space
            target.rotation = transform.rotation;
            target.Translate(Vector3.right * Input.GetAxis("Horizontal") * panSpeed);
            //target.Translate(Vector3.right * -Input.GetAxis("Mouse X") * panSpeed);
            //target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
        }

        ////////Orbit Position

        // affect the desired Zoom distance if we roll the scrollwheel
        desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
        //clamp the zoom min/max
        desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
        // For smoothing of the zoom, lerp distance
        currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening);

        // calculate position based on the new currentDistance 
        position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
        transform.position = position;
    }

    private static float ClampAngle(float angle, float min, float max)
    {
        if (angle < -360)
            angle += 360;
        if (angle > 360)
            angle -= 360;
        return Mathf.Clamp(angle, min, max);
    }
}

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hab nochmal was geändert, hatte nicht so 100% funktioniert:
 

//
//Filename: maxCamera.cs
//
// original: http://www.unifycommunity.com/wiki/index.php?title=MouseOrbitZoom
//
// --01-18-2010 - create temporary target, if none supplied at start

using UnityEngine;
using System.Collections;


[AddComponentMenu("Camera-Control/3dsMax Camera Style")]
public class maxCamera : MonoBehaviour
{
    public Transform target;
    public Vector3 targetOffset;
    public float distance = 5.0f;
    public float maxDistance = 20;
    public float minDistance = .6f;
    public float xSpeed = 200.0f;
    public float ySpeed = 200.0f;
    public int yMinLimit = -80;
    public int yMaxLimit = 80;
    public int zoomRate = 40;
    public float panSpeed = 0.3f;
    public float zoomDampening = 5.0f;

    private float xDeg = 0.0f;
    private float yDeg = 0.0f;
    private float currentDistance;
    private float desiredDistance;
    private Quaternion currentRotation;
    private Quaternion desiredRotation;
    private Quaternion rotation;
    private Vector3 position;

    void Start() { Init(); }
    void OnEnable() { Init(); }

    public void Init()
    {
        //If there is no target, create a temporary target at 'distance' from the cameras current viewpoint
        if (!target)
        {
            GameObject go = new GameObject("Cam Target");
            go.transform.position = transform.position + (transform.forward * distance);
            target = go.transform;
        }

        distance = Vector3.Distance(transform.position, target.position);
        currentDistance = distance;
        desiredDistance = distance;

        //be sure to grab the current rotations as starting points.
        position = transform.position;
        rotation = transform.rotation;
        currentRotation = transform.rotation;
        desiredRotation = transform.rotation;

        xDeg = Vector3.Angle(Vector3.right, transform.right);
        yDeg = Vector3.Angle(Vector3.up, transform.up);
    }

    /*
     * Camera logic on LateUpdate to only update after all character movement logic has been handled. 
     */
    void LateUpdate()
    {
        if (!Input.GetMouseButton(1))
        {
            target.position = transform.position + (transform.forward * distance);
            desiredDistance = Vector3.Distance(transform.position, target.position);
        }

        // If Control and Alt and Middle button? ZOOM!
        //if (Input.GetMouseButton(2) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftControl))
        if (Input.GetMouseButton(1) && (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)))
        {
            //desiredDistance -= Input.GetAxis("Vertical") * Time.deltaTime * zoomRate * 0.125f * Mathf.Abs(desiredDistance);
            target.Translate(transform.forward * Input.GetAxis("Vertical") * panSpeed, Space.World);
        }
        // If middle mouse and left alt are selected? ORBIT
        else if (Input.GetMouseButton(1))
        {
            xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
            yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

            ////////OrbitAngle

            //Clamp the vertical axis for the orbit
            yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
            // set camera rotation 
            desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
            currentRotation = transform.rotation;

            rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
            transform.rotation = rotation;
        }
        // otherwise if middle mouse is selected, we pan by way of transforming the target in screenspace
        //else if (Input.GetMouseButton(2))
        if (Input.GetMouseButton(1) && (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)))
        {
            //grab the rotation of the camera so we can move in a psuedo local XY space
            target.rotation = transform.rotation;
            target.transform.Translate(transform.right * Input.GetAxis("Horizontal") * panSpeed, Space.World);
            //target.Translate(Vector3.right * -Input.GetAxis("Mouse X") * panSpeed);
            //target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
        }

        ////////Orbit Position

        // affect the desired Zoom distance if we roll the scrollwheel
        desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
        //clamp the zoom min/max
        desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
        // For smoothing of the zoom, lerp distance
        currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening);

        // calculate position based on the new currentDistance 
        position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
        transform.position = position;
    }

    private static float ClampAngle(float angle, float min, float max)
    {
        if (angle < -360)
            angle += 360;
        if (angle > 360)
            angle -= 360;
        return Mathf.Clamp(angle, min, max);
    }
}

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Boah . . Danke das du dir so viel Mühe gibst mir zu helfen :wub: ! Aber es ist leider nicht das was ich gemeint habe :unsure:

Ich möchte halt die Steuerung vom Editor drin haben.

Rechter Maustaste: umsehen (Nicht bewegen)

W S A D: Vor, zurück-Bewegung usw.

E: Rauf

Q: Runter

Das währe genial wenn das funktionieren würde ^_^

Link zu diesem Kommentar
Auf anderen Seiten teilen

Ich habe jetzt was Echt Gutes gefunden ! ! Aber ich muss noch rumspielen mit denn Einstellungen.

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Assets.Elenesski.Camera.Utilities {

    public class GenericMoveCamera : MonoBehaviour {

        private Movement _Forward;
        private Movement _PanX;
        private Movement _RotateX;
        private Movement _PanY;
        private Movement _RotateY;
        private float _Resolution = 3.0f;

        [Header("Operational")]
        public bool Operational = true;

        [Header("Input Method")]
        public GenericMoveCameraInputs GetInputs = new GenericMoveCameraInputs();

        [Header("Camera")]
        public bool LevelCamera = true;
        [Range(0f,00f)]
        public float LevelCameraAngleThreshold = 0.0f;
        public bool ForwardMovementLockEnabled = true;

        [Header("Movement Speed")]
        public float MovementSpeedMagnification = 0f;
        public float WheelMouseMagnification = 0f;
        public float ShiftKeyMagnification = 0.0f;
        public float ControlKeyMagnification = 0.00f;
        public float RotationMagnification = 0f;

        [Header("Pan Speed Modifications")]
        public float PanLeftRightSensitivity = 0f;
        public float PanUpDownSensitivity = 0f;

        [Header("Mouse Rotation Sensitivity")]
        public float MouseRotationSensitivity = 0.0f;

        [Header("Dampening")]
        public float ForwardDampenRate = 0.0f;
        public float PanningDampenRate = 0.0f;
        public float RotateDampenRate = 0.0f;

        [Header("Look At")]
        public GameObject LookAtTarget = null;
        public float MinimumZoom = 00f;
        public float MaximumZoom = 00f;

        [Header("Movement Limits - X")]
        public bool LockX = false;
        public bool UseXRange;
        public float XRangeMin;
        public float XRangeMax;

        [Header("Movement Limits - Y")]
        public bool LockY = false;
        public bool UseYRange;
        public float YRangeMin;
        public float YRangeMax;

        [Header("Movement Limits - Z")]
        public bool LockZ = false;
        public bool UseZRange;
        public float ZRangeMin;
        public float ZRangeMax;

        // Rotation when in Awake(), to prevent weird rotations later
        private Vector3 _DefaultRotation;

        private class Movement {
            private readonly Action<float> _Action;
            private readonly Func<float> _DampenRate;
            private float _Velocity;
            private float _Dampen;

            public Movement(Action<float> aAction, Func<float> aDampenRate) {
                _Action = aAction;
                _DampenRate = aDampenRate;
                _Velocity = 0f;
                _Dampen = 0;
            }

            public void ChangeVelocity(float aAmount) {
                _Velocity += aAmount;
                _Dampen = _DampenRate();
            }

            public void SetVelocity(float aAmount) {
                _Velocity = aAmount;
                _Dampen = _DampenRate();
            }

            public void Update(bool aDampen = true) {
                if (_Dampen > 0)
                    if (_Velocity >= -0.000f && _Velocity <= 0.000f) {
                        _Dampen = 0;
                        _Velocity = 0;
                    } else {
                        if (aDampen)
                            _Velocity *= _Dampen;

                        _Action(_Velocity);
                    }
            }
        }

        public void SetResolution(float aResolution) {
            _Resolution = aResolution;
        }

        public void Awake() {
            if ( GetInputs == null )
                GetInputs = new GenericMoveCameraInputs();

            _DefaultRotation = gameObject.transform.localRotation.eulerAngles;

            GetInputs.Initialize();
        }

        public void Start() {
            if (LookAtTarget == null) {
                _Forward = new Movement(aAmount => gameObject.transform.Translate(Vector3.forward*aAmount), () => ForwardDampenRate);
            } else {
                _Forward = new Movement(aAmount => gameObject.GetComponent<UnityEngine.Camera>().fieldOfView += aAmount, () => ForwardDampenRate);
            }

            _PanX = new Movement(aAmount => gameObject.transform.Translate(Vector3.left*aAmount), () => PanningDampenRate);
            _PanY = new Movement(aAmount => gameObject.transform.Translate(Vector3.up*aAmount), () => PanningDampenRate);

            _RotateX = new Movement(aAmount => gameObject.transform.Rotate(Vector3.up*aAmount), () => RotateDampenRate);
            _RotateY = new Movement(aAmount => gameObject.transform.Rotate(Vector3.left*aAmount), () => RotateDampenRate);

        }

        public void Update() {

            if (!Operational)
                return;

            GetInputs.QueryInputSystem();

            Vector3 START_POSITION = gameObject.transform.position;

            if (GetInputs.ResetMovement) {
                ResetMovement();
            } else {

                float MAG = (GetInputs.isSlowModifier ? ControlKeyMagnification : 1.5f)*(GetInputs.isFastModifier ? ShiftKeyMagnification : 1.5f);

                if (GetInputs.isPanLeft) {
                    _PanX.ChangeVelocity(0.00f*MAG*_Resolution*PanLeftRightSensitivity);
                } else if (GetInputs.isPanRight) {
                    _PanX.ChangeVelocity(-0.00f*MAG*_Resolution*PanLeftRightSensitivity);
                }

                if ( _PanX != null )
                    _PanX.Update();

                if (GetInputs.isMoveForward ) {
                    _Forward.ChangeVelocity(0.000f*MAG*_Resolution*MovementSpeedMagnification);
                } else if (GetInputs.isMoveBackward ) {
                    _Forward.ChangeVelocity(-0.000f*MAG*_Resolution*MovementSpeedMagnification);
                }

                if (GetInputs.isMoveForwardAlt) {
                    _Forward.ChangeVelocity(0.000f*MAG*_Resolution*MovementSpeedMagnification*WheelMouseMagnification);
                } else if (GetInputs.isMoveBackwardAlt) {
                    _Forward.ChangeVelocity(-0.000f*MAG*_Resolution*MovementSpeedMagnification*WheelMouseMagnification);
                }

                if (GetInputs.isPanUp) {
                    _PanY.ChangeVelocity(0.000f*MAG*_Resolution*PanUpDownSensitivity);
                } else if (GetInputs.isPanDown) {
                    _PanY.ChangeVelocity(-0.000f*MAG*_Resolution*PanUpDownSensitivity);
                }

                bool FORWARD_LOCK = GetInputs.isLockForwardMovement && ForwardMovementLockEnabled;
                _Forward.Update(!FORWARD_LOCK);

                _PanY.Update();

                // Pan
                if (GetInputs.isRotateAction) {

                    float X = (Input.mousePosition.x - GetInputs.RotateActionStart.x)/Screen.width*MouseRotationSensitivity;
                    float Y = (Input.mousePosition.y - GetInputs.RotateActionStart.y)/Screen.height*MouseRotationSensitivity;

                    _RotateX.SetVelocity(X*MAG*RotationMagnification*_Resolution);
                    _RotateY.SetVelocity(Y*MAG*RotationMagnification*_Resolution);

                }

                _RotateX.Update();
                _RotateY.Update();
            }


            // Lock at object
            if (LookAtTarget != null ) {
                transform.LookAt(LookAtTarget.transform);
                if (gameObject.GetComponent<UnityEngine.Camera>().fieldOfView < MinimumZoom) {
                    ResetMovement();
                    gameObject.GetComponent<UnityEngine.Camera>().fieldOfView = MinimumZoom;
                } else if (gameObject.GetComponent<UnityEngine.Camera>().fieldOfView > MaximumZoom) {
                    ResetMovement();
                    gameObject.GetComponent<UnityEngine.Camera>().fieldOfView = MaximumZoom;
                }
            }

            // Set ranges
            Vector3 END_POSITION = transform.position;

            if (LockX)
                END_POSITION.x = START_POSITION.x;
            if (LockY)
                END_POSITION.y = START_POSITION.y;
            if (LockZ)
                END_POSITION.z = START_POSITION.z;

            if (UseXRange && gameObject.transform.position.x < XRangeMin) END_POSITION.x = XRangeMin;
            if (UseXRange && gameObject.transform.position.x > XRangeMax) END_POSITION.x = XRangeMax;

            if (UseYRange && gameObject.transform.position.y < YRangeMin) END_POSITION.y = YRangeMin;
            if (UseYRange && gameObject.transform.position.y > YRangeMax) END_POSITION.y = YRangeMax;

            if (UseZRange && gameObject.transform.position.z < ZRangeMin) END_POSITION.z = ZRangeMin;
            if (UseZRange && gameObject.transform.position.z > ZRangeMax) END_POSITION.z = ZRangeMax;

            transform.position = END_POSITION;

            // Level Camera
            if (LevelCamera) {
                // Fix 1.2
                // When leveling the camera you want to make sure you don't look straight up or straight down, otherwise the camera rolls wildly.
                // This code prevents this rolling from occurring.
                Vector3 ROT = gameObject.transform.rotation.eulerAngles;
                if (ROT.x > 180)
                    ROT.x -= 360;

                if (ROT.x > (90-LevelCameraAngleThreshold)) {
                    ROT.x = (90-LevelCameraAngleThreshold);
                    gameObject.transform.rotation = Quaternion.Euler(ROT);
                } else if (ROT.x < (-90+LevelCameraAngleThreshold)) {
                    ROT.x = -90+LevelCameraAngleThreshold;
                    gameObject.transform.rotation = Quaternion.Euler(ROT);

                }

                LevelTheCamera();
            }

        }

        public void ResetMovement() {
            _PanX.SetVelocity(0);
            _PanY.SetVelocity(0);
            _Forward.SetVelocity(0);
            _RotateX.SetVelocity(0);
            _RotateY.SetVelocity(0);

            _PanX.Update();
            _PanY.Update();
            _Forward.Update();
            _RotateX.Update();
            _RotateY.Update();
        }

        public void OnCollisionEnter(Collision collision) {
            ResetMovement();
        }

        public void PanY( float aMagnitude ) {
            _PanY.ChangeVelocity(0.000f*aMagnitude*_Resolution*PanUpDownSensitivity);
        }

        public void PanX(float aMagnitude) {
            _PanX.ChangeVelocity(-0.00f*aMagnitude*_Resolution*PanLeftRightSensitivity);
        }

        public void ForwardBack( float aMagnitude ) {
            _Forward.ChangeVelocity(-0.000f*aMagnitude*_Resolution*MovementSpeedMagnification);
        }

        public void LevelTheCamera() {
            transform.rotation = Quaternion.LookRotation(transform.forward.normalized, Vector3.up);
        }

    }

}

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Archiviert

Dieses Thema ist jetzt archiviert und für weitere Antworten gesperrt.

×
×
  • Neu erstellen...