public void Load(string mapName) { if (loaded) { Debug.LogWarning("Already loaded"); //return; В теории это не требуется. Да и мешается. } LevelName = mapName; string path = ""; path = ResourceManager.GetPath("maps/" + LevelName + ".bsp"); if (path == null) { print("No map detected. Check file path."); print(path); return; } BinaryReader BR = new BinaryReader(File.Open(path, FileMode.Open)); map = new BSPFile(BR, LevelName); loaded = true; if (uSrcSettings.Inst.entities) { ParseEntities(map.entitiesLump); } //=================================================== mapObject = new GameObject(LevelName); mapObject.isStatic = true; modelsObject = new GameObject("models"); modelsObject.transform.SetParent(mapObject.transform); modelsObject.isStatic = true; if (uSrcSettings.Inst.displacements) { dispObject = new GameObject("displacements"); dispObject.transform.SetParent(mapObject.transform); } if (uSrcSettings.Inst.props) { propsObject = new GameObject("props"); propsObject.transform.SetParent(mapObject.transform); propsObject.isStatic = true; } switch (LoadType) { case Type.Full: Debug.Log("Start Loading World Faces"); if (uSrcSettings.Inst.lightmaps & map.hasLightmaps) { lightmapsData = new List <LightmapData> (); curLightmap = 0; lm_allocated = new int[BLOCK_SIZE]; LM_InitBlock(); } models = new GameObject[map.modelsLump.Length]; for (int i = 0; i < map.modelsLump.Length; i++) { CreateModelObject(i); } if (uSrcSettings.Inst.lightmaps & map.hasLightmaps) { LM_UploadBlock(); Debug.Log("Loading " + lightmapsData.Count + " lightmap pages"); LightmapSettings.lightmapsMode = LightmapsMode.NonDirectional; LightmapSettings.lightmaps = lightmapsData.ToArray(); lm_allocated = null; } Debug.Log("Finish World Faces"); GC.Collect(); if (uSrcSettings.Inst.entities) { Debug.Log("Start Loading Entities"); entObject = new GameObject("entities"); entObject.transform.parent = mapObject.transform; for (int i = 0; i < entities.Count; i++) { LoadEntity(i); } Debug.Log("Finish Entities"); } if (uSrcSettings.Inst.displacements) { for (int m = 0; m < map.modelsLump.Length; m++) { for (int i = map.modelsLump[m].firstface; i < map.modelsLump[m].firstface + map.modelsLump[m].numfaces; i++) { if (map.facesLump[i].dispinfo != -1) { GenerateDispFaceObject(i, m); } } } Debug.Log("Finish Displacements"); } //Static props if (uSrcSettings.Inst.props && map.staticPropsReaded) { Debug.Log("Start Loading Static props"); for (int i = 0; i < map.StaticPropCount; i++) { bspStaticPropLump prop = map.StaticPropLump[i]; //Debug.Log ("static prop "+i+" model number is ("+prop.PropType+")"); if (prop.PropType > map.staticPropDict.Length) { Debug.LogWarning("Static prop " + i + " model number is (" + prop.PropType + ")"); continue; } string modelName = map.staticPropDict[prop.PropType]; //Debug.Log ("static prop "+i+" model name is "+modelName); GameObject go = new GameObject(); //GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.name = "prop " + modelName; go.transform.parent = propsObject.transform; //GameObject testGo = (GameObject)MonoBehaviour.Instantiate(TempProp) as GameObject; //testGo.transform.parent=go.transform; go.transform.position = prop.Origin; go.transform.rotation = Quaternion.Euler(prop.Angles); if (prop.UniformScale != 0.0f) { go.transform.localScale = new Vector3(prop.UniformScale, prop.UniformScale, prop.UniformScale); } SourceStudioModel tempModel = ResourceManager.Inst.GetModel(modelName); if (tempModel == null) { //Debug.LogWarning("Error loading: "+modelName); GameObject prim = GameObject.CreatePrimitive(PrimitiveType.Cube); prim.transform.parent = go.transform; prim.transform.localPosition = Vector3.zero; } else { tempModel.GetInstance(go, false, 0); } go.isStatic = true; Props.Add(go); } Debug.Log("Finish Static Props"); } break; case Type.WithoutBatching: for (int i = 0; i < map.modelsLump.Length; i++) { models[i] = new GameObject("*" + i); models[i].transform.SetParent(modelsObject.transform); for (int f = map.modelsLump[i].firstface; f < map.modelsLump[i].firstface + map.modelsLump[i].numfaces; f++) { GenerateFaceObject(f).transform.SetParent(models[i].transform); } } break; case Type.OnlyDisplacements: if (uSrcSettings.Inst.displacements) { for (int i = 0; i < map.dispinfoLump.Length; i++) { GenerateDispFaceObject((int)map.dispinfoLump[i].MapFace, 0); Debug.Log("FaceId: " + map.dispinfoLump[i].MapFace + " DispInfoId: " + i + " DispVertStart: " + map.dispinfoLump[i].DispVertStart); } } break; case Type.OneFace: if (uSrcSettings.Inst.displacements & map.facesLump[faceId].dispinfo != -1) { GenerateDispFaceObject(faceId, 0); Debug.Log("FaceId: " + faceId + " DispInfoId: " + map.facesLump[faceId].dispinfo + " DispVertStart: " + map.dispinfoLump[map.facesLump[faceId].dispinfo].DispVertStart); } else { GenerateFaceObject(faceId); } break; } BR.BaseStream.Dispose(); GC.Collect(); }
bspStaticPropLump[] ReadStaticProps(bspgamelump gl) { bspStaticPropLump[] temp = new bspStaticPropLump[StaticPropCount]; for (int i = 0; i < StaticPropCount; i++) { bspStaticPropLump prop = new bspStaticPropLump(); if (gl.version >= 4) { //4 prop.Origin = ConvertUtils.FlipVector(ConvertUtils.ReadVector3(br)) * uSrcSettings.Inst.worldScale; Vector3 ang = ConvertUtils.ReadVector3(br); prop.Angles = new Vector3(-ang.z, -ang.y, -ang.x); prop.PropType = (int)br.ReadUInt16(); /*prop.FirstLeaf=br.ReadUInt16(); * prop.LeafCount=br.ReadUInt16(); * prop.Solid=br.ReadChar(); * prop.Flags=br.ReadChar();*/ br.BaseStream.Seek(6, SeekOrigin.Current); prop.Skin = br.ReadInt32(); prop.FadeMinDist = br.ReadSingle(); prop.FadeMaxDist = br.ReadSingle(); prop.LightingOrigin = ConvertUtils.ReadVector3(br); } if (gl.version >= 5) { prop.ForcedFadeScale = br.ReadSingle(); //br.BaseStream.Seek(12,SeekOrigin.Current); } if (gl.version >= 6 & gl.version < 8) { prop.MinDXLevel = br.ReadUInt16(); prop.MaxDXLevel = br.ReadUInt16(); } if (gl.version >= 8) { prop.minCPULevel = br.ReadByte(); prop.maxCPULevel = br.ReadByte(); prop.minGPULevel = br.ReadByte(); prop.maxGPULevel = br.ReadByte(); prop.diffuseModulation = new Color32(br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte()); } if (gl.version >= 9) { //prop.DisableX360=br.ReadBoolean(); br.BaseStream.Seek(4, SeekOrigin.Current); } if (gl.version >= 10) { prop.FlagsEx = br.ReadInt32(); } if (gl.version >= 11) { prop.UniformScale = br.ReadSingle(); } temp[i] = prop; } return(temp); }