using UnityEngine; class NetPackageSyncWeaponLabelColor : NetPackage { public NetPackageSyncWeaponLabelColor Setup(int entityId, bool isText, Color color, int index0, int index1, int nameId) { this.entityId = entityId; this.isText = isText; this.color = color; this.index0 = index0; if (!isText) { this.index1 = index1; this.nameId = nameId; } return this; } public override int GetLength() { return isText ? 20 : 28; } public override void ProcessPackage(World _world, GameManager _callbacks) { if (_world == null) return; NetSyncSetWeaponLabelColor(_world.GetEntity(entityId) as EntityAlive, isText, index0, color, index1, nameId, true); } public static void NetSyncSetWeaponLabelColor(EntityAlive holdingEntity, bool isText, int slot0, Color color, int slot1, int nameId, bool fromNet = false) { if (!holdingEntity || (holdingEntity.isEntityRemote && !fromNet)) { if (holdingEntity) Log.Out("netsync failed! isEntityRemote: " + holdingEntity.isEntityRemote + " fromNet: " + fromNet); else Log.Out("Entity not found!"); return; } if (SetWeaponLabelColor(holdingEntity, isText, slot0, color, slot1, nameId)) { //Log.Out("trying to set weapon label on " + (SingletonMonoBehaviour.Instance.IsServer ? "server" : "client") + " color: " + color.ToString() + " entity: " + holdingEntity.entityId + " from net: " + fromNet); if (SingletonMonoBehaviour.Instance.IsServer && SingletonMonoBehaviour.Instance.ClientCount() > 0) { int allButAttachedToEntityId = holdingEntity.entityId; if (holdingEntity && holdingEntity.AttachedMainEntity) allButAttachedToEntityId = holdingEntity.AttachedMainEntity.entityId; SingletonMonoBehaviour.Instance.SendPackage(NetPackageManager.GetPackage().Setup(holdingEntity.entityId, isText, color, slot0, slot1, nameId), false, -1, allButAttachedToEntityId, allButAttachedToEntityId, null, 15); } else if (SingletonMonoBehaviour.Instance.IsClient && !fromNet) SingletonMonoBehaviour.Instance.SendToServer(NetPackageManager.GetPackage().Setup(holdingEntity.entityId, isText, color, slot0, slot1, nameId)); } } public static bool SetWeaponLabelColor(EntityAlive holdingEntity, bool isText, int slot0, Color color, int slot1, int nameId) { if (GameManager.IsDedicatedServer) return true; if (isText) { WeaponLabelControllerBase controller = holdingEntity.inventory.GetHoldingItemTransform()?.GetComponent(); //if (holdingEntity.emodel.avatarController is AvatarMultiBodyController multiBody && multiBody.HeldItemTransform != null) // controller = multiBody.HeldItemTransform.GetComponent(); //else if (holdingEntity.emodel.avatarController is LegacyAvatarController legacy && legacy.HeldItemTransform != null) // controller = legacy.HeldItemTransform.GetComponent(); return controller && controller.setLabelColor(slot0, color); } else { WeaponColorControllerBase controller = holdingEntity.inventory.GetHoldingItemTransform()?.GetComponent(); //if (holdingEntity.emodel.avatarController is AvatarMultiBodyController multiBody && multiBody.HeldItemTransform != null) // controller = multiBody.HeldItemTransform.GetComponent(); //else if (holdingEntity.emodel.avatarController is LegacyAvatarController legacy && legacy.HeldItemTransform != null) // controller = legacy.HeldItemTransform.GetComponent(); return controller && controller.setMaterialColor(slot0, slot1, nameId, color); } } public override void read(PooledBinaryReader _reader) { entityId = _reader.ReadInt32(); isText = _reader.ReadBoolean(); color = StreamUtils.ReadColor(_reader); index0 = _reader.ReadChar(); if (!isText) { index1 = _reader.ReadChar(); nameId = _reader.ReadInt32(); } } public override void write(PooledBinaryWriter _writer) { base.write(_writer); _writer.Write(entityId); _writer.Write(isText); StreamUtils.Write(_writer, color); _writer.Write((char)index0); if (!isText) { _writer.Write((char)index1); _writer.Write(nameId); } } private int entityId; private bool isText; private Color color; private int index0; private int index1; private int nameId; }