57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using AibisDream.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class AirGate : MonoBehaviour, IMoveable
|
|
{
|
|
private EngineSystem _engineSystem;
|
|
|
|
[SerializeField] private int _curLevel;
|
|
|
|
[SerializeField] private float heightY;
|
|
|
|
private Vector3 _offset;
|
|
|
|
private void Awake()
|
|
{
|
|
_engineSystem = transform.parent.GetComponent<EngineSystem>();
|
|
_offset = transform.position;
|
|
}
|
|
|
|
public void StartMove()
|
|
{
|
|
Debug.Log("Move");
|
|
}
|
|
|
|
public void Move(Vector2 mousePos)
|
|
{
|
|
SwitchAirLevel(mousePos.y);
|
|
UpdateTransform();
|
|
_engineSystem.UpdateAirLevel(_curLevel);
|
|
}
|
|
|
|
private void UpdateTransform()
|
|
{
|
|
float levelHeight = heightY / (_engineSystem.maxLevel - 1);
|
|
var curY = levelHeight * _curLevel + _offset.y;
|
|
transform.position = new Vector3(transform.position.x, curY, transform.position.z);
|
|
}
|
|
|
|
private void SwitchAirLevel(float mouseY)
|
|
{
|
|
mouseY -= _offset.y;
|
|
|
|
float levelHeight = heightY / _engineSystem.maxLevel;
|
|
_curLevel = (int)((mouseY) / levelHeight);
|
|
if (_curLevel >= _engineSystem.maxLevel) _curLevel = _engineSystem.maxLevel - 1;
|
|
if (_curLevel < 0) _curLevel = 0;
|
|
}
|
|
|
|
public void StopMove()
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|