예제 #1
0
        public override void OnAssetLoaded(string name, object asset, Dictionary <string, byte[]> userData)
        {
            if (asset is not BuildingInfo prefab || userData == null || !userData.TryGetValue(DataId, out byte[] data) || !userData.TryGetValue(MapId, out byte[] map))
            {
                return;
            }

            Mod.Logger.Debug($"Start load prefab data \"{prefab.name}\"");
            try
            {
                var decompress = Loader.Decompress(data);
                var config     = XmlExtension.Parse(decompress);

                var count    = map.Length / 6;
                var segments = new ushort[count];
                var nodes    = new ushort[count * 2];

                for (var i = 0; i < count; i += 1)
                {
                    segments[i]      = GetUShort(map[i * 6], map[i * 6 + 1]);
                    nodes[i * 2]     = GetUShort(map[i * 6 + 2], map[i * 6 + 3]);
                    nodes[i * 2 + 1] = GetUShort(map[i * 6 + 4], map[i * 6 + 5]);
                }

                AssetMarkings[prefab] = new AssetMarking(config, segments, nodes);

                Mod.Logger.Debug($"Prefab data was loaded; Size = {data.Length} bytes");
            }
            catch (Exception error)
            {
                Mod.Logger.Error("Could not load prefab data", error);
            }
        }
예제 #2
0
 public static bool TryGetValue(BuildingInfo buildingInfo, out AssetMarking assetMarking) => AssetMarkings.TryGetValue(buildingInfo, out assetMarking);