Esempio n. 1
0
    static void _ExportEquip()
    {
        // Bring up save panel
        string path = EditorUtility.SaveFolderPanel("Save Resource", "", "");

        if (path.Length != 0)
        {
            // Build the resource file from the active selection.
            Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

            AssetBundleBuildParamCollecter bundleCollector = new AssetBundleBuildParamCollecter();
            foreach (Object sel in selection)
            {
                BuildOneEquip(sel, path, bundleCollector);
            }
            BuildAssetBundles(path, bundleCollector.ToArray());
            Selection.objects = selection;
        }
    }
Esempio n. 2
0
    public static void BuildOneEquip(Object ass, string path, AssetBundleBuildParamCollecter bundleCollector)
    {
        GameObject obj = ass as GameObject;

        if (obj == null)
        {
            return;
        }

        GameObject          inst = (GameObject)GameObject.Instantiate(obj);
        SkinnedMeshRenderer smr  = inst.GetComponentInChildren <SkinnedMeshRenderer>();

        if (smr == null)
        {
            Object.DestroyImmediate(inst);
            return;
        }

        if (smr.sharedMesh == null)
        {
            Object.DestroyImmediate(inst);
            return;
        }

        string asspath       = AssetDatabase.GetAssetPath(ass);
        string meshassetname = asspath + ".asset";
        Object meshasset     = AssetDatabase.LoadMainAssetAtPath(meshassetname);

        if (meshasset == null)
        {
            Object.DestroyImmediate(inst);
            return;
        }

        bundleCollector.Add(meshassetname);

        string lowMeshAssertName = meshassetname.Replace("_m_", "_l_");

        string str;

        str  = "return {\n";
        str += "File = {\n";
        string strTemp = ConvertFileName(meshassetname) + ".u3dext";

        str += "\"" + strTemp + "\",\n";



        Material[] mats = smr.sharedMaterials;
        if (mats != null)
        {
            foreach (Material mat in mats)
            {
                if (mat)
                {
                    string matAssetPath = AssetDatabase.GetAssetPath(mat);
                    bundleCollector.Add(matAssetPath);
                    strTemp = matAssetPath;
                    strTemp = ConvertFileName(strTemp) + ".u3dext";
                    str    += "\"" + strTemp + "\",\n";
                }
            }
        }
        str += "},\n";

        str += "LowMesh = {\n";
        str += "\"" + ConvertFileName(lowMeshAssertName) + ".u3dext" + "\"";
        str += "},\n";

        str += "Bones = {\n";
        for (int i = 0; i < smr.bones.Length; i++)
        {
            GameObject go = smr.bones[i].gameObject;
            str += "\"" + go.name + "\",\n";
        }
        str += "}\n";

        str += "}";
        Object.DestroyImmediate(inst);
        strTemp = ConvertFileName(asspath);
        strTemp = path + "/" + strTemp + ".lua";
        Directory.CreateDirectory(Path.GetDirectoryName(strTemp));
        File.WriteAllBytes(strTemp, System.Text.Encoding.UTF8.GetBytes(str));
    }