60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using EventParts;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Events/EventParts/MoveCamera.cs")]
|
|
public partial class MoveCamera : Node2D, EventPart
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
private Entity follow;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool trackPlayer;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float speed = 1f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool panLerp;
|
|
|
|
public EventController parent { get; set; }
|
|
|
|
public bool parallel { get; set; }
|
|
|
|
public Coroutine routine { get; set; }
|
|
|
|
public IEnumerator Routine()
|
|
{
|
|
if (trackPlayer)
|
|
{
|
|
CameraController.instance.follow = Player.instance;
|
|
yield break;
|
|
}
|
|
CameraController.instance.follow = follow;
|
|
if (panLerp)
|
|
{
|
|
Coroutine p = Coroutine.Start(CameraController.Pan(base.GlobalPosition + CameraController.instance.offset, speed, fixedRate: false));
|
|
while (!p.done)
|
|
{
|
|
yield return null;
|
|
}
|
|
yield break;
|
|
}
|
|
for (int i = 0; i < GetChildCount(); i++)
|
|
{
|
|
Node2D child = GetChild<Node2D>(i);
|
|
Vector2 vector = (child.HasMeta("ignoreX") ? new Vector2(CameraController.instance.GlobalPosition.X, child.GlobalPosition.Y) : ((!child.HasMeta("ignoreY")) ? child.GlobalPosition : new Vector2(child.GlobalPosition.X, CameraController.instance.GlobalPosition.Y)));
|
|
Coroutine p = Coroutine.Start(CameraController.Pan(vector + CameraController.instance.offset, speed));
|
|
while (!p.done)
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|