您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
66 行
2.1 KiB
66 行
2.1 KiB
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEngine.UIElements.Experimental;
|
|
|
|
namespace UnityRoyale
|
|
{
|
|
public class CardElement : VisualElement
|
|
{
|
|
// UxmlFactory and UxmlTraits allow UIBuilder to use CardElement as a building block
|
|
public new class UxmlFactory : UxmlFactory<CardElement, UxmlTraits> {}
|
|
public new class UxmlTraits : VisualElement.UxmlTraits {}
|
|
|
|
public CardData cardData { get; private set; }
|
|
|
|
public void Init(CardData cardData)
|
|
{
|
|
this.cardData = cardData;
|
|
var portraitImage = this.Q<VisualElement>("image");
|
|
portraitImage.style.backgroundImage = this.cardData.cardImage.texture;
|
|
}
|
|
|
|
public void ChangeActiveState(bool isActive)
|
|
{
|
|
this.style.opacity = (isActive) ? .05f : 1f;
|
|
}
|
|
|
|
public void MoveAndScaleIntoPosition(int cardSlot, Vector2 position)
|
|
{
|
|
AnimatedMoveTo(position, .2f + (.05f * cardSlot));
|
|
Scale(1f);
|
|
}
|
|
|
|
public void Scale(float ratio)
|
|
{
|
|
transform.scale = Vector3.one * ratio;
|
|
}
|
|
public void AnimatedScale(float endScale, float tweenDuration)
|
|
{
|
|
experimental.animation.Scale(endScale, Mathf.RoundToInt(tweenDuration * 1000)).Ease(Easing.OutQuad);
|
|
}
|
|
|
|
public void MoveTo(Vector2 screenPosition)
|
|
{
|
|
transform.position = new Vector3(screenPosition.x, screenPosition.y, transform.position.z);
|
|
}
|
|
public void AnimatedMoveTo(Vector2 endPosition, float tweenDuration)
|
|
{
|
|
experimental.animation.Position(new Vector3(endPosition.x, endPosition.y, transform.position.z),
|
|
Mathf.RoundToInt(tweenDuration * 1000)).Ease(Easing.OutQuad);
|
|
}
|
|
public void Translate(Vector2 screenPositionDelta)
|
|
{
|
|
transform.position += (Vector3) screenPositionDelta;
|
|
}
|
|
|
|
public void SetAsLastSibling()
|
|
{
|
|
BringToFront();
|
|
}
|
|
|
|
public void Delete()
|
|
{
|
|
RemoveFromHierarchy();
|
|
}
|
|
}
|
|
}
|