Beispiel #1
0
        public void exportSubMeshBone(SkelMeshParam param, XmlDocument xmlDocSave, XmlElement meshXml)
        {
            XmlElement subMeshXml = xmlDocSave.CreateElement("SubMesh");

            meshXml.AppendChild(subMeshXml);

            List <string> pathList = new List <string>();

            pathList.Add(param.m_inPath);
            pathList.Add(param.m_name);

            string     resPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
            GameObject go      = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(m_resType)) as GameObject;
            string     ret     = "";

            if (go != null)
            {
                SkinnedMeshRenderer render = go.transform.Find(m_name).gameObject.GetComponent <SkinnedMeshRenderer>();
                if (render != null)
                {
                    foreach (Transform tran in render.bones)
                    {
                        if (ret.Length > 0)
                        {
                            ret += ",";
                        }
                        ret += tran.gameObject.name;
                    }
                }
            }

            subMeshXml.SetAttribute("bonelist", ret);
        }
Beispiel #2
0
        public void exportSubMeshBoneFile(SkelMeshParam param, ref string xmlStr)
        {
            List <string> pathList = new List <string>();

            pathList.Add(param.m_inPath);
            pathList.Add(param.m_name);

            string     resPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
            GameObject go      = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(m_resType)) as GameObject;
            string     ret     = "";

            if (go != null)
            {
                SkinnedMeshRenderer render = go.transform.Find(m_name).gameObject.GetComponent <SkinnedMeshRenderer>();
                if (render != null)
                {
                    foreach (Transform tran in render.bones)
                    {
                        if (ret.Length > 0)
                        {
                            ret += ",";
                        }
                        ret += tran.gameObject.name;
                    }
                }
            }

            xmlStr += string.Format("        <SubMesh name=\"{0}\" bonelist=\"{1}\" />\n", m_part, ret);
        }
Beispiel #3
0
        protected void packOneLevelPack(PackParam param)
        {
            string        resPath  = "";
            List <string> nameList = new List <string>();
            List <string> pathList = new List <string>();

            foreach (PackItem packItem in m_packList)
            {
                pathList.Clear();
                pathList.Add(param.m_inPath);
                pathList.Add(packItem.m_path);
                resPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
                nameList.Add(resPath);
            }

            StreamedSceneAssetBundleParam bundleParam = new StreamedSceneAssetBundleParam();

            bundleParam.m_levels = nameList.ToArray();
            pathList.Clear();
            pathList.Add(param.m_outPath);
            pathList.Add(m_name);
            bundleParam.m_locationPath = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray()));

            ExportUtil.BuildStreamedSceneAssetBundle(bundleParam);
        }
Beispiel #4
0
        protected void packOneLevelPack()
        {
            string        resPath  = "";
            List <string> nameList = new List <string>();
            List <string> pathList = new List <string>();

            List <string> filesList = UtilPath.GetAll(ExportUtil.getDataPath(m_packParam.m_inPath));
            string        ext       = "";
            string        nameNoExt = "";
            string        tmpStr    = "";
            StreamedSceneAssetBundleParam bundleParam = new StreamedSceneAssetBundleParam();

            foreach (string filePath in filesList)
            {
                ext       = UtilPath.getFileExt(filePath);
                nameNoExt = UtilPath.getFileNameNoExt(filePath);
                if (ExportUtil.isArrContainElem(ext, m_packParam.m_extArr))
                {
                    resPath = ExportUtil.convFullPath2AssetsPath(filePath);
                    nameList.Add(resPath);
                    bundleParam.m_levels = nameList.ToArray();
                    pathList.Clear();
                    pathList.Add(m_packParam.m_outPath);
                    tmpStr = string.Format("{0}{1}", nameNoExt, UtilApi.DOTUNITY3D);
                    pathList.Add(tmpStr);
                    bundleParam.m_locationPath = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray()));

                    ExportUtil.BuildStreamedSceneAssetBundle(bundleParam);
                }
            }
        }
Beispiel #5
0
        protected void packOneBundlePack()
        {
            string        resPath        = "";
            List <string> assetNamesList = new List <string>();
            List <Object> objList        = new List <Object>();

            UnityEngine.Object go;

            List <string> pathList  = new List <string>();
            List <string> filesList = UtilPath.GetAll(ExportUtil.getDataPath(m_packParam.m_inPath));
            string        ext       = "";
            string        nameNoExt = "";

#if UNITY_4_6
            string tmpStr = "";
#endif
            AssetBundleParam bundleParam = new AssetBundleParam();

            foreach (string filePath in filesList)
            {
                objList.Clear();
                assetNamesList.Clear();
                ext       = UtilPath.getFileExt(filePath);
                nameNoExt = UtilPath.getFileNameNoExt(filePath);
                if (ExportUtil.isArrContainElem(ext, m_packParam.m_extArr))
                {
                    resPath = ExportUtil.convFullPath2AssetsPath(filePath);
                    assetNamesList.Add(resPath);
                    go = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(ExportUtil.convExt2ResStr(ext)));
                    if (go)
                    {
                        objList.Add(go);

#if UNITY_5
                        bundleParam.m_buildList = new AssetBundleBuild[1];
                        bundleParam.m_buildList[0].assetBundleName    = nameNoExt;
                        bundleParam.m_buildList[0].assetBundleVariant = UtilApi.UNITY3D;
                        bundleParam.m_buildList[0].assetNames         = assetNamesList.ToArray();
                        pathList.Clear();
                        pathList.Add(m_packParam.m_outPath);
                        bundleParam.m_pathName = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray()));
#elif UNITY_4_6 || UNITY_4_5
                        bundleParam.m_assets = objList.ToArray();
                        pathList.Clear();
                        pathList.Add(m_packParam.m_outPath);
                        tmpStr = string.Format("{0}{1}", nameNoExt, ExportUtil.DOTUNITY3D);
                        pathList.Add(tmpStr);
                        bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
#endif
                        ExportUtil.BuildAssetBundle(bundleParam);
                    }
                    else
                    {
                        LoggerTool.error(string.Format("AssetDatabase.LoadAssetAtPath 不能加载资源 {0}", filePath));
                    }
                }
            }
        }
Beispiel #6
0
        protected void packOneBundlePack(PackParam param)
        {
            string        resPath        = "";
            List <Object> objList        = new List <Object>();
            List <string> assetNamesList = new List <string>();

            UnityEngine.Object go;

            List <string> pathList = new List <string>();

            foreach (PackItem packItem in m_packList)
            {
                pathList.Clear();
                pathList.Add(param.m_inPath);
                pathList.Add(packItem.m_path);

                resPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
                assetNamesList.Add(resPath);
                go = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(packItem.m_resType));
                if (go)
                {
                    objList.Add(go);
                }
                else
                {
                    LoggerTool.error(string.Format("AssetDatabase.LoadAssetAtPath 不能加载资源 {0}", resPath));
                }
            }

            AssetBundleParam bundleParam = new AssetBundleParam();

#if UNITY_5
            bundleParam.m_buildList = new AssetBundleBuild[1];
            bundleParam.m_buildList[0].assetBundleName    = m_name;
            bundleParam.m_buildList[0].assetBundleVariant = UtilApi.UNITY3D;
            bundleParam.m_buildList[0].assetNames         = assetNamesList.ToArray();
            pathList.Clear();
            pathList.Add(param.m_outPath);
            bundleParam.m_pathName = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray()));
#elif UNITY_4_6 || UNITY_4_5
            bundleParam.m_assets = objList.ToArray();
            pathList.Clear();
            pathList.Add(param.m_outPath);
            pathList.Add(m_name);
            bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
#endif

            ExportUtil.BuildAssetBundle(bundleParam);
        }
Beispiel #7
0
        public void packOnePack(PackParam param)
        {
            List <string> pathList = new List <string>();

            pathList.Add(param.m_outPath);
            pathList.Add(m_name);
            string path = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray()));

            ExportUtil.recurseCreateStreamDirectory(path);

            if (ExportUtil.BUNDLE == param.m_type)
            {
                packOneBundlePack(param);
            }
            else if (ExportUtil.LEVEL == param.m_type)
            {
                packOneLevelPack(param);
            }
        }
Beispiel #8
0
        // 从 Mesh 中添加 SubMesh
        public void addSubMesh()
        {
            List <string> pathList = new List <string>();

            pathList.Add(m_skelMeshParam.m_inPath);
            pathList.Add(m_skelMeshParam.m_name);

            // 目录一定是以 "Assets" 开头的相对目录
            string resPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));

            UnityEngine.Object go_ = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(m_skelMeshParam.m_resType));
            GameObject         go  = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(m_skelMeshParam.m_resType)) as GameObject;

            int                 childCount = go.transform.childCount;
            int                 idx        = 0;
            Transform           childTrans = null;
            SkinnedMeshRenderer render     = null;
            SubMesh             item       = null;

            for (idx = 0; idx < childCount; ++idx)
            {
                render     = null;
                childTrans = go.transform.GetChild(idx);
                render     = childTrans.gameObject.GetComponent <SkinnedMeshRenderer>();

                if (render != null)
                {
                    item = new SubMesh();
                    m_subMeshList.Add(item);
                    item.m_name      = childTrans.gameObject.name;
                    item.m_part      = item.m_name;
                    item.m_resType   = m_skelMeshParam.m_resType;
                    item.m_modelType = m_skelMeshParam.m_modelType;
                    item.m_outPath   = m_skelMeshParam.m_outPath;
                }
            }
        }
Beispiel #9
0
        public void packSubMesh(SkelMeshParam param)
        {
            List <string> pathList = new List <string>();

            pathList.Add(param.m_inPath);
            pathList.Add(param.m_name);

            string     resPath   = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
            GameObject go        = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(m_resType)) as GameObject;
            GameObject subMeshGo = null;
            //GameObject insSubMeshGo = null;

            string        subMeshName    = "";
            string        outPrefabPath  = "";
            List <Object> objList        = new List <Object>();
            List <string> assetNamesList = new List <string>();

            if (go != null)
            {
                subMeshGo = go.transform.Find(m_name).gameObject;
                if (subMeshGo != null)
                {
                    //insSubMeshGo = GameObject.Instantiate(subMeshGo);
                    //insSubMeshGo.transform.parent = null;
                    //subMeshName = ExportUtil.getSubMeshName(param.m_name, m_name);
                    subMeshName = ExportUtil.getSubMeshName(param.m_name, m_name);

                    pathList.Clear();
                    if (string.IsNullOrEmpty(m_outPath))
                    {
                        pathList.Add(SkinAnimSys.m_instance.m_xmlSubMeshRoot.m_outPath);
                    }
                    else
                    {
                        pathList.Add(m_outPath);
                    }
                    //pathList.Add(SkinAnimSys.m_instance.m_xmlSubMeshRoot.m_modelTypes.modelTypeDic[m_modelType].subPath);
                    pathList.Add(subMeshName + ".prefab");

                    outPrefabPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
                    assetNamesList.Add(outPrefabPath);
                    //AssetDatabase.CreateAsset(insSubMeshGo, tmpPrefabPath);
                    //PrefabUtility.CreatePrefab(tmpPrefabPath, insSubMeshGo);
                    PrefabUtility.CreatePrefab(outPrefabPath, subMeshGo);

                    // 现在不打包 AssetBundle ,后期才会打包成 ab
//                    objList.Add(subMeshGo);

//                    AssetBundleParam bundleParam = new AssetBundleParam();
//#if UNITY_5
//                    bundleParam.m_buildList = new AssetBundleBuild[1];
//                    bundleParam.m_buildList[0].assetBundleName = subMeshName;
//                    bundleParam.m_buildList[0].assetBundleVariant = ExportUtil.UNITY3D;
//                    bundleParam.m_buildList[0].assetNames = assetNamesList.ToArray();
//                    pathList.Clear();
//                    pathList.Add(param.m_outPath);
//                    bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
//#elif UNITY_4_6 || UNITY_4_5
//                    bundleParam.m_assets = objList.ToArray();
//                    pathList.Clear();
//                    pathList.Add(param.m_outPath);
//                    pathList.Add(subMeshName + ".unity3d");
//                    bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
//#endif

//                    ExportUtil.BuildAssetBundle(bundleParam);

                    // 释放资源
                    //UtilApi.DestroyImmediate(subMeshGo, false, false);
                    //AssetDatabase.Refresh();
                }
            }
        }
Beispiel #10
0
        public void packSkel()
        {
            List <string> pathList = new List <string>();

            pathList.Add(m_skelMeshParam.m_inPath);
            pathList.Add(m_skelMeshParam.m_name);

            string     resPath   = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
            GameObject go        = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type("prefab")) as GameObject;
            GameObject subMeshGo = null;

            string        skelNoExt      = UtilPath.getFileNameNoExt(m_skelMeshParam.m_name);
            string        outPrefabPath  = "";
            List <Object> objList        = new List <Object>();
            List <string> assetNamesList = new List <string>();

            GameObject instanceGo;

            pathList.Clear();
            if (string.IsNullOrEmpty(m_skelMeshParam.m_outPath))
            {
                pathList.Add(SkinAnimSys.m_instance.m_xmlSubMeshRoot.m_outPath);
            }
            else
            {
                pathList.Add(m_skelMeshParam.m_outPath);
            }
            //pathList.Add(SkinAnimSys.m_instance.m_xmlSkeletonRoot.m_modelTypes.modelTypeDic[m_skelMeshParam.m_modelType].subPath);
            pathList.Add(skelNoExt + ".prefab");

            outPrefabPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
            assetNamesList.Add(outPrefabPath);

            // 原始的资源是不能修改的,必须要 Instantiate 后才能修改,因此这里 Instantiate 一个 GameObject
            instanceGo = UtilApi.Instantiate(go) as GameObject;
            //PrefabUtility.CreatePrefab(outPrefabPath, go);

            //go = AssetDatabase.LoadAssetAtPath(outPrefabPath, ExportUtil.convResStr2Type("prefab")) as GameObject;

            Animator animator = null;

            if (instanceGo != null)
            {
                // 单位化转换
                UtilApi.normalRST(instanceGo.transform);
                // 释放子模型
                foreach (SubMesh subMesh in m_subMeshList)
                {
                    subMeshGo = instanceGo.transform.Find(subMesh.m_name).gameObject;
                    if (subMeshGo != null)
                    {
                        //GameObject.DestroyImmediate(subMeshGo);
                        //GameObject.Destroy(subMeshGo);
                        //GameObject.DestroyImmediate(subMeshGo, true);
                        UtilApi.DestroyImmediate(subMeshGo, false);
                    }
                }
                // 添加控制器
                string controlPath = string.Format("{0}/{1}.controller", m_skelMeshParam.m_controllerPath, skelNoExt);
                controlPath = ExportUtil.getRelDataPath(controlPath);
                animator    = instanceGo.GetComponent <Animator>();
                UnityEngine.Object assetObj = AssetDatabase.LoadAssetAtPath(controlPath, typeof(AnimatorController));
                animator.runtimeAnimatorController = assetObj as RuntimeAnimatorController;

                // 保存资源
                PrefabUtility.CreatePrefab(outPrefabPath, instanceGo);
                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();
                UtilApi.DestroyImmediate(instanceGo, false);

                // 现在不直接打包,需要最后发布的时候才打包
                //go = AssetDatabase.LoadAssetAtPath(outPrefabPath, ExportUtil.convResStr2Type("prefab")) as GameObject;
                //objList.Add(go);

//                AssetBundleParam bundleParam = new AssetBundleParam();
//#if UNITY_5
//                bundleParam.m_buildList = new AssetBundleBuild[1];
//                bundleParam.m_buildList[0].assetBundleName = skelNoExt;
//                bundleParam.m_buildList[0].assetBundleVariant = ExportUtil.UNITY3D;
//                bundleParam.m_buildList[0].assetNames = assetNamesList.ToArray();
//                pathList.Clear();
//                pathList.Add(m_skelMeshParam.m_outPath);
//                bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
//#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);
            }
        }