2024-11-08 18:21:41 +08:00

126 lines
2.8 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 string ID => id;
[SerializeField] private string id = "";
[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 (!CanSelected())
{
return false;
}
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 Reset()
{
if (CanSelected())
{
MaterialPropertyBlock mats = new MaterialPropertyBlock();
mats.SetColor("_VeColor",Color.white);
spine.GetComponent<MeshRenderer>().SetPropertyBlock(mats);
}
else
{
MaterialPropertyBlock mats = new MaterialPropertyBlock();
mats.SetColor("_VeColor",Color.gray);
spine.GetComponent<MeshRenderer>().SetPropertyBlock(mats);
}
}
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;
}