Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into experiments/moonsharp
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Nov 24, 2023
2 parents 81f328d + 1433142 commit 3a0a585
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ jobs:
extraoptions: -btb-il2cpp -btb-disableAccountLogins

steps:
- name: Set masking
run: echo "::add-mask::$UNITY_PASSWORD"
- name: Free extra space
# This takes several minutes, so we only do it where required. As of 12/10/2023, this increases free space from 18GB to 41GB
if: matrix.targetPlatform == 'Android' || matrix.targetPlatform == 'StandaloneWindows64'
Expand Down
1 change: 1 addition & 0 deletions Assets/Plugins/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" />
</application>
<uses-permission android:name="android.permission.RECORD_AUDIO" tools:node="remove"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
</manifest>
21 changes: 21 additions & 0 deletions Assets/Scenes/Loading.unity
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,27 @@ MonoBehaviour:
m_VrCamera: {fileID: 1815664868}
m_MaximumLoadingTime: 60
m_SceneLoadRatio: 0.75
m_LoadingText:
m_TableReference:
m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86
m_TableEntryReference:
m_KeyId: 287897575133184
m_Key:
m_FallbackState: 0
m_WaitForCompletion: 0
m_LocalVariables: []
m_RequestAndroidFolderPermissions:
m_TableReference:
m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86
m_TableEntryReference:
m_KeyId: 170004956477833216
m_Key:
m_FallbackState: 0
m_WaitForCompletion: 0
m_LocalVariables: []
references:
version: 2
RefIds: []
--- !u!4 &326031496
Transform:
m_ObjectHideFlags: 0
Expand Down
8 changes: 3 additions & 5 deletions Assets/Scripts/API/Lua/Wrappers/AppApiWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static string ReadFile(string path)
[LuaDocsParameter("height", "Image height")]
[LuaDocsParameter("superSampling", "The supersampling strength to apply (between 0.125 and 4.0)")]
[LuaDocsParameter("renderDepth", "If true then render the depth buffer instead of the image")]
public static void TakeSnapshot(TrTransform tr, string filename, int width, int height, float superSampling = 1f, bool renderDepth = false)
public static void TakeSnapshot(TrTransform tr, string filename, int width, int height, float superSampling = 1f, bool renderDepth = false, bool removeBackground = false)
{
bool saveAsPng;
if (filename.ToLower().EndsWith(".jpg") || filename.ToLower().EndsWith(".jpeg"))
Expand All @@ -205,16 +205,14 @@ public static void TakeSnapshot(TrTransform tr, string filename, int width, int
{
var rig = SketchControlsScript.m_Instance.MultiCamCaptureRig;
App.Scene.AsScene[rig.gameObject.transform] = tr;
var rMgr = rig.ManagerFromStyle(
MultiCamStyle.Snapshot
);
var rMgr = rig.ManagerFromStyle(MultiCamStyle.Snapshot);
var initialState = rig.gameObject.activeSelf;
rig.gameObject.SetActive(true);
RenderTexture tmp = rMgr.CreateTemporaryTargetForSave(width, height);
RenderWrapper wrapper = rMgr.gameObject.GetComponent<RenderWrapper>();
float ssaaRestore = wrapper.SuperSampling;
wrapper.SuperSampling = superSampling;
rMgr.RenderToTexture(tmp, asDepth: renderDepth);
rMgr.RenderToTexture(tmp, asDepth: renderDepth, removeBackground: removeBackground);
wrapper.SuperSampling = ssaaRestore;
using (var fs = new FileStream(path, FileMode.Create))
{
Expand Down
68 changes: 68 additions & 0 deletions Assets/Scripts/LoadingScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Localization;

#if UNITY_ANDROID
using UnityEngine.Android;
#endif

namespace TiltBrush
{
Expand All @@ -27,11 +32,17 @@ public class LoadingScene : MonoBehaviour
// Amount of the progress bar taken up by the scene load
[SerializeField] private float m_SceneLoadRatio;

[SerializeField] private LocalizedString m_LoadingText;
[SerializeField] private LocalizedString m_RequestAndroidFolderPermissions;

// We have a slightly faked loading position that will always increase
// The fake loading rate is the minimum amount it will increase in one second, the reciprocal of
// m_MaximumLoadingTime
private float m_FakeLoadingRate;
private float m_CurrentLoadingPosition;
#if UNITY_ANDROID
private bool m_FolderPermissionOverride = false;
#endif

private IEnumerator Start()
{
Expand All @@ -58,6 +69,23 @@ private IEnumerator Start()

DontDestroyOnLoad(gameObject);

#if UNITY_ANDROID
if (Application.platform == RuntimePlatform.Android)
{
if (!UserHasManageExternalStoragePermission())
{
m_Overlay.MessageStatus = m_RequestAndroidFolderPermissions.GetLocalizedString();
AskForManageStoragePermission();
while (!UserHasManageExternalStoragePermission())
{
yield return new WaitForEndOfFrame();
}

m_Overlay.MessageStatus = m_LoadingText.GetLocalizedString();
}
}
#endif

AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Main");
while (!asyncLoad.isDone)
{
Expand Down Expand Up @@ -91,5 +119,45 @@ private void UpdateProgress(float start, float scale, float progress)
m_CurrentLoadingPosition = Mathf.Max(m_CurrentLoadingPosition, position);
m_Overlay.Progress = m_CurrentLoadingPosition;
}

#if UNITY_ANDROID
private bool UserHasManageExternalStoragePermission()
{
bool isExternalStorageManager = false;
try
{
AndroidJavaClass environmentClass = new AndroidJavaClass("android.os.Environment");
isExternalStorageManager = environmentClass.CallStatic<bool>("isExternalStorageManager");
}
catch (AndroidJavaException e)
{
Debug.LogError("Java Exception caught and ignored: " + e.Message);
Debug.LogError("Assuming this means this device doesn't support isExternalStorageManager.");
}
return m_FolderPermissionOverride || isExternalStorageManager;
}

private void AskForManageStoragePermission()
{
try
{
using var unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
using AndroidJavaObject currentActivityObject = unityClass.GetStatic<AndroidJavaObject>("currentActivity");
string packageName = currentActivityObject.Call<string>("getPackageName");
using var uriClass = new AndroidJavaClass("android.net.Uri");
using AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("fromParts", "package", packageName, null);
using var intentObject = new AndroidJavaObject("android.content.Intent", "android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", uriObject);
intentObject.Call<AndroidJavaObject>("addCategory", "android.intent.category.DEFAULT");
currentActivityObject.Call("startActivity", intentObject);
}
catch (AndroidJavaException e)
{
// TODO: only skip this if it's of type act=android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
m_FolderPermissionOverride = true;
Debug.LogError("Java Exception caught and ignored: " + e.Message);
Debug.LogError("Assuming this means we don't need android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION (e.g., Android SDK < 30)");
}
}
#endif
}
} // namespace TiltBrush
15 changes: 14 additions & 1 deletion Assets/Scripts/ScreenshotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public RenderTexture CreateTemporaryTargetForSave(int width, int height)

/// If m_AutoAlignRig is set, you should pass in a RenderTexture created
/// with CreateTemporaryTargetForSave().
public void RenderToTexture(RenderTexture rTexture, bool asDepth = false)
public void RenderToTexture(RenderTexture rTexture, bool asDepth = false, bool removeBackground = false)
{
RenderTextureFormat format = CameraFormat();
int depth = 24;
Expand All @@ -446,6 +446,19 @@ public void RenderToTexture(RenderTexture rTexture, bool asDepth = false)
camera.RenderWithShader(Shader.Find("Hidden/Internal-DepthNormalsTexture"), "");
camera.depthTextureMode = prevDepthTextureMode;
}
else if (removeBackground)
{
var prevClearFlags = camera.clearFlags;
var prevBackgroundColor = camera.backgroundColor;
var prevCullingMask = camera.cullingMask;
camera.clearFlags = CameraClearFlags.SolidColor;
camera.backgroundColor = new Color(0, 0, 0, 0);
camera.cullingMask = LayerMask.GetMask("MainCanvas");;
camera.Render();
camera.clearFlags = prevClearFlags;
camera.backgroundColor = prevBackgroundColor;
camera.cullingMask = prevCullingMask;
}
else
{
camera.Render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ MonoBehaviour:
m_Metadata:
m_Items: []
- m_Id: 287897575133184
m_Key: LOADING_SCENE_OVERLAY_MESSAGE
m_Key: LOADING_SCENE_OVERLAY_LOADING
m_Metadata:
m_Items: []
- m_Id: 7892854560759808
Expand Down Expand Up @@ -3275,6 +3275,10 @@ MonoBehaviour:
m_Key: POPUP_RECORD_UNSUPPORTED_TEXT
m_Metadata:
m_Items: []
- m_Id: 170004956477833216
m_Key: LOADING_SCENE_OVERLAY_ANDROIDPERMISSIONS
m_Metadata:
m_Items: []
m_Metadata:
m_Items: []
m_KeyGenerator:
Expand Down
8 changes: 6 additions & 2 deletions Assets/Settings/Localization/Strings/Strings_en.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3461,11 +3461,15 @@ MonoBehaviour:
m_Metadata:
m_Items: []
- m_Id: 151490030713540608
m_Localized: 'You can create a video of your sketch by opening it on a Mac or PC.
Search for "Exporting video" on our docs website: https://docs.openbrush.app
m_Localized: 'You can create a video of your sketch by opening it on a Mac or
PC. Search for "Exporting video" on our docs website: https://docs.openbrush.app
for a step by step guide.'
m_Metadata:
m_Items: []
- m_Id: 170004956477833216
m_Localized: Please give Open Brush file access to save your creations!
m_Metadata:
m_Items: []
references:
version: 2
RefIds: []
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ PlayerSettings:
tvOS: 0
overrideDefaultApplicationIdentifier: 1
AndroidBundleVersionCode: 1
AndroidMinSdkVersion: 27
AndroidTargetSdkVersion: 29
AndroidMinSdkVersion: 29
AndroidTargetSdkVersion: 32
AndroidPreferredInstallLocation: 0
aotOptions:
stripEngineCode: 1
Expand Down

0 comments on commit 3a0a585

Please sign in to comment.