Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move sample app #310

Merged
merged 2 commits into from
Oct 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
unityVersion: 2021.3.26f1
projectPath: './src/Packages/Passport/Samples~/sample'
projectPath: './sample'
githubToken: ${{ secrets.GITHUB_TOKEN }}
testMode: 'EditMode'
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
with:
unityVersion: 2021.3.26f1
targetPlatform: ${{ matrix.targetPlatform }}
projectPath: './src/Packages/Passport/Samples~/sample'
projectPath: './sample'
- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
if: matrix.targetPlatform == 'WebGL'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ crashlytics-build.properties
sample-passport-unity-game/
src/Packages/Passport/Samples~/sample/iosBuild
!src/Packages/Passport/Samples~/sample/webgl/Build/
sample/iosBuild
sample/webgl/Build/

# Android
src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/**/*.meta
Expand Down
8 changes: 8 additions & 0 deletions sample/Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions sample/Assets/Editor/AndroidBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#if UNITY_EDITOR

using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using AltTester.AltTesterUnitySDK.Editor;
using AltTester.AltTesterUnitySDK;
using System;
using System.IO;

public class AndroidBuilder
{
private const string DefaultBuildPath = "Builds/Android/SampleApp.apk";

static void Build()
{
BuildPlayer(DefaultBuildPath, BuildOptions.Development);
}

static void BuildForAltTester()
{
BuildPlayer(DefaultBuildPath, BuildOptions.Development | BuildOptions.IncludeTestAssemblies, true);
}


private static void BuildPlayer(string defaultBuildPath, BuildOptions buildOptions, bool setupForAltTester = false)
{
try
{
string buildPath = GetBuildPathFromArgs(defaultBuildPath);

BuildPlayerOptions buildPlayerOptions = CreateBuildPlayerOptions(buildPath, buildOptions);

if (setupForAltTester)
{
SetupAltTester(buildPlayerOptions);
}

var results = BuildPipeline.BuildPlayer(buildPlayerOptions);

if (setupForAltTester)
{
// Clean up AltTester settings after build
AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Android);
RemoveAltFromScene(buildPlayerOptions.scenes[0]);
}
}
catch (Exception exception)
{
Debug.LogException(exception);
}
}

private static string GetBuildPathFromArgs(string defaultBuildPath)
{
string[] args = Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "--buildPath" && i + 1 < args.Length)
{
return args[i + 1];
}
}
return defaultBuildPath;
}

private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, BuildOptions buildOptions)
{
return new BuildPlayerOptions
{
scenes = new[]
{
"Assets/Scenes/SelectAuthMethod.unity",
"Assets/Scenes/UnauthenticatedScene.unity",
"Assets/Scenes/AuthenticatedScene.unity",
"Assets/Scenes/ZkEvmGetBalance.unity",
"Assets/Scenes/ZkEvmGetTransactionReceipt.unity",
"Assets/Scenes/ZkEvmSendTransaction.unity",
"Assets/Scenes/ImxNftTransfer.unity"
},
locationPathName = buildPath,
target = BuildTarget.Android,
options = buildOptions
};
}

private static void SetupAltTester(BuildPlayerOptions buildPlayerOptions)
{
AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(BuildTargetGroup.Android);
AltBuilder.CreateJsonFileForInputMappingOfAxis();

var instrumentationSettings = new AltInstrumentationSettings();
AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings);
}

public static void RemoveAltFromScene(string scene)
{
Debug.Log("Removing AltTesterPrefab from the [" + scene + "] scene.");

var sceneToModify = EditorSceneManager.OpenScene(scene);

// Find the AltTesterPrefab instance in the scene
var altRunner = GameObject.FindObjectOfType<AltRunner>();

if (altRunner != null)
{
// Destroy the AltTesterPrefab instance
GameObject.DestroyImmediate(altRunner.gameObject);

// Mark the scene as dirty and save it
EditorSceneManager.MarkSceneDirty(sceneToModify);
EditorSceneManager.SaveOpenScenes();

Debug.Log("AltTesterPrefab successfully removed from the [" + scene + "] scene.");
}
else
{
Debug.LogWarning("AltTesterPrefab was not found in the [" + scene + "] scene.");
}
}

}

#endif
11 changes: 11 additions & 0 deletions sample/Assets/Editor/AndroidBuilder.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 121 additions & 0 deletions sample/Assets/Editor/MacBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#if UNITY_EDITOR_OSX

using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using AltTester.AltTesterUnitySDK.Editor;
using AltTester.AltTesterUnitySDK;
using System;

public class MacBuilder
{
private const string DefaultBuildPath = "Builds/MacOS/SampleApp.app";

static void Build()
{
BuildPlayer(DefaultBuildPath, BuildOptions.None);
}

static void BuildForAltTester()
{
BuildPlayer(DefaultBuildPath, BuildOptions.Development | BuildOptions.IncludeTestAssemblies | BuildOptions.AutoRunPlayer, true);
}

private static void BuildPlayer(string defaultBuildPath, BuildOptions buildOptions, bool setupForAltTester = false)
{
try
{
string buildPath = GetBuildPathFromArgs(defaultBuildPath);
BuildPlayerOptions buildPlayerOptions = CreateBuildPlayerOptions(buildPath, buildOptions);

if (setupForAltTester)
{
SetupAltTester(buildPlayerOptions);
}

var results = BuildPipeline.BuildPlayer(buildPlayerOptions);

if (setupForAltTester)
{
// Clean up AltTester settings after build
AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone);
RemoveAltFromScene(buildPlayerOptions.scenes[0]);
}
}
catch (Exception exception)
{
Debug.LogException(exception);
}
}

private static string GetBuildPathFromArgs(string defaultBuildPath)
{
string[] args = Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "--buildPath" && i + 1 < args.Length)
{
return args[i + 1];
}
}
return defaultBuildPath;
}

private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, BuildOptions buildOptions)
{
return new BuildPlayerOptions
{
scenes = new[]
{
"Assets/Scenes/SelectAuthMethod.unity",
"Assets/Scenes/UnauthenticatedScene.unity",
"Assets/Scenes/AuthenticatedScene.unity",
"Assets/Scenes/ZkEvmGetBalance.unity",
"Assets/Scenes/ZkEvmGetTransactionReceipt.unity",
"Assets/Scenes/ZkEvmSendTransaction.unity",
"Assets/Scenes/ImxNftTransfer.unity"
},
locationPathName = buildPath,
target = BuildTarget.StandaloneOSX,
options = buildOptions
};
}

private static void SetupAltTester(BuildPlayerOptions buildPlayerOptions)
{
AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(BuildTargetGroup.Standalone);
AltBuilder.CreateJsonFileForInputMappingOfAxis();

var instrumentationSettings = new AltInstrumentationSettings();
AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings);
}

public static void RemoveAltFromScene(string scene)
{
Debug.Log("Removing AltTesterPrefab from the [" + scene + "] scene.");

var sceneToModify = EditorSceneManager.OpenScene(scene);

// Find the AltTesterPrefab instance in the scene
var altRunner = GameObject.FindObjectOfType<AltRunner>();

if (altRunner != null)
{
// Destroy the AltTesterPrefab instance
GameObject.DestroyImmediate(altRunner.gameObject);

// Mark the scene as dirty and save it
EditorSceneManager.MarkSceneDirty(sceneToModify);
EditorSceneManager.SaveOpenScenes();

Debug.Log("AltTesterPrefab successfully removed from the [" + scene + "] scene.");
}
else
{
Debug.LogWarning("AltTesterPrefab was not found in the [" + scene + "] scene.");
}
}

}

#endif
11 changes: 11 additions & 0 deletions sample/Assets/Editor/MacBuilder.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading