示例#1
0
        //[MenuItem("Ragnarok/Import World Resource")]
        public static RagnarokWorld LoadResourceFile(string path)
        {
            var loader = new RagnarokResourceLoader();

            return(loader.Load(path));

            //DestroyImmediate(loader);
        }
        static void ImportFiles()
        {
            var files = StandaloneFileBrowser.OpenFilePanel("Open File", RagnarokDirectory.GetRagnarokDataDirectory, "gnd", true);

            if (files.Length <= 0)
            {
                return;
            }

            //var saveDir = EditorUtility.SaveFolderPanel("Save Folder", Application.dataPath, "");
            var saveDir = Path.Combine(Application.dataPath, "maps").Replace("\\", "/");

            //Debug.Log(saveDir);

            foreach (var f in files)
            {
                var lastDirectory = Path.GetDirectoryName(f);
                var baseName      = Path.GetFileNameWithoutExtension(f);
                Debug.Log(f);

                var relativeDir = saveDir.Substring(saveDir.IndexOf("Assets/"));

                var loader   = new RagnarokMapLoader();
                var data     = loader.ImportMap(f, relativeDir);
                var dataPath = Path.Combine(relativeDir, data.name + ".asset").Replace("\\", "/");

                AssetDatabase.CreateAsset(data, dataPath);

                data = AssetDatabase.LoadAssetAtPath <RoMapData>(dataPath);

                data.RefreshTextureLookup();
                data.RebuildAtlas();

                var gatPath = Path.Combine(lastDirectory, baseName + ".gat");
                data.WalkData = LoadWalkData(gatPath);


                var resourcePath = Path.Combine(lastDirectory, baseName + ".rsw");
                if (File.Exists(resourcePath))
                {
                    var world = RagnarokResourceLoader.LoadResourceFile(resourcePath);
                    world.name = baseName + " world data";

                    var worldFolder = Path.Combine(relativeDir, "world");
                    if (!Directory.Exists(worldFolder))
                    {
                        Directory.CreateDirectory(worldFolder);
                    }

                    var worldAssetPath = Path.Combine(worldFolder, baseName + "_world.asset").Replace("\\", "/");

                    AssetDatabase.CreateAsset(world, worldAssetPath);

                    foreach (var model in world.Models)
                    {
                        var baseFolder = Path.Combine(RagnarokDirectory.GetRagnarokDataDirectory, "model");

                        var modelPath = Path.Combine(baseFolder, model.FileName);
                        var relative  = DirectoryHelper.GetRelativeDirectory(baseFolder, Path.GetDirectoryName(modelPath));
                        var mBaseName = Path.GetFileNameWithoutExtension(model.FileName);

                        var prefabFolder = Path.Combine("Assets/models/prefabs/", relative).Replace("\\", "/");
                        var prefabPath   = Path.Combine(prefabFolder, mBaseName + ".prefab").Replace("\\", "/");

                        if (!Directory.Exists(prefabFolder))
                        {
                            Directory.CreateDirectory(prefabFolder);
                        }


                        if (!File.Exists(prefabPath))
                        {
                            var modelLoader = new RagnarokModelLoader();

                            modelLoader.LoadModel(modelPath, relative);
                            var obj = modelLoader.Compile();

                            PrefabUtility.SaveAsPrefabAssetAndConnect(obj, prefabPath, InteractionMode.AutomatedAction);

                            var prefabRef = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);
                            DestroyImmediate(obj);
                        }
                    }

                    //var builder = new RagnarokWorldSceneBuilder();
                    //builder.Load(data, world);
                }

                AssetDatabase.SaveAssets();

                EditorUtility.UnloadUnusedAssetsImmediate();

                var importer = new RagnarokMapDataImporter(dataPath, baseName);
                importer.Import(true, true, true, true, true);

                AssetDatabase.SaveAssets();
            }
        }