Exemple #1
0
            public void Deserialize(DataSerializer s)
            {
                var count = s.ReadInt32();

#if DEBUG
                Debug.Log($"Deserializing {count} active options");
#endif

                for (var i = 0; i < count; i++)
                {
                    var prefabName = s.ReadUniqueString();

                    var prefab = PrefabCollection <NetInfo> .FindLoaded(prefabName);

                    if (prefab == null)
                    {
                        continue;
                    }

                    var options = new SegmentData();
                    options.Deserialize(s);

#if DEBUG
                    Debug.Log($"{prefabName} --> {options.ToString()}");
#endif
                    SegmentDataManager.Instance.SetActiveOptions(prefab, options);
                }
            }
Exemple #2
0
 private void DeleteIfNotInUse(SegmentData segmentData)
 {
     if (segmentData.UsedCount <= 0)
     {
         _usedSegmentData.Remove(segmentData);
     }
 }
Exemple #3
0
 protected bool Equals(SegmentData other)
 {
     return(Features == other.Features &&
            string.Equals(TreeLeft, other.TreeLeft) &&
            string.Equals(TreeMiddle, other.TreeMiddle) &&
            string.Equals(TreeRight, other.TreeRight) &&
            string.Equals(StreetLight, other.StreetLight) &&
            (Features.IsFlagSet(FeatureFlags.RepeatDistances) == Vector4.Equals(RepeatDistances, other.RepeatDistances)));
 }
Exemple #4
0
        public SegmentData(SegmentData segmentData)
        {
            if (segmentData == null)
            {
                return;
            }

            Features        = segmentData.Features;
            TreeLeft        = segmentData.TreeLeft;
            TreeMiddle      = segmentData.TreeMiddle;
            TreeRight       = segmentData.TreeRight;
            StreetLight     = segmentData.StreetLight;
            RepeatDistances = segmentData.RepeatDistances;

            TreeLeftPrefab   = segmentData.TreeLeftPrefab;
            TreeMiddlePrefab = segmentData.TreeMiddlePrefab;
            TreeRightPrefab  = segmentData.TreeRightPrefab;
            PillarPrefab     = segmentData.PillarPrefab;
        }
Exemple #5
0
        public void SetActiveOptions(NetInfo prefab, SegmentData segmentOptions)
        {
            var options = _assetMode ? _assetSegmentOptions : _selectedSegmentOptions;

            // Delete existing data if it is not used anymore
            var activeSegmentData = GetActiveOptions(prefab);

            if (activeSegmentData != null)
            {
                options.Remove(prefab);
                activeSegmentData.UsedCount--;
                DeleteIfNotInUse(activeSegmentData);
            }

            // No new data? Stop here
            if (segmentOptions == null || segmentOptions.Features == SegmentData.FeatureFlags.None)
            {
                return;
            }

            // Check if there is an equal data object
            var equalSegmentData = _usedSegmentData.FirstOrDefault(segmentOptions.Equals);

            if (equalSegmentData != null)
            {
                // yes? use that, discard the one we created
                options[prefab] = equalSegmentData;
                equalSegmentData.UsedCount++;
            }
            else
            {
                // no? Use the one we got
                _usedSegmentData.Add(segmentOptions);
                options[prefab] = segmentOptions;
                segmentOptions.UsedCount++;
            }
        }