Skip to content

Commit

Permalink
refactor!: place ResourceManager classes under SDK directory
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Feb 27, 2021
1 parent fe2f97f commit c67a456
Show file tree
Hide file tree
Showing 26 changed files with 531 additions and 255 deletions.
30 changes: 30 additions & 0 deletions Assets/MediaPipe/Examples/Scenes/DesktopDemo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,36 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 90, y: 180, z: 0}
--- !u!1 &501670066
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 501670067}
m_Layer: 0
m_Name: ResourceManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &501670067
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 501670066}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &624144232
GameObject:
m_ObjectHideFlags: 0
Expand Down
23 changes: 0 additions & 23 deletions Assets/MediaPipe/Examples/Scripts/AsyncOperationAwaiter.cs

This file was deleted.

7 changes: 0 additions & 7 deletions Assets/MediaPipe/Examples/Scripts/AsyncOperationExtension.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

public sealed class AssetBundleLoader : MonoBehaviour {
Mediapipe.AssetBundleManager resourceManager;

void Start() {
resourceManager = new Mediapipe.AssetBundleManager();
}

void PrepareAsset(string name, string uniqueKey) {
resourceManager.PrepareAsset(name, uniqueKey);
}

void PrepareAsset(string name) {
resourceManager.PrepareAsset(name, name);
}
}

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

public sealed class LocalAssetLoader : MonoBehaviour {
Mediapipe.LocalAssetManager resourceManager;

void Start() {
resourceManager = new Mediapipe.LocalAssetManager();
}

void PrepareAsset(string name, string uniqueKey) {
resourceManager.PrepareAsset(name, uniqueKey);
}

void PrepareAsset(string name) {
resourceManager.PrepareAsset(name, name);
}
}

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

This file was deleted.

34 changes: 4 additions & 30 deletions Assets/MediaPipe/Examples/Scripts/SceneDirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class SceneDirector : MonoBehaviour {
static IntPtr currentContext = IntPtr.Zero;

const int MAX_WAIT_FRAME = 1000;
bool IsAssetLoaded = false;
bool IsAssetLoadFailed = false;

void OnEnable() {
// for debugging
Expand All @@ -39,7 +37,7 @@ public class SceneDirector : MonoBehaviour {
}
#endif

async void Start() {
void Start() {
#if UNITY_EDITOR_OSX || UNITY_EDITOR_WIN
#if UNITY_STANDALONE
if (useGPU) {
Expand All @@ -59,21 +57,12 @@ public class SceneDirector : MonoBehaviour {
}
#endif

var resourceManager = GameObject.Find("ResourceManager");
#if UNITY_EDITOR
var resourceManager = LocalAssetManager.Instance;
resourceManager.AddComponent<LocalAssetLoader>();
#else
var resourceManager = AssetBundleManager.Instance;
resourceManager.AddComponent<AssetBundleLoader>();
#endif

ResourceUtil.InitializeResourceManager(resourceManager);

try {
await resourceManager.LoadAllAssetsAsync();
IsAssetLoaded = true;
} catch (Exception e) {
Debug.LogError(e);
IsAssetLoadFailed = true;
}
}

void OnDisable() {
Expand Down Expand Up @@ -158,13 +147,6 @@ public class SceneDirector : MonoBehaviour {
}

IEnumerator RunGraph() {
yield return WaitForAssets();

if (IsAssetLoadFailed) {
Debug.LogError("Failed to load assets. Stopping...");
yield break;
}

yield return WaitForGraph();

if (graphPrefab == null) {
Expand Down Expand Up @@ -204,14 +186,6 @@ public class SceneDirector : MonoBehaviour {
}
}

IEnumerator WaitForAssets() {
if (!IsAssetLoaded && !IsAssetLoadFailed) {
Debug.Log("Waiting for assets to be loaded...");
}

yield return new WaitUntil(() => IsAssetLoaded || IsAssetLoadFailed);
}

IEnumerator WaitForGraph() {
var waitFrame = MAX_WAIT_FRAME;

Expand Down
2 changes: 1 addition & 1 deletion Assets/MediaPipe/SDK/Scripts/Core/InternalException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace Mediapipe {
public class InternalException : ApplicationException {
public class InternalException : Exception {
public InternalException(string message) : base(message) {}
}
}
2 changes: 1 addition & 1 deletion Assets/MediaPipe/SDK/Scripts/Core/MediaPipeException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace Mediapipe {
public class MediaPipeException : ApplicationException {
public class MediaPipeException : Exception {
public MediaPipeException(string message) : base(message) {}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace Mediapipe {
public class MediaPipePluginException : ApplicationException {
public class MediaPipePluginException : Exception {
public MediaPipePluginException(string message) : base(message) {}
}
}
Loading

0 comments on commit c67a456

Please sign in to comment.