aha
This commit is contained in:
71
Assets/Scripts/LobbyHandle.cs
Normal file
71
Assets/Scripts/LobbyHandle.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using Steamworks;
|
||||
|
||||
public class LobbyHandle : MonoBehaviour
|
||||
{
|
||||
private NetworkManager networkManager;
|
||||
public GameObject hostButton;
|
||||
protected Callback<LobbyCreated_t> lobbyCreated;
|
||||
protected Callback<GameLobbyJoinRequested_t> gameLobbyJoinRequested;
|
||||
protected Callback<LobbyEnter_t> lobbyEnter;
|
||||
private const string hostAddressKey = "hostAddress";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
networkManager = GetComponent<NetworkManager>();
|
||||
|
||||
if (!SteamManager.Initialized)
|
||||
{
|
||||
Debug.LogError("Steamworks not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
lobbyCreated = Callback<LobbyCreated_t>.Create(OnLobbyCreated);
|
||||
gameLobbyJoinRequested = Callback<GameLobbyJoinRequested_t>.Create(OnGameLobbyJoinRequested);
|
||||
lobbyEnter = Callback<LobbyEnter_t>.Create(OnLobbyEnter);
|
||||
}
|
||||
|
||||
public void HostLobby()
|
||||
{
|
||||
hostButton.SetActive(false);
|
||||
|
||||
SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypeFriendsOnly, networkManager.maxConnections);
|
||||
}
|
||||
|
||||
private void OnLobbyCreated(LobbyCreated_t callback)
|
||||
{
|
||||
if (callback.m_eResult != EResult.k_EResultOK)
|
||||
{
|
||||
Debug.LogError("Failed to create lobby");
|
||||
hostButton.SetActive(true);
|
||||
return;
|
||||
}
|
||||
|
||||
SteamMatchmaking.SetLobbyData(new CSteamID(callback.m_ulSteamIDLobby), hostAddressKey, SteamUser.GetSteamID().ToString());
|
||||
|
||||
networkManager.StartHost();
|
||||
NetworkServer.SpawnObjects();
|
||||
networkManager.ServerChangeScene("Game");
|
||||
}
|
||||
|
||||
|
||||
private void OnGameLobbyJoinRequested(GameLobbyJoinRequested_t callback)
|
||||
{
|
||||
SteamMatchmaking.JoinLobby(callback.m_steamIDLobby);
|
||||
}
|
||||
|
||||
private void OnLobbyEnter(LobbyEnter_t callback)
|
||||
{
|
||||
if (NetworkServer.active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string hostAddress = SteamMatchmaking.GetLobbyData(new CSteamID(callback.m_ulSteamIDLobby), hostAddressKey);
|
||||
networkManager.networkAddress = hostAddress;
|
||||
networkManager.StartClient();
|
||||
|
||||
hostButton.SetActive(false);
|
||||
}
|
||||
}
|
2
Assets/Scripts/LobbyHandle.cs.meta
Normal file
2
Assets/Scripts/LobbyHandle.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 208ed2c79aff99f4499b18f969233679
|
88
Assets/Scripts/MenuFunctions.cs
Normal file
88
Assets/Scripts/MenuFunctions.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class MenuFunctions : MonoBehaviour
|
||||
{
|
||||
public Slider sensXSlider = null;
|
||||
public TextMeshProUGUI multiplierText = null;
|
||||
public float multiplier = 100f;
|
||||
public float fov = 60f;
|
||||
public Slider fovSlider = null;
|
||||
public TextMeshProUGUI fovText = null;
|
||||
public bool IsInMainMenu = false;
|
||||
public void QuitGame()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
if (IsInMainMenu)
|
||||
{
|
||||
if (!PlayerPrefs.HasKey("GameInitialized"))
|
||||
{
|
||||
SetDefaultPreferences();
|
||||
PlayerPrefs.SetInt("GameInitialized", 1);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
if (sensXSlider != null)
|
||||
{
|
||||
sensXSlider.value = PlayerPrefs.GetInt("multiplier", 0);
|
||||
}
|
||||
if (fovSlider != null)
|
||||
{
|
||||
fovSlider.value = PlayerPrefs.GetInt("fov", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
void SetDefaultPreferences()
|
||||
{
|
||||
PlayerPrefs.SetInt("multiplier", 100);
|
||||
PlayerPrefs.SetInt("fov", 60);
|
||||
}
|
||||
public void SetSens()
|
||||
{
|
||||
PlayerPrefs.SetInt("multiplier", (int)sensXSlider.value);
|
||||
multiplier = PlayerPrefs.GetInt("multiplier", 0);
|
||||
multiplierText.text = "Multiplier: " + multiplier.ToString();
|
||||
}
|
||||
public void SetFov()
|
||||
{
|
||||
PlayerPrefs.SetInt("fov", (int)fovSlider.value);
|
||||
fov = PlayerPrefs.GetInt("fov", 0);
|
||||
fovText.text = "Fov: " + fov.ToString();
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
if (sensXSlider != null)
|
||||
{
|
||||
SetSens();
|
||||
}
|
||||
if (fovSlider != null)
|
||||
{
|
||||
SetFov();
|
||||
}
|
||||
}
|
||||
public void play(int value)
|
||||
{
|
||||
SceneManager.LoadScene(value);
|
||||
}
|
||||
public void retry()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
public void MainMenuButton()
|
||||
{
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
public void nextlevel()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/MenuFunctions.cs.meta
Normal file
2
Assets/Scripts/MenuFunctions.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b863d9d881d9b0641ba7e27e4bdc37e5
|
161
Assets/Scripts/Movement.cs
Normal file
161
Assets/Scripts/Movement.cs
Normal file
@ -0,0 +1,161 @@
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using static Mirror.NetworkIdentity;
|
||||
using static Mirror.NetworkBehaviour;
|
||||
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class Movement : NetworkBehaviour
|
||||
{
|
||||
[Header("Movement")] public float walkSpeed = 5f;
|
||||
public float sprintSpeed = 8f;
|
||||
public float crouchSpeed = 2.5f;
|
||||
public float jumpForce = 7f;
|
||||
public float airControl = 0.5f;
|
||||
public float groundDrag = 5f;
|
||||
public float airDrag = 1f;
|
||||
|
||||
[Header("Ground Check")] public Transform groundCheck;
|
||||
public float groundDistance = 0.4f;
|
||||
public LayerMask groundMask;
|
||||
|
||||
[Header("References")] public PlayerCameraController cameraController;
|
||||
public Transform orientation;
|
||||
|
||||
private Rigidbody rb;
|
||||
private Vector3 moveDirection;
|
||||
private bool isGrounded;
|
||||
private float originalHeight;
|
||||
private Vector3 originalScale;
|
||||
private bool isCursorLocked = true;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!isLocalPlayer) return;
|
||||
|
||||
rb = GetComponent<Rigidbody>();
|
||||
rb.freezeRotation = true;
|
||||
originalHeight = transform.localScale.y;
|
||||
originalScale = transform.localScale;
|
||||
|
||||
if (cameraController == null) cameraController = GetComponentInChildren<PlayerCameraController>();
|
||||
if (orientation == null) CreateOrientation();
|
||||
|
||||
UpdateCursorState();
|
||||
}
|
||||
|
||||
private void CreateOrientation()
|
||||
{
|
||||
orientation = new GameObject("Orientation").transform;
|
||||
orientation.parent = transform;
|
||||
orientation.localPosition = Vector3.zero;
|
||||
orientation.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isLocalPlayer) return;
|
||||
|
||||
HandleCursorToggle();
|
||||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
|
||||
if (cameraController != null)
|
||||
orientation.rotation = Quaternion.Euler(0, cameraController.transform.eulerAngles.y, 0);
|
||||
|
||||
HandleJump();
|
||||
HandleCrouch();
|
||||
SpeedControl();
|
||||
ApplyDrag();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!isLocalPlayer) return;
|
||||
MovePlayer();
|
||||
}
|
||||
|
||||
private void HandleCursorToggle()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftAlt) || Input.GetKeyDown(KeyCode.RightAlt))
|
||||
{
|
||||
ToggleCursor();
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleCursor()
|
||||
{
|
||||
isCursorLocked = !isCursorLocked;
|
||||
UpdateCursorState();
|
||||
}
|
||||
|
||||
private void UpdateCursorState()
|
||||
{
|
||||
Cursor.lockState = isCursorLocked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !isCursorLocked;
|
||||
|
||||
if (cameraController != null)
|
||||
cameraController.enabled = isCursorLocked;
|
||||
}
|
||||
|
||||
private void MovePlayer()
|
||||
{
|
||||
float horizontal = Input.GetAxisRaw("Horizontal");
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
moveDirection = orientation.forward * vertical + orientation.right * horizontal;
|
||||
moveDirection = Vector3.ProjectOnPlane(moveDirection, Vector3.up).normalized;
|
||||
|
||||
float currentSpeed = GetCurrentSpeed();
|
||||
float speedMultiplier = isGrounded ? 1f : airControl;
|
||||
rb.AddForce(moveDirection * currentSpeed * 10f * speedMultiplier, ForceMode.Force);
|
||||
}
|
||||
|
||||
private float GetCurrentSpeed()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftControl)) return crouchSpeed;
|
||||
if (Input.GetKey(KeyCode.LeftShift)) return sprintSpeed;
|
||||
return walkSpeed;
|
||||
}
|
||||
|
||||
private void HandleJump()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
|
||||
{
|
||||
rb.linearVelocity = new Vector3(rb.linearVelocity.x, 0f, rb.linearVelocity.z);
|
||||
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
|
||||
if (cameraController != null) cameraController.JumpEffect();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCrouch()
|
||||
{
|
||||
bool shouldCrouch = Input.GetKey(KeyCode.LeftControl);
|
||||
float targetHeight = shouldCrouch ? originalHeight * 0.5f : originalHeight;
|
||||
Vector3 newScale = new Vector3(originalScale.x, targetHeight, originalScale.z);
|
||||
transform.localScale = Vector3.Lerp(transform.localScale, newScale, 10f * Time.deltaTime);
|
||||
if (cameraController != null) cameraController.SetCrouch(shouldCrouch);
|
||||
}
|
||||
|
||||
private void SpeedControl()
|
||||
{
|
||||
Vector3 flatVel = new Vector3(rb.linearVelocity.x, 0f, rb.linearVelocity.z);
|
||||
float currentMaxSpeed = GetCurrentSpeed();
|
||||
|
||||
if (flatVel.magnitude > currentMaxSpeed)
|
||||
{
|
||||
Vector3 limitedVel = flatVel.normalized * currentMaxSpeed;
|
||||
rb.linearVelocity = new Vector3(limitedVel.x, rb.linearVelocity.y, limitedVel.z);
|
||||
}
|
||||
|
||||
if (rb.linearVelocity.y > 10f) rb.linearVelocity = new Vector3(rb.linearVelocity.x, 10f, rb.linearVelocity.z);
|
||||
}
|
||||
|
||||
private void ApplyDrag() => rb.linearDamping = isGrounded ? groundDrag : airDrag;
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (groundCheck != null)
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(groundCheck.position, groundDistance);
|
||||
}
|
||||
}
|
||||
}
|
2
Assets/Scripts/Movement.cs.meta
Normal file
2
Assets/Scripts/Movement.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2d99809cd04140038624f26ae8e3b9f
|
102
Assets/Scripts/PlayerCameraController.cs
Normal file
102
Assets/Scripts/PlayerCameraController.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using static Mirror.NetworkIdentity;
|
||||
using static Mirror.NetworkBehaviour;
|
||||
|
||||
public class PlayerCameraController : NetworkBehaviour
|
||||
{
|
||||
[Header("Camera Settings")]
|
||||
public float sensitivity = 1f;
|
||||
public float verticalClampAngle = 90f; // Max felfelé/lefelé nézés szöge
|
||||
public float fov = 60f;
|
||||
public float zoomSpeed = 2f;
|
||||
public float minFov = 15f;
|
||||
public float maxFov = 90f;
|
||||
|
||||
[Header("Effects")]
|
||||
public float crouchLerpSpeed = 5f;
|
||||
public float jumpBounceIntensity = 0.1f;
|
||||
public float jumpBounceDuration = 0.5f;
|
||||
public float crouchCameraOffset = 0.2f;
|
||||
|
||||
private Transform player;
|
||||
private Camera cam;
|
||||
private Vector3 baseLocalPosition;
|
||||
private float xRotation = 0f;
|
||||
private float yRotation = 0f;
|
||||
private float bounceTimer = 0f;
|
||||
private float currentBounceOffset = 0f;
|
||||
private bool isCrouching = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
player = transform.parent;
|
||||
cam = GetComponent<Camera>();
|
||||
baseLocalPosition = transform.localPosition;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (player == null || cam == null) return;
|
||||
|
||||
HandleRotation();
|
||||
HandleZoom();
|
||||
HandlePosition();
|
||||
|
||||
fov = PlayerPrefs.GetInt("fov", 0);
|
||||
|
||||
sensitivity = PlayerPrefs.GetInt("multiplier", 0);
|
||||
}
|
||||
|
||||
private void HandleRotation()
|
||||
{
|
||||
float mouseX = Input.GetAxis("Mouse X") * sensitivity * 100 * Time.deltaTime;
|
||||
float mouseY = Input.GetAxis("Mouse Y") * sensitivity * 100 * Time.deltaTime;
|
||||
|
||||
// Víszintes forgás (játékos test)
|
||||
yRotation += mouseX;
|
||||
player.localRotation = Quaternion.Euler(0f, yRotation, 0f);
|
||||
|
||||
// Függőleges forgás (csak kamera)
|
||||
xRotation -= mouseY;
|
||||
xRotation = Mathf.Clamp(xRotation, -verticalClampAngle, verticalClampAngle);
|
||||
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
|
||||
}
|
||||
|
||||
private void HandleZoom()
|
||||
{
|
||||
fov -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
|
||||
fov = Mathf.Clamp(fov, minFov, maxFov);
|
||||
cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, fov, 10f * Time.deltaTime);
|
||||
}
|
||||
|
||||
private void HandlePosition()
|
||||
{
|
||||
// Alap pozíció (gugolás figyelembevételével)
|
||||
Vector3 targetPosition = baseLocalPosition;
|
||||
if (isCrouching)
|
||||
{
|
||||
targetPosition.y -= crouchCameraOffset;
|
||||
}
|
||||
|
||||
// Ugrás effekt
|
||||
if (bounceTimer > 0)
|
||||
{
|
||||
float bounceProgress = 1f - (bounceTimer / jumpBounceDuration);
|
||||
currentBounceOffset = Mathf.Sin(bounceProgress * Mathf.PI) * jumpBounceIntensity;
|
||||
bounceTimer -= Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentBounceOffset = Mathf.Lerp(currentBounceOffset, 0f, 10f * Time.deltaTime);
|
||||
}
|
||||
|
||||
// Végső pozíció alkalmazása
|
||||
transform.localPosition = targetPosition + Vector3.up * currentBounceOffset;
|
||||
}
|
||||
|
||||
public void SetCrouch(bool crouch) => isCrouching = crouch;
|
||||
public void JumpEffect() => bounceTimer = jumpBounceDuration;
|
||||
}
|
2
Assets/Scripts/PlayerCameraController.cs.meta
Normal file
2
Assets/Scripts/PlayerCameraController.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50ca196548f4e49f8896db6c1d79e942
|
5
Assets/Scripts/Steamworks.NET.meta
Normal file
5
Assets/Scripts/Steamworks.NET.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ddefd95a62cbc4ea1a2aabc009a378
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
182
Assets/Scripts/Steamworks.NET/SteamManager.cs
Normal file
182
Assets/Scripts/Steamworks.NET/SteamManager.cs
Normal file
@ -0,0 +1,182 @@
|
||||
// The SteamManager is designed to work with Steamworks.NET
|
||||
// This file is released into the public domain.
|
||||
// Where that dedication is not recognized you are granted a perpetual,
|
||||
// irrevocable license to copy and modify this file as you see fit.
|
||||
//
|
||||
// Version: 1.0.13
|
||||
|
||||
#if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX)
|
||||
#define DISABLESTEAMWORKS
|
||||
#endif
|
||||
|
||||
using UnityEngine;
|
||||
#if !DISABLESTEAMWORKS
|
||||
using System.Collections;
|
||||
using Steamworks;
|
||||
#endif
|
||||
|
||||
//
|
||||
// The SteamManager provides a base implementation of Steamworks.NET on which you can build upon.
|
||||
// It handles the basics of starting up and shutting down the SteamAPI for use.
|
||||
//
|
||||
[DisallowMultipleComponent]
|
||||
public class SteamManager : MonoBehaviour {
|
||||
#if !DISABLESTEAMWORKS
|
||||
protected static bool s_EverInitialized = false;
|
||||
|
||||
protected static SteamManager s_instance;
|
||||
protected static SteamManager Instance {
|
||||
get {
|
||||
if (s_instance == null) {
|
||||
return new GameObject("SteamManager").AddComponent<SteamManager>();
|
||||
}
|
||||
else {
|
||||
return s_instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected bool m_bInitialized = false;
|
||||
public static bool Initialized {
|
||||
get {
|
||||
return Instance.m_bInitialized;
|
||||
}
|
||||
}
|
||||
|
||||
protected SteamAPIWarningMessageHook_t m_SteamAPIWarningMessageHook;
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(SteamAPIWarningMessageHook_t))]
|
||||
protected static void SteamAPIDebugTextHook(int nSeverity, System.Text.StringBuilder pchDebugText) {
|
||||
Debug.LogWarning(pchDebugText);
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
// In case of disabled Domain Reload, reset static members before entering Play Mode.
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void InitOnPlayMode()
|
||||
{
|
||||
s_EverInitialized = false;
|
||||
s_instance = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
protected virtual void Awake() {
|
||||
// Only one instance of SteamManager at a time!
|
||||
if (s_instance != null) {
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
s_instance = this;
|
||||
|
||||
if(s_EverInitialized) {
|
||||
// This is almost always an error.
|
||||
// The most common case where this happens is when SteamManager gets destroyed because of Application.Quit(),
|
||||
// and then some Steamworks code in some other OnDestroy gets called afterwards, creating a new SteamManager.
|
||||
// You should never call Steamworks functions in OnDestroy, always prefer OnDisable if possible.
|
||||
throw new System.Exception("Tried to Initialize the SteamAPI twice in one session!");
|
||||
}
|
||||
|
||||
// We want our SteamManager Instance to persist across scenes.
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
if (!Packsize.Test()) {
|
||||
Debug.LogError("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.", this);
|
||||
}
|
||||
|
||||
if (!DllCheck.Test()) {
|
||||
Debug.LogError("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.", this);
|
||||
}
|
||||
|
||||
try {
|
||||
// If Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the
|
||||
// Steam client and also launches this game again if the User owns it. This can act as a rudimentary form of DRM.
|
||||
// Note that this will run which ever version you have installed in steam. Which may not be the precise executable
|
||||
// we were currently running.
|
||||
|
||||
// Once you get a Steam AppID assigned by Valve, you need to replace AppId_t.Invalid with it and
|
||||
// remove steam_appid.txt from the game depot. eg: "(AppId_t)480" or "new AppId_t(480)".
|
||||
// See the Valve documentation for more information: https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
|
||||
if (SteamAPI.RestartAppIfNecessary(AppId_t.Invalid)) {
|
||||
Debug.Log("[Steamworks.NET] Shutting down because RestartAppIfNecessary returned true. Steam will restart the application.");
|
||||
|
||||
Application.Quit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (System.DllNotFoundException e) { // We catch this exception here, as it will be the first occurrence of it.
|
||||
Debug.LogError("[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n" + e, this);
|
||||
|
||||
Application.Quit();
|
||||
return;
|
||||
}
|
||||
|
||||
// Initializes the Steamworks API.
|
||||
// If this returns false then this indicates one of the following conditions:
|
||||
// [*] The Steam client isn't running. A running Steam client is required to provide implementations of the various Steamworks interfaces.
|
||||
// [*] The Steam client couldn't determine the App ID of game. If you're running your application from the executable or debugger directly then you must have a [code-inline]steam_appid.txt[/code-inline] in your game directory next to the executable, with your app ID in it and nothing else. Steam will look for this file in the current working directory. If you are running your executable from a different directory you may need to relocate the [code-inline]steam_appid.txt[/code-inline] file.
|
||||
// [*] Your application is not running under the same OS user context as the Steam client, such as a different user or administration access level.
|
||||
// [*] Ensure that you own a license for the App ID on the currently active Steam account. Your game must show up in your Steam library.
|
||||
// [*] Your App ID is not completely set up, i.e. in Release State: Unavailable, or it's missing default packages.
|
||||
// Valve's documentation for this is located here:
|
||||
// https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
|
||||
m_bInitialized = SteamAPI.Init();
|
||||
if (!m_bInitialized) {
|
||||
Debug.LogError("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.", this);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
s_EverInitialized = true;
|
||||
}
|
||||
|
||||
// This should only ever get called on first load and after an Assembly reload, You should never Disable the Steamworks Manager yourself.
|
||||
protected virtual void OnEnable() {
|
||||
if (s_instance == null) {
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
if (!m_bInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_SteamAPIWarningMessageHook == null) {
|
||||
// Set up our callback to receive warning messages from Steam.
|
||||
// You must launch with "-debug_steamapi" in the launch args to receive warnings.
|
||||
m_SteamAPIWarningMessageHook = new SteamAPIWarningMessageHook_t(SteamAPIDebugTextHook);
|
||||
SteamClient.SetWarningMessageHook(m_SteamAPIWarningMessageHook);
|
||||
}
|
||||
}
|
||||
|
||||
// OnApplicationQuit gets called too early to shutdown the SteamAPI.
|
||||
// Because the SteamManager should be persistent and never disabled or destroyed we can shutdown the SteamAPI here.
|
||||
// Thus it is not recommended to perform any Steamworks work in other OnDestroy functions as the order of execution can not be garenteed upon Shutdown. Prefer OnDisable().
|
||||
protected virtual void OnDestroy() {
|
||||
if (s_instance != this) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_instance = null;
|
||||
|
||||
if (!m_bInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
SteamAPI.Shutdown();
|
||||
}
|
||||
|
||||
protected virtual void Update() {
|
||||
if (!m_bInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run Steam client callbacks
|
||||
SteamAPI.RunCallbacks();
|
||||
}
|
||||
#else
|
||||
public static bool Initialized {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif // !DISABLESTEAMWORKS
|
||||
}
|
8
Assets/Scripts/Steamworks.NET/SteamManager.cs.meta
Normal file
8
Assets/Scripts/Steamworks.NET/SteamManager.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef4bffeda13d7a748973ff9204401c07
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
Reference in New Issue
Block a user