UI替换与对应代码进行调整

This commit is contained in:
YiHan0621
2025-09-13 16:25:35 +08:00
parent fe0b8cec77
commit db68c377bd
106 changed files with 6559 additions and 1151 deletions

View File

@@ -14,7 +14,7 @@ namespace TcgEngine.UI
{
public string group;
public bool active;
// public GameObject highlight;
public GameObject highlight;
public UIPanel ui_panel;
public UnityAction onClick;
@@ -47,8 +47,8 @@ namespace TcgEngine.UI
void Update()
{
// if (highlight != null)
// highlight.SetActive(active);
if (highlight != null)
highlight.SetActive(active);
}
private void OnClick()

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace TcgEngine.UI
{
public class ToggleImage : MonoBehaviour
{
public Sprite onSprite;
public Sprite offSprite;
private Button _button;
private Image _image;
private bool _isShowOnSprite = false;
private void Awake()
{
_button = GetComponent<Button>();
if (_button != null)
{
_button.onClick.AddListener(SwitchButtonStatus);
_image = _button.GetComponent<Image>();
}
else
{
Debug.LogError("请检查是否存在按钮!");
}
}
private void SwitchButtonStatus()
{
_isShowOnSprite = !_isShowOnSprite;
_image.sprite = _isShowOnSprite ? onSprite : offSprite;
}
public bool GetButtonStatus()
{
return _isShowOnSprite;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59aa0138a79f8154991279d70c301fb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -15,6 +15,12 @@ namespace TcgEngine.UI
public Color on_color = Color.yellow;
public Color off_color = Color.white;
public int on_size = 42;
public int off_size = 36;
[Header("判断启用文字颜色选中还是文字大小选中")]
public bool is_color = true;
private Toggle toggle;
private Text toggle_txt;
@@ -28,6 +34,8 @@ namespace TcgEngine.UI
private void Start()
{
on_size = toggle_txt.fontSize;
off_size = (int)(toggle_txt.fontSize * 0.8f);
Refresh();
}
@@ -39,8 +47,17 @@ namespace TcgEngine.UI
private void Refresh()
{
toggle_txt.color = toggle.isOn ? on_color : off_color;
if (is_color)
{
toggle_txt.color = toggle.isOn ? on_color : off_color;
}
else
{
toggle_txt.fontSize = toggle.isOn ? on_size : off_size;
toggle_txt.fontStyle = toggle.isOn ? FontStyle.Bold : FontStyle.Normal;
}
previous = toggle.isOn;
}
}
}