Files
valheim/Assets/_Valheim/Scripts/Laboratory/StartCard.cs

113 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using DarkTonic.MasterAudio;
using DG.Tweening;
using TMPro;
using UnityEngine;
using UnityEngine.UIElements;
using Valheim;
public class StartCard : MonoBehaviour
{
public int cardId;
public GameObject outLight;
public GameObject descUI;
public TMP_Text nameTxt,attributeTxt,habitTxt;
public GameObject[] stars;
private bool _isRotate;
public SpriteRenderer handSprite;
[SoundGroup] public string selectedSound;
public void Init()
{
outLight.SetActive(false);
descUI.SetActive(false);
_isRotate = true;
SetData();
}
public void SetData()
{
var data=GameManager.Ins.EnemyDataList[cardId];
string skillStr = "";
foreach (var skillId in data.SkillIds)
{
skillStr += GameManager.Ins.SkillDataList[skillId].SkillName + " ";
}
nameTxt.text = data.Name;
//attributeTxt.text = data.Attribute;
habitTxt.text = skillStr;
for (int i = 0; i < stars.Length; i++)
{
stars[i].SetActive(i<=data.EnemyType);
}
handSprite.sprite = Resources.Load<Sprite>("Texture/PetIcon/" + cardId);
}
private void Update()
{
if (_isRotate)
{
transform.Rotate(0, 50 * Time.deltaTime, 0);
}
}
public void Up()
{
if(cardId== GameManager.Ins.selectCardId)
return;
MasterAudio.PlaySound3DFollowTransform(selectedSound, transform);
_isRotate = false;
transform.localScale*=1.2f;
outLight.SetActive(true);
descUI.SetActive(true);
GameManager.Ins.selectCardId = cardId;
}
public void Down()
{
_isRotate = true;
outLight.SetActive(false);
transform.localScale=new Vector3(10f,10f,1f);
descUI.SetActive(false);
GameManager.Ins.selectCardId = -1;
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Weapon"))
{
//Up();
// 打印触碰对象信息
Debug.Log($"触碰到卡牌卡牌ID: {cardId}");
Debug.Log($"触碰物体: {other.gameObject.name}, 位置: {other.transform.position}");
GetCard();
}
}
public void GetCard()
{
GameManager.Ins.selectCardId = cardId;
GameManager.Ins.SelectCard();
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Weapon"))
{
//Down();
}
}
public void Show()
{
gameObject.SetActive(true);
Up();
}
}