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 _grids; [SerializeField] private SkeletonAnimation spine; public Grid startGrid;//开始坐标 public Vector3 dev; public Vector3 mouseDev; public int orderIndexSet = 1; public int itemID = 0; public void SetOccGrid(List _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++; var itemData = JsonTab.Instance.tables.Prop.Get(itemID); itemID = itemData.NextLevelID; ResetSkin(); ResetAni(); GameManager.ins.ResetPropattributes(); return true; } /// /// 设置等级和id /// /// /// public void SetLevel(int saveLevel,int saveItemID) { level = saveLevel; itemID = saveItemID; ResetSkin(); ResetAni(); } public void ResetSkin() { spine.Skeleton.SetSkin(itemName+"/"+itemName+"_"+(level+1)); spine.Skeleton.SetSlotsToSetupPose(); } /// /// 层级计算 /// /// public int OrderIndex() { int order = 0; foreach (var grid in _grids) { if (order().SetPropertyBlock(mats); } else { MaterialPropertyBlock mats = new MaterialPropertyBlock(); mats.SetColor("_VeColor",Color.gray); spine.GetComponent().SetPropertyBlock(mats); } } public void ResetOrder() { if (_grids.Any(grid => grid.GetItemObj() != this)) { spine.GetComponent().sortingOrder = orderIndexSet; return; } spine.GetComponent().sortingOrder = orderIndexSet; } 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; }