From b31c5fbb4ba690b9a0dd29621973ea4eeaee5524 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Fri, 6 Dec 2024 08:23:44 +0200 Subject: [PATCH 1/2] Add a pre-commit config to run with the specific defines of major projects Run with pre-commit run -a -c .pre-commit-config-defines.yaml This is not enabled by default, because the code, which is rather convoluted due to the inability to pass --define to dotnet format, coupled with our files' containing BOMs, doesn't run on Windows. It barely runs on Linux, tbh ;-) --- .pre-commit-config-defines.yaml | 26 +++++++ pre-commit-dotnet-format-multiplayer.sh | 26 +++++++ pre-commit-dotnet-format-oculus.sh | 20 ++++++ pre-commit-dotnet-format-windows.sh | 22 ++++++ pre_commit_dotnet_format.sh | 95 +++++++++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 .pre-commit-config-defines.yaml create mode 100755 pre-commit-dotnet-format-multiplayer.sh create mode 100755 pre-commit-dotnet-format-oculus.sh create mode 100755 pre-commit-dotnet-format-windows.sh create mode 100755 pre_commit_dotnet_format.sh diff --git a/.pre-commit-config-defines.yaml b/.pre-commit-config-defines.yaml new file mode 100644 index 0000000000..5003cc3ab2 --- /dev/null +++ b/.pre-commit-config-defines.yaml @@ -0,0 +1,26 @@ +--- +repos: + - repo: local + hooks: + - id: dotnet-format-windows + name: dotnet-format for Windows + language: system + entry: ./pre-commit-dotnet-format-windows.sh + types_or: [c#, vb] + exclude: ^(Assets/ThirdParty)|(Packages/)|(Assets/Photon/) + - repo: local + hooks: + - id: dotnet-format-multiplayer + name: dotnet-format for multiplayer + language: system + entry: ./pre-commit-dotnet-format-multiplayer.sh + types_or: [c#, vb] + exclude: ^(Assets/ThirdParty)|(Packages/)|(Assets/Photon/) + - repo: local + hooks: + - id: dotnet-format-oculus + name: dotnet-format for oculus + language: system + entry: ./pre-commit-dotnet-format-oculus.sh + types_or: [c#, vb] + exclude: ^(Assets/ThirdParty)|(Packages/)|(Assets/Photon/) diff --git a/pre-commit-dotnet-format-multiplayer.sh b/pre-commit-dotnet-format-multiplayer.sh new file mode 100755 index 0000000000..7ee1789db0 --- /dev/null +++ b/pre-commit-dotnet-format-multiplayer.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +export DEFINES=" +CROSS_PLATFORM_INPUT +FUSION2 +FUSION_WEAVER +MOBILE_INPUT +PHOTON_UNITY_NETWORKING +PHOTON_VOICE_DEFINED +PUN_2_0_OR_NEWER +PUN_2_19_OR_NEWER +PUN_2_OR_NEWER +TILT_BRUSH +UNITY_2017_2_OR_NEWER +UNITY_2018_4_OR_NEWER +UNITY_2019_3_OR_NEWER +UNITY_2020_3_OR_NEWER +UNITY_5_4_OR_NEWER +UNITY_5_6_OR_NEWER +UNITY_EDITOR +UNITY_EDITOR_WIN +UNITY_STANDALONE_WIN +UNITY_WIN +USE_TILT_BRUSH_CPP +" +./pre_commit_dotnet_format.sh "$@" diff --git a/pre-commit-dotnet-format-oculus.sh b/pre-commit-dotnet-format-oculus.sh new file mode 100755 index 0000000000..ca69932a47 --- /dev/null +++ b/pre-commit-dotnet-format-oculus.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +export DEFINES=" +FORCE_FOCUSAWARE +FORCE_HEADTRACKING +FORCE_QUEST_SUPPORT_DEVICE +OCULUS_SUPPORTED +PASSTHROUGH_SUPPORTED +TILT_BRUSH +UNITY_2017_2_OR_NEWER +UNITY_2018_4_OR_NEWER +UNITY_2019_3_OR_NEWER +UNITY_2020_3_OR_NEWER +UNITY_5_4_OR_NEWER +UNITY_5_6_OR_NEWER +UNITY_ANDROID +UNITY_EDITOR +USE_TILT_BRUSH_CPP +" +./pre_commit_dotnet_format.sh "$@" diff --git a/pre-commit-dotnet-format-windows.sh b/pre-commit-dotnet-format-windows.sh new file mode 100755 index 0000000000..7645c32f89 --- /dev/null +++ b/pre-commit-dotnet-format-windows.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +export DEFINES=" +AUDIO_REACTIVE +FBX_SUPPORTED +PASSTHROUGH_SUPPORTED +SELECTION_ON +TILT_BRUSH +UNITY_2017_2_OR_NEWER +UNITY_2018_4_OR_NEWER +UNITY_2019_3_OR_NEWER +UNITY_2020_3_OR_NEWER +UNITY_5_4_OR_NEWER +UNITY_5_6_OR_NEWER +UNITY_EDITOR +UNITY_EDITOR_WIN +UNITY_STANDALONE_WIN +UNITY_WIN +USD_SUPPORTED +USE_TILT_BRUSH_CPP +" +./pre_commit_dotnet_format.sh "$@" diff --git a/pre_commit_dotnet_format.sh b/pre_commit_dotnet_format.sh new file mode 100755 index 0000000000..724ee4e03e --- /dev/null +++ b/pre_commit_dotnet_format.sh @@ -0,0 +1,95 @@ +#!/bin/bash +set -e + +# Check if the DEFINES environment variable is set +if [[ -z "$DEFINES" ]]; then + echo "Error: The DEFINES environment variable is not set." + exit 1 +fi + +# Convert the DEFINES environment variable into an array +IFS=', ' read -r -a defines <<< "$DEFINES" + +# Temporary marker to identify added lines +marker="### TEMP DEFINES ###" + +# Read the list of staged files from pre-commit +staged_files=("$@") + +# Check if we are running on macOS or Linux +if [[ "$(uname)" == "Darwin" ]]; then + SED_CMD="gsed" # Use gsed on macOS +else + SED_CMD="sed" # Use sed on Linux +fi + +# Process only staged files +echo "Processing staged files..." +for file in "${staged_files[@]}"; do + # Skip non-C# files + if [[ "$file" != *.cs ]]; then + continue + fi + + # Check if the file has a BOM (EF BB BF at the start of the file) using xxd + bom_present=false + bom_hex=$(xxd -p -l 3 "$file") + if [[ "$bom_hex" == "efbbbf" ]]; then + bom_present=true + fi + + # If BOM is present, remove it temporarily + if $bom_present; then + # Remove BOM bytes (first 3 bytes) using tail and save content to temporary file + tail -c +4 "$file" > "$file.tmp" && mv "$file.tmp" "$file" + fi + + # Add defines only if marker is not already present + if ! grep -q "$marker" "$file"; then + # Add each define line separately using sed to insert at the top + for define in "${defines[@]}"; do + $SED_CMD -i "1i\\#define $define" "$file" + done + # Insert marker to identify where defines were added + $SED_CMD -i "1i\\$marker" "$file" + fi + + # If BOM was present, reinsert it at the beginning of the file + if $bom_present; then + # Reinsert BOM at the start of the file + { echo -n -e '\xEF\xBB\xBF'; cat "$file"; } > "$file.tmp" && mv "$file.tmp" "$file" + fi +done + +# Run dotnet format +echo "Running dotnet format..." +dotnet format whitespace --folder --include "$@" + +# Remove only the added defines +echo "Removing temporary defines..." +for file in "${staged_files[@]}"; do + # Skip non-C# files + if [[ "$file" != *.cs ]]; then + continue + fi + + # Check if the file has a BOM (EF BB BF at the start of the file) using xxd + bom_present=false + bom_hex=$(xxd -p -l 3 "$file") + if [[ "$bom_hex" == "efbbbf" ]]; then + bom_present=true + fi + + # Use a temporary file to preserve BOM while modifying + tmp_file="$file.tmp" + # Remove the marker and added defines, ensuring the BOM stays intact + $SED_CMD "/$marker/,+${#defines[@]}d" "$file" > "$tmp_file" && mv "$tmp_file" "$file" + + # If BOM was present, reinsert it at the beginning of the file + if $bom_present; then + # Reinsert BOM at the start of the file + { echo -n -e '\xEF\xBB\xBF'; cat "$file"; } > "$file.tmp" && mv "$file.tmp" "$file" + fi +done + +echo "Pre-commit hook completed!" From f2bfd9ebaadd4dcb3c4879743b9f79d474e71d87 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Fri, 6 Dec 2024 08:07:54 +0200 Subject: [PATCH 2/2] Run pre-commit one time with actual defines --- .../Debug/Editor/SetStereoRenderPath.cs | 35 +++--- Assets/Scripts/Export/Export.cs | 4 +- Assets/Scripts/Export/ExportUsd.cs | 8 +- Assets/Scripts/FrameTimingInfo.cs | 4 +- Assets/Scripts/ModelCatalog.cs | 4 +- .../Scripts/Multiplayer/MultiplayerManager.cs | 3 +- .../Multiplayer/Photon/PhotonManager.cs | 42 +++---- .../Multiplayer/Photon/PhotonPlayerRig.cs | 8 +- .../Scripts/Multiplayer/Photon/PhotonRPC.cs | 28 ++--- .../Multiplayer/Photon/PhotonStructs.cs | 6 +- Assets/Scripts/PassthroughManager.cs | 2 +- Assets/Scripts/Rendering/RenderWrapper.cs | 37 ++++--- .../Rendering/Selection/SelectionEffect.cs | 25 +++-- Assets/Scripts/Util/AndroidUtils.cs | 103 ++++++++++-------- Assets/Scripts/Util/MathUtils.cs | 21 ++-- Assets/Scripts/VrSdk.cs | 15 +-- Assets/Scripts/Widgets/GrabWidget.cs | 26 +++-- 17 files changed, 202 insertions(+), 169 deletions(-) diff --git a/Assets/Scripts/Debug/Editor/SetStereoRenderPath.cs b/Assets/Scripts/Debug/Editor/SetStereoRenderPath.cs index 8e00941737..2a81e7889e 100644 --- a/Assets/Scripts/Debug/Editor/SetStereoRenderPath.cs +++ b/Assets/Scripts/Debug/Editor/SetStereoRenderPath.cs @@ -17,25 +17,30 @@ namespace TiltBrush { #if UNITY_ANDROID || UNITY_IOS -[InitializeOnLoadAttribute] -public class SetStereoRenderPath { + [InitializeOnLoadAttribute] + public class SetStereoRenderPath + { - private static StereoRenderingPath s_OriginalStereoPath; + private static StereoRenderingPath s_OriginalStereoPath; - static SetStereoRenderPath() { - EditorApplication.playModeStateChanged += OnPlayModeChanged; - } + static SetStereoRenderPath() + { + EditorApplication.playModeStateChanged += OnPlayModeChanged; + } - static void OnPlayModeChanged(PlayModeStateChange stateChange) { - if (stateChange == PlayModeStateChange.ExitingEditMode) { - s_OriginalStereoPath = PlayerSettings.stereoRenderingPath; - PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass; - } + static void OnPlayModeChanged(PlayModeStateChange stateChange) + { + if (stateChange == PlayModeStateChange.ExitingEditMode) + { + s_OriginalStereoPath = PlayerSettings.stereoRenderingPath; + PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass; + } - if (stateChange == PlayModeStateChange.EnteredEditMode) { - PlayerSettings.stereoRenderingPath = s_OriginalStereoPath; + if (stateChange == PlayModeStateChange.EnteredEditMode) + { + PlayerSettings.stereoRenderingPath = s_OriginalStereoPath; + } + } } - } -} #endif } // namespace TiltBrush diff --git a/Assets/Scripts/Export/Export.cs b/Assets/Scripts/Export/Export.cs index 7f08b8acf3..2ba3dc7d71 100644 --- a/Assets/Scripts/Export/Export.cs +++ b/Assets/Scripts/Export/Export.cs @@ -27,8 +27,8 @@ public static class Export { const string kExportDocumentationUrl = "https://docs.google.com/document/d/11ZsHozYn9FnWG7y3s3WAyKIACfbfwb4PbaS8cZ_xjvo#heading=h.im5f33smiavy"; #if UNITY_ANDROID || UNITY_IOS - const string kExportReadmeName = "README.txt"; - const string kExportReadmeBody = "Please see " + kExportDocumentationUrl; + const string kExportReadmeName = "README.txt"; + const string kExportReadmeBody = "Please see " + kExportDocumentationUrl; #else const string kExportReadmeName = "README.url"; const string kExportReadmeBody = @"[InternetShortcut] diff --git a/Assets/Scripts/Export/ExportUsd.cs b/Assets/Scripts/Export/ExportUsd.cs index e4b6082fbe..1d47a03c12 100644 --- a/Assets/Scripts/Export/ExportUsd.cs +++ b/Assets/Scripts/Export/ExportUsd.cs @@ -30,7 +30,7 @@ static class ExportUsd // Serialization Classes // -------------------------------------------------------------------------------------------- // -#region "Geometry Classes for Serialization" + #region "Geometry Classes for Serialization" /// The root / sketch metadata for the file. [Serializable] @@ -109,9 +109,9 @@ public class BrushCurvesSample : USD.NET.Unity.BasisCurvesSample public float[] pressures; } -#endregion + #endregion -#region "Material Classes for Serialization" + #region "Material Classes for Serialization" [Serializable] [UsedImplicitly(ImplicitUseTargetFlags.Members)] @@ -224,7 +224,7 @@ public PrimvarReader4fSample(string primvarName) } } -#endregion + #endregion // -------------------------------------------------------------------------------------------- // // Conversion Helpers diff --git a/Assets/Scripts/FrameTimingInfo.cs b/Assets/Scripts/FrameTimingInfo.cs index a15014553f..814d6a559c 100644 --- a/Assets/Scripts/FrameTimingInfo.cs +++ b/Assets/Scripts/FrameTimingInfo.cs @@ -70,8 +70,8 @@ void Update() // Oculus only computes cumulative frames dropped, so we reset the perf stats // each frame after recording. #if OCULUS_SUPPORTED - // TODO: Currently not supported on Oculus OpenXR backend. - // OVRPlugin.ResetAppPerfStats(); + // TODO: Currently not supported on Oculus OpenXR backend. + // OVRPlugin.ResetAppPerfStats(); #endif // OCULUS_SUPPORTED } diff --git a/Assets/Scripts/ModelCatalog.cs b/Assets/Scripts/ModelCatalog.cs index 4a8b7aea07..2522f3c63a 100644 --- a/Assets/Scripts/ModelCatalog.cs +++ b/Assets/Scripts/ModelCatalog.cs @@ -295,10 +295,10 @@ void ProcessDirectory(string sPath, Dictionary oldModels) List extensions = new() { ".gltf2", ".gltf", ".glb", ".ply", ".svg" }; #if USD_SUPPORTED - extensions.AddRange(new [] { ".usda", ".usdc", ".usd" }); + extensions.AddRange(new[] { ".usda", ".usdc", ".usd" }); #endif #if FBX_SUPPORTED - extensions.AddRange(new [] { ".obj", ".fbx" }); + extensions.AddRange(new[] { ".obj", ".fbx" }); #endif for (int i = 0; i < aFiles.Length; ++i) diff --git a/Assets/Scripts/Multiplayer/MultiplayerManager.cs b/Assets/Scripts/Multiplayer/MultiplayerManager.cs index 91d588b393..bb5c3deec5 100644 --- a/Assets/Scripts/Multiplayer/MultiplayerManager.cs +++ b/Assets/Scripts/Multiplayer/MultiplayerManager.cs @@ -60,7 +60,8 @@ void Start() { #if OCULUS_SUPPORTED - OVRPlatform.Users.GetLoggedInUser().OnComplete((msg) => { + OVRPlatform.Users.GetLoggedInUser().OnComplete((msg) => + { if (!msg.IsError) { myOculusUserId = msg.GetUser().ID; diff --git a/Assets/Scripts/Multiplayer/Photon/PhotonManager.cs b/Assets/Scripts/Multiplayer/Photon/PhotonManager.cs index 579b06bc88..95b33efe9f 100644 --- a/Assets/Scripts/Multiplayer/Photon/PhotonManager.cs +++ b/Assets/Scripts/Multiplayer/Photon/PhotonManager.cs @@ -44,7 +44,7 @@ public PhotonManager(MultiplayerManager manager) public async Task Connect() { - if(m_Runner != null) + if (m_Runner != null) { GameObject.Destroy(m_Runner); } @@ -74,12 +74,12 @@ public async Task Connect() var result = await m_Runner.StartGame(args); return result.Ok; - + } public bool IsConnected() { - if(m_Runner == null) + if (m_Runner == null) { return false; } @@ -88,7 +88,7 @@ public bool IsConnected() public async Task Disconnect(bool force) { - if(m_Runner != null) + if (m_Runner != null) { await m_Runner.Shutdown(forceShutdownProcedure: force); return m_Runner.IsShutdown; @@ -110,11 +110,11 @@ public void Update() } } -#region IConnectionHandler Methods + #region IConnectionHandler Methods public async Task PerformCommand(BaseCommand command) { await Task.Yield(); - return ProcessCommand(command);; + return ProcessCommand(command); ; } public async Task UndoCommand(BaseCommand command) @@ -137,13 +137,13 @@ public async Task RpcSyncToSharedAnchor(string uuid) await Task.Yield(); return true; } -#endregion + #endregion -#region Command Methods + #region Command Methods private bool ProcessCommand(BaseCommand command) { bool success = true; - switch(command) + switch (command) { case BrushStrokeCommand: success = CommandBrushStroke(command as BrushStrokeCommand); @@ -160,9 +160,9 @@ private bool ProcessCommand(BaseCommand command) break; } - if(command.ChildrenCount > 0) + if (command.ChildrenCount > 0) { - foreach(var child in command.Children) + foreach (var child in command.Children) { success &= ProcessCommand(child); } @@ -196,12 +196,12 @@ private bool CommandBrushStroke(BrushStrokeCommand command) // Middle for (int rounds = 1; rounds < numSplits + 1; ++rounds) { - var controlPoints = stroke.m_ControlPoints.Skip(rounds*128).Take(128).ToArray(); - var dropPoints = stroke.m_ControlPointsToDrop.Skip(rounds*128).Take(128).ToArray(); + var controlPoints = stroke.m_ControlPoints.Skip(rounds * 128).Take(128).ToArray(); + var dropPoints = stroke.m_ControlPointsToDrop.Skip(rounds * 128).Take(128).ToArray(); var netControlPoints = new NetworkedControlPoint[controlPoints.Length]; - for (int point = 0; point < controlPoints.Length; ++ point) + for (int point = 0; point < controlPoints.Length; ++point) { netControlPoints[point] = new NetworkedControlPoint().Init(controlPoints[point]); } @@ -231,9 +231,9 @@ private bool CommandDeleteStroke(DeleteStrokeCommand command) PhotonRPC.RPC_DeleteStroke(m_Runner, command.m_TargetStroke.m_Seed, command.Guid, command.ParentGuid, command.ChildrenCount); return true; } -#endregion + #endregion -#region Photon Callbacks + #region Photon Callbacks public void OnConnectedToServer(NetworkRunner runner) { var rpc = m_Runner.gameObject.AddComponent(); @@ -242,13 +242,13 @@ public void OnConnectedToServer(NetworkRunner runner) public void OnPlayerJoined(NetworkRunner runner, PlayerRef player) { - if(player == m_Runner.LocalPlayer) + if (player == m_Runner.LocalPlayer) { var playerPrefab = Resources.Load("Multiplayer/Photon/PhotonPlayerRig") as GameObject; var playerObj = m_Runner.Spawn(playerPrefab, inputAuthority: m_Runner.LocalPlayer); m_LocalPlayer = playerObj.GetComponent(); m_Runner.SetPlayerObject(m_Runner.LocalPlayer, playerObj); - + m_Manager.localPlayerJoined?.Invoke(m_LocalPlayer); } @@ -257,9 +257,9 @@ public void OnPlayerJoined(NetworkRunner runner, PlayerRef player) m_PlayersSpawning.Add(player); } } -#endregion + #endregion -#region Unused Photon Callbacks + #region Unused Photon Callbacks public void OnPlayerLeft(NetworkRunner runner, PlayerRef player) { } public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason) { } public void OnDisconnectedFromServer(NetworkRunner runner) { } @@ -274,7 +274,7 @@ public void OnHostMigration(NetworkRunner runner, HostMigrationToken hostMigrati public void OnReliableDataReceived(NetworkRunner runner, PlayerRef player, ArraySegment data) { } public void OnSceneLoadDone(NetworkRunner runner) { } public void OnSceneLoadStart(NetworkRunner runner) { } -#endregion + #endregion } } diff --git a/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs b/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs index 40a9e81912..6efebe7594 100644 --- a/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs +++ b/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs @@ -69,7 +69,7 @@ public override void Spawned() brushGuid = BrushCatalog.m_Instance.DefaultBrush.m_Guid.ToString(); - if(!Object.HasStateAuthority) + if (!Object.HasStateAuthority) { transientPointer = PointerManager.m_Instance.CreateRemotePointer(); transientPointer.SetBrush(BrushCatalog.m_Instance.DefaultBrush); @@ -81,7 +81,7 @@ public override void FixedUpdateNetwork() { base.FixedUpdateNetwork(); - if(Object.HasStateAuthority) + if (Object.HasStateAuthority) { m_PlayerHead.transform.position = transmitData.HeadPosition; m_PlayerHead.transform.rotation = transmitData.HeadRotation; @@ -99,14 +99,14 @@ public override void Render() { } - + else { var toolTR = TrTransform.TR(m_Tool.InterpolationTarget.position, m_Tool.InterpolationTarget.rotation); App.Scene.AsScene[transientPointer.transform] = toolTR; transientPointer.SetColor(brushColor); - if(brushGuid.ToString() != string.Empty) + if (brushGuid.ToString() != string.Empty) { transientPointer.SetBrush(BrushCatalog.m_Instance.GetBrush(new System.Guid(brushGuid.ToString()))); } diff --git a/Assets/Scripts/Multiplayer/Photon/PhotonRPC.cs b/Assets/Scripts/Multiplayer/Photon/PhotonRPC.cs index 8125812a57..9647e9e76c 100644 --- a/Assets/Scripts/Multiplayer/Photon/PhotonRPC.cs +++ b/Assets/Scripts/Multiplayer/Photon/PhotonRPC.cs @@ -41,7 +41,7 @@ public void Update() } private bool CheckifChildStillPending(PendingCommand pending) - { + { if (pending.TotalExpectedChildren == pending.Command.ChildrenCount) { bool moreChildrenToAssign = false; @@ -100,7 +100,7 @@ private void TryProcessCommands() } // All children present, begin execution - + m_pendingCommands.RemoveAt(0); InvokePreCommands(command); @@ -152,7 +152,7 @@ public static void CreateBrushStroke(Stroke stroke, Guid commandGuid, Guid paren AddPendingCommand(preAction, commandGuid, parentGuid, command, childCount); } -#region RPCS + #region RPCS [Rpc(InvokeLocal = false)] public static void RPC_SyncToSharedAnchor(NetworkRunner runner, string uuid) { @@ -173,7 +173,7 @@ public static void RPC_PerformCommand(NetworkRunner runner, string commandName, // Temp decode.m_BrushGuid = new System.Guid(guid); - + // Can we set up these more sensibly? decode.m_Type = Stroke.Type.NotCreated; decode.m_IntendedCanvas = App.Scene.MainCanvas; @@ -211,7 +211,7 @@ public static void RPC_BaseCommand(NetworkRunner runner, Guid commandGuid, Guid var parentCommand = FindParentCommand(parentGuid); var command = new BaseCommand(parent: parentCommand); - AddPendingCommand(() => {}, commandGuid, parentGuid, command, childCount); + AddPendingCommand(() => { }, commandGuid, parentGuid, command, childCount); } [Rpc(InvokeLocal = false)] @@ -229,11 +229,11 @@ public static void RPC_BrushStrokeBegin(NetworkRunner runner, Guid id, Networked decode.m_Type = Stroke.Type.NotCreated; decode.m_IntendedCanvas = App.Scene.MainCanvas; - + Array.Resize(ref decode.m_ControlPoints, finalLength); Array.Resize(ref decode.m_ControlPointsToDrop, finalLength); - if(m_inProgressStrokes.ContainsKey(id)) + if (m_inProgressStrokes.ContainsKey(id)) { Debug.LogError("Shouldn't be here!"); return; @@ -241,19 +241,19 @@ public static void RPC_BrushStrokeBegin(NetworkRunner runner, Guid id, Networked m_inProgressStrokes[id] = decode; } - + [Rpc(InvokeLocal = false)] public static void RPC_BrushStrokeContinue(NetworkRunner runner, Guid id, int offset, NetworkedControlPoint[] controlPoints, bool[] dropPoints) { - if(!m_inProgressStrokes.ContainsKey(id)) + if (!m_inProgressStrokes.ContainsKey(id)) { Debug.LogError("shouldn't be here!"); return; } var stroke = m_inProgressStrokes[id]; - - for(int i = 0; i < controlPoints.Length; ++i) + + for (int i = 0; i < controlPoints.Length; ++i) { stroke.m_ControlPoints[offset + i] = NetworkedControlPoint.ToControlPoint(controlPoints[i]); stroke.m_ControlPointsToDrop[offset + i] = dropPoints[i]; @@ -263,7 +263,7 @@ public static void RPC_BrushStrokeContinue(NetworkRunner runner, Guid id, int of [Rpc(InvokeLocal = false)] public static void RPC_BrushStrokeComplete(NetworkRunner runner, Guid id, Guid commandGuid, Guid parentGuid = default, int childCount = 0) { - if(!m_inProgressStrokes.ContainsKey(id)) + if (!m_inProgressStrokes.ContainsKey(id)) { Debug.LogError("shouldn't be here!"); return; @@ -286,14 +286,14 @@ public static void RPC_DeleteStroke(NetworkRunner runner, int seed, Guid command var parentCommand = FindParentCommand(parentGuid); var command = new DeleteStrokeCommand(foundStroke, parent: parentCommand); - AddPendingCommand(() => {}, commandGuid, parentGuid, command, childCount); + AddPendingCommand(() => { }, commandGuid, parentGuid, command, childCount); } else { Debug.LogError($"couldn't find stroke with seed: {seed}"); } } -#endregion + #endregion } } diff --git a/Assets/Scripts/Multiplayer/Photon/PhotonStructs.cs b/Assets/Scripts/Multiplayer/Photon/PhotonStructs.cs index 10d6787740..75ddba1175 100644 --- a/Assets/Scripts/Multiplayer/Photon/PhotonStructs.cs +++ b/Assets/Scripts/Multiplayer/Photon/PhotonStructs.cs @@ -40,7 +40,7 @@ public PendingCommand(Guid guid, BaseCommand command, Action action, int count) ChildCommands = new List(); } } - + public struct NetworkCommandData : INetworkStruct { public Guid CommandGuid; @@ -152,13 +152,13 @@ public NetworkedStroke Init(Stroke data) m_ControlPointsCapacity = data.m_ControlPoints.Length; - for(int i = 0; i < data.m_ControlPoints.Length; i++) + for (int i = 0; i < data.m_ControlPoints.Length; i++) { var point = new NetworkedControlPoint().Init(data.m_ControlPoints[i]); m_ControlPoints.Set(i, point); } - for(int i = 0; i < data.m_ControlPointsToDrop.Length; i++) + for (int i = 0; i < data.m_ControlPointsToDrop.Length; i++) { m_ControlPointsToDrop.Set(i, data.m_ControlPointsToDrop[i]); } diff --git a/Assets/Scripts/PassthroughManager.cs b/Assets/Scripts/PassthroughManager.cs index ca61695e0e..936690ec5a 100644 --- a/Assets/Scripts/PassthroughManager.cs +++ b/Assets/Scripts/PassthroughManager.cs @@ -21,7 +21,7 @@ public class PassthroughManager : MonoBehaviour void Start() { #if OCULUS_SUPPORTED - var passthrough = gameObject.AddComponent(); + var passthrough = gameObject.AddComponent(); passthrough.overlayType = OVROverlay.OverlayType.Underlay; App.VrSdk.m_OvrManager.shouldBoundaryVisibilityBeSuppressed = true; #endif // OCULUS_SUPPORTED diff --git a/Assets/Scripts/Rendering/RenderWrapper.cs b/Assets/Scripts/Rendering/RenderWrapper.cs index 965fb62b6b..8d39ae0df2 100644 --- a/Assets/Scripts/Rendering/RenderWrapper.cs +++ b/Assets/Scripts/Rendering/RenderWrapper.cs @@ -240,9 +240,9 @@ public void OnPreRender() VideoRecorderUtils.ActiveVideoRecording.IsCapturing; #if UNITY_ANDROID || UNITY_IOS - // TODO:Mikesky - setting MSAA seems to crash quest when in Vulkan - - int msaa = QualityControls.m_Instance.MSAALevel; + // TODO:Mikesky - setting MSAA seems to crash quest when in Vulkan + + int msaa = QualityControls.m_Instance.MSAALevel; #if UNITY_IOS && ZAPBOX_SUPPORTED // Force MSAA off on iOS Zapbox - Unity implementation is poor on iOS @@ -250,22 +250,25 @@ public void OnPreRender() msaa = 0; #endif - // MSAA disabled in QualityControls = 0, but render texture wants 1. - if (msaa == 0) { - msaa = 1; - } - if (msaa != 1 && msaa != 2 && msaa != 4 && msaa != 8) { - UnityEngine.Debug.LogWarningFormat("Invalid MSAA {0} != [1,2,4,8]", msaa); - msaa = 1; - } + // MSAA disabled in QualityControls = 0, but render texture wants 1. + if (msaa == 0) + { + msaa = 1; + } + if (msaa != 1 && msaa != 2 && msaa != 4 && msaa != 8) + { + UnityEngine.Debug.LogWarningFormat("Invalid MSAA {0} != [1,2,4,8]", msaa); + msaa = 1; + } - if (msaa != QualitySettings.antiAliasing) { - QualitySettings.antiAliasing = msaa; - } - GetComponent().allowMSAA = msaa > 1; + if (msaa != QualitySettings.antiAliasing) + { + QualitySettings.antiAliasing = msaa; + } + GetComponent().allowMSAA = msaa > 1; - // Use a single camera on Android. - return; + // Use a single camera on Android. + return; #else Camera srcCam = GetComponent(); diff --git a/Assets/Scripts/Rendering/Selection/SelectionEffect.cs b/Assets/Scripts/Rendering/Selection/SelectionEffect.cs index bd37513697..453b8a86ff 100644 --- a/Assets/Scripts/Rendering/Selection/SelectionEffect.cs +++ b/Assets/Scripts/Rendering/Selection/SelectionEffect.cs @@ -112,17 +112,20 @@ void OnPosesApplied() Shader.SetGlobalColor("_RightEyeSelectionColor", right); #if FEATURE_MOBILE_SELECTION - TrTransform worldToTransform = App.Scene.SelectionCanvas.Pose; - // Keep the scale within 0.5 and 2 - if (worldToTransform.scale > 2) { - worldToTransform.scale /= Mathf.ClosestPowerOfTwo(Mathf.RoundToInt(worldToTransform.scale)); - } else if (worldToTransform.scale < 0.5) { - worldToTransform.scale *= - Mathf.ClosestPowerOfTwo(Mathf.RoundToInt(1f / worldToTransform.scale)); - } + TrTransform worldToTransform = App.Scene.SelectionCanvas.Pose; + // Keep the scale within 0.5 and 2 + if (worldToTransform.scale > 2) + { + worldToTransform.scale /= Mathf.ClosestPowerOfTwo(Mathf.RoundToInt(worldToTransform.scale)); + } + else if (worldToTransform.scale < 0.5) + { + worldToTransform.scale *= + Mathf.ClosestPowerOfTwo(Mathf.RoundToInt(1f / worldToTransform.scale)); + } - Shader.SetGlobalMatrix("_InverseLimitedScaleSceneMatrix", worldToTransform.inverse.ToMatrix4x4()); - Shader.SetGlobalFloat("_PatternSpeed", m_NoiseSparkleSpeed); + Shader.SetGlobalMatrix("_InverseLimitedScaleSceneMatrix", worldToTransform.inverse.ToMatrix4x4()); + Shader.SetGlobalFloat("_PatternSpeed", m_NoiseSparkleSpeed); #endif #if FEATURE_CUSTOM_MESH_RENDER @@ -152,7 +155,7 @@ public bool RenderHighlight() #if FEATURE_CUSTOM_MESH_RENDER return m_CmrRenderHighlight; #else - throw new InvalidOperationException(); // Don't know what to return + throw new InvalidOperationException(); // Don't know what to return #endif } diff --git a/Assets/Scripts/Util/AndroidUtils.cs b/Assets/Scripts/Util/AndroidUtils.cs index 26932de850..271edaff69 100644 --- a/Assets/Scripts/Util/AndroidUtils.cs +++ b/Assets/Scripts/Util/AndroidUtils.cs @@ -15,61 +15,70 @@ using UnityEngine; #if UNITY_ANDROID -static class AndroidUtils { - public static AndroidJavaObject GetContext() { - if (Application.platform != RuntimePlatform.Android) { - return null; +static class AndroidUtils +{ + public static AndroidJavaObject GetContext() + { + if (Application.platform != RuntimePlatform.Android) + { + return null; + } + + // Unity doesn't document UnityPlayer.currentActivity (or UnityPlayer at all), but it + // does mention it in passing on these two pages: + // https://docs.unity3d.com/2017.3/Documentation/ScriptReference/AndroidJavaRunnable.html + // https://docs.unity3d.com/2017.3/Documentation/ScriptReference/AndroidJavaProxy.html + AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); + AndroidJavaObject context = unityPlayer.GetStatic("currentActivity"); + return context; } - // Unity doesn't document UnityPlayer.currentActivity (or UnityPlayer at all), but it - // does mention it in passing on these two pages: - // https://docs.unity3d.com/2017.3/Documentation/ScriptReference/AndroidJavaRunnable.html - // https://docs.unity3d.com/2017.3/Documentation/ScriptReference/AndroidJavaProxy.html - AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); - AndroidJavaObject context = unityPlayer.GetStatic("currentActivity"); - return context; - } + /// Returns versionCode from AndroidManifest.xml. + public static int GetVersionCode() + { + if (Application.platform != RuntimePlatform.Android) + { + return 13; // just some placeholder + } - /// Returns versionCode from AndroidManifest.xml. - public static int GetVersionCode() { - if (Application.platform != RuntimePlatform.Android) { - return 13; // just some placeholder + var context = GetContext(); + string packageName = context.Call("getPackageName"); + var packageMgr = context.Call("getPackageManager"); + var packageInfo = packageMgr.Call("getPackageInfo", packageName, 0); + return packageInfo.Get("versionCode"); } - var context = GetContext(); - string packageName = context.Call("getPackageName"); - var packageMgr = context.Call("getPackageManager"); - var packageInfo = packageMgr.Call("getPackageInfo", packageName, 0); - return packageInfo.Get("versionCode"); - } - - /// Returns versionName from AndroidManifest.xml. - /// - /// Unity fills in Manifest.versionName from PlayerSettings.bundleVersion. - /// BuildTiltBrush fills in PlayerSettings.bundleVersion from Config.m_VersionNumber - /// and m_BuildStamp. - /// This should therefore have the same info as you'd find in Config. - /// Sample return values: "19.0b-(menuitem)", "18.3-d8239842" - public static string GetVersionName() { - if (Application.platform != RuntimePlatform.Android) { - return "versionNamePlaceholder"; + /// Returns versionName from AndroidManifest.xml. + /// + /// Unity fills in Manifest.versionName from PlayerSettings.bundleVersion. + /// BuildTiltBrush fills in PlayerSettings.bundleVersion from Config.m_VersionNumber + /// and m_BuildStamp. + /// This should therefore have the same info as you'd find in Config. + /// Sample return values: "19.0b-(menuitem)", "18.3-d8239842" + public static string GetVersionName() + { + if (Application.platform != RuntimePlatform.Android) + { + return "versionNamePlaceholder"; + } + + var context = GetContext(); + string packageName = context.Call("getPackageName"); + var packageMgr = context.Call("getPackageManager"); + var packageInfo = packageMgr.Call("getPackageInfo", packageName, 0); + return packageInfo.Get("versionName"); } - var context = GetContext(); - string packageName = context.Call("getPackageName"); - var packageMgr = context.Call("getPackageManager"); - var packageInfo = packageMgr.Call("getPackageInfo", packageName, 0); - return packageInfo.Get("versionName"); - } + /// Returns package name. + public static string GetPackageName() + { + if (Application.platform != RuntimePlatform.Android) + { + return "com.placeholder.packagename"; + } - /// Returns package name. - public static string GetPackageName() { - if (Application.platform != RuntimePlatform.Android) { - return "com.placeholder.packagename"; + var context = GetContext(); + return context.Call("getPackageName"); } - - var context = GetContext(); - return context.Call("getPackageName"); - } } #endif diff --git a/Assets/Scripts/Util/MathUtils.cs b/Assets/Scripts/Util/MathUtils.cs index 7696904cf5..2a8713858e 100644 --- a/Assets/Scripts/Util/MathUtils.cs +++ b/Assets/Scripts/Util/MathUtils.cs @@ -27,19 +27,26 @@ static public class MathUtils static public class TiltBrushCpp { #if USE_TILT_BRUSH_CPP - [DllImport("TiltBrushCpp")] unsafe public static extern void TransformVector3AsPoint( + [DllImport("TiltBrushCpp")] + unsafe public static extern void TransformVector3AsPoint( Matrix4x4 mat, int iVert, int iVertEnd, Vector3* v3); - [DllImport("TiltBrushCpp")] unsafe public static extern void TransformVector3AsVector( + [DllImport("TiltBrushCpp")] + unsafe public static extern void TransformVector3AsVector( Matrix4x4 mat, int iVert, int iVertEnd, Vector3* v3); - [DllImport("TiltBrushCpp")] unsafe public static extern void TransformVector3AsZDistance( + [DllImport("TiltBrushCpp")] + unsafe public static extern void TransformVector3AsZDistance( float scale, int iVert, int iVertEnd, Vector3* v3); - [DllImport("TiltBrushCpp")] unsafe public static extern void TransformVector4AsPoint( + [DllImport("TiltBrushCpp")] + unsafe public static extern void TransformVector4AsPoint( Matrix4x4 mat, int iVert, int iVertEnd, Vector4* v4); - [DllImport("TiltBrushCpp")] unsafe public static extern void TransformVector4AsVector( + [DllImport("TiltBrushCpp")] + unsafe public static extern void TransformVector4AsVector( Matrix4x4 mat, int iVert, int iVertEnd, Vector4* v4); - [DllImport("TiltBrushCpp")] unsafe public static extern void TransformVector4AsZDistance( + [DllImport("TiltBrushCpp")] + unsafe public static extern void TransformVector4AsZDistance( float scale, int iVert, int iVertEnd, Vector4* v4); - [DllImport("TiltBrushCpp")] unsafe public static extern void GetBoundsFor( + [DllImport("TiltBrushCpp")] + unsafe public static extern void GetBoundsFor( Matrix4x4 m, int iVert, int iVertEnd, Vector3* v3, Vector3* center, Vector3* size); #endif diff --git a/Assets/Scripts/VrSdk.cs b/Assets/Scripts/VrSdk.cs index 16953fe571..4ef115c9fc 100644 --- a/Assets/Scripts/VrSdk.cs +++ b/Assets/Scripts/VrSdk.cs @@ -228,7 +228,8 @@ void Awake() if (Unity.XR.Oculus.Utils.GetSystemHeadsetType() != Unity.XR.Oculus.SystemHeadset.Oculus_Quest) { Oculus.Platform.Core.Initialize(appId); - Oculus.Platform.UserAgeCategory.Get().OnComplete((msg) => { + Oculus.Platform.UserAgeCategory.Get().OnComplete((msg) => + { var unused = msg.Data.AgeCategory; }); } @@ -372,12 +373,12 @@ private void RefreshRoomBoundsCache() Vector3[] points_RS = null; #if OCULUS_SUPPORTED - // N points, clockwise winding (but axis is undocumented), undocumented convexity - // In practice, it's clockwise looking along Y- - points_RS = OVRManager.boundary - ?.GetGeometry(OVRBoundary.BoundaryType.OuterBoundary) - ?.Select(v => UnityFromOculus(v)) - .ToArray(); + // N points, clockwise winding (but axis is undocumented), undocumented convexity + // In practice, it's clockwise looking along Y- + points_RS = OVRManager.boundary + ?.GetGeometry(OVRBoundary.BoundaryType.OuterBoundary) + ?.Select(v => UnityFromOculus(v)) + .ToArray(); #else // OCULUS_SUPPORTED // if (App.Config.m_SdkMode == SdkMode.SteamVR) // { diff --git a/Assets/Scripts/Widgets/GrabWidget.cs b/Assets/Scripts/Widgets/GrabWidget.cs index d545381987..bf9dd15c62 100644 --- a/Assets/Scripts/Widgets/GrabWidget.cs +++ b/Assets/Scripts/Widgets/GrabWidget.cs @@ -919,15 +919,19 @@ void Update() private void LateUpdate() { #if UNITY_ANDROID || UNITY_IOS - if (m_Highlighted != m_OldHighlighted) { - if (m_Highlighted) { - AddKeyword("HIGHLIGHT_ON"); - } else { - RemoveKeyword("HIGHLIGHT_ON"); - } - } - m_OldHighlighted = m_Highlighted; - m_Highlighted = false; + if (m_Highlighted != m_OldHighlighted) + { + if (m_Highlighted) + { + AddKeyword("HIGHLIGHT_ON"); + } + else + { + RemoveKeyword("HIGHLIGHT_ON"); + } + } + m_OldHighlighted = m_Highlighted; + m_Highlighted = false; #endif } @@ -1568,7 +1572,7 @@ virtual public void RegisterHighlight() } } #else - m_Highlighted = true; + m_Highlighted = true; #endif } @@ -1583,7 +1587,7 @@ virtual protected void UnregisterHighlight() } } #else - m_Highlighted = false; + m_Highlighted = false; #endif }