(client) feat:右键菜单全局与UI分离,Building生成支持,双层地图重写
This commit is contained in:
@ -25,6 +25,7 @@ namespace UI
|
||||
InitEvent();
|
||||
InitCharacter();
|
||||
InitMonster();
|
||||
InitBuilding();
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +33,10 @@ namespace UI
|
||||
{
|
||||
var title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "事件菜单";
|
||||
|
||||
title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "未定义任何事件";
|
||||
title.text.color = Color.red;
|
||||
// for (int i = 0; i < 30; i++)
|
||||
// {
|
||||
// var button= InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
@ -46,6 +51,36 @@ namespace UI
|
||||
title.Label = "生成人物";
|
||||
|
||||
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.CharacterDef>();
|
||||
if (defList == null || defList.Length == 0)
|
||||
{
|
||||
title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "未定义任何角色";
|
||||
title.text.color = Color.red;
|
||||
}
|
||||
else
|
||||
foreach (var def in defList)
|
||||
{
|
||||
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
button.Label = def.label;
|
||||
var pawnDef = def;
|
||||
button.AddListener(() => GenerateEntityCallback(pawnDef));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void InitMonster()
|
||||
{
|
||||
var title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "生成怪物";
|
||||
|
||||
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.MonsterDef>();
|
||||
if (defList == null || defList.Length == 0)
|
||||
{
|
||||
title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "未定义任何怪物";
|
||||
title.text.color = Color.red;
|
||||
}
|
||||
else
|
||||
foreach (var def in defList)
|
||||
{
|
||||
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
@ -55,19 +90,26 @@ namespace UI
|
||||
}
|
||||
}
|
||||
|
||||
private void InitMonster()
|
||||
private void InitBuilding()
|
||||
{
|
||||
var title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "生成怪物";
|
||||
title.Label = "生成建筑";
|
||||
|
||||
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.MonsterDef>();
|
||||
foreach (var def in defList)
|
||||
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.BuildingDef>();
|
||||
if (defList == null || defList.Length == 0)
|
||||
{
|
||||
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
button.Label = def.label;
|
||||
var pawnDef = def;
|
||||
button.AddListener(() => GenerateEntityCallback(pawnDef));
|
||||
title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "未定义任何建筑";
|
||||
title.text.color = Color.red;
|
||||
}
|
||||
else
|
||||
foreach (var def in defList)
|
||||
{
|
||||
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
button.Label = def.label;
|
||||
var pawnDef = def;
|
||||
button.AddListener(() => GenerateBuildingCallback(pawnDef));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,13 +145,21 @@ namespace UI
|
||||
{
|
||||
entityPlacementUI.currentAction = () =>
|
||||
{
|
||||
// 将鼠标屏幕坐标转换为世界坐标,并确保 Z 值为 0
|
||||
if (!Camera.main) return;
|
||||
var worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
worldPosition.z = 0;
|
||||
Managers.EntityManage.Instance.GenerateEntity(pawnDef, worldPosition);
|
||||
Managers.EntityManage.Instance.GenerateEntity(pawnDef, Utils.MousePosition.GetWorldPosition());
|
||||
};
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{pawnDef.label}\n描述:{pawnDef.description}";
|
||||
entityPlacementUI.snapEnabled = false;
|
||||
Base.UIInputControl.Instance.Show(entityPlacementUI);
|
||||
}
|
||||
|
||||
private void GenerateBuildingCallback(BuildingDef def)
|
||||
{
|
||||
entityPlacementUI.currentAction = () =>
|
||||
{
|
||||
Managers.EntityManage.Instance.GenerateBuildingEntity(def, Utils.MousePosition.GetSnappedWorldPosition());
|
||||
};
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{def.label}\n描述:{def.description}";
|
||||
entityPlacementUI.snapEnabled = true;
|
||||
Base.UIInputControl.Instance.Show(entityPlacementUI);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user