146 lines
2.9 KiB
C#
Raw Normal View History

2024-10-22 09:17:28 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2024-10-22 11:31:23 +08:00
using DG.Tweening;
using Script;
2024-10-22 09:17:28 +08:00
using Script.Map;
using UnityEngine;
2024-10-22 11:31:23 +08:00
using UnityEngine.UI;
2024-10-22 09:17:28 +08:00
2024-10-22 11:31:23 +08:00
//格子脚本,用于获取相邻信息
2024-10-22 09:17:28 +08:00
public class Grid : MonoBehaviour
{
2024-10-22 11:31:23 +08:00
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);
}
2024-10-22 09:17:28 +08:00
public void SetData(int _x,int _y)
{
2024-10-22 11:31:23 +08:00
gx = _x;
gy = _y;
2024-10-22 09:17:28 +08:00
}
public void SetBool(bool bo)
{
2024-10-22 11:31:23 +08:00
gOpen= bo;
2024-10-22 09:17:28 +08:00
}
public void SetRestPostion()
{
2024-10-22 11:31:23 +08:00
transform.localPosition = new Vector3(X*100, Y * -100,0);
2024-10-22 09:17:28 +08:00
}
public void SetAdjacentGrid()
{
2024-10-22 11:31:23 +08:00
if (X - 1>=0)
2024-10-22 09:17:28 +08:00
{
2024-10-22 11:31:23 +08:00
MapManager.ins.MapGrid[X - 1,Y].SetEast(this);
2024-10-22 09:17:28 +08:00
}
2024-10-22 11:31:23 +08:00
if (Y - 1>=0)
2024-10-22 09:17:28 +08:00
{
2024-10-22 11:31:23 +08:00
MapManager.ins.MapGrid[X,Y - 1].SetSouth(this);
2024-10-22 09:17:28 +08:00
}
2024-10-22 11:31:23 +08:00
if (Y + 1<MapManager.ins.y)
2024-10-22 09:17:28 +08:00
{
2024-10-22 11:31:23 +08:00
MapManager.ins.MapGrid[X,Y + 1].SetNorth(this);
2024-10-22 09:17:28 +08:00
}
2024-10-22 11:31:23 +08:00
if (X + 1<MapManager.ins.x)
2024-10-22 09:17:28 +08:00
{
2024-10-22 11:31:23 +08:00
MapManager.ins.MapGrid[X + 1,Y].SetWest(this);
2024-10-22 09:17:28 +08:00
}
}
public void SetEast(Grid grid)
{
2024-10-22 11:31:23 +08:00
gEast = grid;
2024-10-22 09:17:28 +08:00
}
public void SetSouth(Grid grid)
{
2024-10-22 11:31:23 +08:00
gSouth = grid;
2024-10-22 09:17:28 +08:00
}
public void SetWest(Grid grid)
{
2024-10-22 11:31:23 +08:00
gWest = grid;
2024-10-22 09:17:28 +08:00
}
public void SetNorth(Grid grid)
{
2024-10-22 11:31:23 +08:00
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;
passenger.transform.DOMove(transform.position, 0.2f).OnComplete(() =>
{
gAniPlay = false;
action?.Invoke();
});
2024-10-22 09:17:28 +08:00
}
public void ResetPosition()
{
}
2024-10-22 11:31:23 +08:00
private void ButtonEvent()
{
buttonAction?.Invoke();
}
public void PlaySystemEvent()
{
GameManager.ins.MoveWaitEvent(this);
}
2024-10-22 09:17:28 +08:00
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}