110 lines
2.7 KiB
C#
110 lines
2.7 KiB
C#
using System;
|
|
using AibisDream.Framework;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
[RequireComponent(typeof(Collider2D))]
|
|
public class CoolingBottle : MonoBehaviour, IMoveable
|
|
{
|
|
private const float SnapMoveTime = 0.3f;
|
|
private static readonly Vector2 VerticalBox = new(1, 3.11f);
|
|
private static readonly Vector2 HorizontalBox = new(4.7f, 1.65f);
|
|
|
|
public CoolingBottleData data;
|
|
|
|
#region 引用
|
|
|
|
private BoxCollider2D _collider;
|
|
|
|
private SpriteRenderer _verticalSprite;
|
|
private SpriteRenderer _horizontalSprite;
|
|
|
|
public BottleSlot curSnapSlot;
|
|
public BottleSlot targetSnapSlot;
|
|
|
|
#endregion
|
|
|
|
private void Awake()
|
|
{
|
|
InitRefs();
|
|
}
|
|
|
|
private void InitRefs()
|
|
{
|
|
_collider = GetComponent<BoxCollider2D>();
|
|
_collider.size = VerticalBox;
|
|
|
|
_verticalSprite = transform.Find("竖立图片").GetComponent<SpriteRenderer>();
|
|
_horizontalSprite = transform.Find("水平图片").GetComponent<SpriteRenderer>();
|
|
}
|
|
|
|
#region
|
|
|
|
public void LiquidDown()
|
|
{
|
|
}
|
|
|
|
public void LiquidUp()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 移动逻辑
|
|
|
|
public bool IsBlock { get; set; }
|
|
|
|
public void StartMove()
|
|
{
|
|
}
|
|
|
|
public void Move(Vector2 mousePos)
|
|
{
|
|
transform.position = mousePos;
|
|
}
|
|
|
|
public void StopMove()
|
|
{
|
|
if (targetSnapSlot)
|
|
{
|
|
curSnapSlot = targetSnapSlot;
|
|
}
|
|
|
|
targetSnapSlot = null;
|
|
|
|
// 吸附到目标位置
|
|
transform.DOMove(curSnapSlot.transform.position, SnapMoveTime);
|
|
curSnapSlot.InsertSlot(this);
|
|
// TODO 停止描边
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换碰撞箱形状
|
|
/// </summary>
|
|
/// <param name="isVertical">是否水平</param>
|
|
public void SwitchColliderSize(bool isVertical)
|
|
{
|
|
_collider.size = isVertical ? VerticalBox : HorizontalBox;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void Load(CoolingBottleData targetData)
|
|
{
|
|
data = targetData;
|
|
_verticalSprite.sprite = ResourceKit.LoadSpriteFromPsd($"Art/Fix/Cooling/冷却系统/{data.verticalSprite}");
|
|
_horizontalSprite.sprite = ResourceKit.LoadSpriteFromPsd($"Art/Fix/Cooling/冷却系统/{data.horizontalSprite}");
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public struct CoolingBottleData
|
|
{
|
|
public string name;
|
|
public string description;
|
|
public string verticalSprite;
|
|
public string horizontalSprite;
|
|
}
|
|
} |