163 lines
3.6 KiB
C#
163 lines
3.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Spine.Unity;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
/// <summary>
|
|
/// 格子数据
|
|
/// </summary>
|
|
public class Grid : MonoBehaviour
|
|
{
|
|
public GridType Type;
|
|
public int X => gX;
|
|
[SerializeField] private int gX;
|
|
public int Y => gY;
|
|
[SerializeField] private int gY;
|
|
public SkeletonAnimation Spine => spine;
|
|
[SerializeField] private SkeletonAnimation spine;
|
|
public bool unLock => gridLock;
|
|
[SerializeField] private bool gridLock = true;
|
|
public ItemObj item;
|
|
public Stack<ItemObj> stackItem=new Stack<ItemObj>();
|
|
[SerializeField] private GameObject back;
|
|
[SerializeField] private GameObject backGrid;
|
|
|
|
public void SetData(int lx,int ly)
|
|
{
|
|
gX = lx;
|
|
gY = ly;
|
|
}
|
|
|
|
public void SetLock(bool gLock)
|
|
{
|
|
gridLock = gLock;
|
|
back.SetActive(false);
|
|
backGrid.SetActive(false);
|
|
if (gLock)
|
|
{
|
|
spine.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
spine.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
public void SaveItemObj(ItemObj itemObj)
|
|
{
|
|
stackItem.Push(itemObj);
|
|
}
|
|
|
|
public ItemObj itemObj()
|
|
{
|
|
RemoveNullStack();
|
|
if (stackItem.Count==0)
|
|
{
|
|
return null;
|
|
}
|
|
return stackItem.Peek();
|
|
}
|
|
|
|
public void RemoveNullStack()
|
|
{
|
|
if (stackItem.Count>0&&stackItem.Peek()==null)
|
|
{
|
|
stackItem.Pop();
|
|
RemoveNullStack();
|
|
}
|
|
}
|
|
|
|
public ItemObj Pop()
|
|
{
|
|
return stackItem.Pop();
|
|
}
|
|
|
|
public void PlayEnterAnimation()
|
|
{
|
|
if (spine.AnimationName!="play_1")
|
|
{
|
|
spine.AnimationState.SetAnimation(0, "play_1", false);
|
|
}
|
|
}
|
|
|
|
public void PlayExitAnimation()
|
|
{
|
|
if (spine.AnimationName!="play_2")
|
|
{
|
|
spine.AnimationState.SetAnimation(0, "play_2", false);
|
|
}
|
|
}
|
|
|
|
public void ResetBack(int index)
|
|
{
|
|
if (!gridLock)
|
|
{
|
|
switch (index)
|
|
{
|
|
case 0:
|
|
back.SetActive(true);
|
|
backGrid.SetActive(false);
|
|
break;
|
|
case 1:
|
|
back.SetActive(false);
|
|
backGrid.SetActive(true);
|
|
break;
|
|
case 2:
|
|
back.SetActive(false);
|
|
backGrid.SetActive(false);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnMouseEnter()
|
|
{
|
|
GameManager.ins.stopGrid = this;
|
|
}
|
|
|
|
private void OnMouseExit()
|
|
{
|
|
if (GameManager.ins.stopGrid==this)
|
|
{
|
|
GameManager.ins.stopGrid = null;
|
|
}
|
|
}
|
|
|
|
public ItemObj GetItemObj()
|
|
{
|
|
return Type switch
|
|
{
|
|
GridType.box => item,
|
|
GridType.wait => itemObj(),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
switch (Type)
|
|
{
|
|
case GridType.box:
|
|
if (item!=null&& item.CanSelected())
|
|
{
|
|
GameManager.ins.seletObj = item;
|
|
}
|
|
break;
|
|
case GridType.wait:
|
|
if (itemObj()!=null && itemObj().CanSelected())
|
|
{
|
|
GameManager.ins.seletObj = itemObj();
|
|
}
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum GridType
|
|
{
|
|
box,
|
|
wait
|
|
} |