unity游戏拆包后mat文件导入3dsmax模型导入unity怎么修改

这几天一直在研究热更新方案
主要思路是:
1.先将代码打包成dll,然后用unity 打包成assetsbundle,
2.WWW加载进入主程序,
3使用System.Reflection.Assembly来创建程序集,
4.然后通过GetType(className),来获取这个类
5.AddComponent进入主程序,加载的dll就执行起来了。
ExportAssetBundles.cs
//打包工具,该工具是网上找来都。谢谢作者!
public class ExportAssetBundles : MonoBehaviour {
//在Unity编辑器中添加菜单
[MenuItem("Custom Editor/Create AssetBunldes ALL")]
static void ExportResource()
// 打开保存面板,获得用户选择的路径
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "assetbundle");
if (path.Length != 0)
// 选择的要保存的对象
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | pleteAssets, BuildTarget.StandaloneWindows);
1234567891011121314151617181920
//打包工具,该工具是网上找来都。谢谢作者!public class ExportAssetBundles : MonoBehaviour {&&&&&//在Unity编辑器中添加菜单&&&&&&[MenuItem("Custom Editor/Create AssetBunldes ALL")]&&&&static void ExportResource()&&&&{&&&&&&&&// 打开保存面板,获得用户选择的路径&&&&&&&&&&string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "assetbundle");&&&&&&&&&if (path.Length != 0)&&&&&&&&{&&&&&&&&&&&&// 选择的要保存的对象&&&&&&&&&&&&&&Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);&&&&&&&&&&&&//打包&&&&&&&&&&&&&&BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.StandaloneWindows);&&&&&&&&&&&&&&}&&&&}&&}
using UnityE
using System.C
using System.R
//代码加载器
public class Index : MonoBehaviour
private WWW
public static WWW uiWWW;
private System.Reflection.A
// Use this for initialization
void Start ()
StartCoroutine(loadScript());
private IEnumerator loadScript()
//加载我的代码资源
www = new WWW("http://localhost/Main.assetbundle");
AssetBundle bundle = www.assetB
TextAsset asset = bundle.Load("Main", typeof(TextAsset)) as TextA
assembly = System.Reflection.Assembly.Load(asset.bytes);
Assembly[] assLis = System.AppDomain.CurrentDomain.GetAssemblies();
System.Type script = assembly.GetType("Main");
gameObject.AddComponent(script);
12345678910111213141516171819202122232425262728293031323334353637
using UnityEngine;using System.Collections;using System.Reflection;&//代码加载器public class Index : MonoBehaviour{&&&&&private WWW www;&&&&&public static WWW uiWWW;&&&&&private System.Reflection.Assembly assembly;& // Use this for initialization void Start () &&&&{&&&&&&&&StartCoroutine(loadScript()); }&&&&&private IEnumerator loadScript()&&&&{&&&&&&&&//加载我的代码资源&&&&&&&&www = new WWW("http://localhost/Main.assetbundle");&&&&&&&&yield return www;&&&&&&&&&AssetBundle bundle = www.assetBundle;&&&&&&&&TextAsset asset = bundle.Load("Main", typeof(TextAsset)) as TextAsset;&&&&&&&&assembly = System.Reflection.Assembly.Load(asset.bytes);&&&&&&&&&Assembly[] assLis = System.AppDomain.CurrentDomain.GetAssemblies();&&&&&&&&&System.Type script = assembly.GetType("Main");&&&&&&&&&gameObject.AddComponent(script);&&&&}}
因为在加载的时候遇见安全沙箱问题,所以我将这个策略文件记录下来,方便下次复制粘贴
crossdomain.xml
&?xml version="1.0"?&
&cross-domain-policy&
&site-control permitted-cross-domain-policies=”master-only” /&
&allow-access-from domain="" /&
&allow-access-from domain="*"/&
&/cross-domain-policy&
&?xml version="1.0"?&&cross-domain-policy&&site-control permitted-cross-domain-policies=”master-only” /&&allow-access-from domain="" /&&allow-access-from domain="*"/&&/cross-domain-policy&
本地调试程序时解决跨域问题的方法:
Edit-&Project Settings-&Eidtor
刚开始的时候想使用序列化来存储一些数据,但是后来却连一个很简单的类序列化dll里面都没法获得
官方对象序列号
[MenuItem("Custom Editor/WriteSpriteData")]
static void FileWriteSpriteData()
TextAsset textasset = AssetDatabase.LoadAssetAtPath("Assets/Resources/Packer/Packer.txt", typeof(TextAsset)) as TextA
Atlas atlas = ScriptableObject.CreateInstance&Atlas&();
//Json其实是NGUIJson这个类,我只是把他提出来。改了个名字
atlas.mList = Json.LoadSpriteData(textasset as TextAsset);
if (atlas.mList == null)
string path = "Assets/Resources/Packer/Packer.asset";
AssetDatabase.CreateAsset(atlas, path);
//Atlas是一个只有一个mList属性都类 mList = new List&UISpriteData&();
Object o = AssetDatabase.LoadAssetAtPath(path, typeof(Atlas));
Object texture = AssetDatabase.LoadAssetAtPath("Assets/Resources/Packer/Packer.mat", typeof(Material));
Object[] t = {texture};
BuildPipeline.BuildAssetBundle(o, t, "Assets/Resources/Packer/Packer.assetbundle");
//AssetDatabase.DeleteAsset(path);
12345678910111213141516171819202122232425
[MenuItem("Custom Editor/WriteSpriteData")]&&&&static void FileWriteSpriteData()&&&&{&&&&&&&&TextAsset textasset = AssetDatabase.LoadAssetAtPath("Assets/Resources/Packer/Packer.txt", typeof(TextAsset)) as TextAsset;&&&&&&&&&Atlas atlas = ScriptableObject.CreateInstance&Atlas&();//Json其实是NGUIJson这个类,我只是把他提出来。改了个名字&&&&&&&&atlas.mList = Json.LoadSpriteData(textasset as TextAsset);&&&&&&&&&if (atlas.mList == null)&&&&&&&&&&&&return;&&&&&&&&&string path = "Assets/Resources/Packer/Packer.asset";&&&&&&&&&AssetDatabase.CreateAsset(atlas, path);//Atlas是一个只有一个mList属性都类 mList = new List&UISpriteData&();&&&&&&&&Object o = AssetDatabase.LoadAssetAtPath(path, typeof(Atlas));&&&&&&&&Object texture = AssetDatabase.LoadAssetAtPath("Assets/Resources/Packer/Packer.mat", typeof(Material));&&&&&&&&&Object[] t = {texture};&&&&&&&&&BuildPipeline.BuildAssetBundle(o, t, "Assets/Resources/Packer/Packer.assetbundle");&&&&&&&&&&&&&&&&//AssetDatabase.DeleteAsset(path);&&&&}
这是使用序列化数据的加载方式,在不用反射的情况下,下面代码加载能够成功,但是使用了反射,下面的代码就加载不成功了。这个问题我也很费解,暂时我没办法解决
读取序列化对象
IEnumerator LoadAtlas()
www = new WWW("http://localhost/Packer.assetbundle");
//WoodenAtlas.assetbundle
//Packer.assetbundle
//用来断点都时候看看里面所包含都数据
Object[] os = www.assetBundle.LoadAll();
Material mete = www.assetBundle.Load("Packer", typeof(Material)) as M
Atlas atlas = www.assetBundle.mainAsset as A
GameObject go = new GameObject("UIAtlas");
UIAtlas uiatlas = go.AddComponent&UIAtlas&();
uiatlas.spriteMaterial =
uiatlas.spriteList = atlas.mL
GameObject sprite = new GameObject("Sprite");
UISprite ui = NGUITools.AddChild&UISprite&(sprite);
ui.atlas =
ui.spriteName = "dynamite";
Debug.Log("Load");
www.assetBundle.Unload(false);
www.Dispose();
1234567891011121314151617181920212223242526
IEnumerator LoadAtlas()&&&&{&&&&&&&&www = new WWW("http://localhost/Packer.assetbundle");&&&&&&&&//WoodenAtlas.assetbundle&&&&&&&&//Packer.assetbundle&&&&&&&&yield return www;//用来断点都时候看看里面所包含都数据&&&&&&&&Object[] os = www.assetBundle.LoadAll();&&&&&&&&&Material mete = www.assetBundle.Load("Packer", typeof(Material)) as Material;&&&&&&&&Atlas atlas = www.assetBundle.mainAsset as Atlas;&&&&&&&&GameObject go = new GameObject("UIAtlas");&&&&&&&&UIAtlas uiatlas = go.AddComponent&UIAtlas&();&&&&&&&&uiatlas.spriteMaterial = mete;&&&&&&&&uiatlas.spriteList = atlas.mList;&&&&&&&&&GameObject sprite = new GameObject("Sprite");&&&&&&&&UISprite ui = NGUITools.AddChild&UISprite&(sprite);&&&&&&&&ui.atlas = uiatlas;&&&&&&&&ui.spriteName = "dynamite";&&&&&&&&Debug.Log("Load");&&&&&&&&&www.assetBundle.Unload(false);&&&&&&&&www.Dispose();&&&&&&&&&&&&}
因为要看一下代码的执行效率,所以我寻找到了这个类。感觉还可以。使用josn数据,mat文件创建一个UIAtlas的时间大概是30毫秒左右。
System.Diagnostics.S
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
System.Diagnostics.Stopwatch;Stopwatch stopWatch = new Stopwatch();stopWatch.Start();Thread.Sleep(10000);stopWatch.Stop();
我使用没有任何Unity环境以外代码来实现壳的制作(我们暂且将其称为Index,其实他就是上面的Index类,代码少得可怜。)
然后主程序是在另一个Unity项目中(这个项目在发布的时候打包成Main.dll)
Main.dll项目通过上面的Index来加载,然后添加到一个GameObject上,主程序的Awake()方法就会执行(Awake是整个程序的主入口)
这个时候所有的资源加载都会在Main.dll里面完成。
在这个过程中,遇到了一个比较麻烦的问题就是,我打包的一些UIAtlas.prefab文件上的UIAtlas这个类,无法找到。
这让我有一些无法理解,因为NGUI的代码已经打包进入了Main.dll,那么为什么我加载prefab的时候,却找不到UIAtlas这个类呢?
最后我只能动态的制作UIAtlas对象来完成这样工作。
那么这样的话,以后做界面,做任何prefab都不能绑定脚本了。都只能加载到内存中动态AddComponent了。这样界面也得用配置文件了。
不过对于我这种从页游转过来的程序,这到不是问题,我有现成的界面编辑器(我博客里有),直接生成XML在游戏中进行组装了。对于能够热更新来说,这点麻烦,其实应该不算麻烦了。
动态生成UIAtlas后,创建了几个Sprite、Button,基本的功能都已经实现,说明这个解决方案是可行的。接下来我将把这个方案运用到我的项目中,更加全面的去实验一下。
这样设计的优点:
1、对IOS的打包也是比较方便。打包IOS 直接拿Main项目打包就可以了。因为不需要热更新了。把代码打包在本地就行了。
2、打包Android项目的时候发布apk只需要发布Index,项目发布版本和没写代码一样大,想到这里我想吐槽一下,Unity就算不写任何代码,发布一个apk也得有7M左右。这也太大了点吧。我可啥都没做啊。
1、哪位大神能给我说说上面我遇到的那个问题,为什么找不到绑定在prefab上的类呢?这是程序集的问题么?哎,刚转C#的人伤不起。
[…] 3、这也是最主要的,如果你看过我上一篇文章《Unity代码热更新解决方案测试结果总结》你就会知道我为什么要这么做了,都是泪啊。。 […]楼主,该代码要放在哪个对象上
(非注册用户请填昵称)
(非注册用户请留空)
您还没有登录,请或3dsmax模型动画导入Unity游戏引擎技术视频教程 Udemy Using Animated 3D Studio Ma... - 游戏开发 - 人人素材社区 - Powered by Discuz!
只需一步,快速开始
后使用快捷导航没有帐号?
请完成以下验证码
所属分类: &
本版主题: 471
今日更新: 36
3dsmax模型动画导入Unity游戏引擎技术视频教程 Udemy Using Animated 3D Studio Ma...
签到天数: 57 天[LV.5]常住居民I&成长值: 6070
3dsmax模型动画导入Unity游戏引擎技术视频教程.jpg (45.95 KB, 下载次数: 4)
12:19 上传
本是由Udemy机构出品的模型动画导入Unity游戏引擎技术视频教程,Udemy Using Animated 3D Studio Max Character Models in Unity Games,时长:1小时,大小:310 MB,MP4高清视频格式,教程使用软件:Unity 5, 作者:Knowledge Base,共6个章节,语言:英语。
Unity是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。Unity类似于Director, game engine, Virtools 或 Torque Game Builder等利用交互的图型化开发环境为首要方式的软件其编辑器运行在Windows 和Mac OS X下,可发布游戏至Windows、Mac、Wii、iPhone、Windows phone 8和Android平台。也可以利用Unity web player插件发布网页游戏,支持Mac和Windows的网页浏览。它的网页播放器也被Mac widgets所支持。
3D Studio Max,常简称为3ds Max或MAX,是Autodesk公司开发的基于PC系统的三维动画渲染和制作软件。其前身是基于DOS操作系统的3D Studio系列软件,最新版本是2013。在Windows NT出现以前,工业级的CG制作被SGI图形工作站所垄断。3D Studio Max + Windows NT组合的出现一下子降低了CG制作的门槛,首选开始运用在电脑游戏中的动画制作,后更进一步开始参与影视片的特效制作,例如:《X战警II》,《最后的武士》等。
Udemy是一个在线教和学的平台,也是唯一一个有中文版本的国际教学机构。网站主要提供教育或培训教程,内容涵盖生活方式、创业、科技、一般技术等等. 它鼓励会员开设自己的在线课程,也可以搜索他人开设或上传的课程。 Udemy大多都是免费的课程,也有部分收费的课程,课程的含金量完全由市场说了算. 它的目标就是教会任何人任何事!
Udemy Using Animated 3D Studio Max Character Models in Unity Games
Use the 3D modeling and animation program 3DS Max for your game’s character models along with the Unity 3D game engine
Making 3D games has never been easier now that we have game engines like Unity.
You may have realized that to make a full game, you need to go beyond the stock 3D models they give you in the engine. So now you’ve got yourself an animated model in 3D Studio Max, you may not know how exactly to use this in Unity?
Aside from the basics, there are a lot of tips and tricks to exporting animated 3D models from 3DS Max and importing them to Unity. This tutorial covers both of the basics and the tips and to help you hit the ground running with your 3D game.
You’ll even learn how to use the models you imported in a game character that responds to inputs with a quick code!
Before starting this course, you should be familiar with how Unity organizes assets. Since there is no in-depth explanation of the scripts used here, a basic knowledge of Unity scripting with C# will also help.
解压密码:游客,如果您要查看本帖隐藏内容请
推广排行榜:
签到天数: 350 天[LV.8]以坛为家I
回帖奖励 +2
不错的教程
签到天数: 662 天[LV.9]以坛为家II
回帖奖励 +2
不错的资源游戏引擎 很喜欢 谢谢
签到天数: 976 天[LV.10]以坛为家III
回帖奖励 +2
超級感謝值得推薦!!
签到天数: 597 天[LV.9]以坛为家II
回帖奖励 +2
谢谢啦。。。。。。。。。。。。
签到天数: 1240 天[LV.10]以坛为家III
回帖奖励 +2
感谢分享啊
签到天数: 608 天[LV.9]以坛为家II
这个很好啊
签到天数: 3 天[LV.2]偶尔看看I
支持楼主& &很好很强大
签到天数: 3 天[LV.2]偶尔看看I
很强大,过来学习学习
签到天数: 814 天[LV.10]以坛为家III
好!!还不错的的人模
大家好!人人素材网第128期中文字幕翻译教程来啦!
教程简介:
本套教程主要讲述了AE软件中的时间特效——时间伸缩、时间重映射、时间反转和时间扭曲,并且在教程的最后,通过剪辑技巧和时间特效的配合,制作出一个完美的镜头。教程详细的介绍了不同时间特效的优劣势,以及出现问题的解决方案,只需要简单的一个小时,就能把AE中最常用的特效玩转熟稔,同时又能保持整洁的AE操作界面。最后教程还讲述了帧融合的数种技术,通过一系列的对比与测试,让你明白在合适的时候,选择最适用于自己的特效。DT一贯的明快简洁的风格,在本套教程中体现的淋漓尽致,通过深入浅出的原理剖析,让你知其然,还能知其所以然!
大家好!人人素材网第129期中文字幕翻译教程来啦!
教程简介:
Vectorworks可以帮助用户使用高效的工作流程设计和制作项目。本教程中,我们会熟悉这款强大软件的核心功能。讲师亨利·桑托斯(Henry Santos)为我们介绍用户界面,展示如何管理工作区。另外,通过为大家讲解一个小项目——设计桌子,让我们亲身实践,学习这款软件的应用。他也会为我们讲解绘图工具和设计工作,制作基本的3D模型,为我们展示如何使用资源管理器,等等。
大家好!人人素材网第130期中文字幕翻译教程来啦!
教程简介:
本套是Modo角色绑定的基础入门教程,主要会讲解角色绑定的核心概念和工具、流程。角色绑定是做动画之前最重要的一个步骤,是连接模型到动画的核心环节,成为优秀的动画师,必须要深刻的理解绑定的原理和技术,然后才能用它们来制作动画。教程首先制作模型,然后创建角色骨骼,搭建基础的骨骼框架,为骨骼进行蒙皮操作,调整优化结构,学习权重绘制技巧。最后教程会讲解如何制作非常具有亲和力的动画控制系统,并通过约束操作、表达式节点、通道链接工具……让整个绑定犀利而高效!教程结束后,你一定可以胸有成足的在MODO进行角色动画绑定!自定义拓展Editor导入Unity3d资源自动生成材质
在3d项目中,有时候导入一些资源时候,需要对应创建材质球,如果每次自己动手创建,还是挺麻烦的,下面是如何导入资源时候自动创建材质球。
废话不说贴上Editor脚本代码
using UnityE
using System.C
using System.Collections.G
using UnityE
using System.IO;
public class BuildMaterial : UnityEditor.AssetModificationProcessor
//生成出的Material的路径
private static string MaterialsPath = &Assets/Resources/Skin/&;
// 创建菜单按钮,手工调用创建材质
[MenuItem (&HETools/BuildMaterials&)]
static void CreateMateral ()
Object[] selectObject = Selection.
List&string& path = new List&string& ();
foreach (Object obj in selectObject) {
path.Add (AssetDatabase.GetAssetPath (obj));
foreach (string p in path) {
CreateOneMateral (p);
System.GC.Collect ();
// 监控assets资源添加,发现指定目录ThemeTile有新增加的texture,就自动生成材质
public static void OnWillCreateAsset (string path)
int index = path.LastIndexOf (&.&);
string file = path.Substring (index);
string[] pathArr = path.Split ('/');
if (pathArr [pathArr.Length - 3] != &ThemeTile&)
CreateOneMateral (path);
System.GC.Collect ();
// 创建材质球
static void CreateOneMateral (string p)
p = p.Replace (&.meta&, &&);
Debug.Log (&CreateOneMateral from path: & + p);
int pos = p.LastIndexOf ('/');
if (pos == -1)
string[] strArr = p.Split ('/');
string themeIDStr = strArr [strArr.Length - 2];
Texture textur = (Texture)AssetDatabase.LoadAssetAtPath (p, typeof(Texture)) as T
string name = strArr [strArr.Length - 1];
int y = name.IndexOf ('.');
name = name.Substring (0, y);
Material mater = new Material (Shader.Find (&Mobile/VertexLit&));
mater.mainTexture =
AssetDatabase.CreateAsset (mater, MaterialsPath + themeIDStr + &/& + name + &.mat&);
自定义拓展Editor导入Unity3d资源自动生成材质
注意,上面代码中我是规定了只有指定的目录添加texture才会自动生成材质,所以使用时候,请自行修改下。
这里发现了个问题:
导入贴图时候,自动创建出来的材质球丢失了纹理图,而采用菜单按钮点击创建出来的正常。问题还没有解决,有哪位朋友知道解决办法可以告诉我下.
好了,本篇unity3d教程到此结束,下篇我们再会!
首发地址: 自定义拓展Editor导入Unity3d资源自动生成材质__丝路教育
资源地址: (分享请保留)
关注微信,有惊喜!
Powered by SILUCG! X1.0
我们一直在努力!
在线客服01:
在线客服02:

我要回帖

更多关于 unity导入max文件 的文章

 

随机推荐