// This is called when the mod is first loaded. public override void OnLoad() { // Initialize messages Messages.CloakProgress = ModNetworking.CreateMessageType(DataType.Block, DataType.Single, DataType.Boolean, DataType.Single, DataType.Vector3, DataType.Boolean); // Script after message has been received ModNetworking.Callbacks[Messages.CloakProgress] += message2 => { // Save and convert data that just received from message Block block = (Block)message2.GetData(0); float sizee = (float)message2.GetData(1); bool Activation = (bool)message2.GetData(2); float timer = (float)message2.GetData(3); Vector3 position = (Vector3)message2.GetData(4); bool flashish = (bool)message2.GetData(5); // I used static method so I can get the desired detector script // Note that block.SimBlock is the simulating instance of desired block. if not using SimBlock then the building instance will be given. StealthCloakFieldScript clk = StealthCloakFieldScriptMP.getSCFS(block.SimBlock); if (clk.GetType() == typeof(StealthCloakFieldScriptMP)) { // Some method for syncing ((StealthCloakFieldScriptMP)clk).CloakSizeModifier(sizee, Activation, timer, position, flashish); } }; Messages.CloakSimuStart = ModNetworking.CreateMessageType(DataType.Block); ModNetworking.Callbacks[Messages.CloakSimuStart] += message4 => { Block block = (Block)message4.GetData(0); // The script on cloak block in client PROCloakScript clk = block.SimBlock.GameObject.GetComponent <PROCloakScript>(); // Use the initialization clk.Initialization(); }; }
public static void PushInNewSCFS(Block cloakBlock, StealthCloakFieldScript instancee) { try { StealthCloakFieldScript blockk = dicForSCFS[cloakBlock.Guid]; Destroy(blockk.gameObject); } catch { } dicForSCFS[cloakBlock.Guid] = instancee; }
public void Initialization() { if (FieldDetector != null) { return; // Avoid initializaiton running multiple times } ReactivationTimer = CloakExtendingTime.Value; AudioInit(); FieldSize = CloakFieldSize.Value; CoolDownTime = 0; InvBumpTex = new Material(Shader.Find("FX/Glass/Stained BumpDistort")); InvBumpTex.color = new Color(1, 1, 1, 0); InvBumpTex.mainTexture = ModResource.GetTexture("Cloak disturb.png"); InvBumpTex.SetTexture("_BumpMap", ModResource.GetTexture("Cloak disturb.png")); InvTex = new Material(Shader.Find("Transparent/Diffuse")); InvTex.color = new Color(1, 1, 1, 0); InvTex.mainTexture = ModResource.GetTexture("ALL BLACK.jpg"); FieldDetector = GameObject.CreatePrimitive(PrimitiveType.Sphere); FieldDetector.name = "StealthFieldDetector"; FieldDetector.GetComponent <SphereCollider>().isTrigger = true; FieldDetector.transform.position = Vector3.down * 999999; Destroy(FieldDetector.GetComponent <Renderer>()); // Polymorphism StealthCloakFieldScript a = null; // Decide whether create a MP version of detector or a normal version. Note that host will still use normal version. if (StatMaster.isMP && StatMaster.isClient) { a = FieldDetector.AddComponent <StealthCloakFieldScriptMP>(); } else { a = FieldDetector.AddComponent <StealthCloakFieldScript>(); } a.setCloakTimer(CloakExtendingTime.Value); a.useFlashVFX = this.DirectionVisualization.IsActive; // Use the static method to store the detector instance StealthCloakFieldScript.PushInNewSCFS(Block.From(this).SimBlock, a); // This is for deletion usage a.MyBeloning = this; // Adding Cloak script to other blocks foreach (MeshRenderer renderer in Machine.SimulationMachine.GetComponentsInChildren <MeshRenderer>()) { getCloakScript(renderer); } }