public void UpdateVehicleChildren(NitroxId id, List <InteractiveChildObjectIdentifier> interactiveChildrenGuids) { Optional <GameObject> go = NitroxEntity.GetObjectFrom(id); Validate.IsTrue(go.HasValue, $"Tried to set children ids for vehicle but could not find it with Nitrox id '{id}'"); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(go.Value, interactiveChildrenGuids); }
public void UpdateVehicleChildren(NitroxId id, List<InteractiveChildObjectIdentifier> interactiveChildrenGuids) { Optional<GameObject> Object = NitroxIdentifier.GetObjectFrom(id); if (Object.IsPresent()) { GameObject T = Object.Get(); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(T, interactiveChildrenGuids); } }
public override void Process(ConstructorBeginCrafting packet) { GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.ConstructorId); Crafter crafter = gameObject.RequireComponentInChildren <Crafter>(true); crafter.ReflectionCall("OnCraftingBegin", false, false, new object[] { packet.VehicleModel.TechType.ToUnity(), packet.Duration }); vehicles.AddVehicle(packet.VehicleModel); Optional <object> opConstructedObject = Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.HasValue) { GameObject constructedObject = (GameObject)opConstructedObject.Value; NitroxEntity.SetNewId(constructedObject, packet.VehicleModel.Id); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(constructedObject, packet.VehicleModel.InteractiveChildIdentifiers); } else { Log.Error($"Could not find constructed object {packet.VehicleModel.Id} from constructor {packet.ConstructorId}"); } }
public override void Process(ConstructorBeginCrafting packet) { GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.ConstructorId); Crafter crafter = gameObject.RequireComponentInChildren <Crafter>(true); vehicles.AddVehicle(VehicleModelFactory.BuildFrom(packet)); MethodInfo onCraftingBegin = typeof(Crafter).GetMethod("OnCraftingBegin", BindingFlags.NonPublic | BindingFlags.Instance); Validate.NotNull(onCraftingBegin); onCraftingBegin.Invoke(crafter, new object[] { packet.TechType.Enum(), packet.Duration }); //TODO: take into account latency for duration Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.IsPresent()) { GameObject constructedObject = (GameObject)opConstructedObject.Get(); NitroxEntity.SetNewId(constructedObject, packet.ConstructedItemId); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(constructedObject, packet.InteractiveChildIdentifiers); } else { Log.Error("Could not find constructed object!"); } }
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); } }