96 lines
2.6 KiB
C#
96 lines
2.6 KiB
C#
using CSNetwork.GPDataType;
|
|
using CSNetwork.Protocols.RPCData;
|
|
using System.Data;
|
|
using Unity.Cinemachine;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class GameController : MonoBehaviour
|
|
{
|
|
private static GameController instance;
|
|
|
|
[SerializeField] private GameObject characterPrefab;
|
|
[SerializeField] private CECMonster monsterPrefab;
|
|
[SerializeField] private CECNPCServer npcServerPrefab;
|
|
[SerializeField] private CinemachineCamera cinemachineCamera;
|
|
//[SerializeField] private Transform ground;
|
|
CECHostPlayer hostPlayer;
|
|
|
|
public static GameController Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = FindAnyObjectByType<GameController>();
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
private void Awake()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this;
|
|
}
|
|
}
|
|
|
|
public void Log(string s)
|
|
{
|
|
Debug.LogError(s);
|
|
}
|
|
public CECHostPlayer GetHostPlayer()
|
|
{
|
|
if (hostPlayer == null)
|
|
{
|
|
hostPlayer = FindAnyObjectByType<CECHostPlayer>();
|
|
}
|
|
return hostPlayer;
|
|
}
|
|
public void InitCharacter(cmd_self_info_1 info)
|
|
{
|
|
if (characterPrefab == null)
|
|
{
|
|
Debug.LogError("null prefab");
|
|
return;
|
|
}
|
|
CECPlayer.InitStaticRes();
|
|
hostPlayer = Instantiate(characterPrefab, transform).AddComponent<CECHostPlayer>();
|
|
hostPlayer.InitCharacter(info);
|
|
cinemachineCamera.Follow = hostPlayer.transform;
|
|
cinemachineCamera.ForceCameraPosition(hostPlayer.transform.position, Quaternion.identity);
|
|
CinemachineTouchOrbit.Instance.SetOrbitTarget(hostPlayer.transform);
|
|
//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 CECMonster GetMonster()
|
|
{
|
|
return Instantiate(monsterPrefab, transform);
|
|
}
|
|
|
|
public CECNPCServer GetNPCServer()
|
|
{
|
|
return Instantiate(npcServerPrefab, transform);
|
|
}
|
|
public GameObject InitCharacter(info_player_1 info)
|
|
{
|
|
if (characterPrefab == null)
|
|
{
|
|
Debug.LogError("null prefab");
|
|
return null;
|
|
}
|
|
GameObject character = Instantiate(characterPrefab, transform);
|
|
return character.gameObject;
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
instance = null;
|
|
}
|
|
}
|