Esempio n. 1
0
        IEnumerator Start()
        {
            Logger.SetLogger(new MemoizedLogger(100));
            Logger.minLogLevel = Logger.LogLevel.Debug;

            Logger.LogInfo(TAG, "Starting console window...");
            Instantiate(consolePrefab, screen.transform);
            yield return(new WaitForEndOfFrame());

            Logger.LogInfo(TAG, "Setting global flags...");
            GlobalConfigManager.SetFlags();

            if (enableGlog)
            {
                if (Glog.logDir != null)
                {
                    if (!Directory.Exists(Glog.logDir))
                    {
                        Directory.CreateDirectory(Glog.logDir);
                    }
                    Logger.LogVerbose(TAG, $"Glog will output files under {Glog.logDir}");
                }
                Glog.Initialize("MediaPipeUnityPlugin");
                isGlogInitialized = true;
            }

            Logger.LogInfo(TAG, "Initializing AssetLoader...");
            switch (assetLoaderType)
            {
            case AssetLoaderType.AssetBundle: {
                AssetLoader.Provide(new AssetBundleResourceManager(Path.Combine(Application.streamingAssetsPath, "mediapipe")));
                break;
            }

            case AssetLoaderType.StreamingAssets: {
                AssetLoader.Provide(new StreamingAssetsResourceManager());
                break;
            }

            default: {
#if UNITY_EDITOR
                AssetLoader.Provide(new LocalResourceManager());
                break;
#else
                Logger.LogError("LocalResourceManager is only supported on UnityEditor");
                yield break;
#endif
            }
            }

            DecideInferenceMode();
            if (inferenceMode == InferenceMode.GPU)
            {
                Logger.LogInfo(TAG, "Initializing GPU resources...");
                yield return(GpuManager.Initialize());
            }

            Logger.LogInfo(TAG, "Preparing ImageSource...");
            ImageSourceProvider.SwitchSource(defaultImageSource);
            DontDestroyOnLoad(GameObject.Find("Image Source"));

            DontDestroyOnLoad(this.gameObject);
            isFinished = true;

            Logger.LogInfo(TAG, "Loading the first scene...");
            var sceneLoadReq = SceneManager.LoadSceneAsync(1);
            yield return(new WaitUntil(() => sceneLoadReq.isDone));
        }
        private IEnumerator Init()
        {
            Logger.SetLogger(new MemoizedLogger(100));
            Logger.MinLogLevel = Logger.LogLevel.Debug;

            Protobuf.SetLogHandler(Protobuf.DefaultLogHandler);

            Logger.LogInfo(_TAG, "Setting global flags...");
            GlobalConfigManager.SetFlags();

            if (_enableGlog)
            {
                if (Glog.LogDir != null)
                {
                    if (!Directory.Exists(Glog.LogDir))
                    {
                        Directory.CreateDirectory(Glog.LogDir);
                    }
                    Logger.LogVerbose(_TAG, $"Glog will output files under {Glog.LogDir}");
                }
                Glog.Initialize("MediaPipeUnityPlugin");
                _isGlogInitialized = true;
            }

            Logger.LogInfo(_TAG, "Initializing AssetLoader...");
            switch (_assetLoaderType)
            {
            case AssetLoaderType.AssetBundle:
            {
                AssetLoader.Provide(new AssetBundleResourceManager("mediapipe"));
                break;
            }

            case AssetLoaderType.StreamingAssets:
            {
                AssetLoader.Provide(new StreamingAssetsResourceManager());
                break;
            }

            case AssetLoaderType.Local:
            {
#if UNITY_EDITOR
                AssetLoader.Provide(new LocalResourceManager());
                break;
#else
                Logger.LogError("LocalResourceManager is only supported on UnityEditor");
                yield break;
#endif
            }

            default:
            {
                Logger.LogError($"AssetLoaderType is unknown: {_assetLoaderType}");
                yield break;
            }
            }

            DecideInferenceMode();
            if (inferenceMode == InferenceMode.GPU)
            {
                Logger.LogInfo(_TAG, "Initializing GPU resources...");
                yield return(GpuManager.Initialize());

                if (!GpuManager.IsInitialized)
                {
                    Logger.LogWarning("If your native library is built for CPU, change 'Preferable Inference Mode' to CPU from the Inspector Window for Bootstrap");
                }
            }

            Logger.LogInfo(_TAG, "Preparing ImageSource...");
            ImageSourceProvider.ImageSource = GetImageSource(_defaultImageSource);

            isFinished = true;
        }