public static void Save(GameObjectCollection instance, string file) { if (System.IO.File.Exists(file)) { System.IO.File.Delete(file); } var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(GameObjectCollection)); using (var stream = System.IO.File.OpenWrite(file)) { serializer.WriteObject(stream, instance); } }
public void Triggered(GameObject source, GameConsole console) { GameObjectCollection parent = null; Parent.TryGetTarget(out parent); ResolvedTargets = GameObjectParser.ResolveTargets(this, TargetIds, parent, console, DeepProcess); for (int i = 0; i < ResolvedTargets.Length; i++) { if (ResolvedTargets[i] is ITarget) { ((ITarget)ResolvedTargets[i]).Triggered(this, console); } } }
public override void Process(GameConsole console) { // Check for condition pass if (Condition(this, console)) { GameObjectCollection parent = null; Parent.TryGetTarget(out parent); ResolvedTargets = GameObjectParser.ResolveTargets(this, TargetIds, parent, console, DeepProcess); //Result(this, parent, console); for (int i = 0; i < ResolvedTargets.Length; i++) { if (ResolvedTargets[i] is ITarget) { ((ITarget)ResolvedTargets[i]).Triggered(this, console); } } } }
public static GameObject[] ResolveTargets(GameObject source, IEnumerable <string> TargetIds, GameObjectCollection parent, GameConsole console, bool DeepProcess) { // If it passed, find all targets and activate them List <GameObject> foundTargets = new List <GameObject>(5); foreach (var item in parent) { if (item.Value != source && TargetIds.Contains(item.Value.GetSetting("id"))) { foundTargets.Add(item.Value); } } // Process all known collections if (DeepProcess) { for (int i = 0; i < console.Layers; i++) { var objects = console.GetLayerMetadata(i).GameObjects; if (objects != parent) { foreach (var item in objects) { if (item.Value != source && TargetIds.Contains(item.Value.GetSetting("id"))) { foundTargets.Add(item.Value); } } } } } return(foundTargets.ToArray()); }