161 lines
3.6 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-11-08 18:21:41 +08:00
// using Unity.VisualScripting;
2024-10-23 17:55:55 +08:00
using UnityEngine;
public class ItemObj : MonoBehaviour
{
public ItemSize itemSize => size;
2024-10-24 16:54:32 +08:00
public GridType type = GridType.wait;
2024-11-08 18:21:41 +08:00
public string ID => id;
[SerializeField] private string id = "";
[SerializeField] private int maxLevel = 4;
[SerializeField] private string itemName;
2024-11-04 17:29:11 +08:00
public int Level => level;//等级
2024-10-29 15:22:32 +08:00
[SerializeField] private int level = 0;
2024-11-04 17:29:11 +08:00
[SerializeField] private ItemSize size;//物体大小
2024-10-23 17:55:55 +08:00
[SerializeField] public List<Grid> _grids;
[SerializeField] private SkeletonAnimation spine;
2024-11-04 17:29:11 +08:00
public Grid startGrid;//开始坐标
2024-10-23 17:55:55 +08:00
public Vector3 dev;
2024-10-29 15:22:32 +08:00
public Vector3 mouseDev;
2024-11-21 09:35:48 +08:00
public int orderIndexSet = 1;
public int itemID = 0;
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
{
2024-11-04 17:29:11 +08:00
if (!CanSelected())
{
return false;
}
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++;
2024-11-21 09:35:48 +08:00
var itemData = JsonTab.Instance.tables.Prop.Get(itemID);
itemID = itemData.NextLevelID;
ResetSkin();
ResetAni();
2024-11-21 09:35:48 +08:00
GameManager.ins.ResetPropattributes();
2024-10-29 15:22:32 +08:00
return true;
}
2024-11-21 09:35:48 +08:00
/// <summary>
/// 设置等级和id
/// </summary>
/// <param name="saveLevel"></param>
/// <param name="saveItemID"></param>
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();
2024-11-21 09:35:48 +08:00
}
/// <summary>
/// 层级计算
/// </summary>
/// <returns></returns>
public int OrderIndex()
{
int order = 0;
foreach (var grid in _grids)
{
if (order<grid.stackItem.Count)
{
order = grid.stackItem.Count;
}
}
return order;
}
private void ResetAni()
{
spine.state.SetAnimation(0, "a_1", false);
}
2024-11-04 17:29:11 +08:00
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))
{
2024-11-21 09:35:48 +08:00
spine.GetComponent<MeshRenderer>().sortingOrder = orderIndexSet;
return;
}
2024-11-21 09:35:48 +08:00
spine.GetComponent<MeshRenderer>().sortingOrder = orderIndexSet;
}
public bool CanSelected()
{
foreach (var grid in _grids)
{
if (grid.GetItemObj() != this)
{
return false;
}
}
return true;
}
private void Awake()
{
2024-11-04 17:29:11 +08:00
}
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;
}