149 lines
3.0 KiB
C#
149 lines
3.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using Script;
|
|
using Script.Map;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
//格子脚本,用于获取相邻信息
|
|
public class Grid : MonoBehaviour
|
|
{
|
|
public int X => gx;
|
|
[SerializeField] private int gx;
|
|
public int Y => gy;
|
|
[SerializeField] private int gy;
|
|
public bool Open => gOpen;
|
|
[SerializeField] private bool gOpen=true;
|
|
public Grid East => gEast;
|
|
[SerializeField] private Grid gEast;
|
|
public Grid South => gSouth;
|
|
[SerializeField] private Grid gSouth;
|
|
public Grid West => gWest;
|
|
[SerializeField] private Grid gWest;
|
|
public Grid North => gNorth;
|
|
[SerializeField] private Grid gNorth;
|
|
public bool aniPlay => gAniPlay;
|
|
[SerializeField] private bool gAniPlay=false;
|
|
|
|
public PassengerObject passenger;
|
|
|
|
public Action action = null;
|
|
public Action buttonAction=null;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
GetComponent<Button>().onClick.AddListener(ButtonEvent);
|
|
}
|
|
|
|
public void SetData(int _x,int _y)
|
|
{
|
|
gx = _x;
|
|
gy = _y;
|
|
}
|
|
|
|
public void SetBool(bool bo)
|
|
{
|
|
gOpen= bo;
|
|
}
|
|
|
|
public void SetRestPostion()
|
|
{
|
|
transform.localPosition = new Vector3(X*100, Y * -100,0);
|
|
}
|
|
|
|
|
|
public void SetAdjacentGrid()
|
|
{
|
|
if (X - 1>=0)
|
|
{
|
|
MapManager.ins.MapGrid[X - 1,Y].SetEast(this);
|
|
}
|
|
if (Y - 1>=0)
|
|
{
|
|
MapManager.ins.MapGrid[X,Y - 1].SetSouth(this);
|
|
}
|
|
if (Y + 1<MapManager.ins.y)
|
|
{
|
|
MapManager.ins.MapGrid[X,Y + 1].SetNorth(this);
|
|
}
|
|
if (X + 1<MapManager.ins.x)
|
|
{
|
|
MapManager.ins.MapGrid[X + 1,Y].SetWest(this);
|
|
}
|
|
}
|
|
|
|
public void SetEast(Grid grid)
|
|
{
|
|
gEast = grid;
|
|
}
|
|
public void SetSouth(Grid grid)
|
|
{
|
|
gSouth = grid;
|
|
}
|
|
public void SetWest(Grid grid)
|
|
{
|
|
gWest = grid;
|
|
}
|
|
public void SetNorth(Grid grid)
|
|
{
|
|
gNorth = grid;
|
|
}
|
|
|
|
public bool NorthOpen()
|
|
{
|
|
if (gAniPlay)
|
|
{
|
|
return false;
|
|
}
|
|
if (gNorth==null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return gNorth.passenger==null;
|
|
}
|
|
/// <summary>
|
|
/// 播放当前点动画
|
|
/// </summary>
|
|
public void PassengerAni()
|
|
{
|
|
gAniPlay = true;
|
|
if (passenger!=null)
|
|
{
|
|
passenger.transform.DOMove(transform.position, 0.2f).OnComplete(() =>
|
|
{
|
|
gAniPlay = false;
|
|
action?.Invoke();
|
|
});
|
|
}
|
|
}
|
|
public void ResetPosition()
|
|
{
|
|
|
|
}
|
|
|
|
private void ButtonEvent()
|
|
{
|
|
buttonAction?.Invoke();
|
|
}
|
|
|
|
public void PlaySystemEvent()
|
|
{
|
|
GameManager.ins.MoveWaitEvent(this);
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|