2024-10-23 17:55:55 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-10-31 17:38:26 +08:00
|
|
|
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 = "";
|
2024-10-31 17:38:26 +08:00
|
|
|
[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;
|
2024-10-31 17:38:26 +08:00
|
|
|
[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
|
|
|
|
2024-10-31 17:38:26 +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;
|
|
|
|
}
|
2024-10-31 17:38:26 +08:00
|
|
|
if (itemObj.ID!=ID)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemObj.Level!=Level)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2024-11-26 15:44:50 +08:00
|
|
|
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;
|
2024-10-31 17:38:26 +08:00
|
|
|
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();
|
|
|
|
}
|
2024-10-31 17:38:26 +08:00
|
|
|
|
|
|
|
public void ResetSkin()
|
|
|
|
{
|
2024-11-26 15:44:50 +08:00
|
|
|
spine.Skeleton.SetSkin(itemName+"/"+itemName+"_"+(level));
|
2024-10-31 17:38:26 +08:00
|
|
|
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;
|
2024-10-31 17:38:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ResetAni()
|
|
|
|
{
|
2024-11-29 21:37:01 +08:00
|
|
|
spine.state.SetAnimation(0, "b_1", false);
|
2024-10-31 17:38:26 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2024-11-26 15:44:50 +08:00
|
|
|
foreach (var grid in _grids)
|
|
|
|
{
|
|
|
|
grid.ResetWaitWait();
|
|
|
|
}
|
2024-11-04 17:29:11 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MaterialPropertyBlock mats = new MaterialPropertyBlock();
|
|
|
|
mats.SetColor("_VeColor",Color.gray);
|
|
|
|
spine.GetComponent<MeshRenderer>().SetPropertyBlock(mats);
|
2024-11-26 15:44:50 +08:00
|
|
|
|
2024-11-04 17:29:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-31 17:38:26 +08:00
|
|
|
public void ResetOrder()
|
|
|
|
{
|
|
|
|
if (_grids.Any(grid => grid.GetItemObj() != this))
|
|
|
|
{
|
2024-11-21 09:35:48 +08:00
|
|
|
spine.GetComponent<MeshRenderer>().sortingOrder = orderIndexSet;
|
2024-10-31 17:38:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-21 09:35:48 +08:00
|
|
|
spine.GetComponent<MeshRenderer>().sortingOrder = orderIndexSet;
|
2024-10-31 17:38:26 +08:00
|
|
|
}
|
|
|
|
|
2024-11-26 15:44:50 +08:00
|
|
|
public void SetOrder(int order)
|
|
|
|
{
|
|
|
|
spine.GetComponent<MeshRenderer>().sortingOrder = order;
|
|
|
|
}
|
|
|
|
|
2024-10-31 17:38:26 +08:00
|
|
|
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-31 17:38:26 +08:00
|
|
|
}
|
|
|
|
|
2024-10-23 17:55:55 +08:00
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
2024-10-31 17:38:26 +08:00
|
|
|
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;
|
|
|
|
}
|