private bool LoadSkinData() { Debug.Log("NS: Loading skin data!"); try { var data = SimulationManager.instance.m_SerializableDataWrapper.LoadData(DataKey); if (data == null) { Debug.Log("NS: No data found!"); return(false); } NetworkSkinDataContainer dataContainer; using (var stream = new MemoryStream(data)) { dataContainer = DataSerializer.Deserialize <NetworkSkinDataContainer>(stream, DataSerializer.Mode.Memory, NetworkSkinsMod.ResolveSerializedType); } _loadErrors = dataContainer.Errors; } catch (Exception e) { _loadErrors = new NetworkSkinLoadErrors(); _loadErrors.MajorException(e); } return(true); }
public T FindPrefab <T>(string prefabName, NetworkSkinLoadErrors errors) where T : PrefabInfo { if (prefabName != null) { var prefab = PrefabCollection <T> .FindLoaded(prefabName); if (prefab == null) { errors.PrefabNotFound(prefabName); } return(prefab); } else { return(null); } }
public T FindPrefab <T>(string prefabName, NetworkSkinLoadErrors errors) where T : PrefabInfo { TestUtils.LogTest($"FindPrefab<{typeof(T)}> {prefabName}"); if (typeof(T) == typeof(NetInfo) && prefabName == TestNet.name) { return(TestNet as T); } else if (typeof(T) == typeof(BuildingInfo) && prefabName == TestBuilding.name) { return(TestBuilding as T); } else if (typeof(T) == typeof(BuildingInfo) && prefabName == TestBuilding2.name) { return(TestBuilding2 as T); } else if (typeof(T) == typeof(PropInfo) && prefabName == TestProp.name) { return(TestProp as T); } else if (typeof(T) == typeof(TreeInfo) && prefabName == TestTree.name) { return(TestTree as T); } else if (typeof(T) == typeof(TreeInfo) && prefabName == TestTree2.name) { return(TestTree2 as T); } else { if (prefabName != null) { errors.PrefabNotFound(prefabName); } return(null); } }
private void LoadLegacySkinData() { Debug.Log("NS: Loading legacy skin data!"); try { var data = SimulationManager.instance.m_SerializableDataWrapper.LoadData(LegacyDataKey); if (data == null) { Debug.Log("NS: No legacy data found!"); return; } LegacySegmentData[] legacyData; using (var stream = new MemoryStream(data)) { legacyData = DataSerializer.DeserializeArray <LegacySegmentData>(stream, DataSerializer.Mode.Memory, LegacySegmentData.ResolveSerializedType); } var netManager = new GameNetManager(); var length = Math.Min(legacyData.Length, SegmentSkins.Length); for (ushort segment = 0; segment < length; segment++) { var segmentData = legacyData[segment]; if (segmentData != null && netManager.IsSegmentCreated(segment)) { segmentData.FindPrefabs(); var prefab = netManager.GetSegmentInfo(segment); var modifiers = new List <NetworkSkinModifier>(); var customRepeatDistances = (segmentData.Features & LegacySegmentData.FeatureFlags.RepeatDistances) != 0; if ((segmentData.Features & LegacySegmentData.FeatureFlags.StreetLight) != 0) { var repeatDistance = customRepeatDistances ? segmentData.RepeatDistances.w : StreetLightUtils.GetDefaultRepeatDistance(prefab); modifiers.Add(new StreetLightModifier(segmentData.StreetLightPrefab, repeatDistance)); } if ((segmentData.Features & LegacySegmentData.FeatureFlags.TreeLeft) != 0) { var repeatDistance = customRepeatDistances ? segmentData.RepeatDistances.x : TreeUtils.GetDefaultRepeatDistance(prefab, LanePosition.Left); modifiers.Add(new TreeModifier(LanePosition.Left, segmentData.TreeLeftPrefab, repeatDistance)); } if ((segmentData.Features & LegacySegmentData.FeatureFlags.TreeMiddle) != 0) { var repeatDistance = customRepeatDistances ? segmentData.RepeatDistances.y : TreeUtils.GetDefaultRepeatDistance(prefab, LanePosition.Middle); modifiers.Add(new TreeModifier(LanePosition.Middle, segmentData.TreeMiddlePrefab, repeatDistance)); } if ((segmentData.Features & LegacySegmentData.FeatureFlags.TreeRight) != 0) { var repeatDistance = customRepeatDistances ? segmentData.RepeatDistances.z : TreeUtils.GetDefaultRepeatDistance(prefab, LanePosition.Right); modifiers.Add(new TreeModifier(LanePosition.Right, segmentData.TreeRightPrefab, repeatDistance)); } if (modifiers.Count > 0) { var skin = NetworkSkin.GetMatchingSkinFromList(AppliedSkins, prefab, modifiers); if (skin == null) { skin = new NetworkSkin(prefab, modifiers); } SegmentSkins[segment] = skin; UsageAdded(skin); } } } SimulationManager.instance.m_SerializableDataWrapper.EraseData(LegacyDataKey); Debug.Log("NS: Legacy data imported and erased"); } catch (Exception e) { _loadErrors = new NetworkSkinLoadErrors(); _loadErrors.MajorException(e); } }
public void OnLevelUnloading() { _loadErrors = null; ClearSkinData(); }
// nullable public static NetworkSkin Deserialize(DataSerializer s, IPrefabCollection prefabCollection, NetworkSkinLoadErrors errors) { var prefab = prefabCollection.FindPrefab <NetInfo>(s.ReadUniqueString(), errors); var modifiersCount = s.ReadInt32(); var modifiers = new List <NetworkSkinModifier>(); for (var m = 0; m < modifiersCount; m++) { var modifier = NetworkSkinModifier.Deserialize(s, prefabCollection, errors); if (modifier != null) { modifiers.Add(modifier); } } // We are checking if the prefab is null after all the modifiers are deserialized! // This is important for the deserialization of the next items! if (prefab == null) { return(null); } return(new NetworkSkin(prefab, modifiers)); }
public static TreeModifier DeserializeImpl(DataSerializer s, IPrefabCollection prefabCollection, NetworkSkinLoadErrors errors) { var position = (LanePosition)s.ReadInt32(); var tree = prefabCollection.FindPrefab <TreeInfo>(s.ReadUniqueString(), errors); var repeatDistance = s.ReadFloat(); return(new TreeModifier(position, tree, repeatDistance)); }
public static ColorModifier DeserializeImpl(DataSerializer s, NetworkSkinLoadErrors errors) { var color = new Color32((byte)s.ReadUInt8(), (byte)s.ReadUInt8(), (byte)s.ReadUInt8(), (byte)s.ReadUInt8()); return(new ColorModifier(color)); }
public static StreetLightModifier DeserializeImpl(DataSerializer s, IPrefabCollection prefabCollection, NetworkSkinLoadErrors errors) { var streetLight = prefabCollection.FindPrefab <PropInfo>(s.ReadUniqueString(), errors); var repeatDistance = s.ReadFloat(); return(new StreetLightModifier(streetLight, repeatDistance)); }
public static TerrainSurfaceModifier DeserializeImpl(DataSerializer s, NetworkSkinLoadErrors errors) { var groundType = (Surface)s.ReadUInt8(); return(new TerrainSurfaceModifier(groundType)); }
public static PillarModifier DeserializeImpl(DataSerializer s, IPrefabCollection prefabCollection, NetworkSkinLoadErrors errors) { var type = (PillarType)s.ReadInt32(); var pillar = prefabCollection.FindPrefab <BuildingInfo>(s.ReadUniqueString(), errors); return(new PillarModifier(type, pillar)); }
// nullable public static NetworkSkinModifier Deserialize(DataSerializer s, IPrefabCollection prefabCollection, NetworkSkinLoadErrors errors) { var type = (NetworkSkinModifierType)s.ReadUInt8(); switch (type) { case NetworkSkinModifierType.TerrainSurface: return(TerrainSurfaceModifier.DeserializeImpl(s, errors)); case NetworkSkinModifierType.Color: return(ColorModifier.DeserializeImpl(s, errors)); case NetworkSkinModifierType.StreetLight: return(StreetLightModifier.DeserializeImpl(s, prefabCollection, errors)); case NetworkSkinModifierType.Tree: return(TreeModifier.DeserializeImpl(s, prefabCollection, errors)); case NetworkSkinModifierType.Pillar: return(PillarModifier.DeserializeImpl(s, prefabCollection, errors)); case NetworkSkinModifierType.Catenary: return(CatenaryModifier.DeserializeImpl(s, prefabCollection, errors)); default: return(null); } }
public static CatenaryModifier DeserializeImpl(DataSerializer s, IPrefabCollection prefabCollection, NetworkSkinLoadErrors errors) { var catenary = prefabCollection.FindPrefab <PropInfo>(s.ReadUniqueString(), errors); return(new CatenaryModifier(catenary)); }