-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVesselCommander.cs
50 lines (42 loc) · 1.56 KB
/
VesselCommander.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace MajiirKerbalLib
{
internal class VesselCommander
{
#region Static factory
private static Dictionary<WeakReference<Vessel>, VesselCommander> commanders = new Dictionary<WeakReference<Vessel>, VesselCommander>();
public static VesselCommander GetInstance(Vessel vessel)
{
foreach (var wr in commanders.Keys.ToArray())
{
var v = wr.Target;
if (v == null)
{
commanders.Remove(wr);
MonoBehaviour.print(String.Format("[MajiirKerbalLib] Removed VesselCommander for collected vessel ({0} remaining)", commanders.Count));
continue;
}
if (v == vessel)
{
return commanders[wr];
}
}
var commander = new VesselCommander();
commanders[new WeakReference<Vessel>(vessel)] = commander;
MonoBehaviour.print(String.Format("[MajiirKerbalLib] Created VesselCommander for {0} ({1} total)", vessel.name, commanders.Count));
return commander;
}
#endregion
private VesselCommander()
{
this.EngineCommander = new EngineCommander();
this.ReturnRealRCS = true;
}
public EngineCommander EngineCommander { get; private set; }
public bool ReturnRealRCS { get; set; }
public float RequestedRCS { get; set; }
}
}