45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class ShadowBallManager : Spatial {
|
|
private Dictionary<Guid, ShadowBall> mBallDict = new Dictionary<Guid, ShadowBall>();
|
|
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");
|
|
|
|
}
|
|
|
|
public Guid AddBall() {
|
|
var guid = Guid.NewGuid();
|
|
var instance = mTemplateShadowBall.Instance<ShadowBall>();
|
|
|
|
AddChild(instance);
|
|
mBallDict.Add(guid, instance);
|
|
return guid;
|
|
}
|
|
|
|
public void SetBallName(Guid ballid, string new_name) {
|
|
if (mBallDict.TryGetValue(ballid, out ShadowBall entity)) {
|
|
entity.SetPlayerName(new_name);
|
|
}
|
|
}
|
|
|
|
public void SetBallState(Guid ballid, Vector3 pos, Quat quad, ShadowBallType btype) {
|
|
if (mBallDict.TryGetValue(ballid, out ShadowBall entity)) {
|
|
entity.SetBallState(pos, quad, btype);
|
|
}
|
|
}
|
|
|
|
public void RemoveBall(Guid ballid) {
|
|
if (mBallDict.TryGetValue(ballid, out ShadowBall entity)) {
|
|
RemoveChild(entity);
|
|
entity.QueueFree();
|
|
mBallDict.Remove(ballid);
|
|
}
|
|
}
|
|
|
|
}
|