-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.IO; | ||
using System; | ||
|
||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
using UnityEngine.Playables; | ||
using UnityEngine.Timeline; | ||
using UnityEditor.PackageManager; | ||
|
||
using Unity.Formats.USD; | ||
|
||
public class AttachCamController : EditorWindow | ||
{ | ||
public static DropdownField m_dropDown; | ||
public static DropdownField m_orientationDropdown; | ||
private static List<string> listOfCameras = new List<string>(); | ||
|
||
[MenuItem("USD/Previsualization Panels/Add Camera Controller", priority = 130)] | ||
public static void FullDomeView() | ||
{ | ||
EditorWindow wnd = GetWindow<AttachCamController>(); | ||
wnd.titleContent = new GUIContent("[Previz] Camera Controller"); | ||
|
||
// this makes it so that its not resizable | ||
wnd.minSize = new Vector2(300,140); | ||
wnd.maxSize = new Vector2(300,140); | ||
|
||
wnd.ShowPopup(); | ||
} | ||
|
||
void CreateGUI() { | ||
m_dropDown = new DropdownField(); | ||
|
||
foreach (Camera cam in FindObjectsOfType<Camera>()) | ||
{ | ||
listOfCameras.Add(cam.name); | ||
m_dropDown.value = cam.name; | ||
} | ||
|
||
m_dropDown.choices = listOfCameras; | ||
|
||
rootVisualElement.Add(new Label("\n Select a camera to attach controller script:")); | ||
rootVisualElement.Add(m_dropDown); | ||
rootVisualElement.Add(new Label("")); | ||
|
||
var switchButton = new Button(); | ||
switchButton.text = "Switch to Camera"; | ||
switchButton.clicked += switchCamera; | ||
rootVisualElement.Add(switchButton); | ||
|
||
var addButton = new Button(); | ||
addButton.text = "Add Camera Controller Script"; | ||
addButton.clicked += addScript; | ||
rootVisualElement.Add(addButton); | ||
|
||
var removeButton = new Button(); | ||
removeButton.text = "Remove Camera Controller Script"; | ||
removeButton.clicked += removeScript; | ||
rootVisualElement.Add(removeButton); | ||
|
||
} | ||
|
||
// add camera movement script | ||
private void addScript() { | ||
if (m_dropDown.value == null) { | ||
return; | ||
} | ||
|
||
GameObject.Find(m_dropDown.value).AddComponent<CameraController>(); | ||
|
||
Debug.Log("[PREVIZ] Added the camera controller script to the " + m_dropDown.value + " camera!"); | ||
} | ||
|
||
// remove camera movement script | ||
private void removeScript() { | ||
if (m_dropDown.value == null) { | ||
return; | ||
} | ||
|
||
if (GameObject.Find(m_dropDown.value).GetComponent<CameraController>() != null) { | ||
if (Application.isPlaying) { | ||
Destroy(GameObject.Find(m_dropDown.value).GetComponent<CameraController>()); | ||
} else { | ||
DestroyImmediate(GameObject.Find(m_dropDown.value).GetComponent<CameraController>()); | ||
} | ||
Debug.Log("[PREVIZ] Removed the camera controller script from the " + m_dropDown.value + " camera!"); | ||
} | ||
} | ||
|
||
// switch to selected camera | ||
private void switchCamera() { | ||
foreach (string camname in listOfCameras) | ||
{ | ||
if (camname == m_dropDown.value) | ||
{ | ||
GameObject.Find(camname).GetComponent<Camera>().enabled = true; | ||
} | ||
else | ||
{ | ||
GameObject.Find(camname).GetComponent<Camera>().enabled = false; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using UnityEngine; | ||
|
||
// Daniel Flanigan, 2014 | ||
// This is a combined mouse look and camera move script. | ||
// The cam move script is by: Francis R. Griffiths-Keam | ||
// original source: https://forum.unity.com/threads/combined-camera-movement-and-mouse-look-script.283290/ | ||
|
||
public class CameraController : MonoBehaviour | ||
{ | ||
Vector2 _mouseAbsolute; | ||
Vector2 _smoothMouse; | ||
[Space(20)] | ||
[Header("Mouse Look Settings :")] | ||
public Vector2 | ||
clampInDegrees = new Vector2(360, 180); | ||
public bool lockCursor; | ||
public Vector2 sensitivity = new Vector2(2, 2); | ||
public Vector2 smoothing = new Vector2(3, 3); | ||
public Vector2 targetDirection; | ||
public Vector2 targetCharacterDirection; | ||
|
||
// Assign this if there's a parent object controlling motion, such as a Character Controller. | ||
// Yaw rotation will affect this object instead of the camera if set. | ||
public GameObject characterBody; | ||
|
||
[Space(20)] | ||
[Header("Camera Move Settings :")] | ||
|
||
public float speed = 5.0f; | ||
|
||
public KeyCode fwdKey = KeyCode.W; | ||
public KeyCode leftKey = KeyCode.A; | ||
public KeyCode backKey = KeyCode.S; | ||
public KeyCode rightKey = KeyCode.D; | ||
|
||
Animator animator; | ||
|
||
void Start() | ||
{ | ||
// Set target direction to the camera's initial orientation. | ||
targetDirection = transform.localRotation.eulerAngles; | ||
|
||
// Set target direction for the character body to its inital state. | ||
if (characterBody) | ||
targetCharacterDirection = characterBody.transform.localRotation.eulerAngles; | ||
} | ||
|
||
void Update() | ||
{ | ||
// Ensure the cursor is always locked when set | ||
Screen.lockCursor = lockCursor; | ||
|
||
// Allow the script to clamp based on a desired target value. | ||
var targetOrientation = Quaternion.Euler(targetDirection); | ||
var targetCharacterOrientation = Quaternion.Euler(targetCharacterDirection); | ||
|
||
// Get raw mouse input for a cleaner reading on more sensitive mice. | ||
var mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); | ||
|
||
// Scale input against the sensitivity setting and multiply that against the smoothing value. | ||
mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y)); | ||
|
||
// Interpolate mouse movement over time to apply smoothing delta. | ||
_smoothMouse.x = Mathf.Lerp(_smoothMouse.x, mouseDelta.x, 1f / smoothing.x); | ||
_smoothMouse.y = Mathf.Lerp(_smoothMouse.y, mouseDelta.y, 1f / smoothing.y); | ||
|
||
// Find the absolute mouse movement value from point zero. | ||
_mouseAbsolute += _smoothMouse; | ||
|
||
// Clamp and apply the local x value first, so as not to be affected by world transforms. | ||
if (clampInDegrees.x < 360) | ||
_mouseAbsolute.x = Mathf.Clamp(_mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f); | ||
|
||
var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right); | ||
transform.localRotation = xRotation; | ||
|
||
// Then clamp and apply the global y value. | ||
if (clampInDegrees.y < 360) | ||
_mouseAbsolute.y = Mathf.Clamp(_mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f); | ||
|
||
transform.localRotation *= targetOrientation; | ||
|
||
// If there's a character body that acts as a parent to the camera | ||
if (characterBody) | ||
{ | ||
var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, characterBody.transform.up); | ||
characterBody.transform.localRotation = yRotation; | ||
characterBody.transform.localRotation *= targetCharacterOrientation; | ||
} | ||
else | ||
{ | ||
var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, transform.InverseTransformDirection(Vector3.up)); | ||
transform.localRotation *= yRotation; | ||
} | ||
|
||
if (Input.GetKey(rightKey)) | ||
{ | ||
transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0)); | ||
} | ||
if (Input.GetKey(leftKey)) | ||
{ | ||
transform.Translate(new Vector3(-speed * Time.deltaTime, 0, 0)); | ||
} | ||
if (Input.GetKey(backKey)) | ||
{ | ||
transform.Translate(new Vector3(0, 0, -speed * Time.deltaTime)); | ||
} | ||
if (Input.GetKey(fwdKey)) | ||
{ | ||
transform.Translate(new Vector3(0, 0, speed * Time.deltaTime)); | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.