UI替换与资源初步提交
This commit is contained in:
124
Assets/TcgEngine/Scripts/GameLogic/CardCarousel.cs
Normal file
124
Assets/TcgEngine/Scripts/GameLogic/CardCarousel.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TcgEngine.UI
|
||||
{
|
||||
public class CardCarousel : UIPanel
|
||||
{
|
||||
// 技能名称
|
||||
public Text skillName_text;
|
||||
|
||||
// 技能描述
|
||||
public Text description_text;
|
||||
|
||||
public List<SkillData> skills = new List<SkillData>();
|
||||
|
||||
public Transform SkillDisplayPanel;
|
||||
|
||||
public GameObject cardPrefab;
|
||||
public List<GameObject> cards;
|
||||
|
||||
public float centerScale = 1.2f;
|
||||
public float sideScale = 0.8f;
|
||||
|
||||
public float sideOffset = 200f;
|
||||
|
||||
private int currentIndex = 0;
|
||||
|
||||
[Header("初始化图层顺序")] [SerializeField] private int baseOrder = 25;
|
||||
|
||||
[SerializeField] private Button nextButton;
|
||||
[SerializeField] private Button prevButton;
|
||||
|
||||
[SerializeField] private Button choice_Button;
|
||||
|
||||
void Start()
|
||||
{
|
||||
nextButton.onClick.AddListener(NextCard);
|
||||
prevButton.onClick.AddListener(PrevCard);
|
||||
|
||||
choice_Button.onClick.AddListener(OnChoice);
|
||||
|
||||
InitCard();
|
||||
}
|
||||
|
||||
public void InitCard()
|
||||
{
|
||||
// 清空现有列表
|
||||
skills.Clear();
|
||||
cards.Clear();
|
||||
|
||||
// 后续改成数据传入
|
||||
SkillData[] loadedSkills = Resources.LoadAll<SkillData>("Skill测试用的/Data");
|
||||
|
||||
skills.AddRange(loadedSkills);
|
||||
|
||||
foreach (var skill in skills)
|
||||
{
|
||||
GameObject objec = Instantiate(cardPrefab, SkillDisplayPanel);
|
||||
objec.name = skill.name;
|
||||
var card = objec.GetComponent<SkillCard>();
|
||||
card.skillName = skill.skillName;
|
||||
card.description = skill.description;
|
||||
card.skill_Icon.sprite = skill.icon;
|
||||
card.InitManaConsume(skill.manaCost);
|
||||
|
||||
cards.Add(objec);
|
||||
}
|
||||
|
||||
UpdateCards();
|
||||
}
|
||||
|
||||
private void NextCard()
|
||||
{
|
||||
if (currentIndex < cards.Count - 1)
|
||||
{
|
||||
currentIndex++;
|
||||
UpdateCards();
|
||||
}
|
||||
}
|
||||
|
||||
private void PrevCard()
|
||||
{
|
||||
if (currentIndex > 0)
|
||||
{
|
||||
currentIndex--;
|
||||
UpdateCards();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCards()
|
||||
{
|
||||
for (int i = 0; i < cards.Count; i++)
|
||||
{
|
||||
GameObject card = cards[i];
|
||||
Canvas can = card.GetComponent<Canvas>();
|
||||
|
||||
int distance = Mathf.Abs(i - currentIndex);
|
||||
|
||||
float scale = (i == currentIndex) ? centerScale : sideScale;
|
||||
card.transform.localScale = Vector3.one * scale;
|
||||
|
||||
float x = (i - currentIndex) * sideOffset;
|
||||
card.transform.localPosition = new Vector3(x, 0, 0);
|
||||
|
||||
can.overrideSorting = true;
|
||||
can.sortingOrder = baseOrder + (cards.Count - distance);
|
||||
|
||||
if (i == currentIndex)
|
||||
{
|
||||
var data = cards[i].GetComponent<SkillCard>();
|
||||
skillName_text.text = data.skillName;
|
||||
description_text.text = data.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnChoice()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/TcgEngine/Scripts/GameLogic/CardCarousel.cs.meta
Normal file
11
Assets/TcgEngine/Scripts/GameLogic/CardCarousel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6bc56acb068470469a0dfdf71fba629
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/TcgEngine/Scripts/GameLogic/SkillCard.cs
Normal file
23
Assets/TcgEngine/Scripts/GameLogic/SkillCard.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TcgEngine
|
||||
{
|
||||
public class SkillCard : MonoBehaviour
|
||||
{
|
||||
|
||||
public Sprite[] mana_Consume_Sprite;
|
||||
public Image mp_Image;
|
||||
public string skillName;
|
||||
public string description;
|
||||
public Image skill_Icon;
|
||||
|
||||
public void InitManaConsume(int mana)
|
||||
{
|
||||
mp_Image.sprite = mana_Consume_Sprite[mana];
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/TcgEngine/Scripts/GameLogic/SkillCard.cs.meta
Normal file
11
Assets/TcgEngine/Scripts/GameLogic/SkillCard.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86b2aed19506083498b442e3df316d7f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user