105 lines
2.2 KiB
C#
105 lines
2.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Spine.Unity;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class ItemObj : MonoBehaviour
|
|
{
|
|
public ItemSize itemSize => size;
|
|
public GridType type = GridType.wait;
|
|
public int ID => id;
|
|
[SerializeField] private int id = 0;
|
|
[SerializeField] private int maxLevel = 4;
|
|
[SerializeField] private string itemName;
|
|
public int Level => level;
|
|
[SerializeField] private int level = 0;
|
|
[SerializeField] private ItemSize size;
|
|
|
|
[SerializeField] public List<Grid> _grids;
|
|
[SerializeField] private SkeletonAnimation spine;
|
|
public Grid startGrid;
|
|
public Vector3 dev;
|
|
public Vector3 mouseDev;
|
|
|
|
public void SetOccGrid(List<Grid> _list)
|
|
{
|
|
_grids = _list;
|
|
}
|
|
|
|
public bool LevelUp(ItemObj itemObj)
|
|
{
|
|
if (itemObj.ID!=ID)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (itemObj.Level!=Level)
|
|
{
|
|
return false;
|
|
}
|
|
if (level + 1 >= maxLevel) return false;
|
|
level++;
|
|
ResetSkin();
|
|
ResetAni();
|
|
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()
|
|
{
|
|
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
ResetSkin();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class ItemSize
|
|
{
|
|
public int x = 1;
|
|
public int y = 1;
|
|
} |