using System; using System.Collections; using System.Collections.Generic; using BITKit; using BITKit.Game; using BITKit.SceneManagement; #if STEAMWORKS_NET using BITKit.Steamwork; #endif using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.SceneManagement; namespace BITFALL.Game{ [Serializable] public sealed class GameServiceSingleton:GameServiceImplement { protected override IGameService service => GameService.Singleton; } public sealed class GameService : StateBasedMonoBehaviour,IGameService { [SerializeReference,SubclassSelector] private INetClient netClient; [SerializeReference,SubclassSelector] private INetProvider netProvider; [SerializeReference,SubclassSelector] private ISceneService sceneService; #if STEAMWORKS_NET [SerializeReference, SubclassSelector] private ISteamService steamService; #endif [SerializeField] private Optional allowLoadOfflineMap; public static IGameService Singleton { get; set; } private void Awake() { Singleton = this; } private void Start() { netProvider.AddCommandListener(ChangeMap); netClient.OnConnected += OnConnected; } private void OnConnected() { #if STEAMWORKS_NET netClient.SendServerMessage($"{steamService.Name} is connected"); #endif netClient.SendServerMessage($"{Environment.UserDomainName} is connected"); } private void ChangeMap(GameChangeMapCommand obj) { sceneService.LoadSceneAsync(obj.MapName,default,LoadSceneMode.Single).Forget(); } public void Play() { if (allowLoadOfflineMap.Allow) { ChangeMap(new GameChangeMapCommand(){MapName = allowLoadOfflineMap.Value}); } else { netProvider.ServerCommand(new GameRequestMapCommand(){MapName = "Map1"}); } } public void Stop() { //if (allowLoadOfflineMap.Allow) { sceneService.UnloadSceneAsync(allowLoadOfflineMap.Value,default).Forget(); } } } }