Unity Game Session MVP
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcc16ddf2ea9dc340920ca8bcc54629c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,261 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 10
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 13
|
||||
m_BakeOnSceneLoad: 0
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 12
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAmbientOcclusion: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 2
|
||||
m_BakeBackend: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVRBounces: 2
|
||||
m_PVREnvironmentSampleCount: 256
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_PVRFilteringMode: 1
|
||||
m_PVRDenoiserTypeDirect: 1
|
||||
m_PVRDenoiserTypeIndirect: 1
|
||||
m_PVRDenoiserTypeAO: 1
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVREnvironmentMIS: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 1
|
||||
m_PVRFilteringGaussRadiusAO: 1
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_LightingDataAsset: {fileID: 20201, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_LightingSettings: {fileID: 0}
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 3
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
buildHeightMesh: 0
|
||||
maxJobWorkers: 0
|
||||
preserveTilesOutsideBounds: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &105404090
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 105404091}
|
||||
- component: {fileID: 105404092}
|
||||
m_Layer: 0
|
||||
m_Name: Boostrap
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &105404091
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 105404090}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &105404092
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 105404090}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2781611f0f83bf54290a9ec600543440, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_nextSceneName: LoginScene
|
||||
--- !u!1 &591506935
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 591506937}
|
||||
- component: {fileID: 591506936}
|
||||
m_Layer: 0
|
||||
m_Name: GameSession
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &591506936
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 591506935}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c9177aa9fcd28a94b9042f8a89fdac2d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!4 &591506937
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 591506935}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1654552490
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1654552492}
|
||||
- component: {fileID: 1654552491}
|
||||
m_Layer: 0
|
||||
m_Name: AutoIniializer
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1654552491
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1654552490}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: ddf01aaf66ec43f2bc9deda891a457d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!4 &1654552492
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1654552490}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1660057539 &9223372036854775807
|
||||
SceneRoots:
|
||||
m_ObjectHideFlags: 0
|
||||
m_Roots:
|
||||
- {fileID: 1654552492}
|
||||
- {fileID: 591506937}
|
||||
- {fileID: 105404091}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40f9b53766c74f541b85df4d35cfc767
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48fc9d6a0ce7ade4ba2075f927f8e305
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bb534640fcb98b4cb869bdbb0059eb6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace BrewMonster
|
||||
{
|
||||
public class BoostrapSceneController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string _nextSceneName;
|
||||
|
||||
IEnumerator Start()
|
||||
{
|
||||
// Load the next scene after 1 second
|
||||
yield return new WaitForSeconds(1f);
|
||||
LoadNextScene();
|
||||
}
|
||||
|
||||
private void LoadNextScene()
|
||||
{
|
||||
SceneManager.LoadScene(_nextSceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2781611f0f83bf54290a9ec600543440
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07afa074c434449b84fc580e4bd1b17e
|
||||
timeCreated: 1757239245
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BrewMonster
|
||||
{
|
||||
public class AutoInitializer : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
var interfaceType = typeof(IAutoInitialize);
|
||||
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
Type[] typesInAssembly;
|
||||
try
|
||||
{
|
||||
typesInAssembly = assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException e)
|
||||
{
|
||||
typesInAssembly = e.Types;
|
||||
}
|
||||
|
||||
if (typesInAssembly == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var type in typesInAssembly)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type.IsAbstract || type.IsInterface)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!interfaceType.IsAssignableFrom(type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object instance = null;
|
||||
try
|
||||
{
|
||||
if (typeof(ScriptableObject).IsAssignableFrom(type))
|
||||
{
|
||||
instance = ScriptableObject.CreateInstance(type);
|
||||
}
|
||||
else if (typeof(MonoBehaviour).IsAssignableFrom(type))
|
||||
{
|
||||
var go = new GameObject(type.Name);
|
||||
go.transform.SetParent(transform, worldPositionStays: false);
|
||||
instance = go.AddComponent(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = Activator.CreateInstance(type);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"AutoInitializer: Failed to create instance of {type.FullName}: {ex}");
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
(instance as IAutoInitialize)?.Initialize();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"AutoInitializer: Failed to initialize {type.FullName}: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddf01aaf66ec43f2bc9deda891a457d3
|
||||
timeCreated: 1757239452
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BrewMonster
|
||||
{
|
||||
public class CoroutineRunner : MonoSingleton<CoroutineRunner>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8a86796c56d63447aa1df962fb3abf6
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace BrewMonster
|
||||
{
|
||||
public interface IAutoInitialize
|
||||
{
|
||||
void Initialize();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64cd9342d8974df18056b12aeb6f2651
|
||||
timeCreated: 1757239258
|
||||
@@ -0,0 +1,32 @@
|
||||
#define ENALBE_LOGGING
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace BrewMonster
|
||||
{
|
||||
public class Logger
|
||||
{
|
||||
public static void Log(string message)
|
||||
{
|
||||
#if ENALBE_LOGGING
|
||||
Debug.Log(message);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void LogError(string message)
|
||||
{
|
||||
#if ENALBE_LOGGING
|
||||
Debug.LogError(message);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void LogWarning(string message)
|
||||
{
|
||||
#if ENALBE_LOGGING
|
||||
Debug.LogWarning(message);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e4b9f6cd855f4a4c9b02f681b12af2d
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BrewMonster
|
||||
{
|
||||
public class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
private static T _instance;
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = FindFirstObjectByType<T>();
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject obj = new GameObject(typeof(T).Name);
|
||||
_instance = obj.AddComponent<T>();
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_instance = this as T;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>Override this method to initialize the singleton</summary>
|
||||
protected virtual void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 139eb655406d7d447ba2d30309a84e00
|
||||
@@ -1,17 +1,25 @@
|
||||
using CSNetwork;
|
||||
using BrewMonster;
|
||||
using CSNetwork;
|
||||
|
||||
namespace PerfectWorld.Scripts.Managers
|
||||
{
|
||||
namespace BrewMonster.Managers
|
||||
{
|
||||
public class EC_ManPlayer : IMsgHandler
|
||||
public class EC_ManPlayer : IMsgHandler, IAutoInitialize
|
||||
{
|
||||
public void Initialize()
|
||||
{
|
||||
EC_ManMessage.RegisterHandler(this); // add to the message handler list
|
||||
}
|
||||
|
||||
|
||||
public int HandlerId => MANAGER_INDEX.MAN_PLAYER;
|
||||
public bool ProcessMessage(ECMSG Msg)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using CSNetwork;
|
||||
using CSNetwork.Protocols;
|
||||
using System;
|
||||
using BrewMonster;
|
||||
using CSNetwork.Security;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using CSNetwork.Protocols.RPCData;
|
||||
|
||||
namespace BrewMonster.Network
|
||||
{
|
||||
// How to connect to the server:
|
||||
// 1. Set the connection info
|
||||
// 2. Login
|
||||
public class UnityGameSession : MonoSingleton<UnityGameSession>
|
||||
{
|
||||
private GameSession _gameSession;
|
||||
|
||||
private bool _isInitialized = false;
|
||||
private string _ip = "";
|
||||
private int _port = 0;
|
||||
private string _username = "";
|
||||
private string _password = "";
|
||||
|
||||
/// <summary>
|
||||
/// Send a
|
||||
/// </summary>
|
||||
/// <param name="protocol"></param>
|
||||
/// <param name="complete"></param>
|
||||
public static void SendProtocol(Protocol protocol, Action complete = null)
|
||||
{
|
||||
if (!Instance._isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Instance._gameSession.SendProtocol(protocol, complete);
|
||||
}
|
||||
|
||||
/// <summary>Set the connection info. This MUST be called call before login</summary>
|
||||
public static void SetConnectionInfo(string ip, int port)
|
||||
{
|
||||
Logger.Log($"Set connection info {ip} {port}");
|
||||
Instance._ip = ip;
|
||||
Instance._port = port;
|
||||
}
|
||||
|
||||
public static async Task Login(string username, string password, Action<bool> onLoginComplete = null)
|
||||
{
|
||||
Instance._username = username;
|
||||
Instance._password = password;
|
||||
|
||||
if (Instance._ip == "" || Instance._port == 0)
|
||||
{
|
||||
Logger.LogError($"IP or port is not set {Instance._ip} {Instance._port}");
|
||||
onLoginComplete?.Invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await Instance.ConnectAsync(Instance._ip, Instance._port);
|
||||
|
||||
if (!Instance._gameSession.IsConnected)
|
||||
{
|
||||
Logger.LogError($"Failed to connect to {Instance._ip} {Instance._port}");
|
||||
onLoginComplete?.Invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance._gameSession.LoginAsync(username, password, onLoginComplete);
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
BaseSecurity.Initizalize();
|
||||
ProtocolFactory.RegisterAllProtocols();
|
||||
_gameSession = new GameSession();
|
||||
_isInitialized = true;
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Make sure username and password is set before calling this method</summary>
|
||||
private async Task ConnectAsync(string ip, int port)
|
||||
{
|
||||
if (!Instance._isInitialized)
|
||||
{
|
||||
Logger.LogError("GameSession is not initialized");
|
||||
return;
|
||||
}
|
||||
await Instance._gameSession.ConnectAsync(ip, port);
|
||||
}
|
||||
|
||||
/// <summary>Get the list of created characters</summary>
|
||||
public static void GetRoleListAsync(Action<List<RoleInfo>> callback = null)
|
||||
{
|
||||
Instance._gameSession.GetRoleListAsync(callback);
|
||||
}
|
||||
|
||||
public static void SelectRoleAsync(RoleInfo roleInfo, Action<RoleInfo> callback = null)
|
||||
{
|
||||
Instance._gameSession.SelectRoleAsync(roleInfo, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9177aa9fcd28a94b9042f8a89fdac2d
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7104ee5d1d322d64fb82447c7a9ab4c1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5410bc4cbeb43b748a536a3de8683843
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,122 @@
|
||||
using System.Collections.Generic;
|
||||
using BrewMonster.Network;
|
||||
using CSNetwork.Protocols;
|
||||
using CSNetwork.Protocols.RPCData;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BrewMonster.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Login Flow:
|
||||
/// 1. Enter username and password
|
||||
/// 2. Click login button
|
||||
/// 3. Login success, get the list of characters
|
||||
/// 4. Open the select character screen
|
||||
/// </summary>
|
||||
public class LoginScreenUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_InputField _usernameInputField;
|
||||
[SerializeField] private TMP_InputField _passwordInputField;
|
||||
[SerializeField] private Button _loginButton;
|
||||
[SerializeField] private SelecScreenCharacter _selectCharacterScreen;
|
||||
|
||||
private List<RoleInfo> _roleInfos;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_loginButton.onClick.AddListener(OnLoginButtonClicked);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (_roleInfos != null)
|
||||
{
|
||||
_selectCharacterScreen.InitScreen(_roleInfos, OnClickSelectCharacter);
|
||||
_roleInfos = null;
|
||||
}
|
||||
}
|
||||
|
||||
public async void OnLoginButtonClicked()
|
||||
{
|
||||
Logger.Log("OnLoginButtonClicked");
|
||||
string username = _usernameInputField.text;
|
||||
string password = _passwordInputField.text;
|
||||
UnityGameSession.SetConnectionInfo("103.182.22.52", 29000);
|
||||
await UnityGameSession.Login(username, password, OnLoginComplete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback when the login is complete.
|
||||
/// Then get the list of characters
|
||||
/// </summary>
|
||||
private void OnLoginComplete(bool result)
|
||||
{
|
||||
if (!result)
|
||||
{
|
||||
Logger.LogError("Login failed");
|
||||
return;
|
||||
}
|
||||
UnityGameSession.GetRoleListAsync(OnGetRoleListComplete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback when the list of characters is retrieved.
|
||||
/// Then move to the select character screen
|
||||
/// </summary>
|
||||
private void OnGetRoleListComplete(List<RoleInfo> roleInfos)
|
||||
{
|
||||
Logger.Log($"OnGetRoleListComplete {roleInfos.Count}");
|
||||
|
||||
_roleInfos = roleInfos;
|
||||
}
|
||||
|
||||
private void OnClickSelectCharacter(RoleInfo roleInfo)
|
||||
{
|
||||
Logger.Log($"OnClickSelectCharacter {roleInfo.name}");
|
||||
UnityGameSession.SelectRoleAsync(roleInfo, OnSelectRoleComplete);
|
||||
}
|
||||
|
||||
private void OnSelectRoleComplete(RoleInfo roleInfo)
|
||||
{
|
||||
Logger.Log($"OnSelectRoleComplete {roleInfo.name} - {roleInfo.roleid}");
|
||||
|
||||
// now we have to enter the world
|
||||
UnityGameSession.SendProtocol(
|
||||
new enterworld()
|
||||
{
|
||||
Roleid = roleInfo.roleid,
|
||||
Provider_link_id = 0,
|
||||
L_timeout = 0,
|
||||
Localsid = 0,
|
||||
Locktime = 0,
|
||||
Settime = 0,
|
||||
Timeout = 0
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
if (_usernameInputField == null)
|
||||
{
|
||||
// find childrend with name "username"
|
||||
_usernameInputField = transform.Find("username").GetComponent<TMP_InputField>();
|
||||
}
|
||||
if (_passwordInputField == null)
|
||||
{
|
||||
// find childrend with name "password"
|
||||
_passwordInputField = transform.Find("password").GetComponent<TMP_InputField>();
|
||||
}
|
||||
if (_loginButton == null)
|
||||
{
|
||||
// find childrend with name "LoginBtn"
|
||||
_loginButton = transform.Find("LoginBtn").GetComponent<Button>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 994f35e190b055c47903eb55ae125a9a
|
||||
Reference in New Issue
Block a user