(client)feat:实现子弹定义以及生成,实现初始化动画,实现血条 (#43)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
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>
|
||||
@ -99,17 +141,25 @@ namespace UI
|
||||
return instantiatedComponent;
|
||||
}
|
||||
|
||||
private void GenerateEntityCallback(PawnDef pawnDef)
|
||||
private void GenerateEntityCallback(EntityDef entityDef)
|
||||
{
|
||||
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(entityDef, Utils.MousePosition.GetWorldPosition());
|
||||
};
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{pawnDef.label}\n描述:{pawnDef.description}";
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{entityDef.label}\n描述:{entityDef.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);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ namespace UI
|
||||
|
||||
public NonReturnCallback currentAction;
|
||||
|
||||
public GameObject focusBox;
|
||||
public bool snapEnabled = false;
|
||||
|
||||
public string Prompt
|
||||
{
|
||||
get => promptText.text;
|
||||
@ -30,7 +33,28 @@ namespace UI
|
||||
{
|
||||
currentAction();
|
||||
}
|
||||
|
||||
if (snapEnabled)
|
||||
{
|
||||
focusBox.transform.position = Utils.MousePosition.GetSnappedWorldPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
focusBox.transform.position = Utils.MousePosition.GetWorldPosition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
focusBox.SetActive(true);
|
||||
}
|
||||
|
||||
override public void Hide()
|
||||
{
|
||||
base.Hide();
|
||||
focusBox.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user