Beispiel #1
0
        public static NetInfo.Segment SetConsistentUVs(this NetInfo.Segment segment)
        {
            var colors   = new List <Color>();
            var colors32 = new List <Color32>();

            for (int i = 0; i < segment.m_mesh.vertexCount; i++)
            {
                colors.Add(new Color(255, 0, 255, 255));
                colors32.Add(new Color32(255, 0, 255, 255));
            }
            segment.m_mesh.colors   = colors.ToArray();
            segment.m_mesh.colors32 = colors32.ToArray();

            colors   = new List <Color>();
            colors32 = new List <Color32>();
            for (int i = 0; i < segment.m_lodMesh.vertexCount; i++)
            {
                colors.Add(new Color(255, 0, 255, 255));
                colors32.Add(new Color32(255, 0, 255, 255));
            }
            segment.m_lodMesh.colors   = colors.ToArray();
            segment.m_lodMesh.colors32 = colors32.ToArray();

            return(segment);
        }
        private static void SetupSegmentButtons(ReferenceChain refChain, NetInfo.Segment segmentInfo)
        {
            try
            {
                Debug.Log("SetupSegmentButtons() called");
                if (segmentInfo.m_mesh != null && segmentInfo.m_mesh.isReadable && GUILayout.Button("Dump"))
                {
                    var outPath = refChain.ToString().Replace(' ', '_');
                    DumpUtil.DumpMeshAndTextures(
                        outPath,
                        segmentInfo.m_mesh,
                        segmentInfo.m_material);
                    DumpUtil.DumpMeshAndTextures(
                        outPath + "_lod",
                        segmentInfo.m_lodMesh,
                        segmentInfo.m_lodMaterial);
                }

                SetupMeshPreviewButtons(name: null, segmentInfo.m_mesh, segmentInfo.m_material, segmentInfo.m_lodMesh, segmentInfo.m_lodMaterial);
                Debug.Log("SetupSegmentButtons() successful");
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Beispiel #3
0
 public static void CalculateGroupData(NetInfo.Segment segmentInfo, ref int vertexCount, ref int triangleCount, ref int objectCount, ref RenderGroup.VertexArrays vertexArrays)
 {
     RenderGroup.MeshData meshData = segmentInfo.m_combinedLod.m_key.m_mesh.m_data;
     vertexCount   += meshData.m_vertices.Length;
     triangleCount += meshData.m_triangles.Length;
     objectCount++;
     vertexArrays |= meshData.VertexArrayMask() | RenderGroup.VertexArrays.Colors | RenderGroup.VertexArrays.Uvs2 | RenderGroup.VertexArrays.Uvs4;
 }
Beispiel #4
0
        public static bool CheckFlags(NetInfo.Segment segmentInfo, ushort segmentID, ref bool turnAround)
        {
            var segmentInfoExt = segmentInfo?.GetMetaData();

            if (segmentInfoExt == null)
            {
                return(true);                        // bypass
            }
            ref NetSegmentExt netSegmentExt   = ref man_.SegmentBuffer[segmentID];
Beispiel #5
0
        public static NetInfo.Segment SetFlagsDefault(this NetInfo.Segment segment)
        {
            segment.m_backwardForbidden = NetSegment.Flags.None;
            segment.m_backwardRequired  = NetSegment.Flags.None;

            segment.m_forwardForbidden = NetSegment.Flags.None;
            segment.m_forwardRequired  = NetSegment.Flags.None;

            return(segment);
        }
 public static void HandleAsymSegmentFlags(NetInfo.Segment fSegment, NetInfo.Segment bSegment = null)
 {
     fSegment.m_forwardForbidden |= NetSegment.Flags.Invert;
     fSegment.m_backwardRequired |= NetSegment.Flags.Invert;
     if (bSegment != null)
     {
         bSegment.m_forwardRequired   |= NetSegment.Flags.Invert;
         bSegment.m_backwardForbidden |= NetSegment.Flags.Invert;
     }
 }
        public static NetInfo.Segment SetMeshes(this NetInfo.Segment segment, string newMeshPath, string newLODMeshPath = null)
        {
            segment.m_mesh = AssetManager.instance.GetMesh(newMeshPath);

            if (newLODMeshPath != null)
            {
                segment.m_lodMesh = AssetManager.instance.GetMesh(newLODMeshPath);
            }

            return(segment);
        }
Beispiel #8
0
 public static bool CheckFlags(this NetInfo.Segment segmentInfo, NetSegment.Flags flags, bool turnAround)
 {
     if (!turnAround)
     {
         return(flags.CheckFlags(segmentInfo.m_forwardRequired, segmentInfo.m_forwardForbidden));
     }
     else
     {
         return(flags.CheckFlags(segmentInfo.m_backwardRequired, segmentInfo.m_backwardForbidden));
     }
 }
Beispiel #9
0
 public static NetInfo.Segment GetSegment(NetInfo info, int textureID)
 {
     NetInfo.Segment segmentInfo = null;
     foreach (var segmentInfo2 in info.m_segments ?? Enumerable.Empty <NetInfo.Segment>())
     {
         if (segmentInfo2.m_segmentMaterial.TryGetTexture2D(textureID) != null)
         {
             segmentInfo = segmentInfo2;
             break;
         }
     }
     return(segmentInfo);
 }
Beispiel #10
0
        public static Segment GetOrCreateMetaData(this NetInfo.Segment segment)
        {
            Assertion.Assert(segment is IInfoExtended);
            var segment2 = segment as IInfoExtended;
            var ret      = segment2.GetMetaData <Segment>();

            if (ret == null)
            {
                ret = new Segment(segment);
                segment2.SetMetaData(ret);
            }
            return(ret);
        }
Beispiel #11
0
 public static void OnAfterDrawMesh(
     ushort segmentID,
     NetInfo.Segment segmentInfo,
     bool turnAround)
 {
     if (segmentInfo == Overlay.HoveredInfo)
     {
         var data = new Overlay.SegmentData {
             SegmentID  = segmentID,
             TurnAround = turnAround,
         };
         Overlay.SegmentQueue.Enqueue(data);
     }
 }
        private Mesh GetSegmentMesh(ushort segmentId, out Vector3 position)
        {
            NetSegment segment = netManager.m_segments.m_buffer[segmentId];
            NetInfo    info    = segment.Info;

            NetInfo.Segment seg = info.m_segments.Length == 1 ? info.m_segments[0] : info.m_segments[2];

            Vector3 position1 = netManager.m_nodes.m_buffer[(int)segment.m_startNode].m_position;
            Vector3 position2 = netManager.m_nodes.m_buffer[(int)segment.m_endNode].m_position;

            position = (position1 + position2) * 0.5f;

            float vscale = info.m_netAI.GetVScale();

            segment.CalculateCorner(segmentId, true, true, true, out Vector3 cornerPos1, out Vector3 cornerDirection1,
                                    out bool smooth1);
            segment.CalculateCorner(segmentId, true, false, true, out Vector3 cornerPos2, out Vector3 cornerDirection2,
                                    out bool smooth2);
            segment.CalculateCorner(segmentId, true, true, false, out Vector3 cornerPos3, out Vector3 cornerDirection3,
                                    out smooth1);
            segment.CalculateCorner(segmentId, true, false, false, out Vector3 cornerPos4, out Vector3 cornerDirection4,
                                    out smooth2);

            NetSegment.CalculateMiddlePoints(cornerPos1, cornerDirection1, cornerPos4, cornerDirection4, smooth1,
                                             smooth2, out Vector3 middlePos1_1, out Vector3 middlePos2_1);
            NetSegment.CalculateMiddlePoints(cornerPos3, cornerDirection3, cornerPos2, cornerDirection2, smooth1,
                                             smooth2, out Vector3 middlePos1_2, out Vector3 middlePos2_2);

            Matrix4x4 leftMatrix = NetSegment.CalculateControlMatrix(cornerPos1, middlePos1_1, middlePos2_1,
                                                                     cornerPos4, cornerPos3, middlePos1_2, middlePos2_2, cornerPos2, position, vscale);
            Matrix4x4 rightMatrix = NetSegment.CalculateControlMatrix(cornerPos3, middlePos1_2, middlePos2_2,
                                                                      cornerPos2, cornerPos1, middlePos1_1, middlePos2_1, cornerPos4, position, vscale);

            Bezier3 leftBezier = new Bezier3(
                leftMatrix.GetColumn(0),
                leftMatrix.GetColumn(1),
                leftMatrix.GetColumn(2),
                leftMatrix.GetColumn(3));
            Bezier3 rightBezier = new Bezier3(
                rightMatrix.GetColumn(0),
                rightMatrix.GetColumn(1),
                rightMatrix.GetColumn(2),
                rightMatrix.GetColumn(3));

            Mesh mesh = BendMesh(seg.m_segmentMesh, leftBezier, rightBezier, info);

            return(mesh);
        }
 public static NetInfo GetParent(this NetInfo.Segment segment, out int segmentIndex)
 {
     foreach (var netInfo in NetInfoExtionsion.EditedNetInfos)
     {
         for (int i = 0; i < netInfo.m_segments.Length; ++i)
         {
             if (netInfo.m_segments[i] == segment)
             {
                 segmentIndex = i;
                 return(netInfo);
             }
         }
     }
     segmentIndex = -1;
     return(null);
 }
Beispiel #14
0
 static bool IsSegmentInfoSuitable(NetInfo.Segment segmentInfo)
 {
     if (segmentInfo == null)
     {
         return(false);
     }
     if (!segmentInfo.m_mesh || !segmentInfo.m_material)
     {
         return(false);
     }
     if (segmentInfo.m_material.name.Contains("NetworkTiling"))
     {
         return(false);
     }
     if (!segmentInfo.m_material.TryGetTexture2D(TextureUtils.ID_Defuse))
     {
         return(false);
     }
     return(segmentInfo.CheckFlags(NetSegment.Flags.None, out _));
 }
Beispiel #15
0
        public static NetInfo.Segment SetTextures(this NetInfo.Segment segment, TextureSet newTextures, LODTextureSet newLODTextures = null)
        {
            if (newTextures != null)
            {
                if (segment.m_material != null)
                {
                    segment.m_material = newTextures.CreateRoadMaterial(segment.m_material);
                }
            }

            if (newLODTextures != null)
            {
                if (segment.m_lodMaterial != null)
                {
                    segment.m_lodMaterial = newLODTextures.CreateRoadMaterial(segment.m_lodMaterial);
                }
            }

            return(segment);
        }
        public static NetInfo.Segment SetTextures(this NetInfo.Segment segment, TexturesSet newTextures, TexturesSet newLODTextures = null)
        {
            if (segment.m_material != null)
            {
                segment.m_material = segment.m_material.Clone(newTextures);
            }

            if (segment.m_segmentMaterial != null)
            {
                segment.m_segmentMaterial = segment.m_segmentMaterial.Clone(newTextures);
            }

            if (segment.m_lodMaterial != null)
            {
                if (newLODTextures != null)
                {
                    segment.m_lodMaterial = segment.m_lodMaterial.Clone(newLODTextures);
                }
            }

            return(segment);
        }
Beispiel #17
0
        public static NetInfo.Segment SetConsistentUVs(this NetInfo.Segment segment, bool isPowerLines = true)
        {
            var     colors   = new List <Color>();
            var     colors32 = new List <Color32>();
            Color   color;
            Color32 color32;

            if (isPowerLines)
            {
                color   = new Color(0, 0, 0, 255);
                color32 = new Color32(0, 0, 0, 255);
            }
            else
            {
                color   = new Color(255, 0, 255, 255);
                color32 = new Color32(255, 0, 255, 255);
            }

            for (int i = 0; i < segment.m_mesh.vertexCount; i++)
            {
                colors.Add(color);
                colors32.Add(color32);
            }
            segment.m_mesh.colors   = colors.ToArray();
            segment.m_mesh.colors32 = colors32.ToArray();

            colors   = new List <Color>();
            colors32 = new List <Color32>();
            for (int i = 0; i < segment.m_lodMesh.vertexCount; i++)
            {
                colors.Add(color);
                colors32.Add(color32);
            }
            segment.m_lodMesh.colors   = colors.ToArray();
            segment.m_lodMesh.colors32 = colors32.ToArray();

            return(segment);
        }
Beispiel #18
0
        public void PopulateGroupData(ushort segmentID, int groupX, int groupZ, int layer, ref int vertexIndex, ref int triangleIndex, Vector3 groupPosition, RenderGroup.MeshData data, ref Vector3 min, ref Vector3 max, ref float maxRenderDistance, ref float maxInstanceDistance, ref bool requireSurfaceMaps)
        {
            bool       hasProps = false;
            NetInfo    info     = Info;
            NetManager instance = Singleton <NetManager> .instance;

            if (m_problems != Notification.Problem.None && layer == Singleton <NotificationManager> .instance.m_notificationLayer)
            {
                Vector3 middlePosition = m_middlePosition;
                middlePosition.y += info.m_maxHeight;
                Notification.PopulateGroupData(m_problems, middlePosition, 1f, groupX, groupZ, ref vertexIndex, ref triangleIndex, groupPosition, data, ref min, ref max, ref maxRenderDistance, ref maxInstanceDistance);
            }
            if (info.m_hasForwardVehicleLanes != info.m_hasBackwardVehicleLanes && layer == Singleton <NetManager> .instance.m_arrowLayer)
            {
                Bezier3 bezier = default(Bezier3);
                bezier.a = Singleton <NetManager> .instance.m_nodes.m_buffer[m_startNode].m_position;
                bezier.d = Singleton <NetManager> .instance.m_nodes.m_buffer[m_endNode].m_position;
                CalculateMiddlePoints(bezier.a, m_startDirection, bezier.d, m_endDirection, smoothStart: true, smoothEnd: true, out bezier.b, out bezier.c);
                Vector3 pos = bezier.Position(0.5f);
                pos.y += info.m_netAI.GetSnapElevation();
                Vector3 vector = VectorUtils.NormalizeXZ(bezier.Tangent(0.5f)) * (4f + info.m_halfWidth * 0.5f);
                if ((m_flags & Flags.Invert) != 0 == info.m_hasForwardVehicleLanes)
                {
                    vector = -vector;
                }
                PopulateArrowGroupData(pos, vector, ref vertexIndex, ref triangleIndex, groupPosition, data, ref min, ref max, ref maxRenderDistance, ref maxInstanceDistance);
            }
            if (info.m_lanes != null)
            {
                bool          invert;
                NetNode.Flags flags;
                NetNode.Flags flags2;
                if ((m_flags & Flags.Invert) != 0)
                {
                    invert = true;
                    instance.m_nodes.m_buffer[m_endNode].Info.m_netAI.GetNodeFlags(m_endNode, ref instance.m_nodes.m_buffer[m_endNode], segmentID, ref this, out flags);
                    instance.m_nodes.m_buffer[m_startNode].Info.m_netAI.GetNodeFlags(m_startNode, ref instance.m_nodes.m_buffer[m_startNode], segmentID, ref this, out flags2);
                }
                else
                {
                    invert = false;
                    instance.m_nodes.m_buffer[m_startNode].Info.m_netAI.GetNodeFlags(m_startNode, ref instance.m_nodes.m_buffer[m_startNode], segmentID, ref this, out flags);
                    instance.m_nodes.m_buffer[m_endNode].Info.m_netAI.GetNodeFlags(m_endNode, ref instance.m_nodes.m_buffer[m_endNode], segmentID, ref this, out flags2);
                }
                bool  terrainHeight = info.m_segments == null || info.m_segments.Length == 0;
                float startAngle    = (float)(int)m_cornerAngleStart * ((float)Math.PI / 128f);
                float endAngle      = (float)(int)m_cornerAngleEnd * ((float)Math.PI / 128f);
                bool  destroyed     = (m_flags & Flags.Collapsed) != 0;
                uint  num           = m_lanes;
                for (int i = 0; i < info.m_lanes.Length; i++)
                {
                    if (num == 0)
                    {
                        break;
                    }
                    instance.m_lanes.m_buffer[num].PopulateGroupData(segmentID, num, info.m_lanes[i], destroyed, flags, flags2, startAngle, endAngle, invert, terrainHeight, layer, ref vertexIndex, ref triangleIndex, groupPosition, data, ref min, ref max, ref maxRenderDistance, ref maxInstanceDistance, ref hasProps);
                    num = instance.m_lanes.m_buffer[num].m_nextLane;
                }
            }
            if ((info.m_netLayers & (1 << layer)) == 0)
            {
                return;
            }
            bool flag = info.m_segments != null && info.m_segments.Length != 0;

            if (!flag && !hasProps)
            {
                return;
            }
            min = Vector3.Min(min, m_bounds.min);
            max = Vector3.Max(max, m_bounds.max);
            maxRenderDistance   = Mathf.Max(maxRenderDistance, 30000f);
            maxInstanceDistance = Mathf.Max(maxInstanceDistance, 1000f);
            if (!flag)
            {
                return;
            }
            float vScale = info.m_netAI.GetVScale();

            CalculateCorner(segmentID, heightOffset: true, start: true, leftSide: true, out var cornerPosSL, out var cornerDirectionSL, out var smoothStart);
            CalculateCorner(segmentID, heightOffset: true, start: false, leftSide: true, out var cornerPosEL, out var cornerDirectionEL, out var smoothEnd);
            CalculateCorner(segmentID, heightOffset: true, start: true, leftSide: false, out var cornerPosSR, out var cornerDirectionSR, out smoothStart);
            CalculateCorner(segmentID, heightOffset: true, start: false, leftSide: false, out var cornerPosER, out var cornerDirectionER, out smoothEnd);
            CalculateMiddlePoints(cornerPosSL, cornerDirectionSL, cornerPosER, cornerDirectionER, smoothStart, smoothEnd, out var b1, out var c1);
            CalculateMiddlePoints(cornerPosSR, cornerDirectionSR, cornerPosEL, cornerDirectionEL, smoothStart, smoothEnd, out var b2, out var c2);
            Vector3 position           = instance.m_nodes.m_buffer[m_startNode].m_position;
            Vector3 position2          = instance.m_nodes.m_buffer[m_endNode].m_position;
            Vector4 meshScale          = new Vector4(0.5f / info.m_halfWidth, 1f / info.m_segmentLength, 1f, 1f);
            Vector4 colorLocationStart = RenderManager.GetColorLocation((uint)(49152 + segmentID));
            Vector4 colorlocationEnd   = colorLocationStart;

            if (NetNode.BlendJunction(m_startNode))
            {
                colorLocationStart = RenderManager.GetColorLocation((uint)(86016 + m_startNode));
            }
            if (NetNode.BlendJunction(m_endNode))
            {
                colorlocationEnd = RenderManager.GetColorLocation((uint)(86016 + m_endNode));
            }
            Vector4 objectIndex0 = new Vector4(colorLocationStart.x, colorLocationStart.y, colorlocationEnd.x, colorlocationEnd.y);

            for (int j = 0; j < info.m_segments.Length; j++)
            {
                NetInfo.Segment segment    = info.m_segments[j];
                bool            turnAround = false;
                if (segment.m_layer == layer && segment.CheckFlags(m_flags, out turnAround) && segment.m_combinedLod != null)
                {
                    Vector4 objectIndex = objectIndex0;
                    if (segment.m_requireWindSpeed)
                    {
                        objectIndex.w = Singleton <WeatherManager> .instance.GetWindSpeed((position + position2) * 0.5f);
                    }
                    else if (turnAround)
                    {
                        objectIndex = new Vector4(objectIndex.z, objectIndex.w, objectIndex.x, objectIndex.y);
                    }
                    Matrix4x4 leftMatrix;
                    Matrix4x4 rightMatrix;
                    if (turnAround)
                    {
                        leftMatrix  = CalculateControlMatrix(cornerPosEL, c2, b2, cornerPosSR, cornerPosER, c1, b1, cornerPosSL, groupPosition, vScale);
                        rightMatrix = CalculateControlMatrix(cornerPosER, c1, b1, cornerPosSL, cornerPosEL, c2, b2, cornerPosSR, groupPosition, vScale);
                    }
                    else
                    {
                        leftMatrix  = CalculateControlMatrix(cornerPosSL, b1, c1, cornerPosER, cornerPosSR, b2, c2, cornerPosEL, groupPosition, vScale);
                        rightMatrix = CalculateControlMatrix(cornerPosSR, b2, c2, cornerPosEL, cornerPosSL, b1, c1, cornerPosER, groupPosition, vScale);
                    }
                    PopulateGroupData(info, segment, leftMatrix, rightMatrix, meshScale, objectIndex, ref vertexIndex, ref triangleIndex, groupPosition, data, ref requireSurfaceMaps);
                }
            }
        }
Beispiel #19
0
        public static void PopulateGroupData(NetInfo info, NetInfo.Segment segmentInfo, Matrix4x4 leftMatrix, Matrix4x4 rightMatrix, Vector4 meshScale, Vector4 objectIndex,
                                             ref int vertexIndex, ref int triangleIndex, Vector3 groupPosition, RenderGroup.MeshData meshData, ref bool requireSurfaceMaps)
        {
            if (segmentInfo.m_requireSurfaceMaps)
            {
                requireSurfaceMaps = true;
            }
            RenderGroup.MeshData meshData2 = segmentInfo.m_combinedLod.m_key.m_mesh.m_data;
            int[] triangles = meshData2.m_triangles;
            int   num       = triangles.Length;

            for (int i = 0; i < num; i++)
            {
                meshData.m_triangles[triangleIndex++] = triangles[i] + vertexIndex;
            }
            RenderGroup.VertexArrays vertexArrays = meshData2.VertexArrayMask();
            Vector3[] vertices = meshData2.m_vertices;
            Vector3[] normals  = meshData2.m_normals;
            Vector4[] tangents = meshData2.m_tangents;
            Vector2[] uvs      = meshData2.m_uvs;
            Vector2[] uvs2     = meshData2.m_uvs3;
            Color32[] colors   = meshData2.m_colors;
            int       num2     = vertices.Length;
            Vector2   vector   = new Vector2(objectIndex.x, objectIndex.y);
            Vector2   vector2  = new Vector2(objectIndex.z, objectIndex.w);

            for (int i = 0; i < num2; i++)
            {
                Vector3 vertex = vertices[i];
                vertex.x = vertex.x * meshScale.x + 0.5f;
                vertex.z = vertex.z * meshScale.y + 0.5f;
                Vector4   vector4  = new Vector4(vertex.z, 1f - vertex.z, 3f * vertex.z, 0f - vertex.z);
                Vector4   vector5  = new Vector4(vector4.y * vector4.y * vector4.y, vector4.z * vector4.y * vector4.y, vector4.z * vector4.x * vector4.y, vector4.x * vector4.x * vector4.x);
                Vector4   vector6  = new Vector4(vector4.y * (-1f - vector4.w) * 3f, vector4.y * (1f - vector4.z) * 3f, vector4.x * (2f - vector4.z) * 3f, vector4.x * (0f - vector4.w) * 3f);
                Vector4   vector7  = leftMatrix * vector5;
                Vector4   vector8  = vector7 + (rightMatrix * vector5 - vector7) * vertex.x;
                Vector4   vector9  = leftMatrix * vector6;
                Vector3   vector10 = Vector3.Normalize(vector9 + (rightMatrix * vector6 - vector9) * vertex.x);
                Vector3   vector11 = Vector3.Normalize(new Vector3(vector10.z, 0f, 0f - vector10.x));
                Matrix4x4 matrix4x = default(Matrix4x4);
                matrix4x.SetColumn(0, vector11);
                matrix4x.SetColumn(1, Vector3.Cross(vector10, vector11));
                matrix4x.SetColumn(2, vector10);
                if (segmentInfo.m_requireHeightMap)
                {
                    vector8.y = Singleton <TerrainManager> .instance.SampleDetailHeight((Vector3)vector8 + groupPosition);
                }
                meshData.m_vertices[vertexIndex] = new Vector3(vector8.x, vector8.y + vertex.y, vector8.z);
                if ((vertexArrays & RenderGroup.VertexArrays.Normals) != 0)
                {
                    meshData.m_normals[vertexIndex] = matrix4x.MultiplyVector(normals[i]);
                }
                else
                {
                    meshData.m_normals[vertexIndex] = new Vector3(0f, 1f, 0f);
                }
                if ((vertexArrays & RenderGroup.VertexArrays.Tangents) != 0)
                {
                    Vector4 vector12 = tangents[i];
                    Vector3 vector13 = matrix4x.MultiplyVector(vector12);
                    vector12.x = vector13.x;
                    vector12.y = vector13.y;
                    vector12.z = vector13.z;
                    meshData.m_tangents[vertexIndex] = vector12;
                }
                else
                {
                    meshData.m_tangents[vertexIndex] = new Vector4(1f, 0f, 0f, 1f);
                }
                Color32 color = (((vertexArrays & RenderGroup.VertexArrays.Colors) == 0) ? new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue) : colors[i]);
                if ((vertexArrays & RenderGroup.VertexArrays.Uvs) != 0)
                {
                    Vector2 vector14 = uvs[i];
                    vector14.y = Mathf.Lerp(vector14.y, vector8.w, (float)(int)color.g * 0.003921569f);
                    meshData.m_uvs[vertexIndex] = vector14;
                }
                else
                {
                    Vector2 vector15 = default(Vector2);
                    vector15.y = Mathf.Lerp(vector15.y, vector8.w, (float)(int)color.g * 0.003921569f);
                    meshData.m_uvs[vertexIndex] = vector15;
                }
                meshData.m_colors[vertexIndex] = info.m_netAI.GetGroupVertexColor(segmentInfo, i);
                meshData.m_uvs2[vertexIndex]   = vector;
                meshData.m_uvs4[vertexIndex]   = vector2;
                if ((vertexArrays & RenderGroup.VertexArrays.Uvs3) != 0)
                {
                    meshData.m_uvs3[vertexIndex] = uvs2[i];
                }
                vertexIndex++;
            }
        }
Beispiel #20
0
        public bool CalculateGroupData(ushort segmentID, int layer, ref int vertexCount, ref int triangleCount, ref int objectCount, ref RenderGroup.VertexArrays vertexArrays)
        {
            bool    result   = false;
            bool    hasProps = false;
            NetInfo info     = Info;

            if (m_problems != Notification.Problem.None && layer == Singleton <NotificationManager> .instance.m_notificationLayer && Notification.CalculateGroupData(ref vertexCount, ref triangleCount, ref objectCount, ref vertexArrays))
            {
                result = true;
            }
            if (info.m_hasForwardVehicleLanes != info.m_hasBackwardVehicleLanes && layer == Singleton <NetManager> .instance.m_arrowLayer && CalculateArrowGroupData(ref vertexCount, ref triangleCount, ref objectCount, ref vertexArrays))
            {
                result = true;
            }
            if (info.m_lanes != null)
            {
                bool          invert;
                NetNode.Flags flags;
                NetNode.Flags flags2;
                if ((m_flags & Flags.Invert) != 0)
                {
                    invert = true;
                    m_endNode.ToNode().Info.m_netAI.GetNodeFlags(m_endNode, ref m_endNode.ToNode(), segmentID, ref this, out flags);
                    m_startNode.ToNode().Info.m_netAI.GetNodeFlags(m_startNode, ref m_startNode.ToNode(), segmentID, ref this, out flags2);
                }
                else
                {
                    invert = false;
                    m_startNode.ToNode().Info.m_netAI.GetNodeFlags(m_startNode, ref m_startNode.ToNode(), segmentID, ref this, out flags);
                    m_endNode.ToNode().Info.m_netAI.GetNodeFlags(m_endNode, ref m_endNode.ToNode(), segmentID, ref this, out flags2);
                }
                bool destroyed = (m_flags & Flags.Collapsed) != 0;
                uint laneID    = m_lanes;
                for (int i = 0; i < info.m_lanes.Length; i++)
                {
                    if (laneID == 0)
                    {
                        break;
                    }
                    if (laneID.ToLane().CalculateGroupData(laneID, info.m_lanes[i], destroyed, flags, flags2, invert, layer, ref vertexCount, ref triangleCount, ref objectCount, ref vertexArrays, ref hasProps))
                    {
                        result = true;
                    }
                    laneID = laneID.ToLane().m_nextLane;
                }
            }
            if ((info.m_netLayers & (1 << layer)) != 0)
            {
                bool hasSegments = !info.m_segments.IsNullorEmpty();
                if (hasSegments || hasProps)
                {
                    result = true;
                    if (hasSegments)
                    {
                        for (int i = 0; i < info.m_segments.Length; i++)
                        {
                            NetInfo.Segment segmentInfo = info.m_segments[i];
                            if (segmentInfo.m_layer == layer && segmentInfo.CheckFlags(m_flags, out _) && segmentInfo.m_combinedLod != null)
                            {
                                CalculateGroupData(segmentInfo, ref vertexCount, ref triangleCount, ref objectCount, ref vertexArrays);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #21
0
 public static Segment GetMetaData(this NetInfo.Segment segment) =>
 (segment as IInfoExtended)?.GetMetaData <Segment>();
Beispiel #22
0
        protected override void EndRenderingImpl(RenderManager.CameraInfo cameraInfo)
        {
            FastList <RenderGroup> renderedGroups = Singleton <RenderManager> .instance.m_renderedGroups;

            this.m_nameInstanceBuffer.Clear();
            this.m_visibleRoadNameSegment  = 0;
            this.m_visibleTrafficLightNode = 0;
            for (int groupIndex = 0; groupIndex < renderedGroups.m_size; groupIndex++)
            {
                RenderGroup renderGroup = renderedGroups.m_buffer[groupIndex];
                if (renderGroup.m_instanceMask != 0)
                {
                    const int resolutionRatio = NODEGRID_RESOLUTION / RenderManager.GROUP_RESOLUTION; // = 270/45 = 6
                    int       net_x0          = renderGroup.m_x * resolutionRatio;
                    int       net_z0          = renderGroup.m_z * resolutionRatio;
                    int       net_x1          = (renderGroup.m_x + 1) * resolutionRatio - 1; // = net_x + 5
                    int       net_z1          = (renderGroup.m_z + 1) * resolutionRatio - 1; // = net_z + 5
                    for (int net_z = net_z0; net_z <= net_z1; net_z++)
                    {
                        for (int net_x = net_x0; net_x <= net_x1; net_x++)
                        {
                            int    gridIndex = net_z * NODEGRID_RESOLUTION + net_x;
                            ushort nodeID    = this.m_nodeGrid[gridIndex];
                            int    watchdog  = 0;
                            while (nodeID != 0)
                            {
                                nodeID.ToNode().RenderInstance(cameraInfo, nodeID, renderGroup.m_instanceMask);
                                nodeID = nodeID.ToNode().m_nextGridNode;
                                if (++watchdog >= 32768)
                                {
                                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                                    break;
                                }
                            }
                        }
                    }
                    for (int net_z = net_z0; net_z <= net_z1; net_z++)
                    {
                        for (int net_x = net_x0; net_x <= net_x1; net_x++)
                        {
                            int    gridIndex = net_z * 270 + net_x;
                            ushort segmentID = this.m_segmentGrid[gridIndex];
                            int    watchdog  = 0;
                            while (segmentID != 0)
                            {
                                this.m_segments.m_buffer[(int)segmentID].RenderInstance(cameraInfo, segmentID, renderGroup.m_instanceMask);
                                segmentID = this.m_segments.m_buffer[(int)segmentID].m_nextGridSegment;
                                if (++watchdog >= 36864)
                                {
                                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                                    break;
                                }
                            }
                        }
                    }
                }
            }
            this.m_lastVisibleRoadNameSegment  = this.m_visibleRoadNameSegment;
            this.m_lastVisibleTrafficLightNode = this.m_visibleTrafficLightNode;
            int num11 = PrefabCollection <NetInfo> .PrefabCount();

            for (int n = 0; n < num11; n++)
            {
                NetInfo prefab = PrefabCollection <NetInfo> .GetPrefab((uint)n);

                if (prefab != null)
                {
                    if (prefab.m_segments != null)
                    {
                        for (int num12 = 0; num12 < prefab.m_segments.Length; num12++)
                        {
                            NetInfo.Segment  segment     = prefab.m_segments[num12];
                            NetInfo.LodValue combinedLod = segment.m_combinedLod;
                            if (combinedLod != null && combinedLod.m_lodCount != 0)
                            {
                                NetSegment.RenderLod(cameraInfo, combinedLod);
                            }
                        }
                    }
                    if (prefab.m_nodes != null)
                    {
                        for (int num13 = 0; num13 < prefab.m_nodes.Length; num13++)
                        {
                            NetInfo.Node     node         = prefab.m_nodes[num13];
                            NetInfo.LodValue combinedLod2 = node.m_combinedLod;
                            if (combinedLod2 != null && combinedLod2.m_lodCount != 0)
                            {
                                if (node.m_directConnect)
                                {
                                    NetSegment.RenderLod(cameraInfo, combinedLod2);
                                }
                                else
                                {
                                    NetNode.RenderLod(cameraInfo, combinedLod2);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #23
0
 public static bool IsWireSegment(NetInfo.Segment segment)
 {
     return(segment?.m_material?.shader?.name == "Custom/Net/Electricity");
 }
Beispiel #24
0
 /// <summary>
 /// returns an extended clone of <paramref name="info"/>
 /// that can accept metadata.
 /// </summary>
 public static IInfoExtended <NetInfo.Segment> Extend(this NetInfo.Segment info) =>
 ExtendSegmentDelegate(info);
Beispiel #25
0
 // NetNode
 // Token: 0x060034C1 RID: 13505 RVA: 0x0023A834 File Offset: 0x00238C34
 private void RenderInstance(RenderManager.CameraInfo cameraInfo, ushort nodeID, NetInfo info, int iter, NetNode.Flags flags, ref uint instanceIndex, ref RenderManager.Instance data)
 {
     if (data.m_dirty)
     {
         data.m_dirty = false;
         if (iter == 0)
         {
             if ((flags & NetNode.Flags.Junction) != NetNode.Flags.None)
             {
                 this.RefreshJunctionData(nodeID, info, instanceIndex);
             }
             else if ((flags & NetNode.Flags.Bend) != NetNode.Flags.None)
             {
                 this.RefreshBendData(nodeID, info, instanceIndex, ref data);
             }
             else if ((flags & NetNode.Flags.End) != NetNode.Flags.None)
             {
                 this.RefreshEndData(nodeID, info, instanceIndex, ref data);
             }
         }
     }
     if (data.m_initialized)
     {
         if ((flags & NetNode.Flags.Junction) != NetNode.Flags.None)
         {
             if ((data.m_dataInt0 & 8) != 0)
             {
                 ushort segment  = this.GetSegment(data.m_dataInt0 & 7);
                 ushort segment2 = this.GetSegment(data.m_dataInt0 >> 4);
                 if (segment != 0 && segment2 != 0)
                 {
                     NetManager instance = Singleton <NetManager> .instance;
                     info = instance.m_segments.m_buffer[(int)segment].Info;
                     NetInfo       info2  = instance.m_segments.m_buffer[(int)segment2].Info;
                     NetNode.Flags flags2 = flags;
                     if (((instance.m_segments.m_buffer[(int)segment].m_flags | instance.m_segments.m_buffer[(int)segment2].m_flags) & NetSegment.Flags.Collapsed) != NetSegment.Flags.None)
                     {
                         flags2 |= NetNode.Flags.Collapsed;
                     }
                     for (int i = 0; i < info.m_nodes.Length; i++)
                     {
                         NetInfo.Node node = info.m_nodes[i];
                         if (node.CheckFlags(flags2) && node.m_directConnect && (node.m_connectGroup == NetInfo.ConnectGroup.None || (node.m_connectGroup & info2.m_connectGroup & NetInfo.ConnectGroup.AllGroups) != NetInfo.ConnectGroup.None))
                         {
                             Vector4 dataVector  = data.m_dataVector3;
                             Vector4 dataVector2 = data.m_dataVector0;
                             if (node.m_requireWindSpeed)
                             {
                                 dataVector.w = data.m_dataFloat0;
                             }
                             if ((node.m_connectGroup & NetInfo.ConnectGroup.Oneway) != NetInfo.ConnectGroup.None)
                             {
                                 bool flag = instance.m_segments.m_buffer[(int)segment].m_startNode == nodeID == ((instance.m_segments.m_buffer[(int)segment].m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None);
                                 if (info2.m_hasBackwardVehicleLanes != info2.m_hasForwardVehicleLanes || (node.m_connectGroup & NetInfo.ConnectGroup.Directional) != NetInfo.ConnectGroup.None)
                                 {
                                     bool flag2 = instance.m_segments.m_buffer[(int)segment2].m_startNode == nodeID == ((instance.m_segments.m_buffer[(int)segment2].m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None);
                                     if (flag == flag2)
                                     {
                                         goto IL_570;
                                     }
                                 }
                                 if (flag)
                                 {
                                     if ((node.m_connectGroup & NetInfo.ConnectGroup.OnewayStart) == NetInfo.ConnectGroup.None)
                                     {
                                         goto IL_570;
                                     }
                                 }
                                 else
                                 {
                                     if ((node.m_connectGroup & NetInfo.ConnectGroup.OnewayEnd) == NetInfo.ConnectGroup.None)
                                     {
                                         goto IL_570;
                                     }
                                     dataVector2.x = -dataVector2.x;
                                     dataVector2.y = -dataVector2.y;
                                 }
                             }
                             if (cameraInfo.CheckRenderDistance(data.m_position, node.m_lodRenderDistance))
                             {
                                 instance.m_materialBlock.Clear();
                                 instance.m_materialBlock.SetMatrix(instance.ID_LeftMatrix, data.m_dataMatrix0);
                                 instance.m_materialBlock.SetMatrix(instance.ID_RightMatrix, data.m_extraData.m_dataMatrix2);
                                 instance.m_materialBlock.SetVector(instance.ID_MeshScale, dataVector2);
                                 instance.m_materialBlock.SetVector(instance.ID_ObjectIndex, dataVector);
                                 instance.m_materialBlock.SetColor(instance.ID_Color, data.m_dataColor0);
                                 if (node.m_requireSurfaceMaps && data.m_dataTexture1 != null)
                                 {
                                     instance.m_materialBlock.SetTexture(instance.ID_SurfaceTexA, data.m_dataTexture0);
                                     instance.m_materialBlock.SetTexture(instance.ID_SurfaceTexB, data.m_dataTexture1);
                                     instance.m_materialBlock.SetVector(instance.ID_SurfaceMapping, data.m_dataVector1);
                                 }
                                 NetManager netManager = instance;
                                 netManager.m_drawCallData.m_defaultCalls = netManager.m_drawCallData.m_defaultCalls + 1;
                                 Graphics.DrawMesh(node.m_nodeMesh, data.m_position, data.m_rotation, node.m_nodeMaterial, node.m_layer, null, 0, instance.m_materialBlock);
                             }
                             else
                             {
                                 NetInfo.LodValue combinedLod = node.m_combinedLod;
                                 if (combinedLod != null)
                                 {
                                     if (node.m_requireSurfaceMaps && data.m_dataTexture0 != combinedLod.m_surfaceTexA)
                                     {
                                         if (combinedLod.m_lodCount != 0)
                                         {
                                             NetSegment.RenderLod(cameraInfo, combinedLod);
                                         }
                                         combinedLod.m_surfaceTexA    = data.m_dataTexture0;
                                         combinedLod.m_surfaceTexB    = data.m_dataTexture1;
                                         combinedLod.m_surfaceMapping = data.m_dataVector1;
                                     }
                                     combinedLod.m_leftMatrices[combinedLod.m_lodCount]  = data.m_dataMatrix0;
                                     combinedLod.m_rightMatrices[combinedLod.m_lodCount] = data.m_extraData.m_dataMatrix2;
                                     combinedLod.m_meshScales[combinedLod.m_lodCount]    = dataVector2;
                                     combinedLod.m_objectIndices[combinedLod.m_lodCount] = dataVector;
                                     combinedLod.m_meshLocations[combinedLod.m_lodCount] = data.m_position;
                                     combinedLod.m_lodMin = Vector3.Min(combinedLod.m_lodMin, data.m_position);
                                     combinedLod.m_lodMax = Vector3.Max(combinedLod.m_lodMax, data.m_position);
                                     if (++combinedLod.m_lodCount == combinedLod.m_leftMatrices.Length)
                                     {
                                         NetSegment.RenderLod(cameraInfo, combinedLod);
                                     }
                                 }
                             }
                         }
                         IL_570 :;
                     }
                 }
             }
             else
             {
                 ushort segment3 = this.GetSegment(data.m_dataInt0 & 7);
                 if (segment3 != 0)
                 {
                     NetManager instance2 = Singleton <NetManager> .instance;
                     info = instance2.m_segments.m_buffer[(int)segment3].Info;
                     for (int j = 0; j < info.m_nodes.Length; j++)
                     {
                         NetInfo.Node node2 = info.m_nodes[j];
                         if (node2.CheckFlags(flags) && !node2.m_directConnect)
                         {
                             Vector4 dataVector3 = data.m_extraData.m_dataVector4;
                             if (node2.m_requireWindSpeed)
                             {
                                 dataVector3.w = data.m_dataFloat0;
                             }
                             if (cameraInfo.CheckRenderDistance(data.m_position, node2.m_lodRenderDistance))
                             {
                                 instance2.m_materialBlock.Clear();
                                 instance2.m_materialBlock.SetMatrix(instance2.ID_LeftMatrix, data.m_dataMatrix0);
                                 instance2.m_materialBlock.SetMatrix(instance2.ID_RightMatrix, data.m_extraData.m_dataMatrix2);
                                 instance2.m_materialBlock.SetMatrix(instance2.ID_LeftMatrixB, data.m_extraData.m_dataMatrix3);
                                 instance2.m_materialBlock.SetMatrix(instance2.ID_RightMatrixB, data.m_dataMatrix1);
                                 instance2.m_materialBlock.SetVector(instance2.ID_MeshScale, data.m_dataVector0);
                                 instance2.m_materialBlock.SetVector(instance2.ID_CenterPos, data.m_dataVector1);
                                 instance2.m_materialBlock.SetVector(instance2.ID_SideScale, data.m_dataVector2);
                                 instance2.m_materialBlock.SetVector(instance2.ID_ObjectIndex, dataVector3);
                                 instance2.m_materialBlock.SetColor(instance2.ID_Color, data.m_dataColor0);
                                 if (node2.m_requireSurfaceMaps && data.m_dataTexture1 != null)
                                 {
                                     instance2.m_materialBlock.SetTexture(instance2.ID_SurfaceTexA, data.m_dataTexture0);
                                     instance2.m_materialBlock.SetTexture(instance2.ID_SurfaceTexB, data.m_dataTexture1);
                                     instance2.m_materialBlock.SetVector(instance2.ID_SurfaceMapping, data.m_dataVector3);
                                 }
                                 NetManager netManager2 = instance2;
                                 netManager2.m_drawCallData.m_defaultCalls = netManager2.m_drawCallData.m_defaultCalls + 1;
                                 Graphics.DrawMesh(node2.m_nodeMesh, data.m_position, data.m_rotation, node2.m_nodeMaterial, node2.m_layer, null, 0, instance2.m_materialBlock);
                             }
                             else
                             {
                                 NetInfo.LodValue combinedLod2 = node2.m_combinedLod;
                                 if (combinedLod2 != null)
                                 {
                                     if (node2.m_requireSurfaceMaps && data.m_dataTexture0 != combinedLod2.m_surfaceTexA)
                                     {
                                         if (combinedLod2.m_lodCount != 0)
                                         {
                                             NetNode.RenderLod(cameraInfo, combinedLod2);
                                         }
                                         combinedLod2.m_surfaceTexA    = data.m_dataTexture0;
                                         combinedLod2.m_surfaceTexB    = data.m_dataTexture1;
                                         combinedLod2.m_surfaceMapping = data.m_dataVector3;
                                     }
                                     combinedLod2.m_leftMatrices[combinedLod2.m_lodCount]    = data.m_dataMatrix0;
                                     combinedLod2.m_leftMatricesB[combinedLod2.m_lodCount]   = data.m_extraData.m_dataMatrix3;
                                     combinedLod2.m_rightMatrices[combinedLod2.m_lodCount]   = data.m_extraData.m_dataMatrix2;
                                     combinedLod2.m_rightMatricesB[combinedLod2.m_lodCount]  = data.m_dataMatrix1;
                                     combinedLod2.m_meshScales[combinedLod2.m_lodCount]      = data.m_dataVector0;
                                     combinedLod2.m_centerPositions[combinedLod2.m_lodCount] = data.m_dataVector1;
                                     combinedLod2.m_sideScales[combinedLod2.m_lodCount]      = data.m_dataVector2;
                                     combinedLod2.m_objectIndices[combinedLod2.m_lodCount]   = dataVector3;
                                     combinedLod2.m_meshLocations[combinedLod2.m_lodCount]   = data.m_position;
                                     combinedLod2.m_lodMin = Vector3.Min(combinedLod2.m_lodMin, data.m_position);
                                     combinedLod2.m_lodMax = Vector3.Max(combinedLod2.m_lodMax, data.m_position);
                                     if (++combinedLod2.m_lodCount == combinedLod2.m_leftMatrices.Length)
                                     {
                                         NetNode.RenderLod(cameraInfo, combinedLod2);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else if ((flags & NetNode.Flags.End) != NetNode.Flags.None)
         {
             NetManager instance3 = Singleton <NetManager> .instance;
             for (int k = 0; k < info.m_nodes.Length; k++)
             {
                 NetInfo.Node node3 = info.m_nodes[k];
                 if (node3.CheckFlags(flags) && !node3.m_directConnect)
                 {
                     Vector4 dataVector4 = data.m_extraData.m_dataVector4;
                     if (node3.m_requireWindSpeed)
                     {
                         dataVector4.w = data.m_dataFloat0;
                     }
                     if (cameraInfo.CheckRenderDistance(data.m_position, node3.m_lodRenderDistance))
                     {
                         instance3.m_materialBlock.Clear();
                         instance3.m_materialBlock.SetMatrix(instance3.ID_LeftMatrix, data.m_dataMatrix0);
                         instance3.m_materialBlock.SetMatrix(instance3.ID_RightMatrix, data.m_extraData.m_dataMatrix2);
                         instance3.m_materialBlock.SetMatrix(instance3.ID_LeftMatrixB, data.m_extraData.m_dataMatrix3);
                         instance3.m_materialBlock.SetMatrix(instance3.ID_RightMatrixB, data.m_dataMatrix1);
                         instance3.m_materialBlock.SetVector(instance3.ID_MeshScale, data.m_dataVector0);
                         instance3.m_materialBlock.SetVector(instance3.ID_CenterPos, data.m_dataVector1);
                         instance3.m_materialBlock.SetVector(instance3.ID_SideScale, data.m_dataVector2);
                         instance3.m_materialBlock.SetVector(instance3.ID_ObjectIndex, dataVector4);
                         instance3.m_materialBlock.SetColor(instance3.ID_Color, data.m_dataColor0);
                         if (node3.m_requireSurfaceMaps && data.m_dataTexture1 != null)
                         {
                             instance3.m_materialBlock.SetTexture(instance3.ID_SurfaceTexA, data.m_dataTexture0);
                             instance3.m_materialBlock.SetTexture(instance3.ID_SurfaceTexB, data.m_dataTexture1);
                             instance3.m_materialBlock.SetVector(instance3.ID_SurfaceMapping, data.m_dataVector3);
                         }
                         NetManager netManager3 = instance3;
                         netManager3.m_drawCallData.m_defaultCalls = netManager3.m_drawCallData.m_defaultCalls + 1;
                         Graphics.DrawMesh(node3.m_nodeMesh, data.m_position, data.m_rotation, node3.m_nodeMaterial, node3.m_layer, null, 0, instance3.m_materialBlock);
                     }
                     else
                     {
                         NetInfo.LodValue combinedLod3 = node3.m_combinedLod;
                         if (combinedLod3 != null)
                         {
                             if (node3.m_requireSurfaceMaps && data.m_dataTexture0 != combinedLod3.m_surfaceTexA)
                             {
                                 if (combinedLod3.m_lodCount != 0)
                                 {
                                     NetNode.RenderLod(cameraInfo, combinedLod3);
                                 }
                                 combinedLod3.m_surfaceTexA    = data.m_dataTexture0;
                                 combinedLod3.m_surfaceTexB    = data.m_dataTexture1;
                                 combinedLod3.m_surfaceMapping = data.m_dataVector3;
                             }
                             combinedLod3.m_leftMatrices[combinedLod3.m_lodCount]    = data.m_dataMatrix0;
                             combinedLod3.m_leftMatricesB[combinedLod3.m_lodCount]   = data.m_extraData.m_dataMatrix3;
                             combinedLod3.m_rightMatrices[combinedLod3.m_lodCount]   = data.m_extraData.m_dataMatrix2;
                             combinedLod3.m_rightMatricesB[combinedLod3.m_lodCount]  = data.m_dataMatrix1;
                             combinedLod3.m_meshScales[combinedLod3.m_lodCount]      = data.m_dataVector0;
                             combinedLod3.m_centerPositions[combinedLod3.m_lodCount] = data.m_dataVector1;
                             combinedLod3.m_sideScales[combinedLod3.m_lodCount]      = data.m_dataVector2;
                             combinedLod3.m_objectIndices[combinedLod3.m_lodCount]   = dataVector4;
                             combinedLod3.m_meshLocations[combinedLod3.m_lodCount]   = data.m_position;
                             combinedLod3.m_lodMin = Vector3.Min(combinedLod3.m_lodMin, data.m_position);
                             combinedLod3.m_lodMax = Vector3.Max(combinedLod3.m_lodMax, data.m_position);
                             if (++combinedLod3.m_lodCount == combinedLod3.m_leftMatrices.Length)
                             {
                                 NetNode.RenderLod(cameraInfo, combinedLod3);
                             }
                         }
                     }
                 }
             }
         }
         else if ((flags & NetNode.Flags.Bend) != NetNode.Flags.None)
         {
             NetManager instance4 = Singleton <NetManager> .instance;
             for (int l = 0; l < info.m_segments.Length; l++)
             {
                 NetInfo.Segment segment4 = info.m_segments[l];
                 bool            flag3;
                 if (segment4.CheckFlags(info.m_netAI.GetBendFlags(nodeID, ref this), out flag3) && !segment4.m_disableBendNodes)
                 {
                     Vector4 dataVector5 = data.m_dataVector3;
                     Vector4 dataVector6 = data.m_dataVector0;
                     if (segment4.m_requireWindSpeed)
                     {
                         dataVector5.w = data.m_dataFloat0;
                     }
                     if (flag3)
                     {
                         dataVector6.x = -dataVector6.x;
                         dataVector6.y = -dataVector6.y;
                     }
                     if (cameraInfo.CheckRenderDistance(data.m_position, segment4.m_lodRenderDistance))
                     {
                         instance4.m_materialBlock.Clear();
                         instance4.m_materialBlock.SetMatrix(instance4.ID_LeftMatrix, data.m_dataMatrix0);
                         instance4.m_materialBlock.SetMatrix(instance4.ID_RightMatrix, data.m_extraData.m_dataMatrix2);
                         instance4.m_materialBlock.SetVector(instance4.ID_MeshScale, dataVector6);
                         instance4.m_materialBlock.SetVector(instance4.ID_ObjectIndex, dataVector5);
                         instance4.m_materialBlock.SetColor(instance4.ID_Color, data.m_dataColor0);
                         if (segment4.m_requireSurfaceMaps && data.m_dataTexture1 != null)
                         {
                             instance4.m_materialBlock.SetTexture(instance4.ID_SurfaceTexA, data.m_dataTexture0);
                             instance4.m_materialBlock.SetTexture(instance4.ID_SurfaceTexB, data.m_dataTexture1);
                             instance4.m_materialBlock.SetVector(instance4.ID_SurfaceMapping, data.m_dataVector1);
                         }
                         NetManager netManager4 = instance4;
                         netManager4.m_drawCallData.m_defaultCalls = netManager4.m_drawCallData.m_defaultCalls + 1;
                         Graphics.DrawMesh(segment4.m_segmentMesh, data.m_position, data.m_rotation, segment4.m_segmentMaterial, segment4.m_layer, null, 0, instance4.m_materialBlock);
                     }
                     else
                     {
                         NetInfo.LodValue combinedLod4 = segment4.m_combinedLod;
                         if (combinedLod4 != null)
                         {
                             if (segment4.m_requireSurfaceMaps && data.m_dataTexture0 != combinedLod4.m_surfaceTexA)
                             {
                                 if (combinedLod4.m_lodCount != 0)
                                 {
                                     NetSegment.RenderLod(cameraInfo, combinedLod4);
                                 }
                                 combinedLod4.m_surfaceTexA    = data.m_dataTexture0;
                                 combinedLod4.m_surfaceTexB    = data.m_dataTexture1;
                                 combinedLod4.m_surfaceMapping = data.m_dataVector1;
                             }
                             combinedLod4.m_leftMatrices[combinedLod4.m_lodCount]  = data.m_dataMatrix0;
                             combinedLod4.m_rightMatrices[combinedLod4.m_lodCount] = data.m_extraData.m_dataMatrix2;
                             combinedLod4.m_meshScales[combinedLod4.m_lodCount]    = dataVector6;
                             combinedLod4.m_objectIndices[combinedLod4.m_lodCount] = dataVector5;
                             combinedLod4.m_meshLocations[combinedLod4.m_lodCount] = data.m_position;
                             combinedLod4.m_lodMin = Vector3.Min(combinedLod4.m_lodMin, data.m_position);
                             combinedLod4.m_lodMax = Vector3.Max(combinedLod4.m_lodMax, data.m_position);
                             if (++combinedLod4.m_lodCount == combinedLod4.m_leftMatrices.Length)
                             {
                                 NetSegment.RenderLod(cameraInfo, combinedLod4);
                             }
                         }
                     }
                 }
             }
             for (int m = 0; m < info.m_nodes.Length; m++)
             {
                 ushort segment5 = this.GetSegment(data.m_dataInt0 & 7);
                 ushort segment6 = this.GetSegment(data.m_dataInt0 >> 4);
                 if (((instance4.m_segments.m_buffer[(int)segment5].m_flags | instance4.m_segments.m_buffer[(int)segment6].m_flags) & NetSegment.Flags.Collapsed) != NetSegment.Flags.None)
                 {
                     NetNode.Flags flags3 = flags | NetNode.Flags.Collapsed;
                 }
                 NetInfo.Node node4 = info.m_nodes[m];
                 if (node4.CheckFlags(flags) && node4.m_directConnect && (node4.m_connectGroup == NetInfo.ConnectGroup.None || (node4.m_connectGroup & info.m_connectGroup & NetInfo.ConnectGroup.AllGroups) != NetInfo.ConnectGroup.None))
                 {
                     Vector4 dataVector7 = data.m_dataVector3;
                     Vector4 dataVector8 = data.m_dataVector0;
                     if (node4.m_requireWindSpeed)
                     {
                         dataVector7.w = data.m_dataFloat0;
                     }
                     if ((node4.m_connectGroup & NetInfo.ConnectGroup.Oneway) != NetInfo.ConnectGroup.None)
                     {
                         bool flag4 = instance4.m_segments.m_buffer[(int)segment5].m_startNode == nodeID == ((instance4.m_segments.m_buffer[(int)segment5].m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None);
                         bool flag5 = instance4.m_segments.m_buffer[(int)segment6].m_startNode == nodeID == ((instance4.m_segments.m_buffer[(int)segment6].m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None);
                         if (flag4 == flag5)
                         {
                             goto IL_1637;
                         }
                         if (flag4)
                         {
                             if ((node4.m_connectGroup & NetInfo.ConnectGroup.OnewayStart) == NetInfo.ConnectGroup.None)
                             {
                                 goto IL_1637;
                             }
                         }
                         else
                         {
                             if ((node4.m_connectGroup & NetInfo.ConnectGroup.OnewayEnd) == NetInfo.ConnectGroup.None)
                             {
                                 goto IL_1637;
                             }
                             dataVector8.x = -dataVector8.x;
                             dataVector8.y = -dataVector8.y;
                         }
                     }
                     if (cameraInfo.CheckRenderDistance(data.m_position, node4.m_lodRenderDistance))
                     {
                         instance4.m_materialBlock.Clear();
                         instance4.m_materialBlock.SetMatrix(instance4.ID_LeftMatrix, data.m_dataMatrix0);
                         instance4.m_materialBlock.SetMatrix(instance4.ID_RightMatrix, data.m_extraData.m_dataMatrix2);
                         instance4.m_materialBlock.SetVector(instance4.ID_MeshScale, dataVector8);
                         instance4.m_materialBlock.SetVector(instance4.ID_ObjectIndex, dataVector7);
                         instance4.m_materialBlock.SetColor(instance4.ID_Color, data.m_dataColor0);
                         if (node4.m_requireSurfaceMaps && data.m_dataTexture1 != null)
                         {
                             instance4.m_materialBlock.SetTexture(instance4.ID_SurfaceTexA, data.m_dataTexture0);
                             instance4.m_materialBlock.SetTexture(instance4.ID_SurfaceTexB, data.m_dataTexture1);
                             instance4.m_materialBlock.SetVector(instance4.ID_SurfaceMapping, data.m_dataVector1);
                         }
                         NetManager netManager5 = instance4;
                         netManager5.m_drawCallData.m_defaultCalls = netManager5.m_drawCallData.m_defaultCalls + 1;
                         Graphics.DrawMesh(node4.m_nodeMesh, data.m_position, data.m_rotation, node4.m_nodeMaterial, node4.m_layer, null, 0, instance4.m_materialBlock);
                     }
                     else
                     {
                         NetInfo.LodValue combinedLod5 = node4.m_combinedLod;
                         if (combinedLod5 != null)
                         {
                             if (node4.m_requireSurfaceMaps && data.m_dataTexture0 != combinedLod5.m_surfaceTexA)
                             {
                                 if (combinedLod5.m_lodCount != 0)
                                 {
                                     NetSegment.RenderLod(cameraInfo, combinedLod5);
                                 }
                                 combinedLod5.m_surfaceTexA    = data.m_dataTexture0;
                                 combinedLod5.m_surfaceTexB    = data.m_dataTexture1;
                                 combinedLod5.m_surfaceMapping = data.m_dataVector1;
                             }
                             combinedLod5.m_leftMatrices[combinedLod5.m_lodCount]  = data.m_dataMatrix0;
                             combinedLod5.m_rightMatrices[combinedLod5.m_lodCount] = data.m_extraData.m_dataMatrix2;
                             combinedLod5.m_meshScales[combinedLod5.m_lodCount]    = dataVector8;
                             combinedLod5.m_objectIndices[combinedLod5.m_lodCount] = dataVector7;
                             combinedLod5.m_meshLocations[combinedLod5.m_lodCount] = data.m_position;
                             combinedLod5.m_lodMin = Vector3.Min(combinedLod5.m_lodMin, data.m_position);
                             combinedLod5.m_lodMax = Vector3.Max(combinedLod5.m_lodMax, data.m_position);
                             if (++combinedLod5.m_lodCount == combinedLod5.m_leftMatrices.Length)
                             {
                                 NetSegment.RenderLod(cameraInfo, combinedLod5);
                             }
                         }
                     }
                 }
                 IL_1637 :;
             }
         }
     }
     instanceIndex = (uint)data.m_nextInstance;
 }
Beispiel #26
0
        private void RenderInstance(ref NetSegment This, RenderManager.CameraInfo cameraInfo, ushort segmentID, int layerMask, NetInfo info, ref RenderManager.Instance data)
        {
            NetManager instance = Singleton <NetManager> .instance;

            if (data.m_dirty)
            {
                data.m_dirty = false;
                Vector3 position  = instance.m_nodes.m_buffer[m_startNode].m_position;
                Vector3 position2 = instance.m_nodes.m_buffer[m_endNode].m_position;
                data.m_position     = (position + position2) * 0.5f;
                data.m_rotation     = Quaternion.identity;
                data.m_dataColor0   = info.m_color;
                data.m_dataColor0.a = 0f;
                data.m_dataFloat0   = Singleton <WeatherManager> .instance.GetWindSpeed(data.m_position);

                data.m_dataVector0 = new Vector4(0.5f / info.m_halfWidth, 1f / info.m_segmentLength, 1f, 1f);
                Vector4 colorLocation = RenderManager.GetColorLocation((uint)(49152 + segmentID));
                Vector4 vector        = colorLocation;
                if (NetNode.BlendJunction(m_startNode))
                {
                    colorLocation = RenderManager.GetColorLocation((uint)(86016 + m_startNode));
                }
                if (NetNode.BlendJunction(m_endNode))
                {
                    vector = RenderManager.GetColorLocation((uint)(86016 + m_endNode));
                }
                data.m_dataVector3 = new Vector4(colorLocation.x, colorLocation.y, vector.x, vector.y);
                if (info.m_segments == null || info.m_segments.Length == 0)
                {
                    if (info.m_lanes != null)
                    {
                        bool invert;
                        if ((m_flags & Flags.Invert) != 0)
                        {
                            invert = true;
                            instance.m_nodes.m_buffer[m_endNode].Info.m_netAI.GetNodeState(m_endNode, ref instance.m_nodes.m_buffer[m_endNode], segmentID, ref This, out _, out _);       // unused code
                            instance.m_nodes.m_buffer[m_startNode].Info.m_netAI.GetNodeState(m_startNode, ref instance.m_nodes.m_buffer[m_startNode], segmentID, ref This, out _, out _); // unused code
                        }
                        else
                        {
                            invert = false;
                            instance.m_nodes.m_buffer[m_startNode].Info.m_netAI.GetNodeState(m_startNode, ref instance.m_nodes.m_buffer[m_startNode], segmentID, ref This, out _, out _); // unused code
                            instance.m_nodes.m_buffer[m_endNode].Info.m_netAI.GetNodeState(m_endNode, ref instance.m_nodes.m_buffer[m_endNode], segmentID, ref This, out _, out _);       // unused code
                        }
                        float startAngle = (float)(int)m_cornerAngleStart * ((float)Math.PI / 128f);
                        float endAngle   = (float)(int)m_cornerAngleEnd * ((float)Math.PI / 128f);
                        int   propIndex  = 0;
                        uint  num        = m_lanes;
                        for (int i = 0; i < info.m_lanes.Length; i++)
                        {
                            if (num == 0)
                            {
                                break;
                            }
                            instance.m_lanes.m_buffer[num].RefreshInstance(num, info.m_lanes[i], startAngle, endAngle, invert, ref data, ref propIndex);
                            num = instance.m_lanes.m_buffer[num].m_nextLane;
                        }
                    }
                }
                else
                {
                    float vScale = info.m_netAI.GetVScale();
                    CalculateCorner(segmentID, heightOffset: true, start: true, leftSide: true, out var posSL, out var dirSL, out var smoothStart);
                    CalculateCorner(segmentID, heightOffset: true, start: false, leftSide: true, out var posEL, out var dirEL, out var smoothEnd);
                    CalculateCorner(segmentID, heightOffset: true, start: true, leftSide: false, out var posSR, out var dirSR, out smoothStart);
                    CalculateCorner(segmentID, heightOffset: true, start: false, leftSide: false, out var posER, out var dirER, out smoothEnd);
                    CalculateMiddlePoints(posSL, dirSL, posER, dirER, smoothStart, smoothEnd, out var b1, out var c1);
                    CalculateMiddlePoints(posSR, dirSR, posEL, dirEL, smoothStart, smoothEnd, out var b2, out var c2);
                    data.m_dataMatrix0 = CalculateControlMatrix(posSL, b1, c1, posER, posSR, b2, c2, posEL, data.m_position, vScale);
                    data.m_dataMatrix1 = CalculateControlMatrix(posSR, b2, c2, posEL, posSL, b1, c1, posER, data.m_position, vScale);
                }
                if (info.m_requireSurfaceMaps)
                {
                    Singleton <TerrainManager> .instance.GetSurfaceMapping(data.m_position, out data.m_dataTexture0, out data.m_dataTexture1, out data.m_dataVector1);
                }
                else if (info.m_requireHeightMap)
                {
                    Singleton <TerrainManager> .instance.GetHeightMapping(data.m_position, out data.m_dataTexture0, out data.m_dataVector1, out data.m_dataVector2);
                }
            }
            if (info.m_segments != null && (layerMask & info.m_netLayers) != 0)
            {
                for (int j = 0; j < info.m_segments.Length; j++)
                {
                    NetInfo.Segment segment = info.m_segments[j];
                    if (!segment.CheckFlags(m_flags, out var turnAround))
                    {
                        continue;
                    }
                    Vector4 objectIndex = data.m_dataVector3;
                    Vector4 meshScale   = data.m_dataVector0;
                    if (segment.m_requireWindSpeed)
                    {
                        objectIndex.w = data.m_dataFloat0;
                    }
                    if (turnAround)
                    {
                        meshScale.x = 0f - meshScale.x;
                        meshScale.y = 0f - meshScale.y;
                    }
                    if (cameraInfo.CheckRenderDistance(data.m_position, segment.m_lodRenderDistance))
                    {
                        instance.m_materialBlock.Clear();
                        instance.m_materialBlock.SetMatrix(instance.ID_LeftMatrix, data.m_dataMatrix0);
                        instance.m_materialBlock.SetMatrix(instance.ID_RightMatrix, data.m_dataMatrix1);
                        instance.m_materialBlock.SetVector(instance.ID_MeshScale, meshScale);
                        instance.m_materialBlock.SetVector(instance.ID_ObjectIndex, objectIndex);
                        instance.m_materialBlock.SetColor(instance.ID_Color, data.m_dataColor0);
                        if (segment.m_requireSurfaceMaps && data.m_dataTexture0 != null)
                        {
                            instance.m_materialBlock.SetTexture(instance.ID_SurfaceTexA, data.m_dataTexture0);
                            instance.m_materialBlock.SetTexture(instance.ID_SurfaceTexB, data.m_dataTexture1);
                            instance.m_materialBlock.SetVector(instance.ID_SurfaceMapping, data.m_dataVector1);
                        }
                        else if (segment.m_requireHeightMap && data.m_dataTexture0 != null)
                        {
                            instance.m_materialBlock.SetTexture(instance.ID_HeightMap, data.m_dataTexture0);
                            instance.m_materialBlock.SetVector(instance.ID_HeightMapping, data.m_dataVector1);
                            instance.m_materialBlock.SetVector(instance.ID_SurfaceMapping, data.m_dataVector2);
                        }
                        instance.m_drawCallData.m_defaultCalls++;
                        Graphics.DrawMesh(segment.m_segmentMesh, data.m_position, data.m_rotation, segment.m_segmentMaterial, segment.m_layer, null, 0, instance.m_materialBlock);
                        continue;
                    }
                    NetInfo.LodValue combinedLod = segment.m_combinedLod;
                    if (combinedLod == null)
                    {
                        continue;
                    }
                    if (segment.m_requireSurfaceMaps)
                    {
                        if (data.m_dataTexture0 != combinedLod.m_surfaceTexA)
                        {
                            if (combinedLod.m_lodCount != 0)
                            {
                                RenderLod(cameraInfo, combinedLod);
                            }
                            combinedLod.m_surfaceTexA    = data.m_dataTexture0;
                            combinedLod.m_surfaceTexB    = data.m_dataTexture1;
                            combinedLod.m_surfaceMapping = data.m_dataVector1;
                        }
                    }
                    else if (segment.m_requireHeightMap && data.m_dataTexture0 != combinedLod.m_heightMap)
                    {
                        if (combinedLod.m_lodCount != 0)
                        {
                            RenderLod(cameraInfo, combinedLod);
                        }
                        combinedLod.m_heightMap      = data.m_dataTexture0;
                        combinedLod.m_heightMapping  = data.m_dataVector1;
                        combinedLod.m_surfaceMapping = data.m_dataVector2;
                    }
                    ref Matrix4x4 reference = ref combinedLod.m_leftMatrices[combinedLod.m_lodCount];
                    reference = data.m_dataMatrix0;
                    ref Matrix4x4 reference2 = ref combinedLod.m_rightMatrices[combinedLod.m_lodCount];
                    reference2 = data.m_dataMatrix1;
                    combinedLod.m_meshScales[combinedLod.m_lodCount]    = meshScale;
                    combinedLod.m_objectIndices[combinedLod.m_lodCount] = objectIndex;
                    ref Vector4 reference3 = ref combinedLod.m_meshLocations[combinedLod.m_lodCount];
        internal static object CustomDeserialize(Package p, Type t, PackageReader r)
        {
            // Props and trees in buildings and parks.
            if (t == typeof(BuildingInfo.Prop))
            {
                PropInfo pi = Get <PropInfo>(r.ReadString()); // old name format (without package name) is possible
                TreeInfo ti = Get <TreeInfo>(r.ReadString()); // old name format (without package name) is possible

                if (instance.report && UsedAssets.instance.GotAnyContainer())
                {
                    if (pi != null)
                    {
                        string n = pi.gameObject.name;

                        if (!string.IsNullOrEmpty(n) && n.IndexOf('.') >= 0)
                        {
                            UsedAssets.instance.IndirectProps.Add(n);
                        }
                    }

                    if (ti != null)
                    {
                        string n = ti.gameObject.name;

                        if (!string.IsNullOrEmpty(n) && n.IndexOf('.') >= 0)
                        {
                            UsedAssets.instance.IndirectTrees.Add(n);
                        }
                    }
                }

                return(new BuildingInfo.Prop
                {
                    m_prop = pi,
                    m_tree = ti,
                    m_position = r.ReadVector3(),
                    m_angle = r.ReadSingle(),
                    m_probability = r.ReadInt32(),
                    m_fixedHeight = r.ReadBoolean()
                });
            }

            // Paths (nets) in buildings.
            if (t == typeof(BuildingInfo.PathInfo))
            {
                string  fullName           = r.ReadString();
                NetInfo ni                 = Get <NetInfo>(fullName);
                BuildingInfo.PathInfo path = new BuildingInfo.PathInfo();
                path.m_netInfo         = ni;
                path.m_nodes           = r.ReadVector3Array();
                path.m_curveTargets    = r.ReadVector3Array();
                path.m_invertSegments  = r.ReadBoolean();
                path.m_maxSnapDistance = r.ReadSingle();

                if (p.version >= 5)
                {
                    path.m_forbidLaneConnection = r.ReadBooleanArray();
                    path.m_trafficLights        = (BuildingInfo.TrafficLights[])(object) r.ReadInt32Array();
                    path.m_yieldSigns           = r.ReadBooleanArray();
                }

                return(path);
            }

            if (t == typeof(Package.Asset))
            {
                return(r.ReadAsset(p));
            }

            // It seems that trailers are listed in the save game so this is not necessary. Better to be safe however
            // because a missing trailer reference is fatal for the simulation thread.
            if (t == typeof(VehicleInfo.VehicleTrailer))
            {
                string      name     = r.ReadString();
                string      fullName = p.packageName + "." + name;
                VehicleInfo vi       = Get <VehicleInfo>(p, fullName, name, false);

                VehicleInfo.VehicleTrailer trailer;
                trailer.m_info              = vi;
                trailer.m_probability       = r.ReadInt32();
                trailer.m_invertProbability = r.ReadInt32();
                return(trailer);
            }

            if (t == typeof(NetInfo.Lane))
            {
                return(new NetInfo.Lane
                {
                    m_position = r.ReadSingle(),
                    m_width = r.ReadSingle(),
                    m_verticalOffset = r.ReadSingle(),
                    m_stopOffset = r.ReadSingle(),
                    m_speedLimit = r.ReadSingle(),
                    m_direction = (NetInfo.Direction)r.ReadInt32(),
                    m_laneType = (NetInfo.LaneType)r.ReadInt32(),
                    m_vehicleType = (VehicleInfo.VehicleType)r.ReadInt32(),
                    m_stopType = (VehicleInfo.VehicleType)r.ReadInt32(),
                    m_laneProps = GetNetLaneProps(p, r),
                    m_allowConnect = r.ReadBoolean(),
                    m_useTerrainHeight = r.ReadBoolean(),
                    m_centerPlatform = r.ReadBoolean(),
                    m_elevated = r.ReadBoolean()
                });
            }

            if (t == typeof(NetInfo.Segment))
            {
                NetInfo.Segment segment  = new NetInfo.Segment();
                string          checksum = r.ReadString();
                segment.m_mesh              = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, true);
                checksum                    = r.ReadString();
                segment.m_material          = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, true);
                checksum                    = r.ReadString();
                segment.m_lodMesh           = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, false);
                checksum                    = r.ReadString();
                segment.m_lodMaterial       = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, false);
                segment.m_forwardRequired   = (NetSegment.Flags)r.ReadInt32();
                segment.m_forwardForbidden  = (NetSegment.Flags)r.ReadInt32();
                segment.m_backwardRequired  = (NetSegment.Flags)r.ReadInt32();
                segment.m_backwardForbidden = (NetSegment.Flags)r.ReadInt32();
                segment.m_emptyTransparent  = r.ReadBoolean();
                segment.m_disableBendNodes  = r.ReadBoolean();
                return(segment);
            }

            if (t == typeof(NetInfo.Node))
            {
                NetInfo.Node node     = new NetInfo.Node();
                string       checksum = r.ReadString();
                node.m_mesh             = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, true);
                checksum                = r.ReadString();
                node.m_material         = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, true);
                checksum                = r.ReadString();
                node.m_lodMesh          = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, false);
                checksum                = r.ReadString();
                node.m_lodMaterial      = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, false);
                node.m_flagsRequired    = (NetNode.Flags)r.ReadInt32();
                node.m_flagsForbidden   = (NetNode.Flags)r.ReadInt32();
                node.m_connectGroup     = (NetInfo.ConnectGroup)r.ReadInt32();
                node.m_directConnect    = r.ReadBoolean();
                node.m_emptyTransparent = r.ReadBoolean();
                return(node);
            }

            if (t == typeof(NetInfo))
            {
                string name = r.ReadString();
                CustomAssetMetaData.Type type = AssetLoader.instance.GetMetaType(AssetLoader.instance.Current);

                if (type == CustomAssetMetaData.Type.Road || type == CustomAssetMetaData.Type.RoadElevation)
                {
                    return(Get <NetInfo>(p, name));
                }
                else
                {
                    return(Get <NetInfo>(name));
                }
            }

            if (t == typeof(BuildingInfo))
            {
                string name = r.ReadString();
                CustomAssetMetaData.Type type = AssetLoader.instance.GetMetaType(AssetLoader.instance.Current);

                if (type == CustomAssetMetaData.Type.Road || type == CustomAssetMetaData.Type.RoadElevation)
                {
                    return(Get <BuildingInfo>(p, name));
                }
                else
                {
                    return(Get <BuildingInfo>(name));
                }
            }

            // Sub-buildings in buildings.
            if (t == typeof(BuildingInfo.SubInfo))
            {
                string       name     = r.ReadString();
                string       fullName = p.packageName + "." + name;
                BuildingInfo bi       = null;

                if (fullName == AssetLoader.instance.Current.fullName || name == AssetLoader.instance.Current.fullName)
                {
                    Util.DebugPrint("Warning:", fullName, "wants to be a sub-building for itself");
                }
                else
                {
                    bi = Get <BuildingInfo>(p, fullName, name, true);
                }

                BuildingInfo.SubInfo subInfo = new BuildingInfo.SubInfo();
                subInfo.m_buildingInfo = bi;
                subInfo.m_position     = r.ReadVector3();
                subInfo.m_angle        = r.ReadSingle();
                subInfo.m_fixedHeight  = r.ReadBoolean();
                return(subInfo);
            }

            // Prop variations in props.
            if (t == typeof(PropInfo.Variation))
            {
                string   name     = r.ReadString();
                string   fullName = p.packageName + "." + name;
                PropInfo pi       = null;

                if (fullName == AssetLoader.instance.Current.fullName)
                {
                    Util.DebugPrint("Warning:", fullName, "wants to be a prop variation for itself");
                }
                else
                {
                    pi = Get <PropInfo>(p, fullName, name, false);
                }

                return(new PropInfo.Variation
                {
                    m_prop = pi,
                    m_probability = r.ReadInt32()
                });
            }

            // Tree variations in trees.
            if (t == typeof(TreeInfo.Variation))
            {
                string   name     = r.ReadString();
                string   fullName = p.packageName + "." + name;
                TreeInfo ti       = null;

                if (fullName == AssetLoader.instance.Current.fullName)
                {
                    Util.DebugPrint("Warning:", fullName, "wants to be a tree variation for itself");
                }
                else
                {
                    ti = Get <TreeInfo>(p, fullName, name, false);
                }

                return(new TreeInfo.Variation
                {
                    m_tree = ti,
                    m_probability = r.ReadInt32()
                });
            }

            if (t == typeof(VehicleInfo.MeshInfo))
            {
                VehicleInfo.MeshInfo meshinfo = new VehicleInfo.MeshInfo();
                string checksum = r.ReadString();

                if (!string.IsNullOrEmpty(checksum))
                {
                    Package.Asset asset = p.FindByChecksum(checksum);
                    GameObject    go    = AssetDeserializer.Instantiate(asset) as GameObject;
                    meshinfo.m_subInfo = go.GetComponent <VehicleInfoBase>();
                    go.SetActive(false);

                    if (meshinfo.m_subInfo.m_lodObject != null)
                    {
                        meshinfo.m_subInfo.m_lodObject.SetActive(false);
                    }
                }
                else
                {
                    meshinfo.m_subInfo = null;
                }

                meshinfo.m_vehicleFlagsForbidden = (Vehicle.Flags)r.ReadInt32();
                meshinfo.m_vehicleFlagsRequired  = (Vehicle.Flags)r.ReadInt32();
                meshinfo.m_parkedFlagsForbidden  = (VehicleParked.Flags)r.ReadInt32();
                meshinfo.m_parkedFlagsRequired   = (VehicleParked.Flags)r.ReadInt32();
                return(meshinfo);
            }

            return(PackageHelper.CustomDeserialize(p, t, r));
        }
Beispiel #28
0
 public Segment(NetInfo.Segment template)
 {
 }