Exemplo n.º 1
0
        public static void createPrefab(string name)
        {
            string path          = "Assets/Resources/Atlas";
            string prefabName    = "Common";
            string prefabExtName = "prefab";

            string resFullPath = string.Format("{0}.{1}", Path.Combine(path, prefabName), prefabExtName);

            resFullPath = UtilPath.normalPath(resFullPath);

            Type[] comArr = new Type[1];
            comArr[0] = typeof(Image);
            GameObject prefabRootGo = new GameObject(prefabName, comArr);

            Image image = prefabRootGo.GetComponent <Image>();

            Sprite[] allSpritesArr = AtlasPrefabUtil.loadAllSprite();
            image.sprite = allSpritesArr[0];

            // 创建预制,并且添加到编辑器中,以便进行检查
            PrefabUtility.CreatePrefab(resFullPath, prefabRootGo, ReplacePrefabOptions.ConnectToPrefab);
            //UnityEngine.Object emptyPrefab = PrefabUtility.CreateEmptyPrefab(resFullPath);
            //PrefabUtility.ReplacePrefab(prefabRootGo, emptyPrefab, ReplacePrefabOptions.ConnectToPrefab);
            //刷新编辑器
            AssetDatabase.Refresh();
        }
Exemplo n.º 2
0
 public AssetBundleNameDirData(string path, AssetBundleNameXmlPath xmlPath)
 {
     m_dirPath     = path;
     m_xmlPath     = xmlPath;
     m_fullDirPath = ExportUtil.getDataPath(m_dirPath);
     m_fullDirPath = UtilPath.normalPath(m_fullDirPath);
     m_filesList   = new List <AssetBundleNameFileData>();
 }
Exemplo n.º 3
0
 public DirData(string path, AtlasXmlPath xmlPath)
 {
     m_dirPath     = path;
     m_xmlPath     = xmlPath;
     m_fullDirPath = ExportUtil.getDataPath(m_dirPath);
     m_fullDirPath = UtilPath.normalPath(m_fullDirPath);
     m_filesList   = new List <FileData>();
 }
Exemplo n.º 4
0
        protected void onFindFile(string path, string name)
        {
            path = UtilPath.normalPath(path);
            string extName = UtilPath.getFileExt(path);

            if (m_xmlPath.includeExtList.IndexOf(extName) != -1)         // 如果在包含的扩展名列表中
            {
                AssetBundleNameFileData file = new AssetBundleNameFileData(path, this);
                m_filesList.Add(file);
                file.buildData();
            }
        }
Exemplo n.º 5
0
        public static void pkgResources()
        {
            ResExportSys.m_instance.m_targetPlatform = BuildTarget.StandaloneWindows;

            ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath = ExportUtil.getStreamingDataPath("");
            ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath = UtilPath.normalPath(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath);
            UtilPath.deleteDirectory(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath);
            UtilPath.createDirectory(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath);

            ResExportSys.m_instance.parseResourceXml();
            ResExportSys.m_instance.packResourceList();
        }
Exemplo n.º 6
0
        protected void onFindFile(string path, string name)
        {
            path = UtilPath.normalPath(path);
            string extName = UtilPath.getFileExt(path);

            if (m_xmlPath.ignoreExtList.IndexOf(extName) == -1)         // 如果没有在或略的扩展名列表中
            {
                FileData file = new FileData(path, this);
                m_filesList.Add(file);
                file.buildData();
            }
        }
Exemplo n.º 7
0
        public void parseXml(XmlElement packElem, AtlasXmlData data)
        {
            m_data         = data;
            m_inPath       = ExportUtil.getXmlAttrStr(packElem.Attributes["inpath"]);
            m_outPath      = ExportUtil.getXmlAttrStr(packElem.Attributes["outpath"]);
            m_ignoreExtStr = ExportUtil.getXmlAttrStr(packElem.Attributes["ignoreext"]);
            m_resType      = ExportUtil.getXmlAttrUInt(packElem.Attributes["restype"]);

            m_fullDirPath = ExportUtil.getDataPath(m_inPath);
            m_fullDirPath = UtilPath.normalPath(m_fullDirPath);

            findAllFiles();
        }
Exemplo n.º 8
0
        static void ExportByResourcesCfg()
        {
            ResExportSys.instance();
            ResExportSys.m_instance.m_targetPlatform = BuildTarget.StandaloneWindows;

            ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath = ExportUtil.getStreamingDataPath("");
            ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath = UtilPath.normalPath(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath);
            UtilPath.deleteDirectory(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath);
            UtilPath.createDirectory(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath);

            ResExportSys.m_instance.parseResourceXml();
            ResExportSys.m_instance.packResourceList();

            ExportUtil.CopyAssetBundlesTo(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, ResExportSys.m_instance.m_targetPlatform);
        }
        public void parseXml(XmlElement elem)
        {
            m_srcRoot  = ExportUtil.getXmlAttrStr(elem.Attributes["srcroot"]);
            m_destRoot = ExportUtil.getXmlAttrStr(elem.Attributes["destroot"]);
            char[] splitChar = new char[1] {
                ','
            };
            m_unity3dExtNameList = ExportUtil.getXmlAttrStr(elem.Attributes["unity3dextname"]).Split(splitChar).ToList <string>();
            m_ignoreExtList      = ExportUtil.getXmlAttrStr(elem.Attributes["ignoreext"]).Split(splitChar).ToList <string>();

            int idx = 0;

            if (m_unity3dExtNameList.IndexOf("null") != -1)         // 如果扩展名字有 null ,就说明包括没有扩展名字
            {
                for (idx = 0; idx < m_unity3dExtNameList.Count; ++idx)
                {
                    if (m_unity3dExtNameList[idx] == "null")
                    {
                        m_unity3dExtNameList[idx] = "";
                    }
                }
            }

            if (m_ignoreExtList.IndexOf("null") != -1)         // 如果扩展名字有 null ,就说明包括没有扩展名字
            {
                for (idx = 0; idx < m_ignoreExtList.Count; ++idx)
                {
                    if (m_ignoreExtList[idx] == "null")
                    {
                        m_ignoreExtList[idx] = "";
                    }
                }
            }

            m_srcFullPath = Path.Combine(System.Environment.CurrentDirectory, m_srcRoot);
            m_srcFullPath = UtilPath.normalPath(m_srcFullPath);
        }
Exemplo n.º 10
0
    // 打包自己在 Project 窗口中选择的资源
    public static void BuildSelectAssetBundles()
    {
        string path     = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
        string fileName = "";
        string extName  = "";

        path = UtilPath.normalPath(path);

        int lastSlashIdx = 0;
        int dotIdx       = 0;

        lastSlashIdx = path.LastIndexOf("/");
        dotIdx       = path.LastIndexOf(".");

        fileName = path.Substring(lastSlashIdx + 1, dotIdx - lastSlashIdx - 1);
        extName  = path.Substring(dotIdx + 1, path.Length - dotIdx - 1);
        path     = path.Substring(0, lastSlashIdx);

        if (path.Length != 0)
        {
            List <string> assetNameList = new List <string>();
            string        nameStr;
            foreach (Object item in Selection.objects)
            {
                nameStr = AssetDatabase.GetAssetPath(item);
                nameStr = nameStr.Substring(nameStr.IndexOf("Assets"), nameStr.Length - nameStr.IndexOf("Assets"));
                assetNameList.Add(nameStr);
            }

            AssetBundleBuild[] buildList = new AssetBundleBuild[1];
            buildList[0].assetBundleName    = fileName;
            buildList[0].assetBundleVariant = extName;
            buildList[0].assetNames         = assetNameList.ToArray();
            BuildPipeline.BuildAssetBundles(path, buildList, 0, BuildTarget.StandaloneWindows);
        }
    }
Exemplo n.º 11
0
        // 遍历一个文件的时候处理
        public void handleFile(string fullFileName, string name)
        {
            fullFileName = UtilPath.normalPath(fullFileName);
            if (m_ignoreExtList.IndexOf(UtilPath.getFileExt(fullFileName)) == -1)
            {
                string fineNameNoExt = UtilPath.getFileNameNoExt(fullFileName);
                string assetPath     = fullFileName.Substring(fullFileName.IndexOf(ExportUtil.ASSETS));
                string destPath      = "";

                if (m_unity3dExtNameList.IndexOf(UtilPath.getFileExt(fullFileName)) != -1)
                {
                    if (fullFileName.LastIndexOf('/') != m_srcFullPath.Length)
                    {
                        destPath = fullFileName.Substring(m_srcFullPath.Length + 1, fullFileName.LastIndexOf('/') - (m_srcFullPath.Length + 1));
                    }
                    if (!string.IsNullOrEmpty(m_destRoot))
                    {
                        destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, m_destRoot);
                        destPath = Path.Combine(destPath, destPath);
                    }
                    else
                    {
                        destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, destPath);
                    }

                    AssetBundleParam bundleParam = new AssetBundleParam();
#if UNITY_5
                    bundleParam.m_buildList = new AssetBundleBuild[1];
                    bundleParam.m_buildList[0].assetBundleName    = fineNameNoExt;
                    bundleParam.m_buildList[0].assetBundleVariant = UtilApi.UNITY3D;
                    bundleParam.m_buildList[0].assetNames         = new string[1];
                    bundleParam.m_buildList[0].assetNames[0]      = assetPath;
                    bundleParam.m_targetPlatform = ResExportSys.m_instance.m_targetPlatform;
                    bundleParam.m_pathName       = destPath;
#elif UNITY_4_6 || UNITY_4_5
                    bundleParam.m_assets = objList.ToArray();
                    pathList.Clear();
                    pathList.Add(m_skelMeshParam.m_outPath);
                    pathList.Add(skelNoExt + ".unity3d");
                    bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
#endif
                    ExportUtil.BuildAssetBundle(bundleParam);
                    // 打包成 unity3d 后文件名字会变成小写,这里修改一下
                    UtilPath.modifyFileNameToCapital(destPath, fineNameNoExt);
                }
                else        // 直接拷贝过去
                {
                    if (fullFileName.LastIndexOf('/') != m_srcFullPath.Length)
                    {
                        destPath = fullFileName.Substring(m_srcFullPath.Length + 1, fullFileName.Length - (m_srcFullPath.Length + 1));
                    }
                    if (!string.IsNullOrEmpty(m_destRoot))
                    {
                        destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, m_destRoot);
                        destPath = Path.Combine(destPath, destPath);
                    }
                    else
                    {
                        destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, destPath);
                        File.Copy(fullFileName, destPath);
                    }
                }

                addResListItem(fullFileName, destPath);
            }
        }