注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Faye Euler's blog

技術交流歡迎留言

 
 
 

日志

 
 

Unity3d UnpackAssets from editor  

2012-07-16 08:59:17|  分类: Unity3D |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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

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");
    }
}

  评论这张
 
阅读(4427)| 评论(2)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017