WhiteEngine-专注图形渲染与游戏引擎技术的网站

新浪微薄腾讯微薄

最新碎语:暂无碎语

您的位置:WhiteEngine-专注图形渲染与游戏引擎技术的网站 >引擎相关> c#和unity委托结合,资源加载

c#和unity委托结合,资源加载

//资源加载接口

using UnityEngine;

using System.Collections;
using System.Collections.Generic;
using Common;
namespace Manager
{
    
    //后面增加资源管理器有没有资源,没有才去loading有则直接返回
    public partial class Source : Singleton<Source> 
    {
        public delegate void load_back<T>(T obj1, params object[] param);  

        public void Load<T>(string fullPath, CAllEnum.SourceType type,  object obj, params object[] param)
        {
            //缓存池预留
            switch (type)
            {
            case CAllEnum.SourceType.eUIPrefab:
                break;
            case CAllEnum.SourceType.eEffectPrefab:
                break;
            case CAllEnum.SourceType.eFontPrefab:
                break;
            case CAllEnum.SourceType.eAtlasPrefab:
                break;
            case CAllEnum.SourceType.eAnimationClip:
                break;
            case CAllEnum.SourceType.eTable:
                break;
            case CAllEnum.SourceType.eTexture:
                break;
            case CAllEnum.SourceType.eShader:
                break;
            case CAllEnum.SourceType.eSound:
                break;
            case CAllEnum.SourceType.eFont:
                break;
            case CAllEnum.SourceType.eVedio:
                break;
            case CAllEnum.SourceType.eScene:
                break;
            case CAllEnum.SourceType.eDefault:
                break;
            }
            StartCoroutine(load_source<T>(fullPath, obj, param));
        }
    }

}


//加载处理类

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Manager
{
    public partial class Source : Singleton<Source> 
    {
    
        /// <summary>
        /// Load_source the specified fullPath, call_back and param.
        /// </summary>
        /// <param name="fullPath">Full path.</param>
        /// <param name="call_back">Call_back.</param>
        /// <param name="param">Parameter.</param>
        protected IEnumerator load_source<T>(string fullPath, object obj, params object[] param)
        {
            if(SourceGlobal.load_type == SourceGlobal.load_type_enum.resource)
            {
                ResourceRequest resource_request = Resources.LoadAsync(fullPath);
                while (!resource_request.isDone) {
                    yield return 0;
                }
                load_back<T> lb = obj as load_back<T>;
                if(resource_request.asset != null)
                {
                    lb((T)((object)resource_request.asset), param);
                }else
                {
//                    lb(null);
                    Debug.LogWarning("font_ie读取资源为空,资源名称为" + fullPath);
                }
            }else
            {
                //bundle
                yield return null;
            }
//            StopCoroutine(load_source(fullPath, obj, param));
        }
    }
}

//具体调用类

using UnityEngine;
using System.Collections;
using Manager;
public class PrefabExpand : MonoBehaviour {
    public AnimationClip a;
    // Use this for initialization
    void Start () {
//        Source.Instance.load_animation();

//        Source.Instance.Load("Attack_Combo_02", Common.CAllEnum.SourceType.eAnimationClip, tableInfoCallBack, gameObject);
        Source.Instance.Load<AnimationClip>("Attack_Combo_02", Common.CAllEnum.SourceType.eAnimationClip, new Source.load_back<AnimationClip>(tableInfoCallBack), gameObject);
    }
    void tableInfoCallBack (AnimationClip obj, params object[] s)
    {
        Debug.LogError((s[0]as GameObject).name);
        Debug.LogError((obj).name);
    }
    
}

---

转载请注明本文标题和链接:《c#和unity委托结合,资源加载

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交