static void Exec(string Extension, BuildTarget target)
    {
        foreach (UnityEngine.Object tmp in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets))
        {
            string path = AssetDatabase.GetAssetPath(tmp);
            if (path.Contains(".prefab"))
            {
                MassSetTextureImporter.ChangeTextureFormat(tmp);

                //打包window版本
                string dstPath = Common.GetWindowPath(path, Extension);
                Debug.Log("dstPath = " + dstPath);

                Common.CreatePath(dstPath);

                if (BuildPipeline.BuildAssetBundle((UnityEngine.Object)tmp, null, dstPath, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, target))
                {
                    byte[] bytes = AssetsEncrypt.ReadFileToByte(dstPath);
                    AssetsEncrypt.EncryptBytes(bytes);
                    AssetsEncrypt.WriteByteToFile(bytes, dstPath);
                }
            }
            else
            {
                Debug.Log("please make sure you selected the prefab");
            }
        }
    }
Пример #2
0
    static void Execute(string Extension, BuildTarget target)
    {
        BuildAssetBundleOptions options =
            BuildAssetBundleOptions.CollectDependencies |
            BuildAssetBundleOptions.CompleteAssets |
            BuildAssetBundleOptions.DeterministicAssetBundle;

        foreach (UnityEngine.Object tmp in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets))
        {
            string path = AssetDatabase.GetAssetPath(tmp);
            path = path.ToLower();

            string e = "";
            if (path.Contains(".tga") || path.Contains(".png"))
            {
                e = ".tex";
            }
            else if (path.Contains(".mat"))
            {
                e = ".mat";
            }
            else if (path.Contains(".fbx"))
            {
                e = ".fbx";
            }
            else
            {
                continue;
            }

            string dest = Common.GetWindowPath(path, e + Extension);
            Common.CreatePath(dest);

            BuildPipeline.PushAssetDependencies();
            if (BuildPipeline.BuildAssetBundle(tmp, null, dest, options, target))
            {
                byte[] bytes = AssetsEncrypt.ReadFileToByte(dest);
                AssetsEncrypt.EncryptBytes(bytes);
                AssetsEncrypt.WriteByteToFile(bytes, dest);
            }

            BuildPipeline.PopAssetDependencies();
        }
    }
Пример #3
0
    public static void CreateDependencieAssetBundle(string path, string Extension, BuildAssetBundleOptions options, BuildTarget target)
    {
        UnityEngine.Object dependencie = AssetDatabase.LoadMainAssetAtPath(path);

        string dependenciePath = "";
        string fileName        = Path.GetFileNameWithoutExtension(path);

        if (path.Contains(".tga") || path.Contains(".png") || path.Contains(".jpg") || path.Contains(".dds"))
        {
            dependenciePath = "assetbundles/assets/scenes/texture/" + fileName + Extension;
        }
        else if (path.Contains(".shader"))
        {
            dependenciePath = "assetbundles/assets/scenes/shader/" + fileName + Extension;
        }
        else if (path.Contains(".mat"))
        {
            dependenciePath = "assetbundles/assets/scenes/fbx/materials/" + fileName + Extension;
        }
        else if (path.Contains(".fbx"))
        {
            dependenciePath = "assetbundles/assets/scenes/fbx/" + fileName + Extension;
        }
        else
        {
            dependenciePath = Common.GetWindowPath(path, Extension);
        }

        Common.CreatePath(dependenciePath);
        if (BuildPipeline.BuildAssetBundle((UnityEngine.Object)dependencie, null, dependenciePath, options, target))
        {
            byte[] bytes = AssetsEncrypt.ReadFileToByte(dependenciePath);
            AssetsEncrypt.EncryptBytes(bytes);
            AssetsEncrypt.WriteByteToFile(bytes, dependenciePath);
        }
    }
Пример #4
0
    public static void Execute(string extension, BuildTarget target)
    {
        if (!Common.ClearDirectory("assetbundles"))
        {
            EditorUtility.DisplayDialog("����", "��ȷ��assetbundles�ļ���û�б�ռ��", "OK");
            return;
        }
        // ����Asset
        LightMapAsset lightmapAsset = ScriptableObject.CreateInstance <LightMapAsset>();
        int           iCount        = LightmapSettings.lightmaps.Length;

        lightmapAsset.lightmapFar  = new Texture2D[iCount];
        lightmapAsset.lightmapNear = new Texture2D[iCount];


        for (int i = 0; i < iCount; ++i)
        {
            // �����ֱ�Ӱ�lightmap���������
            lightmapAsset.lightmapFar[i]  = LightmapSettings.lightmaps[i].lightmapColor;
            lightmapAsset.lightmapNear[i] = LightmapSettings.lightmaps[i].lightmapDir;
        }

        string currScene     = EditorApplication.currentScene;
        string currSceneName = System.IO.Path.GetFileNameWithoutExtension(currScene);

        string tmpAssetPath = "Assets/tmp.asset";

        AssetDatabase.CreateAsset(lightmapAsset, tmpAssetPath);

        UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(tmpAssetPath, typeof(LightMapAsset));


        // ���
        string dest = Common.GetWindowPath("Assets/lightmap/" + currSceneName, extension);

        Common.CreatePath(dest);

        if (BuildPipeline.BuildAssetBundle(obj, null, dest, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, target))
        {
            byte[] bytes = AssetsEncrypt.ReadFileToByte(dest);
            AssetsEncrypt.EncryptBytes(bytes);
            AssetsEncrypt.WriteByteToFile(bytes, dest);
        }


        // ɾ����ʱ�ļ�
        AssetDatabase.DeleteAsset(tmpAssetPath);

        // ����Ϸ����ʱ�ָ�Lightmap���ݾͷdz����ˣ������Ƿ絶�IJ��Դ���Ƭ��
        //if (info.www.assetBundle.mainAsset is LightMapAsset)
        //{
        //    LightMapAsset lightmapAsset = info.www.assetBundle.mainAsset as LightMapAsset;
        //    int Count = lightmapAsset.lightmapFar.Length;
        //    LightmapData[] lightmapDatas = new LightmapData[Count];

        //     for(int i=0; i<Count; ++i)
        //   {
        //        LightmapData Lightmap = new LightmapData();
        //        Lightmap.lightmapFar = lightmapAsset.lightmapFar;
        //        Lightmap.lightmapNear = lightmapAsset.lightmapNear;
        //        lightmapDatas = Lightmap;
        //    }
        //    LightmapSettings.lightmaps = lightmapDatas;
        // }
    }