private void OnVehiclePrefabLoaded(GameObject prefab, string guid, Vector3 spawnPosition, Quaternion spawnRotation, Optional <List <InteractiveChildObjectIdentifier> > interactiveChildIdentifiers, Optional <string> dockingBayGuid) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; GuidHelper.SetNewGuid(gameObject, guid); if (interactiveChildIdentifiers.IsPresent()) { VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(gameObject, interactiveChildIdentifiers.Get()); //Copy From ConstructorBeginCraftingProcessor } if (dockingBayGuid.IsPresent()) { GameObject dockingBayBase = GuidHelper.RequireObjectFrom(dockingBayGuid.Get()); VehicleDockingBay dockingBay = dockingBayBase.GetComponentInChildren <VehicleDockingBay>(); Vehicle vehicle = gameObject.GetComponent <Vehicle>(); dockingBay.DockVehicle(vehicle); } }
public override void Process(VehicleDocking packet) { GameObject vehicleGo = GuidHelper.RequireObjectFrom(packet.VehicleGuid); GameObject vehicleDockingBayGo = GuidHelper.RequireObjectFrom(packet.DockGuid); Vehicle vehicle = vehicleGo.RequireComponent <Vehicle>(); VehicleDockingBay vehicleDockingBay = vehicleDockingBayGo.RequireComponent <VehicleDockingBay>(); using (packetSender.Suppress <VehicleDocking>()) { vehicleDockingBay.DockVehicle(vehicle); } vehicle.StartCoroutine(DisablePilotingAfterAnimation(packet.VehicleGuid, packet.PlayerId)); }
IEnumerator DelayAnimationAndDisablePiloting(Vehicle vehicle, VehicleDockingBay vehicleDockingBay, NitroxId vehicleId, ushort playerId) { yield return(new WaitForSeconds(1.0f)); // DockVehicle sets the rigid body kinematic of the vehicle to true, we don't want that behaviour // Therefore disable kinematic (again) to remove the bouncing behavior vehicleDockingBay.DockVehicle(vehicle); vehicle.useRigidbody.isKinematic = false; yield return(new WaitForSeconds(2.0f)); vehicles.SetOnPilotMode(vehicleId, playerId, false); if (!vehicle.docked) { Log.Error($"Vehicle {vehicleId} not docked after docking process"); } }
private void OnVehiclePrefabLoaded(TechType techType, GameObject prefab, NitroxId id, Vector3 spawnPosition, Quaternion spawnRotation, IEnumerable <InteractiveChildObjectIdentifier> interactiveChildIdentifiers, Optional <NitroxId> dockingBayId, string name, Vector3[] hsb, Vector3[] colours, float health) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; NitroxEntity.SetNewId(gameObject, id); // Updates names and colours with persisted data if (techType == TechType.Seamoth || techType == TechType.Exosuit) { Vehicle vehicle = gameObject.GetComponent <Vehicle>(); if (dockingBayId.HasValue) { GameObject dockingBayBase = NitroxEntity.RequireObjectFrom(dockingBayId.Value); VehicleDockingBay dockingBay = dockingBayBase.GetComponentInChildren <VehicleDockingBay>(); dockingBay.DockVehicle(vehicle); } else if (techType == TechType.Exosuit) { // exosuits tend to fall through the ground after spawning. This should prevent that vehicle.ReflectionSet("onGround", true); } if (!string.IsNullOrEmpty(name)) { vehicle.vehicleName = name; vehicle.subName.DeserializeName(vehicle.vehicleName); } if (colours != null) { vehicle.vehicleColors = colours; vehicle.subName.DeserializeColors(vehicle.vehicleColors); } vehicle.GetComponent <LiveMixin>().health = health; } else if (techType == TechType.Cyclops) { GameObject target = NitroxEntity.RequireObjectFrom(id); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); subNameInput.OnNameChange(name); subNameTarget.DeserializeColors(hsb); target.GetComponent <LiveMixin>().health = health; // Set internal and external lights SetCyclopsModes(id); } VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(gameObject, interactiveChildIdentifiers); // Send event after everything is created if (VehicleCreated != null) { VehicleCreated(gameObject); } }
private void OnVehiclePrefabLoaded(TechType techType, GameObject prefab, string guid, Vector3 spawnPosition, Quaternion spawnRotation, Optional <List <InteractiveChildObjectIdentifier> > interactiveChildIdentifiers, Optional <string> dockingBayGuid, string name, Vector3[] hsb, Vector3[] colours) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; GuidHelper.SetNewGuid(gameObject, guid); // Updates names and colours with persisted data .....yeah..... if (techType == TechType.Seamoth || techType == TechType.Exosuit) { // Seamoth & Prawn suit Vehicle vehicle = gameObject.GetComponent <Vehicle>(); if (dockingBayGuid.IsPresent()) { GameObject dockingBayBase = GuidHelper.RequireObjectFrom(dockingBayGuid.Get()); VehicleDockingBay dockingBay = dockingBayBase.GetComponentInChildren <VehicleDockingBay>(); dockingBay.DockVehicle(vehicle); } if (!string.IsNullOrEmpty(name)) { vehicle.vehicleName = name; vehicle.subName.DeserializeName(vehicle.vehicleName); } if (colours != null) { Vector3[] colour = new Vector3[5]; for (int i = 0; i < hsb.Length; i++) { colour[i] = hsb[i]; } vehicle.vehicleColors = colour; vehicle.subName.DeserializeColors(vehicle.vehicleColors); } } else if (techType == TechType.Cyclops) // Cyclops { GameObject target = GuidHelper.RequireObjectFrom(guid); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); subNameInput.OnNameChange(name); for (int i = 0; i < hsb.Length; i++) { subNameInput.SetSelected(i); Color tmpColour = new Vector4(colours[i].x, colours[i].y, colours[i].z); subNameTarget.SetColor(i, hsb[i], tmpColour); subNameTarget.DeserializeColors(hsb); } } if (interactiveChildIdentifiers.IsPresent()) { VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(gameObject, interactiveChildIdentifiers.Get()); //Copy From ConstructorBeginCraftingProcessor } }