Exemplo n.º 1
0
        public void UpdateNodeSkin(ushort node, NetworkSkin skin)
        {
            var previousSkin = NodeSkins[node];

            if (Equals(previousSkin, skin))
            {
                return;
            }

            NodeSkins[node] = skin;

            if (previousSkin?.m_color != skin?.m_color)
            {
                NetManager.instance.UpdateNodeColors(node);
            }

            UsageAdded(skin);
            UsageRemoved(previousSkin);
        }
Exemplo n.º 2
0
        private void UsageRemoved(NetworkSkin skin)
        {
            if (skin == null)
            {
                return;
            }

            skin.UseCount--;

            if (skin.UseCount <= 0)
            {
                AppliedSkins.Remove(skin);

                if (!IsActive(skin))
                {
                    skin.Destroy();
                }
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
 private bool IsActive(NetworkSkin skin)
 {
     return(_activeSkins.TryGetValue(skin.Prefab, out var activeSkin) && Equals(activeSkin, skin));
 }
Exemplo n.º 5
0
 public void PasteSegmentSkin(ushort segment, NetworkSkin skin)
 {
     UsageAdded(skin);
     SegmentSkins[segment] = skin;
 }
Exemplo n.º 6
0
 public abstract void Apply(NetworkSkin skin);