コード例 #1
0
        public void BuildPrefab(bool erase = false)
        {
            GameObject zoneGO = new GameObject(FileName);
            ZNDDatas   zndd   = zoneGO.AddComponent <ZNDDatas>();

            zndd = datas;
            string zndFolder = "Assets/Resources/Prefabs/Zones/Datas/";

            ToolBox.DirExNorCreate(zndFolder);
            PrefabUtility.SaveAsPrefabAsset(zoneGO, "Assets/Resources/Prefabs/Zones/Datas/" + FileName + ".prefab");
            AssetDatabase.SaveAssets();
            GameObject.DestroyImmediate(zoneGO);
        }
コード例 #2
0
        public void Build(bool buildPrefab = false)
        {
            // First we need to read the zone informations
            zoneName = ToolBox.MPDToZND(mapName);
            if (zoneName == null)
            {
                Debug.LogWarning(mapName + " has no zone attached !");
                return;
            }

            ZND zndParser = new ZND();

            zndParser.FileName = zoneName;
            string[] hash = FilePath.Split("/"[0]);
            hash[hash.Length - 1] = zoneName;
            zndParser.FilePath    = String.Join("/", hash);
            zndParser.UseDebug    = UseDebug;
            zndParser.Parse(zndParser.FilePath);

            string     zn           = ToolBox.MPDToZND(mapName, true);
            string     zoneFolder   = "Assets/Resources/Prefabs/Zones/" + zn + "/";
            string     zoneFilename = zoneFolder + FileName + ".prefab";
            GameObject mapGO;

            if (buildPrefab)
            {
#if UNITY_EDITOR
                ToolBox.DirExNorCreate("Assets/Resources/Prefabs/Zones/");
                ToolBox.DirExNorCreate("Assets/Resources/Prefabs/Zones/" + zn + "/");
#endif
            }
            else
            {
            }

            mapGO = new GameObject(zn);
            GameObject prefab = PrefabUtility.SaveAsPrefabAsset(mapGO, zoneFilename);

            // Then we can build the room
            MPDDatas datas = mapGO.AddComponent <MPDDatas>();
            ZNDDatas z     = mapGO.AddComponent <ZNDDatas>();
            z.filePath  = String.Join("/", hash);
            z.tims      = zndParser.datas.tims;
            z.MPDInfos  = zndParser.datas.MPDInfos;
            z.ZUDInfos  = zndParser.datas.ZUDInfos;
            datas.doors = doors;
            for (uint i = 0; i < numGroups; i++)
            {
                GameObject groupGO = new GameObject("Group_" + i);
                groupGO.transform.parent = mapGO.transform;
                int lgm = groups[i].meshes.Count;
                for (int j = 0; j < lgm; j++)
                {
                    Mesh           mesh            = new Mesh();
                    List <Vector3> meshVertices    = new List <Vector3>();
                    List <int>     meshTriangles   = new List <int>();
                    List <Vector2> meshTrianglesUV = new List <Vector2>();
                    List <Vector3> meshNormals     = new List <Vector3>();
                    List <Color32> meshColors      = new List <Color32>();
                    int            iv  = 0;
                    int            lmf = groups[i].meshes[j].faces.Count;
                    for (int k = 0; k < lmf; k++)
                    {
                        MPDFace f = groups[i].meshes[j].faces[k];
                        if (f.isQuad)
                        {
                            meshVertices.Add(-f.v1.position / 100);
                            meshVertices.Add(-f.v2.position / 100);
                            meshVertices.Add(-f.v3.position / 100);
                            meshVertices.Add(-f.v4.position / 100);
                            meshColors.Add(f.v1.color);
                            meshColors.Add(f.v2.color);
                            meshColors.Add(f.v3.color);
                            meshColors.Add(f.v4.color);
                            meshTrianglesUV.Add(f.v2.uv / 256);
                            meshTrianglesUV.Add(f.v3.uv / 256);
                            meshTrianglesUV.Add(f.v1.uv / 256);
                            meshTrianglesUV.Add(f.v4.uv / 256);
                            meshNormals.Add(f.n);
                            meshNormals.Add(f.n);
                            meshNormals.Add(f.n);
                            meshNormals.Add(f.n);

                            meshTriangles.Add(iv + 0);
                            meshTriangles.Add(iv + 1);
                            meshTriangles.Add(iv + 2);

                            meshTriangles.Add(iv + 3);
                            meshTriangles.Add(iv + 2);
                            meshTriangles.Add(iv + 1);
                            iv += 4;
                        }
                        else
                        {
                            meshVertices.Add(-f.v1.position / 100);
                            meshVertices.Add(-f.v2.position / 100);
                            meshVertices.Add(-f.v3.position / 100);
                            meshColors.Add(f.v1.color);
                            meshColors.Add(f.v2.color);
                            meshColors.Add(f.v3.color);
                            meshTrianglesUV.Add(f.v2.uv / 256);
                            meshTrianglesUV.Add(f.v3.uv / 256);
                            meshTrianglesUV.Add(f.v1.uv / 256);
                            meshNormals.Add(f.n);
                            meshNormals.Add(f.n);
                            meshNormals.Add(f.n);
                            meshTriangles.Add(iv + 0);
                            meshTriangles.Add(iv + 1);
                            meshTriangles.Add(iv + 2);

                            iv += 3;
                        }
                    }
                    mesh.name      = "mesh_" + i + "-" + j;
                    mesh.vertices  = meshVertices.ToArray();
                    mesh.triangles = meshTriangles.ToArray();
                    mesh.uv        = meshTrianglesUV.ToArray();
                    mesh.normals   = meshNormals.ToArray();
                    mesh.colors32  = meshColors.ToArray();
                    mesh.RecalculateNormals();

                    GameObject meshGo = new GameObject("mesh_" + i + "-" + j);
                    meshGo.transform.parent = groupGO.transform;

                    MeshFilter mf = meshGo.AddComponent <MeshFilter>();
                    mf.mesh = mesh;

                    MeshRenderer mr = meshGo.AddComponent <MeshRenderer>();
                    if (z != null && z.tims.Length > 0)
                    {
                        mr.material = z.GetMaterial(groups[i].meshes[j].textureId, groups[i].meshes[j].clutId);
                    }
                    if (buildPrefab)
                    {
#if UNITY_EDITOR
                        AssetDatabase.AddObjectToAsset(mesh, zoneFilename);
                        if (!AssetDatabase.Contains(mr.sharedMaterial))
                        {
                            AssetDatabase.AddObjectToAsset(mr.sharedMaterial, zoneFilename);
                        }

                        if (!AssetDatabase.Contains(mr.sharedMaterial.mainTexture))
                        {
                            AssetDatabase.AddObjectToAsset(mr.sharedMaterial.mainTexture, zoneFilename);
                        }
#endif
                    }
                }
            }

            if (lights != null)
            {
                for (int i = 0; i < lights.Count; i++)
                {
                    lights[i].transform.parent = mapGO.transform;
                }
            }



            if (buildPrefab)
            {
#if UNITY_EDITOR
                prefab = PrefabUtility.SaveAsPrefabAsset(mapGO, zoneFilename);
                //PrefabUtility.ReplacePrefab(mapGO, prefab);
                AssetDatabase.SaveAssets();


                if (mapGO)
                {
                    GameObject.DestroyImmediate(mapGO);
                }

                if (mapGO)
                {
                    GameObject.Destroy(mapGO);
                }
#endif
            }
            else
            {
                MapGO = mapGO;
            }
        }
コード例 #3
0
        public void Parse(BinaryReader buffer)
        {
            uint mpdPtr   = buffer.ReadUInt32();
            uint mpdLen   = buffer.ReadUInt32();
            uint enemyPtr = buffer.ReadUInt32();
            uint enemyLen = buffer.ReadUInt32();
            uint timPtr   = buffer.ReadUInt32();
            uint timLen   = buffer.ReadUInt32();
            uint wave     = buffer.ReadByte();
            uint mpdNum   = mpdLen / 8;

            buffer.ReadBytes(7); // padding

            if (UseDebug)
            {
                Debug.Log(FileName);
                Debug.Log("mpdPtr : " + mpdPtr);
                Debug.Log("mpdLen : " + mpdLen);
                Debug.Log("mpdNum : " + mpdNum);
                Debug.Log("enemyPtr : " + enemyPtr);
                Debug.Log("enemyLen : " + enemyLen);
                Debug.Log("timPtr : " + timPtr);
                Debug.Log("timLen : " + timLen);
                Debug.Log("wave : " + wave);
                Debug.Log("-------------------------------");
            }

            // MPD Section
            if (buffer.BaseStream.Position != mpdPtr)
            {
                buffer.BaseStream.Position = mpdPtr;
            }

            MPDInfos = new Vector3[mpdNum];
            for (int i = 0; i < mpdNum; i++)
            {
                uint id    = buffer.ReadUInt32();
                uint value = buffer.ReadUInt32();
                if (UseDebug)
                {
                    Debug.Log("LBA MPD = " + id + "  - file size = " + value);
                }

                MPDInfos[i] = new Vector3(id, value);
            }
            // ZUD Section
            if (buffer.BaseStream.Position != enemyPtr)
            {
                buffer.BaseStream.Position = enemyPtr;
            }

            uint numEnemies = buffer.ReadUInt32();

            if (UseDebug)
            {
                Debug.Log("numEnemies : " + numEnemies);
            }

            ZUDInfos = new Vector3[numEnemies];
            for (int i = 0; i < numEnemies; i++)
            {
                uint id    = buffer.ReadUInt32();
                uint value = buffer.ReadUInt32();

                if (UseDebug)
                {
                    Debug.Log("LBA ZUD = " + id + "  - file size = " + value);
                }

                ZUDInfos[i] = new Vector3(id, value);
            }

            datas          = new ZNDDatas();
            datas.monsters = new ZNDMonster[numEnemies];


            // TODO enemy class & parse
            long loopbase = buffer.BaseStream.Position;

            Debug.Log("start loop Position " + buffer.BaseStream.Position);
            Debug.Log("timPtr " + timPtr);

            for (int i = 0; i < numEnemies; i++)
            {
                Debug.Log("ZND ennemy # " + i);

                /*
                 * if (buffer.BaseStream.Position != (loopbase + i * 464))
                 * {
                 *  buffer.BaseStream.Position = (loopbase + i * 464);
                 * }*/
                datas.monsters[i] = new ZNDMonster(buffer);
            }
            Debug.Log("end loop Position " + buffer.BaseStream.Position);


            // Textures section
            if (buffer.BaseStream.Position != timPtr)
            {
                buffer.BaseStream.Position = timPtr;
            }

            // TODO : Move this section in TIM.cs

            uint timSecLen = buffer.ReadUInt32();

            buffer.ReadBytes(12);
            uint numTim = buffer.ReadUInt32();

            timfb = new FrameBuffer();
            tims  = new VSTIM[numTim];
            for (int i = 0; i < numTim; i++)
            {
                if (buffer.BaseStream.Position + 32 < buffer.BaseStream.Length)
                {
                    uint tl = buffer.ReadUInt32();
                    tims[i] = new VSTIM((uint)i, tl, buffer);
                    for (int x = 0; x < tims[i].width; x++)
                    {
                        for (int y = 0; y < tims[i].height; y++)
                        {
                            timfb.setPixel((int)tims[i].fx + x, (int)tims[i].fy + y, ToolBox.BitColorConverter(buffer.ReadUInt16()));
                        }
                    }
                }
            }

            buffer.Close();

            datas.filePath = FilePath;
            datas.tims     = tims;
            datas.MPDInfos = MPDInfos;
            datas.ZUDInfos = ZUDInfos;
        }