Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions CameraPlus/CameraMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ public override bool Init(CameraPlusBehaviour cameraPlus)
}
return false;
}

public override void OnActiveSceneChanged(Scene from, Scene to)
{
if (to.name == "GameCore")
{
//var standardLevelSceneSetupDataSO = Resources.FindObjectsOfTypeAll<StandardLevelScenesTransitionSetupDataSO>().FirstOrDefault();
//if(standardLevelSceneSetupDataSO)
//{
// foreach(var pair in standardLevelSceneSetupDataSO.sceneInfoSceneSetupDataPairs)
// {
// if(pair.data is GameplayCoreSceneSetupData)
// {
// var sceneSetupData = (GameplayCoreSceneSetupData)pair.data;

// var level = sceneSetupData.difficultyBeatmap.level;
// Plugin.Log($"Level: {level.levelID}");
// if (level is SongLoaderPlugin.OverrideClasses.CustomLevel)
// {
// if (LoadCameraData(Path.Combine((level as SongLoaderPlugin.OverrideClasses.CustomLevel).customSongInfo.path, "CameraMovementData.json")))
// data.ActiveInPauseMenu = false;
// }
// }
// }
//}
// var standardLevelSceneSetupDataSO = Resources.FindObjectsOfTypeAll<StandardLevelScenesTransitionSetupDataSO>().FirstOrDefault();
// if(standardLevelSceneSetupDataSO)
// {
// foreach(var pair in standardLevelSceneSetupDataSO.sceneInfoSceneSetupDataPairs)
// {
// if(pair.data is GameplayCoreSceneSetupData)
// {
// var sceneSetupData = (GameplayCoreSceneSetupData)pair.data;
// var level = sceneSetupData.difficultyBeatmap.level;
// Plugin.Log($"Level: {level.levelID}");
// if (level is SongLoaderPlugin.OverrideClasses.CustomLevel)
// {
// if (LoadCameraData(Path.Combine((level as SongLoaderPlugin.OverrideClasses.CustomLevel).customSongInfo.path, "CameraMovementData.json")))
// data.ActiveInPauseMenu = false;
// }
// }
// }
// }
}
else if(dataLoaded)
else if (dataLoaded)
{
dataLoaded = false;
_cameraPlus.ThirdPersonPos = _cameraPlus.Config.Position;
Expand Down Expand Up @@ -95,7 +95,7 @@ public class CameraData
{
public bool ActiveInPauseMenu = true;
public List<Movements> Movements = new List<Movements>();

public bool LoadFromJson(string jsonString)
{
Movements.Clear();
Expand All @@ -121,7 +121,7 @@ public bool LoadFromJson(string jsonString)

newMovement.Delay = movement["Delay"].AsFloat;
newMovement.Duration = Mathf.Clamp(movement["Duration"].AsFloat, 0.01f, float.MaxValue); // Make sure duration is at least 0.01 seconds, to avoid a divide by zero error

if (movement["EaseTransition"].IsBoolean)
newMovement.EaseTransition = movement["EaseTransition"].AsBool;

Expand Down Expand Up @@ -152,7 +152,7 @@ protected void Update()

if (movePerc == 1 && movementDelayEndTime <= DateTime.Now)
UpdatePosAndRot();

long differenceTicks = (movementEndTime - movementStartTime).Ticks;
long currentTicks = (DateTime.Now - movementStartTime).Ticks;
movePerc = Mathf.Clamp((float)currentTicks / (float)differenceTicks, 0, 1);
Expand Down Expand Up @@ -225,7 +225,7 @@ protected bool LoadCameraData(string path)

protected void FindShortestDelta(ref Vector3 from, ref Vector3 to)
{
if(Mathf.DeltaAngle(from.x, to.x) < 0)
if (Mathf.DeltaAngle(from.x, to.x) < 0)
from.x += 360.0f;
if (Mathf.DeltaAngle(from.y, to.y) < 0)
from.y += 360.0f;
Expand Down Expand Up @@ -259,7 +259,7 @@ protected float Ease(float p)
if (!easeTransition)
return p;

if (p < 0.5f) //Cubic Hopefully
if (p < 0.5f) // Cubic Hopefully
{
return 4 * p * p * p;
}
Expand Down
98 changes: 49 additions & 49 deletions CameraPlus/CameraPlusBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum CursorType
DiagonalLeft,
DiagonalRight
}

protected readonly WaitUntil _waitForMainCamera = new WaitUntil(() => Camera.main);
private readonly WaitForSecondsRealtime _waitForSecondsRealtime = new WaitForSecondsRealtime(1f);
protected const int OnlyInThirdPerson = 3;
Expand Down Expand Up @@ -99,7 +99,7 @@ public bool ThirdPerson
public static bool wasWithinBorder = false;
public static bool anyInstanceBusy = false;
private static bool _contextMenuEnabled = true;

public virtual void Init(Config config)
{
DontDestroyOnLoad(gameObject);
Expand All @@ -111,14 +111,14 @@ public virtual void Init(Config config)

StartCoroutine(DelayedInit());
}

protected IEnumerator DelayedInit()
{
yield return _waitForMainCamera;

_mainCamera = Camera.main;
// _menuStrip = null;
if(_contextMenu == null)
// _menuStrip = null;
if (_contextMenu == null)
{
MenuObj = new GameObject("CameraPlusMenu");
_contextMenu = MenuObj.AddComponent<ContextMenu>();
Expand All @@ -128,15 +128,15 @@ protected IEnumerator DelayedInit()
Config.ConfigChangedEvent += PluginOnConfigChangedEvent;

var gameObj = Instantiate(_mainCamera.gameObject);

gameObj.SetActive(false);
gameObj.name = "Camera Plus";
gameObj.tag = "Untagged";
while (gameObj.transform.childCount > 0) DestroyImmediate(gameObj.transform.GetChild(0).gameObject);
DestroyImmediate(gameObj.GetComponent("CameraRenderCallbacksManager"));
DestroyImmediate(gameObj.GetComponent("AudioListener"));
DestroyImmediate(gameObj.GetComponent("MeshCollider"));

_cam = gameObj.GetComponent<Camera>();
_cam.stereoTargetEye = StereoTargetEyeMask.None;
_cam.enabled = true;
Expand Down Expand Up @@ -178,7 +178,7 @@ protected IEnumerator DelayedInit()
_quad.transform.localEulerAngles = new Vector3(0, 180, 0);
_quad.transform.localScale = new Vector3(_cam.aspect, 1, 1);
_cameraPreviewQuad = _quad;

ReadConfig();

if (ThirdPerson)
Expand All @@ -203,12 +203,12 @@ protected IEnumerator DelayedInit()

Plugin.Instance.ActiveSceneChanged += SceneManager_activeSceneChanged;

// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
SceneManager_activeSceneChanged(new Scene(), new Scene());
Logger.Log($"Camera \"{Path.GetFileName(Config.FilePath)}\" successfully initialized!");
}

protected virtual void OnDestroy()
{
Config.ConfigChangedEvent -= PluginOnConfigChangedEvent;
Expand Down Expand Up @@ -247,8 +247,8 @@ protected virtual void ReadConfig()
{
ThirdPersonPos = Config.Position;
ThirdPersonRot = Config.Rotation;
// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
}

SetCullingMask();
Expand Down Expand Up @@ -282,11 +282,11 @@ internal virtual void CreateScreenRenderTexture()

if (!replace)
{
//Logger.Log("Don't need to replace");
// Logger.Log("Don't need to replace");
return;
}

if(Config.fitToCanvas)
if (Config.fitToCanvas)
{
Config.screenPosX = 0;
Config.screenPosY = 0;
Expand All @@ -295,7 +295,7 @@ internal virtual void CreateScreenRenderTexture()
}

_lastRenderUpdate = DateTime.Now;
//GetScaledScreenResolution(Config.renderScale, out var scaledWidth, out var scaledHeight);
// GetScaledScreenResolution(Config.renderScale, out var scaledWidth, out var scaledHeight);
_camRenderTexture.width = Mathf.Clamp(Mathf.RoundToInt(Config.screenWidth * Config.renderScale), 1, int.MaxValue);
_camRenderTexture.height = Mathf.Clamp(Mathf.RoundToInt(Config.screenHeight * Config.renderScale), 1, int.MaxValue);

Expand All @@ -318,12 +318,12 @@ internal virtual void CreateScreenRenderTexture()
_prevScreenPosY = Config.screenPosY;
});
}

public virtual void SceneManager_activeSceneChanged(Scene from, Scene to)
{
StartCoroutine(GetMainCamera());
var vrPointers = to.name == "GameCore" ? Resources.FindObjectsOfTypeAll<VRPointer>() : Resources.FindObjectsOfTypeAll<VRPointer>();
if(vrPointers.Count() == 0)
if (vrPointers.Count() == 0)
{
Logger.Log("Failed to get VRPointer!", LogLevel.Warning);
return;
Expand All @@ -340,8 +340,8 @@ public virtual void SceneManager_activeSceneChanged(Scene from, Scene to)

protected void OnApplicationFocus(bool hasFocus)
{
// if(!hasFocus && GetActiveWindow() == IntPtr.Zero)
// CloseContextMenu();
// if(!hasFocus && GetActiveWindow() == IntPtr.Zero)
// CloseContextMenu();
}

protected virtual void Update()
Expand All @@ -356,8 +356,8 @@ protected virtual void Update()
{
transform.position = _mainCamera.transform.position;
transform.rotation = _mainCamera.transform.rotation;
// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
}
else
{
Expand Down Expand Up @@ -386,21 +386,21 @@ protected virtual void LateUpdate()
_cameraCube.eulerAngles = ThirdPersonRot;
return;
}
// Console.WriteLine(Config.FirstPersonPositionOffset.ToString());
// Console.WriteLine(Config.FirstPersonPositionOffset.ToString());
transform.position = Vector3.Lerp(transform.position, camera.position + Config.FirstPersonPositionOffset,
Config.positionSmooth * Time.unscaledDeltaTime);

if(!Config.forceFirstPersonUpRight)
transform.rotation = Quaternion.Slerp(transform.rotation, camera.rotation * Quaternion.Euler(Config.FirstPersonRotationOffset),
Config.rotationSmooth * Time.unscaledDeltaTime);
else
if (!Config.forceFirstPersonUpRight)
transform.rotation = Quaternion.Slerp(transform.rotation, camera.rotation * Quaternion.Euler(Config.FirstPersonRotationOffset),
Config.rotationSmooth * Time.unscaledDeltaTime);
else

{
Quaternion rot = Quaternion.Slerp(transform.rotation, camera.rotation * Quaternion.Euler(Config.FirstPersonRotationOffset),
Config.rotationSmooth * Time.unscaledDeltaTime);
transform.rotation = rot * Quaternion.Euler(0, 0, -(rot.eulerAngles.z) );
transform.rotation = rot * Quaternion.Euler(0, 0, -(rot.eulerAngles.z));
}

}
catch { }
}
Expand Down Expand Up @@ -444,7 +444,7 @@ internal virtual void SetFOV()

internal virtual void SetCullingMask()
{
if(Config.transparentWalls)
if (Config.transparentWalls)
_cam.cullingMask &= ~(1 << TransparentWallsPatch.WallLayerMask);
else
_cam.cullingMask |= (1 << TransparentWallsPatch.WallLayerMask);
Expand All @@ -471,13 +471,13 @@ public bool IsTopmostRenderAreaAtPos(Vector2 mousePos)
return false;
}

if (c.Config.layer == Config.layer &&
if (c.Config.layer == Config.layer &&
c.Instance._lastRenderUpdate > _lastRenderUpdate)
{
return false;
}

if (c.Instance._mouseHeld && (c.Instance._isMoving ||
if (c.Instance._mouseHeld && (c.Instance._isMoving ||
c.Instance._isResizing || c.Instance._contextMenuOpen))
{
return false;
Expand Down Expand Up @@ -517,7 +517,7 @@ internal void CloseContextMenu()
*/
_contextMenuOpen = false;
}

public static void SetCursor(CursorType type)
{
if (type != currentCursor)
Expand All @@ -538,7 +538,7 @@ public static void SetCursor(CursorType type)
texture = Utils.LoadTextureFromResources("CameraPlus.Resources.Resize_DiagLeft.png");
break;
}
UnityEngine.Cursor.SetCursor(texture, texture ? new Vector2(texture.width / 2, texture.height / 2) : new Vector2(0,0), CursorMode.Auto);
UnityEngine.Cursor.SetCursor(texture, texture ? new Vector2(texture.width / 2, texture.height / 2) : new Vector2(0, 0), CursorMode.Auto);
currentCursor = type;
}
}
Expand All @@ -555,7 +555,7 @@ protected void HandleMouseEvents()
{
if (/*_menuStrip != null &&*/ mousePos.x > 0 && mousePos.x < Screen.width && mousePos.y > 0 && mousePos.y < Screen.height)
{
// CloseContextMenu();
// CloseContextMenu();
}
}

Expand Down Expand Up @@ -611,7 +611,7 @@ protected void HandleMouseEvents()
{
_initialOffset.x = currentMouseOffsetX;
_initialOffset.y = currentMouseOffsetY;

_lastScreenPos = Config.ScreenPosition;
_lastGrabPos = new Vector2(mousePos.x, mousePos.y);

Expand Down Expand Up @@ -649,20 +649,20 @@ protected void HandleMouseEvents()
Config.screenHeight = Mathf.Clamp(Config.screenHeight, 100, Screen.height);
Config.screenPosX = Mathf.Clamp(Config.screenPosX, 0, Screen.width - Config.screenWidth);
Config.screenPosY = Mathf.Clamp(Config.screenPosY, 0, Screen.height - Config.screenHeight);

CreateScreenRenderTexture();
}
else if (holdingRightClick && _contextMenuEnabled)
{
if (_mouseHeld) return;
// if (_menuStrip == null)
// {
DisplayContextMenu();
_contextMenuOpen = true;
// }
// _menuStrip.SetBounds(Cursor.Position.X, Cursor.Position.Y, 0, 0);
// if (!_menuStrip.Visible)
// _menuStrip.Show();
// if (_menuStrip == null)
// {
DisplayContextMenu();
_contextMenuOpen = true;
// }
// _menuStrip.SetBounds(Cursor.Position.X, Cursor.Position.Y, 0, 0);
// if (!_menuStrip.Visible)
// _menuStrip.Show();
anyInstanceBusy = true;
_mouseHeld = true;
}
Expand Down Expand Up @@ -745,8 +745,8 @@ void DisplayContextMenu()
ThirdPerson = Config.thirdPerson;
ThirdPersonPos = Config.Position;
ThirdPersonRot = Config.Rotation;
//FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
CreateScreenRenderTexture();
CloseContextMenu();
Config.Save();
Expand All @@ -771,8 +771,8 @@ void DisplayContextMenu()
Config.FirstPersonRotationOffset = Config.DefaultFirstPersonRotationOffset;
ThirdPersonPos = Config.DefaultPosition;
ThirdPersonRot = Config.DefaultRotation;
//FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
// FirstPersonOffset = Config.FirstPersonPositionOffset;
// FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
Config.Save();
CloseContextMenu();
});
Expand Down
Loading