private void FindDebugger(double rate) { int retries = 10; IDebug debugger = null; do { debugger = ScenePrivate.FindReflective <IDebug>("Simple.Debugger").FirstOrDefault(); if (debugger == null) { Wait(rate); } } while (debugger == null && --retries > 0); if (debugger != null) { __SimpleDebugger = debugger; return; } if (rate < 3.0) { StartCoroutine(() => { FindDebugger(rate * 2); }); } }
override public void Init() { float waitAmount = 0.05f; while (waitAmount < 4) { foreach (IDatabase db in ScenePrivate.FindReflective <IDatabase>("Persistence.Database")) { createTable = db.GetCreateTable(DatabaseName); if (createTable != null) { break; } } Wait(waitAmount); waitAmount += waitAmount; } if (createTable == null) { Log.Write(LogLevel.Warning, ObjectPrivate.Name, "Database not found: " + DatabaseName); return; } DataStore users = createTable("users"); DataStore highScore = createTable("highscore"); // ... }
public override void Init() { thisModelTranslator = ScenePrivate.FindReflective <ISGMTranslator>("Stargate." + _translator_name).FirstOrDefault(); if (thisModelTranslator == null) { Log.Write(LogLevel.Error, "Need a gate model specific translator for the mesh names."); return; } AnalyzeGateStructure(); numberBase = symbols.Count - 1; busy = false; thisGateControl = ScenePrivate.FindReflective <IGateControl>("Stargate.SG_Control").FirstOrDefault(); if (thisGateControl == null) { Log.Write(LogLevel.Error, "Gate Controller not found in scene."); return; } thisEventHorizon = ScenePrivate.FindReflective <IEventHorizon>("Stargate.SG_EventHorizon").FirstOrDefault(); if (thisEventHorizon == null) { Log.Write(LogLevel.Warning, "Gate will not establish an event horizon. Object or script missing."); } thisGateControl.ConnectGate(this); }
public override void Init() { IButton[] buttons = ScenePrivate.FindReflective <IButton>("ReflectiveReceiverScript").ToArray(); foreach (IButton b in buttons) { b.SetButtonEnabled(false); } }
private void SetupSimple() { __debugInitialized = true; __SimpleTag = GetType().Name + " [S:" + Script.ID.ToString() + " O:" + ObjectPrivate.ObjectId.ToString() + "]"; Wait(TimeSpan.FromSeconds(1)); IDebugger debugger = ScenePrivate.FindReflective<IDebugger>("SimpleDebugger").FirstOrDefault(); if (debugger != null) __SimpleDebugging = debugger.DebugSimple; }
public override void Init() { Spawner = ScenePrivate.FindReflective <ISpawner>("Builder.Spawner").FirstOrDefault(); if (Spawner == null) { Log.Write(LogLevel.Error, "Fetcher failed to find the Spawner :("); } ScenePrivate.Chat.Subscribe(Chat.DefaultChannel, OnChat, true); }
public override void Init() { thisGateControl = ScenePrivate.FindReflective <IGateControl>("Stargate.SG_Control").FirstOrDefault(); if (thisGateControl == null) { Log.Write(LogLevel.Error, "Gate Controller not found in scene."); return; } thisGateControl.ConnectDHD(this); ScenePrivate.Chat.Subscribe(0, Chat.User, OnChat); }
public sealed override void Init() { __SimpleTag = GetType().Name + " [S:" + Script.ID.ToString() + " O:" + ObjectPrivate.ObjectId.ToString() + "]"; Wait(TimeSpan.FromSeconds(1)); IDebug debugger = ScenePrivate.FindReflective <IDebug>("Simple.Debugger").FirstOrDefault(); if (debugger != null) { __SimpleDebugging = debugger.DebugSimple; } SimpleInit(); }
public override void Init() { if (ObjectPrivate.TryGetFirstComponent(out RigidBody)) { RigidBody.Subscribe(CollisionEventType.RigidBodyContact, OnCollision); RigidBody.SetMotionType(RigidBodyMotionType.MotionTypeDynamic); } else { Log.Write(LogLevel.Error, "Choppable couldn't find a RigidBody component. That component is needed in order to detect when an avatar walks into them"); return; } Pieces = ScenePrivate.FindReflective <INamedRigidThing>("Kitchen.Chopped").ToList <INamedRigidThing>(); Log.Write(LogLevel.Info, $"Found {Pieces.Count()} chopped bits"); Axe = ScenePrivate.FindReflective <IChopper>("Kitchen.Chopper").FirstOrDefault(); Log.Write(LogLevel.Info, $"Found Axe: {Axe.GetName()}"); }
public static Func <string, DataStore> FindDatabase(ScenePrivate ScenePrivate, Action <double> Wait, string databaseName) { float waitAmount = 0.75f; Func <string, DataStore> createTable; while (waitAmount < 4) { foreach (IDatabase db in ScenePrivate.FindReflective <IDatabase>("Persistence.Database")) { createTable = db.GetCreateTable(databaseName); if (createTable != null) { return(createTable); } ; } Wait(waitAmount); waitAmount += waitAmount; } return(null); }
public override void Init() { // Find the instance of the tracker. FindReflective has a type for the interface to match and takes as a string the class name of the other object. // In this case we want to find a script in the scene whose class is named "ReflectiveTrackerExample" and which implements the ITracker interface. // Because ReflectiveTrackerExample is tagged with [RegisterReflective] it should be registered before this init is called. // FindReflective returns an enumerable in case there are multiple scripts that match the criteria. In this case we expect there to be just one. Tracker = ScenePrivate.FindReflective <ITracker>("ReflectiveExample.Tracker").FirstOrDefault(); // Error out if the tracker is not found. if (Tracker == null) { Log.Write(LogLevel.Error, "Could not find the Tracker."); return; } // Set up a collision handler for colliding with characters RigidBodyComponent Rigidbody; if (ObjectPrivate.TryGetFirstComponent(out Rigidbody)) { Rigidbody.Subscribe(CollisionEventType.CharacterContact, OnHit); } }
public override void Init() { itemId = Guid.NewGuid(); PickupTracker = ScenePrivate.FindReflective <IPickupTracker>("ItemCollector.PickupTracker").FirstOrDefault(); if (PickupTracker == null) { Log.Write(LogLevel.Error, "Pickup Detector couldn't find the master Pickup Tracker. Make sure it's attached to something in the scene, like the floor."); return; } PickupTracker.RegisterPresence(itemId); RigidBodyComponent RigidBody; if (ObjectPrivate.TryGetFirstComponent(out RigidBody)) { RigidBody.Subscribe(CollisionEventType.CharacterContact, OnPickup); } else { Log.Write(LogLevel.Error, "Pickup Detector couldn't find a RigidBody component. That component is needed in order to detect when an avatar walks into them"); return; } }
public override void Init() { // no init needed. The following is an example of using the IBank: IBank bank = ScenePrivate.FindReflective <IBank>("CoroutineLockExample").FirstOrDefault(); if (bank != null) { bank.CreateAccount("bob", 100); bank.CreateAccount("sue", 100); bank.CreateAccount("joe", 100); StartCoroutine(() => { // Send some money from joe to sue every 0.3 seconds while (true) { bank.TransferMoney("joe", "sue", 3); Wait(TimeSpan.FromSeconds(0.3)); } }); StartCoroutine(() => { // Send some money from sue to bob every 0.1 seconds while (true) { bank.TransferMoney("sue", "bob", 1); Wait(TimeSpan.FromSeconds(0.1)); } }); StartCoroutine(() => { // Send some money from sue to bob every 0.1 seconds while (true) { bank.TransferMoney("bob", "joe", 2); Wait(TimeSpan.FromSeconds(0.2)); } }); StartCoroutine(() => { // Send some money all around while (true) { bank.TransferMoney("joe", "bob", 10); bank.TransferMoney("joe", "sue", 10); bank.TransferMoney("sue", "bob", 10); bank.TransferMoney("sue", "joe", 10); bank.TransferMoney("bob", "sue", 10); bank.TransferMoney("bob", "joe", 10); Wait(TimeSpan.FromSeconds(0.1)); } }); // "weekly" reports: StartCoroutine(() => { while (true) { Wait(TimeSpan.FromSeconds(300)); // Note that it is possible for transactions to get in between the reporting in here, due to threading. // We aren't actually getting the entire report atomically here. Log.Write($"Balances: Bob={bank.GetBalance("bob")} Sue={bank.GetBalance("sue")} Joe={bank.GetBalance("joe")}"); } }); // "weekly" atomic reports: StartCoroutine(() => { while (true) { Wait(TimeSpan.FromSeconds(300)); // This report is generated inside the lock and so should be atomic: balances should always total 300 in this example. Log.Write(bank.GetReport()); } }); } }