(client) feat:添加角色定义,为匿名定义建立索引,修复一些数据定义中的错误 (#39)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
80
Client/Assets/Scripts/UI/DevMenuUI.cs
Normal file
80
Client/Assets/Scripts/UI/DevMenuUI.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class DevMenuUI : MonoBehaviour
|
||||
{
|
||||
public GameObject menuContent;
|
||||
|
||||
public Prefab.TextPrefab textTemplate;
|
||||
public Prefab.ButtonPrefab buttonTemplate;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
Managers.DefineManager.Instance.Init();
|
||||
InitEvent();
|
||||
InitCharacter();
|
||||
}
|
||||
void InitEvent()
|
||||
{
|
||||
var title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "事件菜单";
|
||||
// for (int i = 0; i < 30; i++)
|
||||
// {
|
||||
// var button= InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
// button.text.text = i.ToString();
|
||||
// }
|
||||
}
|
||||
|
||||
void InitCharacter()
|
||||
{
|
||||
var title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "点击切换人物";
|
||||
|
||||
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.CharacterDef>();
|
||||
foreach (var def in defList)
|
||||
{
|
||||
var button=InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
button.Label = def.label;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 通用的实例化函数,返回实例化的预制件脚本组件。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">预制件脚本的类型</typeparam>
|
||||
/// <param name="prefab">要实例化的预制件</param>
|
||||
/// <param name="parent">实例化对象的父对象</param>
|
||||
/// <returns>实例化的预制件脚本组件</returns>
|
||||
T InstantiatePrefab<T>(T prefab, Transform parent) where T : Component
|
||||
{
|
||||
if (prefab == null || parent == null)
|
||||
{
|
||||
Debug.LogError("Prefab or parent is null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 实例化预制件
|
||||
GameObject instance = Instantiate(prefab.gameObject, parent);
|
||||
|
||||
// 获取实例化对象的脚本组件
|
||||
T instantiatedComponent = instance.GetComponent<T>();
|
||||
|
||||
if (instantiatedComponent == null)
|
||||
{
|
||||
Debug.LogError($"Failed to get component of type {typeof(T).Name} from the instantiated prefab!");
|
||||
}
|
||||
|
||||
return instantiatedComponent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
2
Client/Assets/Scripts/UI/DevMenuUI.cs.meta
Normal file
2
Client/Assets/Scripts/UI/DevMenuUI.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c83e72721411938449d92dd48c76480d
|
Reference in New Issue
Block a user