void OnDestroy() { if (m_Nodes != null) { foreach (KeyValuePair <int, LSubTerrain> kvp in m_Nodes) { kvp.Value.Release(); } m_Nodes.Clear(); } if (m_map32Trees != null) { m_map32Trees.Clear(); } if (m_mapExistTempTrees != null) { m_mapExistTempTrees.Clear(); } if (m_mapTempTreeInfos != null) { m_mapTempTreeInfos.Clear(); } LSubTerrIO.DestroyInst(m_IO); s_Instance = null; }
public static void DestroyInst(LSubTerrIO io) { if (io != null && io._orgnSubTerrFile != null) { io._orgnSubTerrFile.Close(); io._orgnSubTerrFile = null; } }
public static LSubTerrIO CreateInst() { LSubTerrIO io = new LSubTerrIO(); // Allocate ofs and len io._orgnOfsData = new int [LSubTerrConstant.XZCount]; io._orgnLenData = new int [LSubTerrConstant.XZCount]; io._orgnUcmpLenData = new int [LSubTerrConstant.XZCount]; try{ // Open original subterrain data file io._orgnSubTerrFile = new FileStream(s_orgnFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); }catch { Debug.LogWarning("No Layered subTerrain File, No Trees"); io._orgnSubTerrFile = null; } if (io._orgnSubTerrFile != null) { // Read each subterrain's data offset, len, uncmp-len. BinaryReader br = new BinaryReader(io._orgnSubTerrFile); int orgnLenMax = 0; int orgnUcmpLenMax = 0; io._orgnOfsData[0] = br.ReadInt32(); io._orgnUcmpLenData[0] = br.ReadInt32(); for (int i = 1; i < LSubTerrConstant.XZCount; ++i) { io._orgnOfsData[i] = br.ReadInt32(); io._orgnLenData[i - 1] = io._orgnOfsData[i] - io._orgnOfsData[i - 1]; if (io._orgnOfsData[i - 1] > orgnLenMax) { orgnLenMax = io._orgnOfsData[i - 1]; } io._orgnUcmpLenData[i] = br.ReadInt32(); if (io._orgnUcmpLenData[i] > orgnUcmpLenMax) { orgnUcmpLenMax = io._orgnUcmpLenData[i]; } } io._orgnLenData[LSubTerrConstant.XZCount - 1] = (int)io._orgnSubTerrFile.Length - io._orgnOfsData[LSubTerrConstant.XZCount - 1]; if (io._orgnLenData[LSubTerrConstant.XZCount - 1] > orgnLenMax) { orgnLenMax = io._orgnLenData[LSubTerrConstant.XZCount - 1]; } io._curDataIdxInBuff = -1; io._curDataLenInBuff = 0; io._zippedBuff = new byte[orgnLenMax]; io._unzippedBuff = new byte[orgnUcmpLenMax + 1]; io._thread = new Thread(new ThreadStart(io.ProcessReqs)); io._thread.Start(); } return(io); }
void Init() { // Assign global tree prototype lists GlobalPrototypePrefabList = VEditor.m_treePrototypeList; GlobalPrototypeBendFactorList = VEditor.m_treePrototypeBendfactor; GlobalPrototypeBounds = new Bounds [GlobalPrototypePrefabList.Length]; GlobalPrototypeCollidersType = new ColType[GlobalPrototypePrefabList.Length]; GlobalPrototypeColliders = new GameObject [GlobalPrototypePrefabList.Length]; GlobalPrototypeLights = new GameObject [GlobalPrototypePrefabList.Length]; GlobalPrototypeTPHInfo = new LTreePlaceHolderInfo [GlobalPrototypePrefabList.Length]; // Get bounds for (int i = 0; i < GlobalPrototypeBounds.Length; ++i) { { GameObject go = Instantiate(GlobalPrototypePrefabList[i]) as GameObject; go.transform.parent = PrototypeGroup.transform; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; MeshRenderer mr = go.GetComponent <MeshRenderer>(); MeshFilter mf = go.GetComponent <MeshFilter>(); // Light[] ls = go.GetComponentsInChildren<Light>(); Animator ani = go.GetComponent <Animator>(); Animation anim = go.GetComponent <Animation>(); GlobalPrototypeBounds[i] = mf.mesh.bounds; if (i == TreePlaceHolderPrototypeIndex) { GlobalPrototypeBounds[i].extents = new Vector3(1, 2, 1); } Component.Destroy(mr); Component.Destroy(mf); // foreach (Light l in ls) // Light.Destroy(l); if (ani != null) { Component.Destroy(ani); } if (anim != null) { Component.Destroy(anim); } Collider col = go.GetComponent <Collider>(); if (col != null || go.GetComponentsInChildren <Light>(true).Length >= 1) { BoxCollider bc = go.GetComponent <BoxCollider>(); if (bc != null) { GlobalPrototypeTPHInfo[i] = new LTreePlaceHolderInfo(bc.center, bc.size.y * 0.5f, bc.size.x * 0.5f + bc.size.z * 0.5f); } else { GlobalPrototypeTPHInfo[i] = null; } #if !UNITY_5 Collider[] cs = go.GetComponents <Collider>(); foreach (Collider c in cs) { c.isTrigger = true; } #endif go.name = "Prototype [" + i.ToString() + "]'s Collider"; go.SetActive(false); GlobalPrototypeColliders[i] = go; GlobalPrototypeCollidersType[i] = bc != null ? ColType.BoxCollider : (col != null ? ColType.Collider : ColType.None); } else { Destroy(go); GlobalPrototypeColliders[i] = null; GlobalPrototypeCollidersType[i] = ColType.None; } } { GameObject go = Instantiate(GlobalPrototypePrefabList[i]) as GameObject; go.transform.parent = PrototypeGroup.transform; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; MeshRenderer mr = go.GetComponent <MeshRenderer>(); MeshFilter mf = go.GetComponent <MeshFilter>(); Collider[] cs = go.GetComponentsInChildren <Collider>(); Animator ani = go.GetComponent <Animator>(); Animation anim = go.GetComponent <Animation>(); GlobalPrototypeBounds[i] = mf.mesh.bounds; if (i == TreePlaceHolderPrototypeIndex) { GlobalPrototypeBounds[i].extents = new Vector3(1, 2, 1); } Component.Destroy(mr); Component.Destroy(mf); foreach (Collider c in cs) { Collider.Destroy(c); } if (ani != null) { Component.Destroy(ani); } if (anim != null) { Component.Destroy(anim); } if (go.GetComponentsInChildren <Light>(true).Length >= 1) { go.name = "Prototype [" + i.ToString() + "]'s Light"; go.SetActive(false); GlobalPrototypeLights[i] = go; } else { Destroy(go); GlobalPrototypeLights[i] = null; } } } // Create i/o m_IO = LSubTerrIO.CreateInst(); }