BallanceStalker/scripts/stages/ShadowBallManager.cs

45 lines
1.3 KiB
C#
Raw Normal View History

2022-07-02 21:23:45 +08:00
using Godot;
using System;
using System.Collections.Generic;
public class ShadowBallManager : Spatial {
private Dictionary<Guid, ShadowBall> mBallDict = new Dictionary<Guid, ShadowBall>();
2022-07-02 21:23:45 +08:00
private PackedScene mTemplateShadowBall;
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
mTemplateShadowBall = ResourceLoader.Load<PackedScene>("res://scenes/stages/ShadowBall.tscn");
2022-07-02 21:23:45 +08:00
}
public Guid AddBall() {
var guid = Guid.NewGuid();
var instance = mTemplateShadowBall.Instance<ShadowBall>();
2022-07-02 21:23:45 +08:00
AddChild(instance);
mBallDict.Add(guid, instance);
return guid;
}
public void SetBallName(Guid ballid, string new_name) {
2022-07-02 21:23:45 +08:00
if (mBallDict.TryGetValue(ballid, out ShadowBall entity)) {
entity.SetPlayerName(new_name);
2022-07-02 21:23:45 +08:00
}
}
public void SetBallState(Guid ballid, Vector3 pos, Quat quad, ShadowBallType btype) {
2022-07-02 21:23:45 +08:00
if (mBallDict.TryGetValue(ballid, out ShadowBall entity)) {
entity.SetBallState(pos, quad, btype);
2022-07-02 21:23:45 +08:00
}
}
public void RemoveBall(Guid ballid) {
2022-07-02 21:23:45 +08:00
if (mBallDict.TryGetValue(ballid, out ShadowBall entity)) {
RemoveChild(entity);
entity.QueueFree();
2022-07-02 21:23:45 +08:00
mBallDict.Remove(ballid);
}
}
}