コード例 #1
0
        private void DeserializeSegmentDataMap()
        {
            var data = serializableDataManager.LoadData(SegmentDataId);

            if (data != null)
            {
                try
                {
                    using (var stream = new MemoryStream(data))
                    {
                        SegmentToSegmentDataMap = DataSerializer.DeserializeArray <SegmentData>(stream, DataSerializer.Mode.Memory);
                    }

                    Debug.LogFormat("Network Skins: Selected Data loaded (Data length: {0})", data.Length);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            if (SegmentToSegmentDataMap == null)
            {
                SegmentToSegmentDataMap = new SegmentData[NetManager.instance.m_segments.m_size];
                Debug.Log("Network Skins: No segment data found!");
            }

            _usedSegmentData.AddRange(SegmentToSegmentDataMap.Distinct().Where(segmentData => segmentData != null));
        }
コード例 #2
0
        public override void OnLoadData()
        {
            base.OnLoadData();
#if RELEASE
            try {
#endif
            ServiceBuildingOptions.GetInstance().Clear();
            byte[] bytes = serializableDataManager.LoadData(KEY);
            if (bytes == null)
            {
                return;
            }

            ServiceBuildingData[] dataArray;
            using (var stream = new MemoryStream(bytes))
            {
                dataArray = DataSerializer.DeserializeArray <ServiceBuildingData>(stream, DataSerializer.Mode.Memory);
                foreach (ServiceBuildingData data in dataArray)
                {
                    ServiceBuildingOptions.GetInstance().SetData(data.buildingID, data);
                }
            }

            Utils.LogGeneral($"DSL data loaded (Size in bytes: {bytes.Length})");
#if RELEASE
        }

        catch (Exception ignored) { }
#endif
        }
コード例 #3
0
        public override void OnLoadData()
        {
            base.OnLoadData();

            // get bytes from savegame
            var bytes = serializableDataManager.LoadData(DataId);

            if (bytes == null)
            {
                return;
            }

            BuildingDataContainer[] data;

            // deserialize data from byte[]
            using (var stream = new MemoryStream(bytes))
                data = DataSerializer.DeserializeArray <BuildingDataContainer>(stream, DataSerializer.Mode.Memory);

            foreach (var buildingData in data)
            {
                BuildingDataManager.Data[buildingData.BuildingId] = buildingData;
            }

            Logger.Log("data loaded ({0} bytes)", bytes.Length);
        }
コード例 #4
0
        public override void OnLoadData()
        {
            base.OnLoadData();

            // Get bytes from savegame
            byte[] bytes = serializableDataManager.LoadData(DataId);
            if (bytes == null)
            {
                return;
            }

            // Convert the bytes to an array of BuildingData objects
            using (var stream = new MemoryStream(bytes))
            {
                RICOInstanceData = DataSerializer.DeserializeArray <RICOInstanceData>(stream, DataSerializer.Mode.Memory);
            }

            Debug.LogFormat("Data loaded (Size in bytes: {0})", bytes.Length);
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
 public List <T> DeserializeArray <T>(string storageKey) where T : IDataContainer
 {
     return(new List <T>(DataSerializer.DeserializeArray <T>(CreateLoadStream(storageKey), DataSerializer.Mode.Memory)));
 }