Beta Release
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MSCO
|
||||
{
|
||||
/// <summary>
|
||||
/// Gemeinsame Liste aller PlayMaker-FSMs der Szene. FindObjectsOfType ist teuer (tausende FSMs in MSC);
|
||||
/// statt dass Türen-, Fahrzeug-, Wetter- und Montage-Sync jeweils selbst suchen, wird einmal gesucht
|
||||
/// und das Ergebnis eine Weile geteilt.
|
||||
/// </summary>
|
||||
public static class SceneCache
|
||||
{
|
||||
static PlayMakerFSM[] fsms = new PlayMakerFSM[0];
|
||||
static float builtAt = -1000f;
|
||||
static int builtForLevel = -1;
|
||||
|
||||
/// <summary>Alle FSMs; höchstens maxAge Sekunden alt. Einträge können inzwischen zerstört sein (== null prüfen).</summary>
|
||||
public static PlayMakerFSM[] Fsms(float maxAge)
|
||||
{
|
||||
if (Time.realtimeSinceStartup - builtAt > maxAge || builtForLevel != Application.loadedLevel)
|
||||
{
|
||||
Object[] found = Object.FindObjectsOfType(typeof(PlayMakerFSM));
|
||||
var list = new List<PlayMakerFSM>(found.Length);
|
||||
foreach (Object o in found) list.Add((PlayMakerFSM)o);
|
||||
fsms = list.ToArray();
|
||||
builtAt = Time.realtimeSinceStartup;
|
||||
builtForLevel = Application.loadedLevel;
|
||||
}
|
||||
return fsms;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user