├── CameraPlus
├── packages.config
├── SteamVRCompatibility.cs
├── CameraPlus.sln
├── ScreenCameraBehaviour.cs
├── Properties
│ └── AssemblyInfo.cs
├── ReflectionUtil.cs
├── Plugin.cs
├── Config.cs
├── CameraMoverPointer.cs
├── CameraPlus.csproj
└── CameraPlusBehaviour.cs
├── LICENSE
├── README.md
└── .gitignore
/CameraPlus/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CameraPlus/SteamVRCompatibility.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CameraPlus
4 | {
5 | public static class SteamVRCompatibility
6 | {
7 | public static Type SteamVRCamera;
8 | public static Type SteamVRExternalCamera;
9 | public static Type SteamVRFade;
10 | public static bool IsAvailable => FindSteamVRAsset();
11 |
12 | private static bool FindSteamVRAsset()
13 | {
14 | SteamVRCamera = Type.GetType("SteamVR_Camera, Assembly-CSharp-firstpass", false);
15 | SteamVRExternalCamera = Type.GetType("SteamVR_ExternalCamera, Assembly-CSharp-firstpass", false);
16 | SteamVRFade = Type.GetType("SteamVR_Fade, Assembly-CSharp-firstpass", false);
17 | return SteamVRCamera != null && SteamVRExternalCamera != null && SteamVRFade != null;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CameraPlus/CameraPlus.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CameraPlus", "CameraPlus.csproj", "{EB29D3F0-3BC0-4459-9269-C9DA0F3FCD1A}"
4 | EndProject
5 | Global
6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
7 | Debug|Any CPU = Debug|Any CPU
8 | Release|Any CPU = Release|Any CPU
9 | EndGlobalSection
10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
11 | {EB29D3F0-3BC0-4459-9269-C9DA0F3FCD1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12 | {EB29D3F0-3BC0-4459-9269-C9DA0F3FCD1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
13 | {EB29D3F0-3BC0-4459-9269-C9DA0F3FCD1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
14 | {EB29D3F0-3BC0-4459-9269-C9DA0F3FCD1A}.Release|Any CPU.Build.0 = Release|Any CPU
15 | EndGlobalSection
16 | EndGlobal
17 |
--------------------------------------------------------------------------------
/CameraPlus/ScreenCameraBehaviour.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace CameraPlus
5 | {
6 | ///
7 | /// This is the monobehaviour that goes on the camera that handles
8 | /// displaying the actual feed from the camera to the screen.
9 | ///
10 | public class ScreenCameraBehaviour : MonoBehaviour
11 | {
12 | private Camera _cam;
13 | private RenderTexture _renderTexture;
14 |
15 | public void SetRenderTexture(RenderTexture renderTexture)
16 | {
17 | _renderTexture = renderTexture;
18 | }
19 |
20 | private void Awake()
21 | {
22 | _cam = gameObject.AddComponent();
23 | _cam.clearFlags = CameraClearFlags.Nothing;
24 | _cam.cullingMask = 0;
25 | _cam.depth = -1000;
26 | _cam.stereoTargetEye = StereoTargetEyeMask.None;
27 | }
28 |
29 | private void OnRenderImage(RenderTexture src, RenderTexture dest)
30 | {
31 | if (_renderTexture == null) return;
32 | Graphics.Blit(_renderTexture, dest);
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 xyonico
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/CameraPlus/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("CameraPlus")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("CameraPlus")]
12 | [assembly: AssemblyCopyright("Copyright © xyonico 2018")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("EB29D3F0-3BC0-4459-9269-C9DA0F3FCD1A")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("2.0.1.0")]
35 | [assembly: AssemblyFileVersion("2.0.1.0")]
--------------------------------------------------------------------------------
/CameraPlus/ReflectionUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using UnityEngine;
4 |
5 | namespace CameraPlus
6 | {
7 | public static class ReflectionUtil
8 | {
9 | public static void SetPrivateField(object obj, string fieldName, object value)
10 | {
11 | var prop = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
12 | prop.SetValue(obj, value);
13 | }
14 |
15 | public static T GetPrivateField(object obj, string fieldName)
16 | {
17 | var prop = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
18 | var value = prop.GetValue(obj);
19 | return (T) value;
20 | }
21 |
22 | public static void SetPrivateProperty(object obj, string propertyName, object value)
23 | {
24 | var prop = obj.GetType()
25 | .GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
26 | prop.SetValue(obj, value, null);
27 | }
28 |
29 | public static void InvokePrivateMethod(object obj, string methodName, object[] methodParams)
30 | {
31 | var dynMethod = obj.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
32 | dynMethod.Invoke(obj, methodParams);
33 | }
34 |
35 | public static Component CopyComponent(Component original, Type overridingType, GameObject destination)
36 | {
37 | var copy = destination.AddComponent(overridingType);
38 | var fields = original.GetType()
39 | .GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField);
40 | foreach (var field in fields)
41 | {
42 | field.SetValue(copy, field.GetValue(original));
43 | }
44 |
45 | return copy;
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CameraPlus
2 | Plugin for Beat Saber for a smoother and wider FOV camera.
3 |
4 | [Video Comparison](https://youtu.be/MysLXKSXGTY)
5 | [Third Person Preview](https://youtu.be/ltIhpt-n6b8)
6 |
7 | # Installing
8 | 1. Use the mod installer: https://github.com/Umbranoxio/BeatSaberModInstaller/releases
9 | It is the easiest method, it will do all these steps below in 1 click.
10 |
11 | ### To install manually:
12 | 1b. Make sure that Beat Saber is not running.
13 | 2b. Extract the contents of the zip into Beat Saber's installation folder.
14 | For Oculus Home: \Oculus Apps\Software\hyperbolic-magnetism-beat-saber\
15 | For Steam: \steamapps\common\Beat Saber\
16 | (The folder that contains Beat Saber.exe)
17 | 3b. Done! You've installed the Custom Avatar Plugin.
18 | # Usage
19 | Press F1 to toggle between first and third person.
20 |
21 | After you run the game once, a `cameraplus.cfg` file is created within the Beat Saber folder.
22 | Edit that file to configure CameraPlus:
23 |
24 | `fov=90.0` Horizontal field of view of the camera
25 | `fps=90.0` Frame rate of the camera
26 | `antiAliasing=2` Anti-aliasing setting for the camera (1, 2, 4 or 8 only)
27 | `renderScale` The resolution scale of the camera relative to game window (similar to supersampling for VR)
28 | `positionSmooth=10.0` How much position should smooth **(SMALLER NUMBER = SMOOTHER)**
29 | `rotationSmooth=5.0` How much rotation should smooth **(SMALLER NUMBER = SMOOTHER)**
30 | `thirdPerson=false` Whether third person camera is enabled
31 |
32 | `posx=0` X position of third person camera
33 | `posy=0` Y position of third person camera
34 | `posz=0` Z position of third person camera
35 | `angx=0` X rotation of third person camera
36 | `angy=0` Y rotation of third person camera
37 | `angz=0` Z rotation of third person camera
38 |
39 | If you need help, ask us at the Beat Saber Mod Group Discord Server:
40 | https://discord.gg/BeatSaberMods
41 |
--------------------------------------------------------------------------------
/CameraPlus/Plugin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.IO;
4 | using IllusionPlugin;
5 | using UnityEngine;
6 | using UnityEngine.SceneManagement;
7 | using Object = UnityEngine.Object;
8 |
9 | namespace CameraPlus
10 | {
11 | public class Plugin : IPlugin
12 | {
13 | public readonly Config Config = new Config(Path.Combine(Environment.CurrentDirectory, "cameraplus.cfg"));
14 | private readonly WaitForSecondsRealtime _waitForSecondsRealtime = new WaitForSecondsRealtime(0.1f);
15 |
16 | private CameraPlusBehaviour _cameraPlus;
17 | private bool _init;
18 |
19 | public static Plugin Instance { get; private set; }
20 | public string Name => "CameraPlus";
21 | public string Version => "v2.0.1";
22 |
23 | public void OnApplicationStart()
24 | {
25 | if (_init) return;
26 | _init = true;
27 |
28 | Instance = this;
29 |
30 | SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;
31 | }
32 |
33 | public void OnApplicationQuit()
34 | {
35 | SceneManager.sceneLoaded -= SceneManagerOnSceneLoaded;
36 | Config.Save();
37 | }
38 |
39 | public void OnLevelWasLoaded(int level)
40 | {
41 | }
42 |
43 | public void OnLevelWasInitialized(int level)
44 | {
45 | }
46 |
47 | public void OnUpdate()
48 | {
49 | }
50 |
51 | public void OnFixedUpdate()
52 | {
53 | }
54 |
55 | private void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
56 | {
57 | SharedCoroutineStarter.instance.StartCoroutine(DelayedOnSceneLoaded(scene));
58 | }
59 |
60 | private IEnumerator DelayedOnSceneLoaded(Scene scene)
61 | {
62 | yield return _waitForSecondsRealtime;
63 |
64 | if (scene.buildIndex < 1) yield break;
65 | if (_cameraPlus != null) Object.Destroy(_cameraPlus.gameObject);
66 |
67 | var mainCamera = Camera.main;
68 | if (mainCamera == null)
69 | {
70 | yield break;
71 | }
72 |
73 | var gameObj = new GameObject("CameraPlus");
74 | _cameraPlus = gameObj.AddComponent();
75 | _cameraPlus.Init(mainCamera);
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/CameraPlus/Config.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using UnityEngine;
4 |
5 | namespace CameraPlus
6 | {
7 | public class Config
8 | {
9 | public string FilePath { get; }
10 | public float fov = 90;
11 | public int antiAliasing = 2;
12 | public float renderScale = 1;
13 | public float positionSmooth = 10;
14 | public float rotationSmooth = 5;
15 |
16 | public bool thirdPerson = false;
17 |
18 | public float posx;
19 | public float posy = 2;
20 | public float posz = -1.2f;
21 |
22 | public float angx = 15;
23 | public float angy;
24 | public float angz;
25 |
26 | public event Action ConfigChangedEvent;
27 |
28 | private readonly FileSystemWatcher _configWatcher;
29 | private bool _saving;
30 |
31 | public Vector3 Position
32 | {
33 | get
34 | {
35 | return new Vector3(posx, posy, posz);
36 | }
37 | }
38 |
39 | public Vector3 Rotation
40 | {
41 | get { return new Vector3(angx, angy, angz); }
42 | }
43 |
44 | public Config(string filePath)
45 | {
46 | FilePath = filePath;
47 |
48 | if (File.Exists(FilePath))
49 | {
50 | Load();
51 | var text = File.ReadAllText(FilePath);
52 | if (text.Contains("rotx"))
53 | {
54 |
55 | var oldRotConfig = new OldRotConfig();
56 | ConfigSerializer.LoadConfig(oldRotConfig, FilePath);
57 |
58 | var euler = new Quaternion(oldRotConfig.rotx, oldRotConfig.roty, oldRotConfig.rotz,
59 | oldRotConfig.rotw)
60 | .eulerAngles;
61 | angx = euler.x;
62 | angy = euler.y;
63 | angz = euler.z;
64 |
65 | Save();
66 | }
67 | }
68 | else
69 | {
70 | Save();
71 | }
72 |
73 | _configWatcher = new FileSystemWatcher(Environment.CurrentDirectory)
74 | {
75 | NotifyFilter = NotifyFilters.LastWrite,
76 | Filter = "cameraplus.cfg",
77 | EnableRaisingEvents = true
78 | };
79 | _configWatcher.Changed += ConfigWatcherOnChanged;
80 | }
81 |
82 | ~Config()
83 | {
84 | _configWatcher.Changed -= ConfigWatcherOnChanged;
85 | }
86 |
87 | public void Save()
88 | {
89 | _saving = true;
90 | ConfigSerializer.SaveConfig(this, FilePath);
91 | }
92 |
93 | public void Load()
94 | {
95 | ConfigSerializer.LoadConfig(this, FilePath);
96 | }
97 |
98 | private void ConfigWatcherOnChanged(object sender, FileSystemEventArgs fileSystemEventArgs)
99 | {
100 | if (_saving)
101 | {
102 | _saving = false;
103 | return;
104 | }
105 |
106 | Load();
107 |
108 | if (ConfigChangedEvent != null)
109 | {
110 | ConfigChangedEvent(this);
111 | }
112 | }
113 |
114 | public class OldRotConfig
115 | {
116 | public float rotx;
117 | public float roty;
118 | public float rotz;
119 | public float rotw;
120 | }
121 | }
122 | }
--------------------------------------------------------------------------------
/CameraPlus/CameraMoverPointer.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using VRUIControls;
3 |
4 | namespace CameraPlus
5 | {
6 | public class CameraMoverPointer : MonoBehaviour
7 | {
8 | protected const float MinScrollDistance = 0.25f;
9 | protected const float MaxLaserDistance = 50;
10 |
11 | protected VRPointer _vrPointer;
12 | protected CameraPlusBehaviour _cameraPlus;
13 | protected Transform _cameraCube;
14 | protected VRController _grabbingController;
15 | protected Vector3 _grabPos;
16 | protected Quaternion _grabRot;
17 | protected Vector3 _realPos;
18 | protected Quaternion _realRot;
19 |
20 | public virtual void Init(CameraPlusBehaviour cameraPlus, Transform cameraCube)
21 | {
22 | _cameraPlus = cameraPlus;
23 | _cameraCube = cameraCube;
24 | _realPos = Plugin.Instance.Config.Position;
25 | _realRot = Quaternion.Euler(Plugin.Instance.Config.Rotation);
26 | _vrPointer = GetComponent();
27 | }
28 |
29 | protected virtual void OnEnable()
30 | {
31 | Plugin.Instance.Config.ConfigChangedEvent += PluginOnConfigChangedEvent;
32 | }
33 |
34 | protected virtual void OnDisable()
35 | {
36 | Plugin.Instance.Config.ConfigChangedEvent -= PluginOnConfigChangedEvent;
37 | }
38 |
39 | protected virtual void PluginOnConfigChangedEvent(Config config)
40 | {
41 | _realPos = config.Position;
42 | _realRot = Quaternion.Euler(config.Rotation);
43 | }
44 |
45 | protected virtual void Update()
46 | {
47 | if (_vrPointer.vrController != null)
48 | if (_vrPointer.vrController.triggerValue > 0.9f)
49 | {
50 | if (_grabbingController != null) return;
51 | if (Physics.Raycast(_vrPointer.vrController.position, _vrPointer.vrController.forward, out var hit, MaxLaserDistance))
52 | {
53 | if (hit.transform != _cameraCube) return;
54 | _grabbingController = _vrPointer.vrController;
55 | _grabPos = _vrPointer.vrController.transform.InverseTransformPoint(_cameraCube.position);
56 | _grabRot = Quaternion.Inverse(_vrPointer.vrController.transform.rotation) * _cameraCube.rotation;
57 | }
58 | }
59 |
60 | if (_grabbingController == null || !(_grabbingController.triggerValue <= 0.9f)) return;
61 | if (_grabbingController == null) return;
62 | SaveToConfig();
63 | _grabbingController = null;
64 | }
65 |
66 | protected virtual void LateUpdate()
67 | {
68 | if (_grabbingController != null)
69 | {
70 | var diff = _grabbingController.verticalAxisValue * Time.deltaTime;
71 | if (_grabPos.magnitude > MinScrollDistance)
72 | {
73 | _grabPos -= Vector3.forward * diff;
74 | }
75 | else
76 | {
77 | _grabPos -= Vector3.forward * Mathf.Clamp(diff, float.MinValue, 0);
78 | }
79 | _realPos = _grabbingController.transform.TransformPoint(_grabPos);
80 | _realRot = _grabbingController.transform.rotation * _grabRot;
81 | }
82 |
83 | _cameraPlus.ThirdPersonPos = Vector3.Lerp(_cameraCube.position, _realPos,
84 | Plugin.Instance.Config.positionSmooth * Time.deltaTime);
85 |
86 | _cameraPlus.ThirdPersonRot = Quaternion.Slerp(_cameraCube.rotation, _realRot,
87 | Plugin.Instance.Config.rotationSmooth * Time.deltaTime).eulerAngles;
88 | }
89 |
90 | protected virtual void SaveToConfig()
91 | {
92 | var pos = _realPos;
93 | var rot = _realRot.eulerAngles;
94 |
95 | var config = Plugin.Instance.Config;
96 |
97 | config.posx = pos.x;
98 | config.posy = pos.y;
99 | config.posz = pos.z;
100 |
101 | config.angx = rot.x;
102 | config.angy = rot.y;
103 | config.angz = rot.z;
104 |
105 | config.Save();
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/CameraPlus/CameraPlus.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {EB29D3F0-3BC0-4459-9269-C9DA0F3FCD1A}
8 | Library
9 | Properties
10 | CameraPlus
11 | CameraPlus
12 | v4.6
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Assembly-CSharp.dll
37 |
38 |
39 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Assembly-CSharp-firstpass.dll
40 |
41 |
42 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IllusionPlugin.dll
43 |
44 |
45 |
46 |
47 |
48 |
49 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll
50 |
51 |
52 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll
53 |
54 |
55 | ..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.IMGUIModule.dll
56 |
57 |
58 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.PhysicsModule.dll
59 |
60 |
61 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UI.dll
62 |
63 |
64 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIElementsModule.dll
65 |
66 |
67 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIModule.dll
68 |
69 |
70 | D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.VRModule.dll
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/CameraPlus/CameraPlusBehaviour.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using UnityEngine;
4 | using UnityEngine.SceneManagement;
5 | using UnityEngine.XR;
6 | using VRUIControls;
7 |
8 | namespace CameraPlus
9 | {
10 | public class CameraPlusBehaviour : MonoBehaviour
11 | {
12 | protected const int OnlyInThirdPerson = 3;
13 | protected const int OnlyInFirstPerson = 4;
14 |
15 | protected Camera _mainCamera;
16 |
17 | public bool ThirdPerson
18 | {
19 | get { return _thirdPerson; }
20 | set
21 | {
22 | _thirdPerson = value;
23 | _cameraCube.gameObject.SetActive(_thirdPerson);
24 | _cameraPreviewQuad.gameObject.SetActive(_thirdPerson);
25 |
26 | if (value)
27 | {
28 | _cam.cullingMask &= ~(1 << OnlyInFirstPerson);
29 | _cam.cullingMask |= 1 << OnlyInThirdPerson;
30 | }
31 | else
32 | {
33 | _cam.cullingMask &= ~(1 << OnlyInThirdPerson);
34 | _cam.cullingMask |= 1 << OnlyInFirstPerson;
35 | }
36 | }
37 | }
38 |
39 | protected bool _thirdPerson;
40 |
41 | public Vector3 ThirdPersonPos;
42 | public Vector3 ThirdPersonRot;
43 | protected RenderTexture _camRenderTexture;
44 | protected Material _previewMaterial;
45 | protected Camera _cam;
46 | protected Transform _cameraCube;
47 | protected ScreenCameraBehaviour _screenCamera;
48 | protected GameObject _cameraPreviewQuad;
49 |
50 | protected int _prevScreenWidth;
51 | protected int _prevScreenHeight;
52 | protected int _prevAA;
53 | protected float _prevRenderScale;
54 |
55 | public virtual void Init(Camera mainCamera)
56 | {
57 | _mainCamera = mainCamera;
58 |
59 | XRSettings.showDeviceView = false;
60 |
61 | Plugin.Instance.Config.ConfigChangedEvent += PluginOnConfigChangedEvent;
62 | SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;
63 |
64 | var gameObj = Instantiate(_mainCamera.gameObject);
65 | gameObj.SetActive(false);
66 | gameObj.name = "Camera Plus";
67 | gameObj.tag = "Untagged";
68 | while (gameObj.transform.childCount > 0) DestroyImmediate(gameObj.transform.GetChild(0).gameObject);
69 | DestroyImmediate(gameObj.GetComponent("CameraRenderCallbacksManager"));
70 | DestroyImmediate(gameObj.GetComponent("AudioListener"));
71 | DestroyImmediate(gameObj.GetComponent("MeshCollider"));
72 |
73 | if (SteamVRCompatibility.IsAvailable)
74 | {
75 | DestroyImmediate(gameObj.GetComponent(SteamVRCompatibility.SteamVRCamera));
76 | DestroyImmediate(gameObj.GetComponent(SteamVRCompatibility.SteamVRFade));
77 | }
78 |
79 | _screenCamera = new GameObject("Screen Camera").AddComponent();
80 |
81 | if (_previewMaterial == null)
82 | {
83 | _previewMaterial = new Material(Shader.Find("Hidden/BlitCopyWithDepth"));
84 | }
85 |
86 | _cam = gameObj.GetComponent();
87 | _cam.stereoTargetEye = StereoTargetEyeMask.None;
88 | _cam.enabled = true;
89 |
90 | gameObj.SetActive(true);
91 |
92 | var camera = _mainCamera.transform;
93 | transform.position = camera.position;
94 | transform.rotation = camera.rotation;
95 |
96 | gameObj.transform.parent = transform;
97 | gameObj.transform.localPosition = Vector3.zero;
98 | gameObj.transform.localRotation = Quaternion.identity;
99 | gameObj.transform.localScale = Vector3.one;
100 |
101 | var cameraCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
102 | cameraCube.SetActive(ThirdPerson);
103 | _cameraCube = cameraCube.transform;
104 | _cameraCube.localScale = new Vector3(0.15f, 0.15f, 0.22f);
105 | _cameraCube.name = "CameraCube";
106 |
107 | var quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
108 | DestroyImmediate(quad.GetComponent());
109 | quad.GetComponent().material = _previewMaterial;
110 | quad.transform.parent = _cameraCube;
111 | quad.transform.localPosition = new Vector3(-1f * ((_cam.aspect - 1) / 2 + 1), 0, 0.22f);
112 | quad.transform.localEulerAngles = new Vector3(0, 180, 0);
113 | quad.transform.localScale = new Vector3(_cam.aspect, 1, 1);
114 | _cameraPreviewQuad = quad;
115 |
116 | ReadConfig();
117 |
118 | if (ThirdPerson)
119 | {
120 | ThirdPersonPos = Plugin.Instance.Config.Position;
121 | ThirdPersonRot = Plugin.Instance.Config.Rotation;
122 |
123 | transform.position = ThirdPersonPos;
124 | transform.eulerAngles = ThirdPersonRot;
125 |
126 | _cameraCube.position = ThirdPersonPos;
127 | _cameraCube.eulerAngles = ThirdPersonRot;
128 | }
129 |
130 | SceneManagerOnSceneLoaded(new Scene(), LoadSceneMode.Single);
131 | }
132 |
133 | protected virtual void OnDestroy()
134 | {
135 | Plugin.Instance.Config.ConfigChangedEvent -= PluginOnConfigChangedEvent;
136 | SceneManager.sceneLoaded -= SceneManagerOnSceneLoaded;
137 | }
138 |
139 | protected virtual void PluginOnConfigChangedEvent(Config config)
140 | {
141 | ReadConfig();
142 | }
143 |
144 | protected virtual void ReadConfig()
145 | {
146 | ThirdPerson = Plugin.Instance.Config.thirdPerson;
147 |
148 | if (!ThirdPerson)
149 | {
150 | transform.position = _mainCamera.transform.position;
151 | transform.rotation = _mainCamera.transform.rotation;
152 | }
153 | else
154 | {
155 | ThirdPersonPos = Plugin.Instance.Config.Position;
156 | ThirdPersonRot = Plugin.Instance.Config.Rotation;
157 | }
158 |
159 | CreateScreenRenderTexture();
160 | SetFOV();
161 | }
162 |
163 | protected virtual void CreateScreenRenderTexture()
164 | {
165 | _prevScreenWidth = Screen.width;
166 | _prevScreenHeight = Screen.height;
167 |
168 | HMMainThreadDispatcher.instance.Enqueue(delegate
169 | {
170 | var replace = false;
171 | if (_camRenderTexture == null)
172 | {
173 | _camRenderTexture = new RenderTexture(1, 1, 24);
174 | replace = true;
175 | }
176 | else
177 | {
178 | if (Plugin.Instance.Config.antiAliasing != _prevAA || Plugin.Instance.Config.renderScale != _prevRenderScale)
179 | {
180 | replace = true;
181 |
182 | _cam.targetTexture = null;
183 | _screenCamera.SetRenderTexture(null);
184 |
185 | _camRenderTexture.Release();
186 |
187 | _prevAA = Plugin.Instance.Config.antiAliasing;
188 | _prevRenderScale = Plugin.Instance.Config.renderScale;
189 | }
190 | }
191 |
192 | if (!replace)
193 | {
194 | Console.WriteLine("Don't need to replace");
195 | return;
196 | }
197 |
198 | GetScaledScreenResolution(Plugin.Instance.Config.renderScale, out var scaledWidth, out var scaledHeight);
199 | _camRenderTexture.width = scaledWidth;
200 | _camRenderTexture.height = scaledHeight;
201 |
202 | _camRenderTexture.antiAliasing = Plugin.Instance.Config.antiAliasing;
203 | _camRenderTexture.Create();
204 |
205 | _cam.targetTexture = _camRenderTexture;
206 | _previewMaterial.SetTexture("_MainTex", _camRenderTexture);
207 | _screenCamera.SetRenderTexture(_camRenderTexture);
208 | });
209 | }
210 |
211 | protected virtual void GetScaledScreenResolution(float scale, out int scaledWidth, out int scaledHeight)
212 | {
213 | var ratio = (float) Screen.height / Screen.width;
214 | scaledWidth = Mathf.Clamp(Mathf.RoundToInt(Screen.width * scale), 1, int.MaxValue);
215 | scaledHeight = Mathf.Clamp(Mathf.RoundToInt(scaledWidth * ratio), 1, int.MaxValue);
216 | }
217 |
218 | protected virtual void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
219 | {
220 | var pointer = Resources.FindObjectsOfTypeAll().FirstOrDefault();
221 | if (pointer == null) return;
222 | var movePointer = pointer.gameObject.AddComponent();
223 | movePointer.Init(this, _cameraCube);
224 | }
225 |
226 | protected virtual void LateUpdate()
227 | {
228 | if (Screen.width != _prevScreenWidth || Screen.height != _prevScreenHeight)
229 | {
230 | CreateScreenRenderTexture();
231 | }
232 |
233 | var camera = _mainCamera.transform;
234 |
235 | if (ThirdPerson)
236 | {
237 | transform.position = ThirdPersonPos;
238 | transform.eulerAngles = ThirdPersonRot;
239 | _cameraCube.position = ThirdPersonPos;
240 | _cameraCube.eulerAngles = ThirdPersonRot;
241 | return;
242 | }
243 |
244 | transform.position = Vector3.Lerp(transform.position, camera.position,
245 | Plugin.Instance.Config.positionSmooth * Time.deltaTime);
246 |
247 | transform.rotation = Quaternion.Slerp(transform.rotation, camera.rotation,
248 | Plugin.Instance.Config.rotationSmooth * Time.deltaTime);
249 | }
250 |
251 | protected virtual void SetFOV()
252 | {
253 | if (_cam == null) return;
254 | var fov = (float) (57.2957801818848 *
255 | (2.0 * Mathf.Atan(
256 | Mathf.Tan((float) (Plugin.Instance.Config.fov * (Math.PI / 180.0) * 0.5)) /
257 | _mainCamera.aspect)));
258 | _cam.fieldOfView = fov;
259 | }
260 |
261 | protected virtual void Update()
262 | {
263 | if (Input.GetKeyDown(KeyCode.F1))
264 | {
265 | ThirdPerson = !ThirdPerson;
266 | if (!ThirdPerson)
267 | {
268 | transform.position = _mainCamera.transform.position;
269 | transform.rotation = _mainCamera.transform.rotation;
270 | }
271 | else
272 | {
273 | ThirdPersonPos = Plugin.Instance.Config.Position;
274 | ThirdPersonRot = Plugin.Instance.Config.Rotation;
275 | }
276 |
277 | Plugin.Instance.Config.thirdPerson = ThirdPerson;
278 | Plugin.Instance.Config.Save();
279 | }
280 | }
281 | }
282 | }
--------------------------------------------------------------------------------