public override void Process(VehicleColorChange colorPacket) { SubNameInput subNameInput; if (colorPacket.ParentId.HasValue) { GameObject moonpool = NitroxEntity.RequireObjectFrom(colorPacket.ParentId.Value); GameObject baseCell = moonpool.RequireComponentInParent <BaseCell>().gameObject; subNameInput = baseCell.GetComponentInChildren <SubNameInput>(); } else { if (!NitroxEntity.TryGetObjectFrom(colorPacket.VehicleId, out GameObject vehicleObject)) { return; } subNameInput = vehicleObject.GetComponentInChildren <SubNameInput>(); } using (packetSender.Suppress <VehicleColorChange>()) { if (subNameInput && subNameInput.target) { // Switch to the currently selected tab subNameInput.SetSelected(colorPacket.Index); // OnColorChange calls these two methods, in order to update the vehicle color and the color+text on the ingame panel, respectively: subNameInput.target.SetColor(colorPacket.Index, colorPacket.HSB.ToUnity(), colorPacket.Color.ToUnity()); subNameInput.SetColor(colorPacket.Index, colorPacket.Color.ToUnity()); } else { Log.Error($"[VehicleColorChangeProcessor] SubNameInput or targeted SubName is null with {colorPacket}."); } } }
public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem) { int totalItemDataSynced = 0; using (packetSender.Suppress <ItemContainerAdd>()) { ItemGoalTracker itemGoalTracker = (ItemGoalTracker)itemGoalTrackerMainField.GetValue(null); Dictionary <TechType, List <ItemGoal> > goals = (Dictionary <TechType, List <ItemGoal> >)itemGoalTrackerGoalsField.GetValue(itemGoalTracker); foreach (ItemData itemData in packet.InventoryItems) { waitScreenItem.SetProgress(totalItemDataSynced, packet.InventoryItems.Count); GameObject item; try { item = SerializationHelper.GetGameObject(itemData.SerializedData); } catch (Exception ex) { Log.Error(ex, $"Error deserializing item data. Id: {itemData.ItemId}"); continue; } Log.Debug($"Initial item data for {item.name} giving to container {itemData.ContainerId}"); Pickupable pickupable = item.GetComponent <Pickupable>(); Validate.NotNull(pickupable); if (itemData.ContainerId == packet.PlayerGameObjectId) { goals.Remove(pickupable.GetTechType()); // Remove notification goal event from item player has in any container ItemsContainer container = Inventory.Get().container; InventoryItem inventoryItem = new InventoryItem(pickupable) { container = container }; inventoryItem.item.Reparent(container.tr); container.UnsafeAdd(inventoryItem); } else if (NitroxEntity.TryGetObjectFrom(itemData.ContainerId, out GameObject containerOwner)) { Optional <ItemsContainer> opContainer = InventoryContainerHelper.TryGetContainerByOwner(containerOwner); Validate.IsPresent(opContainer); opContainer.Value.UnsafeAdd(new InventoryItem(pickupable)); ContainerAddItemPostProcessor postProcessor = ContainerAddItemPostProcessor.From(item); postProcessor.process(item, itemData); } totalItemDataSynced++; yield return(null); } foreach (NitroxTechType usedItem in packet.UsedItems) { Player.main.AddUsedTool(usedItem.ToUnity()); } string[] quickSlotsBinding = packet.QuickSlotsBinding.ToArray(); Inventory.main.serializedQuickSlots = quickSlotsBinding; Inventory.main.quickSlots.RestoreBinding(quickSlotsBinding); } Log.Info($"Received initial sync with {totalItemDataSynced} inventory items"); }