mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2026-10-10 04:53:15 +08:00
Deselected the follow object button after clicking it, hid the UE menu after hitting play on the camera path, and fixed the follow object to work in conjunction with the camera paths.
This commit is contained in:
@@ -34,6 +34,8 @@ namespace UnityExplorer.UI.Panels
|
||||
bool closedLoop;
|
||||
float time = 10;
|
||||
|
||||
GameObject followObject = null;
|
||||
|
||||
// ~~~~~~~~ UI construction / callbacks ~~~~~~~~
|
||||
|
||||
protected override void ConstructPanelContent()
|
||||
@@ -73,7 +75,7 @@ namespace UnityExplorer.UI.Panels
|
||||
toggleClosedLoopText.text = "Close path in a loop";
|
||||
|
||||
InputFieldRef TimeInput = null;
|
||||
AddInputField("Time", "Path time (in seconds at 60fps):", $"Default: {time}", out TimeInput, Time_OnEndEdit, false);
|
||||
GameObject secondRow = AddInputField("Time", "Path time (in seconds at 60fps):", $"Default: {time}", out TimeInput, Time_OnEndEdit, false);
|
||||
TimeInput.Text = time.ToString();
|
||||
}
|
||||
|
||||
@@ -99,7 +101,13 @@ namespace UnityExplorer.UI.Panels
|
||||
//Move to Camera
|
||||
ButtonRef moveToCameraButton = UIFactory.CreateButton(horiGroup, "Copy Camera pos and rot", "Copy Camera pos and rot");
|
||||
UIFactory.SetLayoutElement(moveToCameraButton.GameObject, minWidth: 100, minHeight: 25, flexibleWidth: 9999);
|
||||
moveToCameraButton.OnClick += () => {point.position = FreeCamPanel.ourCamera.transform.position; point.rotation = FreeCamPanel.ourCamera.transform.rotation; controlPoints[index] = point; EventSystemHelper.SetSelectedGameObject(null);};
|
||||
moveToCameraButton.OnClick += () => {
|
||||
point.position = followObject != null ? FreeCamPanel.ourCamera.transform.localPosition : FreeCamPanel.ourCamera.transform.position;
|
||||
point.rotation = followObject != null ? FreeCamPanel.ourCamera.transform.localRotation : FreeCamPanel.ourCamera.transform.rotation;
|
||||
controlPoints[index] = point;
|
||||
|
||||
EventSystemHelper.SetSelectedGameObject(null);
|
||||
};
|
||||
|
||||
ButtonRef copyFovButton = UIFactory.CreateButton(horiGroup, "Copy Camera FoV", "Copy Camera FoV");
|
||||
UIFactory.SetLayoutElement(copyFovButton.GameObject, minWidth: 100, minHeight: 25, flexibleWidth: 9999);
|
||||
@@ -107,7 +115,18 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
ButtonRef moveToPointButton = UIFactory.CreateButton(horiGroup, "Move Cam to Node", "Move Cam to Node");
|
||||
UIFactory.SetLayoutElement(moveToPointButton.GameObject, minWidth: 100, minHeight: 25, flexibleWidth: 9999);
|
||||
moveToPointButton.OnClick += () => {FreeCamPanel.ourCamera.transform.position = point.position; FreeCamPanel.ourCamera.transform.rotation = point.rotation; FreeCamPanel.ourCamera.fieldOfView = point.fov; EventSystemHelper.SetSelectedGameObject(null);};
|
||||
moveToPointButton.OnClick += () => {
|
||||
if (followObject != null){
|
||||
FreeCamPanel.ourCamera.transform.localPosition = point.position;
|
||||
FreeCamPanel.ourCamera.transform.localRotation = point.rotation;
|
||||
} else {
|
||||
FreeCamPanel.ourCamera.transform.position = point.position;
|
||||
FreeCamPanel.ourCamera.transform.rotation = point.rotation;
|
||||
}
|
||||
FreeCamPanel.ourCamera.fieldOfView = point.fov;
|
||||
|
||||
EventSystemHelper.SetSelectedGameObject(null);
|
||||
};
|
||||
|
||||
//Add node next
|
||||
|
||||
@@ -139,9 +158,11 @@ namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
if(GetCameraPathsManager()){
|
||||
GetCameraPathsManager().setClosedLoop(closedLoop);
|
||||
GetCameraPathsManager().setLocalPoints(followObject != null);
|
||||
GetCameraPathsManager().setSplinePoints(controlPoints.ToArray());
|
||||
GetCameraPathsManager().setTime(time);
|
||||
GetCameraPathsManager().StartPath();
|
||||
UIManager.ShowMenu = false;
|
||||
}
|
||||
|
||||
EventSystemHelper.SetSelectedGameObject(null);
|
||||
@@ -165,7 +186,12 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
void AddNode_OnClick(){
|
||||
Camera freeCam = FreeCamPanel.ourCamera;
|
||||
CatmullRom.CatmullRomPoint point = new CatmullRom.CatmullRomPoint(freeCam.transform.position, freeCam.transform.rotation, freeCam.fieldOfView);
|
||||
CatmullRom.CatmullRomPoint point = new CatmullRom.CatmullRomPoint(
|
||||
followObject != null ? freeCam.transform.localPosition : freeCam.transform.position,
|
||||
followObject != null ? freeCam.transform.localRotation : freeCam.transform.rotation,
|
||||
freeCam.fieldOfView
|
||||
);
|
||||
|
||||
controlPoints.Add(point);
|
||||
UpdateListNodes();
|
||||
|
||||
@@ -191,5 +217,40 @@ namespace UnityExplorer.UI.Panels
|
||||
private CatmullRom.CatmullRomMover GetCameraPathsManager(){
|
||||
return FreeCamPanel.cameraPathMover;
|
||||
}
|
||||
|
||||
public void UpdatedFollowObject(GameObject obj){
|
||||
if(followObject != null) TranslatePointsToGlobal();
|
||||
followObject = obj;
|
||||
if (obj != null){
|
||||
TranslatePointsToLocal();
|
||||
}
|
||||
UpdateListNodes();
|
||||
}
|
||||
|
||||
void TranslatePointsToGlobal() {
|
||||
List<CatmullRom.CatmullRomPoint> newControlPoints = new List<CatmullRom.CatmullRomPoint>();
|
||||
foreach(CatmullRom.CatmullRomPoint point in controlPoints){
|
||||
Vector3 newPos = followObject.transform.TransformPoint(point.position);
|
||||
Quaternion newRot = followObject.transform.rotation * point.rotation;
|
||||
CatmullRom.CatmullRomPoint newPoint = new CatmullRom.CatmullRomPoint(newPos, newRot, point.fov);
|
||||
|
||||
newControlPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
controlPoints = newControlPoints;
|
||||
}
|
||||
|
||||
void TranslatePointsToLocal() {
|
||||
List<CatmullRom.CatmullRomPoint> newControlPoints = new List<CatmullRom.CatmullRomPoint>();
|
||||
foreach(CatmullRom.CatmullRomPoint point in controlPoints){
|
||||
Vector3 newPos = followObject.transform.InverseTransformPoint(point.position);
|
||||
Quaternion newRot = Quaternion.Inverse(followObject.transform.rotation) * point.rotation;
|
||||
CatmullRom.CatmullRomPoint newPoint = new CatmullRom.CatmullRomPoint(newPos, newRot, point.fov);
|
||||
|
||||
newControlPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
controlPoints = newControlPoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,6 +398,8 @@ namespace UnityExplorer.UI.Panels
|
||||
public static void FollowObjectAction(GameObject obj){
|
||||
followObject = obj;
|
||||
followObjectLabel.text = $"Following: {obj.name}";
|
||||
CamPaths CamPathsPanel = UIManager.GetPanel<CamPaths>(UIManager.Panels.CamPaths);
|
||||
CamPathsPanel.UpdatedFollowObject(obj);
|
||||
}
|
||||
|
||||
void FollowButton_OnClick()
|
||||
@@ -412,6 +414,8 @@ namespace UnityExplorer.UI.Panels
|
||||
followObject = null;
|
||||
followObjectLabel.text = "Not following any object";
|
||||
}
|
||||
CamPaths CamPathsPanel = UIManager.GetPanel<CamPaths>(UIManager.Panels.CamPaths);
|
||||
CamPathsPanel.UpdatedFollowObject(null);
|
||||
}
|
||||
|
||||
static void SetToggleButtonState()
|
||||
|
||||
@@ -102,6 +102,8 @@ namespace UnityExplorer.CatmullRom
|
||||
// Current position in the path, from 0 to 1
|
||||
float delta;
|
||||
|
||||
bool arePointsLocal;
|
||||
|
||||
public CatmullRomMover(){
|
||||
splinePoints = new CatmullRomPoint[] { };
|
||||
lookaheadPoints = new List<CatmullRomPoint>();
|
||||
@@ -137,6 +139,10 @@ namespace UnityExplorer.CatmullRom
|
||||
closedLoop = newClosedLoop;
|
||||
}
|
||||
|
||||
public void setLocalPoints(bool newArePointsLocal){
|
||||
arePointsLocal = newArePointsLocal;
|
||||
}
|
||||
|
||||
public void setSplinePoints(CatmullRomPoint[] newSplinePoints){
|
||||
splinePoints = newSplinePoints;
|
||||
}
|
||||
@@ -145,14 +151,15 @@ namespace UnityExplorer.CatmullRom
|
||||
time = newTime;
|
||||
}
|
||||
|
||||
// We use FixedUpdate here to have a constant velocity no matter the time dilation the game is currently using,
|
||||
// although the game should still run at a capped 60fps.
|
||||
void Update(){
|
||||
if (playingPath) AdvanceMover(Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
private CatmullRomPoint GetCurrentPoint(){
|
||||
return new CatmullRomPoint(FreeCamPanel.ourCamera.transform.position, FreeCamPanel.ourCamera.transform.rotation, FreeCamPanel.ourCamera.fieldOfView);
|
||||
Vector3 camPos = arePointsLocal ? FreeCamPanel.ourCamera.transform.localPosition : FreeCamPanel.ourCamera.transform.position;
|
||||
Quaternion camRot = arePointsLocal ? FreeCamPanel.ourCamera.transform.localRotation : FreeCamPanel.ourCamera.transform.rotation;
|
||||
|
||||
return new CatmullRomPoint(camPos, camRot, FreeCamPanel.ourCamera.fieldOfView);
|
||||
}
|
||||
|
||||
private void AdvanceMover(float dt){
|
||||
@@ -179,7 +186,8 @@ namespace UnityExplorer.CatmullRom
|
||||
room = Vector3.Distance(lookahead.position, currentPoint.position);
|
||||
// While ends, need another lookaheadDelta for the next Update
|
||||
// It will do, at most, 2 iterations
|
||||
while (room <= 0) {
|
||||
// We check a very small number instead of zero because if not it can get stuck in an infinite loop
|
||||
while (room <= 0.0001f) {
|
||||
// If the camera reached the last lookAhead we stop it
|
||||
if (delta >= 1){
|
||||
playingPath = false;
|
||||
@@ -205,14 +213,26 @@ namespace UnityExplorer.CatmullRom
|
||||
Vector4 newRot = ra + rb;
|
||||
newRot.Normalize();
|
||||
|
||||
FreeCamPanel.ourCamera.transform.position += direction.position;
|
||||
FreeCamPanel.ourCamera.transform.rotation = CatmullRomPoint.Vector4ToQuaternion(newRot);
|
||||
if (arePointsLocal){
|
||||
FreeCamPanel.ourCamera.transform.localPosition += direction.position;
|
||||
FreeCamPanel.ourCamera.transform.localRotation = CatmullRomPoint.Vector4ToQuaternion(newRot);
|
||||
} else {
|
||||
FreeCamPanel.ourCamera.transform.position += direction.position;
|
||||
FreeCamPanel.ourCamera.transform.rotation = CatmullRomPoint.Vector4ToQuaternion(newRot);
|
||||
}
|
||||
|
||||
FreeCamPanel.ourCamera.fieldOfView += direction.fov * actual / room;
|
||||
}
|
||||
|
||||
public void MoveCameraToPoint(CatmullRomPoint newPoint){
|
||||
FreeCamPanel.ourCamera.transform.position = newPoint.position;
|
||||
FreeCamPanel.ourCamera.transform.rotation = newPoint.rotation;
|
||||
if (arePointsLocal){
|
||||
FreeCamPanel.ourCamera.transform.localPosition = newPoint.position;
|
||||
FreeCamPanel.ourCamera.transform.localRotation = newPoint.rotation;
|
||||
} else {
|
||||
FreeCamPanel.ourCamera.transform.position = newPoint.position;
|
||||
FreeCamPanel.ourCamera.transform.rotation = newPoint.rotation;
|
||||
}
|
||||
|
||||
FreeCamPanel.ourCamera.fieldOfView = newPoint.fov;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user