示例#1
0
文件: Steamworks.cs 项目: McBuff/DMV
    private void Awake()
    {
        Steam.RestartAppIfNecessary(480);

        // Makes sure that only one instance of this object is in use at a time
        if (SteamInterface == null)
        {
            bool error = false;
            try
            {
                // Starts the library. This will, and can, only be done once.
                SteamInterface = Steam.Initialize();
            }
            catch (AlreadyLoadedException e)
            {
                status = "The native dll is already loaded, this should not happen if ReleaseManagedResources is used and Steam.Initialize() is only called once.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }
            catch (SteamInitializeFailedException e)
            {
                status = "Could not initialize the native Steamworks API. This is usually caused by a missing steam_appid.txt file or if the Steam client is not running.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }
            catch (SteamInterfaceInitializeFailedException e)
            {
                status = "Could not initialize the wanted versions of the Steamworks API. Make sure that you have the correct Steamworks SDK version. See the documentation for more info.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }
            catch (DllNotFoundException e)
            {
                status = "Could not load a dll file. Make sure that the steam_api.dll/libsteam_api.dylib file is placed at the correct location. See the documentation for more info.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }

            if (error)
            {
                SteamInterface = null;
            }
            else
            {
                status = "Steamworks initialized and ready to use.";

                                #if UNITY_WINDOWS
                if (SteamInterface.Utils.IsSteamRunningInVR())
                {
                    HmdError result;
                    result = SteamInterface.Hmd.Init();
                    Debug.Log("Result: " + result);
                }
                                #endif

                // Prevent destruction of this object
                GameObject.DontDestroyOnLoad(this);
                activeInstance = this;

                // An event is used to notify us about any exceptions thrown from native code.
                SteamInterface.ExceptionThrown += ExceptionThrown;

                // Listen to when the game overlay is shown or hidden
                SteamInterface.Friends.GameOverlayActivated += OverlayToggle;

                hasLicense = SteamInterface.User.UserHasLicenseForApp(SteamInterface.User.GetSteamID(), SteamInterface.AppID);
            }
        }
        else
        {
            // Another Steamworks object is already created, destroy this one.
            Destroy(this);
        }
    }
示例#2
0
    private void Awake()
    {
		Steam.RestartAppIfNecessary(480);
	
        // Makes sure that only one instance of this object is in use at a time
        if (SteamInterface == null)
        {
            bool error = false;
            try
            {
                // Starts the library. This will, and can, only be done once.
                SteamInterface = Steam.Initialize();
            }
            catch (AlreadyLoadedException e)
            {
                status = "The native dll is already loaded, this should not happen if ReleaseManagedResources is used and Steam.Initialize() is only called once.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }
            catch (SteamInitializeFailedException e)
            {
                status = "Could not initialize the native Steamworks API. This is usually caused by a missing steam_appid.txt file or if the Steam client is not running.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }
            catch (SteamInterfaceInitializeFailedException e)
            {
                status = "Could not initialize the wanted versions of the Steamworks API. Make sure that you have the correct Steamworks SDK version. See the documentation for more info.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }
            catch (DllNotFoundException e)
            {
                status = "Could not load a dll file. Make sure that the steam_api.dll/libsteam_api.dylib file is placed at the correct location. See the documentation for more info.";
                Debug.LogError(status, this);
                Debug.LogError(e.Message, this);
                error = true;
            }

            if (error)
            {
                SteamInterface = null;
            }
            else
            {
                status = "Steamworks initialized and ready to use.";
                
				#if UNITY_WINDOWS
				if (SteamInterface.Utils.IsSteamRunningInVR())
				{
					HmdError result;
					result = SteamInterface.Hmd.Init();
					Debug.Log("Result: " + result);
				}
				#endif
				
                // Prevent destruction of this object
                GameObject.DontDestroyOnLoad(this);
                activeInstance = this;

                // An event is used to notify us about any exceptions thrown from native code.
                SteamInterface.ExceptionThrown += ExceptionThrown;

                // Listen to when the game overlay is shown or hidden
                SteamInterface.Friends.GameOverlayActivated += OverlayToggle;

                hasLicense = SteamInterface.User.UserHasLicenseForApp(SteamInterface.User.GetSteamID(), SteamInterface.AppID);
            }
        }
        else
        {
            // Another Steamworks object is already created, destroy this one.
            Destroy(this);
        }
    }