public void SpawnCamera(TransformF spawnPoint, GameConnection client) { // Set the control object to the default camera if (!Global.IsObject(client.GetFieldValue("camera"))) { int camId = Global.SpawnObject("Camera", "Observer"); client.SetFieldValue("camera", camId.ToString()); } // If we have a camera then set up some properties if (Global.IsObject(client.GetFieldValue("camera"))) { Core.SimObjects.Collections.MissionCleanup.Add(client.GetFieldValue("camera")); Camera clientCam = Sim.FindObjectById <Camera>(Convert.ToUInt32(client.GetFieldValue("camera"))); clientCam.ScopeToClient(client); client.SetControlObject(clientCam); if (spawnPoint == null) { return; } clientCam.SetTransform(spawnPoint); } }
public void OnTrigger(Camera obj, int trigger, int state) { // state = 0 means that a trigger key was released if (state == 0) { return; } // Default player triggers: 0=fire 1=altFire 2=jump int clientId = obj.GetControllingClient(); GameConnection client = Sim.FindObjectById <GameConnection>((uint)clientId); switch (obj.GetFieldValue("mode")) { case "Observer": // Do something interesting. break; case "Corpse": // Viewing dead corpse, so we probably want to respawn. if (client.IsMethod("spawnPlayer")) { client.Call("spawnPlayer"); } // Set the camera back into observer mode, since in // debug mode we like to switch to it. SetMode(obj, "Observer"); break; } }
public void SetMode(string mode, params string[] args) { Global.Warn("SetMode"); // Punt this one over to our datablock int datablockId = GetDataBlock(); CameraData data = Sim.FindObjectById <CameraData>((uint)datablockId); if (data.IsMethod("setMode")) { data.Call( args.ToList() .Prepend("setMode") .Prepend(GetId().ToString()) .Prepend(mode) .ToArray() ); } }
public static string CallMethodDelegate(IntPtr className, IntPtr classNamespace, uint obj, IntPtr name, IntPtr argv, int argc, out bool result) { string _className = Marshal.PtrToStringAnsi(className); string _classNamespace = Marshal.PtrToStringAnsi(classNamespace); string _name = Marshal.PtrToStringAnsi(name); UnknownSimObject objectBaseWrapper = Sim.FindObjectById <UnknownSimObject>(obj); string[] strings = { }; if (argv != IntPtr.Zero) { strings = StringMarshal.IntPtrToAnsiStringArray(argv, argc); } string strRes = EngineCallbacks.CallScriptMethod(_className, _classNamespace, objectBaseWrapper, _name, strings, out result); return(strRes); }
public static void Entry() { // --- Boilerplate C#-specific setup. Normally Torque uses the main.cs file to set these variables, here we have to do it ourselves. string CSDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).Replace('\\', '/'); Global.SetMainDotCsDir(CSDir); Global.SetCurrentDirectory(CSDir); // --- Global.SetCurrentDirectory(CSDir); Global.SetConsoleString("Core::windowIcon", "data/icon.png"); Global.SetConsoleString("Core::splashWindowImage", "data/splash.png"); // Display a splash window immediately to improve app responsiveness before // engine is initialized and main window created. Global.DisplaySplashWindow(Global.GetConsoleString("Core::splashWindowImage")); // Enable console logging, which creates the file console.log each time you run // the engine. Global.SetLogMode(6); // Disable script trace. Global.Trace(false); // Set the name of our application Global.SetConsoleString("appName", "Game"); //----------------------------------------------------------------------------- // Load up scripts to initialise subsystems. ModuleManager ModuleDatabase = Sim.FindObject <ModuleManager>("ModuleDatabase"); ModuleDatabase.SetModuleExtension("module"); ModuleDatabase.ScanModules("core", false); ModuleDatabase.LoadExplicit("CoreModule"); //----------------------------------------------------------------------------- // Load any gameplay modules ModuleDatabase.ScanModules("data", false); ModuleDatabase.LoadGroup("Game"); //Finally, initialize the client/server structure ModuleDatabase.LoadExplicit("Core_ClientServer"); if (Global.IsFunction("loadStartup")) { Global.Call("loadStartup"); } else { GuiCanvas Canvas = Sim.FindObject <GuiCanvas>("Canvas"); //If nothing else set a main menu, try to do so now if (Canvas != null && Sim.FindObjectById <GuiControl>((uint)Canvas.GetContent()) != null) { Settings ProjectSettings = Sim.FindObject <Settings>("ProjectSettings"); string mainMenuGUI = ProjectSettings?.Value("UI/mainMenuName"); if (Global.IsObject(mainMenuGUI)) { Canvas.SetContent(Sim.FindObject <GuiControl>(mainMenuGUI)); } } } Global.CloseSplashWindow(); Global.Echo("Engine initialized..."); }