Exemple #1
0
        public static void Initialize(string appId = null)
        {
            bool forceWindowsPlatform = UnityEngine.Application.platform == RuntimePlatform.WindowsEditor && !PlatformSettings.UseStandalonePlatform;

            if (!UnityEngine.Application.isEditor || forceWindowsPlatform)
            {
                string configAppID = GetAppIDFromConfig(forceWindowsPlatform);
                if (String.IsNullOrEmpty(appId))
                {
                    if (String.IsNullOrEmpty(configAppID))
                    {
                        throw new UnityException("Update your app id by selecting 'Oculus Platform' -> 'Edit Settings'");
                    }
                    appId = configAppID;
                }
                else
                {
                    if (!String.IsNullOrEmpty(configAppID))
                    {
                        Debug.LogWarningFormat("The 'Oculus App Id ({0})' field in 'Oculus Platform/Edit Settings' is clobbering appId ({1}) that you passed in to Platform.Core.Init.  You should only specify this in one place.  We recommend the menu location.", configAppID, appId);
                    }
                }
            }

            if (forceWindowsPlatform)
            {
                var platform = new WindowsPlatform();
                IsPlatformInitialized = platform.Initialize(appId);
            }
            else if (UnityEngine.Application.isEditor)
            {
                var platform = new StandalonePlatform();
                IsPlatformInitialized = platform.InitializeInEditor();
            }
            else if (UnityEngine.Application.platform == RuntimePlatform.Android)
            {
                var platform = new AndroidPlatform();
                IsPlatformInitialized = platform.Initialize(appId);
            }
            else if (UnityEngine.Application.platform == RuntimePlatform.WindowsPlayer)
            {
                var platform = new WindowsPlatform();
                IsPlatformInitialized = platform.Initialize(appId);
            }
            else
            {
                throw new NotImplementedException("Oculus platform is not implemented on this platform yet.");
            }

            if (!IsPlatformInitialized)
            {
                throw new UnityException("Oculus Platform failed to initialize.");
            }

            if (LogMessages)
            {
                Debug.LogWarning("Oculus.Platform.Core.LogMessages is set to true. This will cause extra heap allocations, and should not be used outside of testing and debugging.");
            }

            // Create the GameObject that will run the callbacks
            (new GameObject("Oculus.Platform.CallbackRunner")).AddComponent <CallbackRunner>();
        }