aaab1e4007
# Conflicts: # Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll # Assets/PerfectWorld/Scripts/Common/AutoInitializer.cs # Assets/Scripts/CECHostPlayer.cs # Assets/Scripts/GameController.cs
98 lines
2.4 KiB
C#
98 lines
2.4 KiB
C#
using CSNetwork.GPDataType;
|
|
using CSNetwork.Protocols.RPCData;
|
|
using System.Data;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class GameController : MonoBehaviour
|
|
{
|
|
private static GameController instance;
|
|
|
|
[SerializeField] private CECHostPlayer characterPrefab;
|
|
//[SerializeField] private Transform ground;
|
|
CECHostPlayer hostPlayer;
|
|
Camera camera;
|
|
|
|
public static GameController Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = FindAnyObjectByType<GameController>();
|
|
if (instance == null)
|
|
{
|
|
var go = new GameObject("GameController");
|
|
instance = go.AddComponent<GameController>();
|
|
DontDestroyOnLoad(go);
|
|
}
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
private void Awake()
|
|
{
|
|
if(instance == null)
|
|
{
|
|
instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else if(instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
camera = Camera.main;
|
|
}
|
|
|
|
public void Log(string s)
|
|
{
|
|
Debug.LogError(s);
|
|
}
|
|
public CECHostPlayer GetHostPlayer()
|
|
{
|
|
if(hostPlayer == null)
|
|
{
|
|
hostPlayer = FindAnyObjectByType<CECHostPlayer>();
|
|
}
|
|
Debug.Log("hostPlayer " + hostPlayer);
|
|
return hostPlayer;
|
|
}
|
|
public void InitCharacter(cmd_self_info_1 info)
|
|
{
|
|
if(characterPrefab == null)
|
|
{
|
|
Debug.LogError("null prefab");
|
|
return;
|
|
}
|
|
hostPlayer = Instantiate(characterPrefab, transform);
|
|
hostPlayer.InitCharacter(info);
|
|
//Vector3 pos = new Vector3(info.pos.x, info.pos.y, info.pos.z);
|
|
//Vector3 posCam = pos;
|
|
//posCam.z -= 10f;
|
|
//camera.transform.position = posCam;
|
|
//Vector3 posGround = pos;
|
|
//posGround.y -= 2f;
|
|
//ground.transform.position = posGround;
|
|
}
|
|
|
|
public GameObject InitCharacter(info_player_1 info)
|
|
{
|
|
if (characterPrefab == null)
|
|
{
|
|
Debug.LogError("null prefab");
|
|
return null;
|
|
}
|
|
CECHostPlayer character = Instantiate(characterPrefab, transform);
|
|
character.InitCharacter(info);
|
|
return character.gameObject;
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
instance = null;
|
|
}
|
|
}
|