89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
using Axibug.Runtime;
|
|
using Bright.Serialization;
|
|
using System.IO;
|
|
using Game.Config;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using static Axibug.Utility;
|
|
using UnityEditor;
|
|
using Axibug.Resources;
|
|
|
|
namespace Game
|
|
{
|
|
public class MainPlayerComponent : GameComponent
|
|
{
|
|
public Transform CamPos;
|
|
|
|
public Transform Player;
|
|
Rigidbody mRigidbody;
|
|
public bool bLoadFinish { get; private set; } = false;
|
|
|
|
private void OnEnable()
|
|
{
|
|
CamPos = transform.Find("CamPos");
|
|
}
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
public void LoadPlayer()
|
|
{
|
|
bLoadFinish = false;
|
|
//TODO Òì²½
|
|
GameObject playergo = Clone("Warrior");
|
|
playergo.transform.localPosition = Vector3.zero;
|
|
this.transform.position = GamePlayEntry.Map.SpawnPos;
|
|
|
|
mRigidbody = this.gameObject.AddComponent<Rigidbody>();
|
|
mRigidbody.isKinematic = false;
|
|
mRigidbody.useGravity = true;
|
|
|
|
////ÉãÏñ»ú
|
|
Camera.main.transform.parent = CamPos;
|
|
Camera.main.transform.localPosition = Vector3.zero;
|
|
Camera.main.transform.localEulerAngles = Vector3.zero;
|
|
|
|
bLoadFinish = true;
|
|
}
|
|
|
|
|
|
private GameObject Clone(string RoleName)
|
|
{
|
|
string rootPath = "Assets/GameAssets";
|
|
string MapName = $"Assets/GameAssets/Prefabs/Role/{RoleName}/{RoleName}.prefab";
|
|
string tmp = MapName.Remove(0, rootPath.Length + 1);
|
|
int idx = tmp.LastIndexOf('/');
|
|
string bundleName = tmp.Substring(0, idx);
|
|
|
|
UnityEngine.Object asset = null;
|
|
if (AppEntry.Base.EditorResourceMode)
|
|
{
|
|
#if UNITY_EDITOR
|
|
asset = AssetDatabase.LoadAssetAtPath<GameObject>(MapName);
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
int id = MapName.GetHashCode();
|
|
asset = PrefabManager.LoadPrefab<UnityEngine.Object>(bundleName.ToLower(), MapName, id, this.transform);
|
|
}
|
|
|
|
if (asset == null)
|
|
{
|
|
Debug.LogError($"asset¼ÓÔØʧ°Ü£¬path={MapName}");
|
|
return null;
|
|
}
|
|
|
|
GameObject go = Instantiate(asset, this.transform) as GameObject;
|
|
if (go == null)
|
|
{
|
|
Debug.LogError("LoadPrefabByEditor2. go == null. asset:" + asset);
|
|
|
|
}
|
|
return go;
|
|
}
|
|
}
|
|
}
|
|
|