战斗场景UI修改
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -42,7 +42,7 @@ namespace TcgEngine.Client
|
||||
Player player = opponent ? GameClient.Get().GetOpponentPlayer() : GameClient.Get().GetPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
|
||||
// 获取卡背数据,如果为空则使用默认路径
|
||||
CardbackData cb = CardbackData.Get(player.cardback);
|
||||
if (deck_render != null)
|
||||
@@ -50,6 +50,7 @@ namespace TcgEngine.Client
|
||||
if (cb != null)
|
||||
{
|
||||
deck_render.sprite = cb.GetDeck();
|
||||
deck_render.gameObject.transform.localScale = Vector3.one * 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -27,6 +27,9 @@ namespace TcgEngine.UI
|
||||
public Animator timeout_animator;
|
||||
public AudioClip timeout_audio;
|
||||
|
||||
public Text player_prompt_text;
|
||||
public Text opponent_prompt_text;
|
||||
|
||||
private float selector_timer = 0f;
|
||||
private float end_turn_timer = 0f;
|
||||
private int prev_time_val = 0;
|
||||
@@ -76,7 +79,12 @@ namespace TcgEngine.UI
|
||||
end_turn_button.interactable = yourturn && end_turn_timer > 1f;
|
||||
end_turn_timer += Time.deltaTime;
|
||||
selector_timer += Time.deltaTime;
|
||||
|
||||
|
||||
// 提示玩家
|
||||
player_prompt_text.text = yourturn ? "正在行动" : "正在等待";
|
||||
opponent_prompt_text.text = yourturn ? "正在等待" : "正在行动";
|
||||
|
||||
|
||||
//Timer
|
||||
turn_count.text = "回合 " + data.turn_count.ToString();
|
||||
turn_timer.enabled = data.turn_timer > 0f;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -13,12 +15,14 @@ namespace TcgEngine.UI
|
||||
public class IconBar : MonoBehaviour
|
||||
{
|
||||
public int value = 0;
|
||||
public int max_value = 4;
|
||||
public int max_value = 10;
|
||||
public bool auto_refresh = true;
|
||||
|
||||
public Image[] icons;
|
||||
public Sprite sprite_full;
|
||||
public Sprite sprite_empty;
|
||||
public List<Image> icons;
|
||||
public Sprite mana_icon_true;
|
||||
public Sprite mana_icon_false;
|
||||
public GameObject mana_gem;
|
||||
public Transform mana_magic_slot;
|
||||
|
||||
[Header("Value Display")]
|
||||
public Text value_text; // 显示当前法力值数字的文本组件
|
||||
@@ -26,7 +30,24 @@ namespace TcgEngine.UI
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InitManaData();
|
||||
}
|
||||
|
||||
private void InitManaData()
|
||||
{
|
||||
icons.Clear();
|
||||
for (int i = 0; i < max_value; i++)
|
||||
{
|
||||
GameObject item = Instantiate(mana_gem, mana_magic_slot);
|
||||
item.name = $"mana--{i}";
|
||||
var img = item.GetComponent<Image>();
|
||||
icons.Add(img);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -39,16 +60,14 @@ namespace TcgEngine.UI
|
||||
{
|
||||
if (icons == null)
|
||||
return;
|
||||
|
||||
int index = 0;
|
||||
foreach (Image icon in icons)
|
||||
|
||||
for (int i = 0; i < icons.Count; i++)
|
||||
{
|
||||
if (icon == null)
|
||||
if (icons[i] == null)
|
||||
continue;
|
||||
|
||||
icon.gameObject.SetActive(index < value || index < max_value);
|
||||
icon.sprite = (index < value) ? sprite_full : sprite_empty;
|
||||
index++;
|
||||
|
||||
// 前 value 个点亮,后面的变灰
|
||||
icons[i].sprite = (i < value) ? mana_icon_true : mana_icon_false;
|
||||
}
|
||||
|
||||
// 更新法力值数字文本
|
||||
@@ -59,26 +78,7 @@ namespace TcgEngine.UI
|
||||
{
|
||||
if (value_text != null)
|
||||
{
|
||||
value_text.text = string.Format(value_format, value);
|
||||
}
|
||||
}
|
||||
|
||||
// 手动设置值并更新文本
|
||||
public void SetValue(int new_value)
|
||||
{
|
||||
value = new_value;
|
||||
UpdateValueText();
|
||||
}
|
||||
|
||||
public void SetMat(Material mat)
|
||||
{
|
||||
if (icons == null)
|
||||
return;
|
||||
|
||||
foreach (Image icon in icons)
|
||||
{
|
||||
if (icon != null)
|
||||
icon.material = mat;
|
||||
value_text.text = string.Format(value_format, value + "/10");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user