105 lines
2.2 KiB
C#
Raw Normal View History

2024-10-23 17:55:55 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Spine.Unity;
2024-10-23 17:55:55 +08:00
using Unity.VisualScripting;
using UnityEngine;
public class ItemObj : MonoBehaviour
{
public ItemSize itemSize => size;
2024-10-24 16:54:32 +08:00
public GridType type = GridType.wait;
2024-10-29 15:22:32 +08:00
public int ID => id;
[SerializeField] private int id = 0;
[SerializeField] private int maxLevel = 4;
[SerializeField] private string itemName;
2024-10-29 15:22:32 +08:00
public int Level => level;
[SerializeField] private int level = 0;
2024-10-23 17:55:55 +08:00
[SerializeField] private ItemSize size;
[SerializeField] public List<Grid> _grids;
[SerializeField] private SkeletonAnimation spine;
2024-10-23 17:55:55 +08:00
public Grid startGrid;
public Vector3 dev;
2024-10-29 15:22:32 +08:00
public Vector3 mouseDev;
2024-10-23 17:55:55 +08:00
public void SetOccGrid(List<Grid> _list)
{
_grids = _list;
}
2024-10-29 15:22:32 +08:00
public bool LevelUp(ItemObj itemObj)
2024-10-29 15:22:32 +08:00
{
if (itemObj.ID!=ID)
{
return false;
}
if (itemObj.Level!=Level)
{
return false;
}
if (level + 1 >= maxLevel) return false;
2024-10-29 15:22:32 +08:00
level++;
ResetSkin();
ResetAni();
2024-10-29 15:22:32 +08:00
return true;
}
public void ResetSkin()
{
spine.Skeleton.SetSkin(itemName+"/"+itemName+"_"+(level+1));
spine.Skeleton.SetSlotsToSetupPose();
}
private void ResetAni()
{
spine.state.SetAnimation(0, "a_1", false);
}
public void ResetOrder()
{
if (_grids.Any(grid => grid.GetItemObj() != this))
{
spine.GetComponent<MeshRenderer>().sortingOrder = 1;
return;
}
spine.GetComponent<MeshRenderer>().sortingOrder = 2;
}
public bool CanSelected()
{
foreach (var grid in _grids)
{
if (grid.GetItemObj() != this)
{
return false;
}
}
return true;
}
private void Awake()
{
}
2024-10-23 17:55:55 +08:00
// Start is called before the first frame update
void Start()
{
ResetSkin();
2024-10-23 17:55:55 +08:00
}
// Update is called once per frame
void Update()
{
}
}
[Serializable]
public class ItemSize
{
public int x = 1;
public int y = 1;
}