private static void SaveRuntimeLoadXml()
    {
        Dictionary <string, RuntimeAssetLoadInfo> runtimeAssetLoadInfos = new Dictionary <string, RuntimeAssetLoadInfo>();

        foreach (KeyValuePair <GameObject, EntitySaveOption> p in entitySaveOptions)
        {
            if (!runtimeAssetLoadInfos.ContainsKey(p.Value.assetName))
            {
                runtimeAssetLoadInfos.Add(p.Value.assetName, new RuntimeAssetLoadInfo(p.Value.categoryIndex, p.Value.specieIndex, p.Value.assetName, p.Key.activeSelf));
            }
        }

        XmlAccessor.WriteRuntimePrefabXml(PathTool.RuntimePrefabXmlPath(), runtimeAssetLoadInfos);
        FileTool.CopyFileToDestFolder(PathTool.RuntimePrefabXmlPath(), PathTool.GetAssetBundlePath());
    }
Beispiel #2
0
    public static void ExportOrganizeData()
    {//改为树形遍历
        AddRegisterToAll();

        Stack <EntityConfig> configs = new Stack <EntityConfig>();
        Queue <GameObject>   objs    = new Queue <GameObject>();

        foreach (GameObject o in SceneManager.GetActiveScene().GetRootGameObjects())
        {
            objs.Enqueue(o);
        }

        while (objs.Count > 0)
        {
            GameObject o = objs.Dequeue();
            if (o.GetComponent <EntityConfig>() != null)
            {
                configs.Push(o.GetComponent <EntityConfig>());
            }
            for (int k = 0; k < o.transform.childCount; k++)
            {
                objs.Enqueue(o.transform.GetChild(k).gameObject);
            }
        }

        Dictionary <string, AssetLoadInfo>            loadDic     = new Dictionary <string, AssetLoadInfo>();
        Stack <KeyValuePair <GameObject, Transform> > parentCache = new Stack <KeyValuePair <GameObject, Transform> >();

        int i = 0;

        while (configs.Count > 0)
        {
            EditorUtility.DisplayProgressBar("Exporting", "逐个导出,请勿退出!", (float)i / (float)configs.Count);
            EntityConfig config = configs.Pop();
            GameObject   go     = config.gameObject;
            config.RecordInfo();

            string catName = "";
            if (config.entitySaveOption != null)
            {
                catName = config.entitySaveOption.categoryName;
            }
            else
            {
                catName = LayerMask.LayerToName(go.layer);
            }

            string name = null;
            if (config.entitySaveOption.ifLoadRuntime)
            {
                name = config.entitySaveOption.name;
            }
            else
            {
                name = go.name;
            }


            string prefabSavePath     = new StringBuilder(PathTool.SceneResourcesPath()).Append("/").Append(catName).Append("/").Append(name).Append(".prefab").ToString();
            string prefabABName       = new StringBuilder(SceneManager.GetActiveScene().name.ToLower()).Append("/").Append(catName.ToLower()).Append(".ld ").Append(name).Append(".prefab").ToString();
            string organizeDataABName = new StringBuilder(PathTool.GetOrganizeDataABName().ToLower()).Append(catName.ToLower()).Append(".ld ").Append(name).Append(".asset").ToString();

            if (config.entitySaveOption.ifLoadRuntime)
            {
                parentCache.Push(new KeyValuePair <GameObject, Transform>(go, go.transform.parent));
                go.transform.SetParent(null, true);
                PrefabUtility.CreatePrefab(prefabSavePath, go, ReplacePrefabOptions.Default);
            }
            else if (!loadDic.ContainsKey(prefabABName))
            {
                loadDic.Add(prefabABName, new AssetLoadInfo(prefabABName, organizeDataABName, i, go.activeSelf));

                string organizeDataPath = new StringBuilder(PathTool.GetOrganizeDataPath()).Append(catName).Append("/").ToString();
                ExportInfo(config.entityInfo, organizeDataPath, name);
                parentCache.Push(new KeyValuePair <GameObject, Transform>(go, go.transform.parent));
                go.transform.SetParent(null, true);
                PrefabUtility.CreatePrefab(prefabSavePath, go, ReplacePrefabOptions.Default);
            }
            else
            {
                continue;
            }

            i++;
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        while (parentCache.Count > 0)
        {
            KeyValuePair <GameObject, Transform> p = parentCache.Pop();
            p.Key.transform.SetParent(p.Value, true);
        }

        XmlAccessor.WriteLoadRecordXml(PathTool.GetLoadRecordFilePath(), loadDic);
        FileTool.CopyFileToDestFolder(PathTool.GetLoadRecordFilePath(), PathTool.GetAssetBundlePath());

        EditorUtility.ClearProgressBar();
    }