Unity模型资源使用流程

        昨天研究了下Unity中AnimatorController自动生成。今天稍微完善了操作流程,并且补充说明了在MMO中如何使用模型资源(AssetBundle),这个使用方法是MMO这样模型资源非常大的情况下才需要的。如果是比较小的情况下,直接塞到Resources目录下,加载Prefab就OK了,根本不用操心这些问题。

       先附上最终修改后的脚本。它创建了一个菜单选项,选择一个文件夹(或者文件),右键选择CreateAnimation就可以自动遍历所有的模型资源,然后创建AnimatorController并创建Prefab文件。在Prefab都生成完毕后(或者在生成的同时),可以使用创建AssetBundle的功能在磁盘任意目录创建AssetBundle。

using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.IO;
using System.Collections;
using System.Collections.Generic;
 
public class CreateAnimation : Editor 
{
    //生成出的Prefab的路径
	private static readonly string PREFAB_PATH = "Assets/Prefab/";
    private static readonly string PATH_TAG = "Assets/";
    private static bool _ingnoreExist = true;
    // 这些动画是循环播放的(除此之外的循环动画需要手动创建)
    private static readonly string[] LOOP_TAG = new string[] { "idle", "walk", "run" };
 
	[MenuItem("Assets/CreateAnimation")]
    static void DoCreateAnimation()
    {
        UnityEngine.Object obj = Selection.activeObject;
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        if (Directory.Exists(path)) {
            // 如果是路径的话
            Walk(path, (string fbxPath)=>{
                fbxPath = fbxPath.Replace("\\", "/").Replace(".FBX", ".fbx");
                string relativePath = fbxPath.Substring(fbxPath.IndexOf(PATH_TAG));
                if (!relativePath.EndsWith(".fbx")) {
                    return;
                }

                DoCreateController(relativePath);
                DoCreatePrefab(relativePath);
            });
        } else if (File.Exists(path)) {
            // 如果是文件的话
            string fbxPath = path.Replace("\\", "/").Replace(".FBX", ".fbx");
            string relativePath = fbxPath.Substring(fbxPath.IndexOf(PATH_TAG));
            if (!relativePath.EndsWith(".fbx")) {
                return;
            }

            DoCreateController(relativePath);
            DoCreatePrefab(relativePath);
        } else {
            // 路径不存在
            Debug.LogError(string.Format("路径不存在: {0}", path));
        }
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值