Unity3d UnpackAssets from editor 解包插件






Unity3d UnpackAssets from editor  

轉載請注明出處,否則追究責任!

http://oulehui.blog.163.com/blog/static/7961469820126168580343/

Installation:

1 - Put this script into "Editor" folder.
2 - press Ctrl + U and select the ".assets" file and him going to decomprime it.

What this Script Extract?
This script extract corectly with the format of assets.

- Terrain
- Materials
- Shaders
- Prefabs

 

 

UnpackAssets from editor.cs

using UnityEngine;
using System.Collections;
using UnityEditor;
using UnityEditorInternal;
using System.IO;

public class UnpackAssets : MonoBehaviour
{
    static void delRecursive (string path)
    {
        try   {
            foreach (string d in Directory.GetFiles(path)) {
                File.Delete (d);
            }
            foreach (string d in Directory.GetDirectories(path)) {
                delRecursive (d);
            }
            Directory.Delete (path);
        } catch {
        }
    }

    [MenuItem("Assets/Unpack %u")]
    static void Unpack ()
    {
        string file = EditorUtility.OpenFilePanel ("Select assets file to unpack", "", "assets");
        if (file.Length == 0)
            return;
        Object[] objs1 = AssetDatabase.LoadAllAssetsAtPath (file);
        string ImportDir = @"/Import_" + Path.GetFileNameWithoutExtension (file) + "/";
        delRecursive (Application.dataPath + ImportDir);
        Directory.CreateDirectory (Application.dataPath + ImportDir);
        foreach (Object obj in objs1) {
            if (obj == null)
                continue;
            System.Type type = obj.GetType ();
            string ext = "asset";

            if (type == typeof(Material) || (type.IsSubclassOf (typeof(Material))))
                ext = "mat";
            else if (type == typeof(AnimationClip) || (type.IsSubclassOf (typeof(AnimationClip))))
                ext = "anim";
            else if (type == typeof(GameObject) || (type.IsSubclassOf (typeof(GameObject))))
                ext = "prefab";

            if (type == typeof(Component) || (type.IsSubclassOf (typeof(Component)))) {
                continue;
            }
            string ThisName = obj.name.Replace ('/', '_');
            if (string.IsNullOrEmpty (ThisName))
                continue;
            string f = @"Assets" + ImportDir + type.Name + @"/" + ThisName + "." + ext;
            Object o = obj;
            if (!Directory.Exists (Application.dataPath + ImportDir + type.Name))
                Directory.CreateDirectory (Application.dataPath + ImportDir + type.Name);

            if (type == typeof(GameObject) || (type.IsSubclassOf (typeof(GameObject)))) {
                Object prefab = PrefabUtility.CreateEmptyPrefab (f);
                if (obj == null) {
                    //Debug.LogError ("NullException");
                }
                AssetDatabase.Refresh ();
                PrefabUtility.ReplacePrefab ((GameObject)(obj), prefab);
                continue;
            } else {
                try {
                    o = Object.Instantiate (obj);
                } catch {
                    o = obj;
                }
            }

            if (o == null)
                continue;

            AssetDatabase.CreateAsset (o, f);
        }
        AssetDatabase.Refresh ();
        File.Copy (file, Application.dataPath + ImportDir + Path.GetFileNameWithoutExtension (file) + ".asset");
        AssetDatabase.Refresh ();
        //Debug.Log ("Done");
    }
}





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值