zoukankan      html  css  js  c++  java
  • Unity3D里Resource方法的二次封装

    /*
     * 
     * 			改编后的unity3D Resources 类,使用起来更加方便,省略了在代码中拆箱装箱的操作
     * 			
     * 			
     * 
     * */
    
    using UnityEngine;
    
    public class ResourcesEx
    {
        private string path;
    
        public ResourcesEx(string path)
        {
            if (path.Length == 0)
            {
                this.path = string.Empty;
            }
            else
            {
                this.path = path;
            }
        }
    
        public T[] LoadAll<T>() where T : Object
        {
            Object[] obj = Resources.LoadAll(this.path, typeof(T));
    
            T[] TLoaded = new T[obj.Length];
            obj.CopyTo(TLoaded, 0);
    
            return TLoaded;
        }
    
        public T[] LoadAll<T>(string dirname) where T : Object
        {
            Object[] obj = Resources.LoadAll(this.path + "/" + dirname, typeof(T));
    
            T[] TLoaded = new T[obj.Length];
            obj.CopyTo(TLoaded, 0);
    
            return TLoaded;
        }
    
        public Texture GetTexture(string textureName)
        {
            Object obj = Resources.Load(this.path + "/" + textureName, typeof(Texture));
            if (obj)
            {
                return obj as Texture;
            }
            else
            {
                Debug.LogError("["+ this.path + textureName + "] Non Exist");
                return new Texture();
            }
        }
    
        public Texture2D GetTexture2D(string textureName)
        {
            Object obj = Resources.Load(this.path + "/" + textureName, typeof(Texture2D));
            if (obj)
            {
                return obj as Texture2D;
            }
            else
            {
                Debug.LogError("["+ this.path + textureName + "] Non Exist");
                return new Texture2D(1, 1);
            }
        }
    
        public T GetObject<T>(string objectName) where T : Object
        {
            Object obj = Resources.Load(this.path + "/" + objectName, typeof(T));
            if (obj)
            {
                return obj as T;
            }
            else
            {
                Debug.LogError("["+ this.path + objectName + "] Non Exist");
                return new Object() as T;
            }
        }
    }
    

      

  • 相关阅读:
    非原创-MongoDB PHP 扩展
    原创-docker命令
    原创-k8s nginx内核参数优化
    原创-阿里云K8S-PVCyaml文件挂载云盘
    原创-k8s反亲和性
    使用Virtualenv隔离Python、Ansible不同发行版
    基于Scrapy分布式爬虫的开发与设计
    CentOS7.3中将Python2.7.5 升级到Python3.5.1
    如何让django的model名和应用名显示为中文
    Django添加ckeditor富文本编辑器
  • 原文地址:https://www.cnblogs.com/vital/p/3559093.html
Copyright © 2011-2022 走看看