当前位置: 首页 > news >正文

建筑招投标信息网专业seo网络营销公司

建筑招投标信息网,专业seo网络营销公司,金融网站建设方法,松阳建设局网站以下内容是根据Unity 2020.1.0f1版本进行编写的   实现一个自定义图集,该怎么入手呢。首先简单思考一下unity是怎么实现图集的。 因为unity的ui部分是开源的,所以我们可以看到UGUI的源代码,另外,Unity的内置Shader也是开源的,可以直接在官网下载(在下载的网页选择Built…

以下内容是根据Unity 2020.1.0f1版本进行编写的

实现一个自定义图集,该怎么入手呢。首先简单思考一下unity是怎么实现图集的。
因为unity的ui部分是开源的,所以我们可以看到UGUI的源代码,另外,Unity的内置Shader也是开源的,可以直接在官网下载(在下载的网页选择Built in shaders下载即可):https://unity.com/releases/editor/archive

首先,图集在Unity编辑器中是可编辑的,因此,需要实现一个自定义图集的Inspector面板,并定义好图集的基础属性,方便使用。

1、实现自定义图集类MyAtlas

using System.Collections.Generic;
using UnityEngine;[CreateAssetMenu(fileName = "MyAtlas", menuName = "My Atlas")]
public class MyAtlas : ScriptableObject
{public string atlasName = "";public List<string> guids = new List<string>();public List<string> packableObjects = new List<string>();public List<string> realPackObjs = new List<string>();public List<UnityEngine.Object> objs = new List<Object>();
}

首先,定义自定义的图集类MyAtlas,这里只定义Inspector面板需要用到的变量。需要继承ScriptableObject类,否则无法实现自定义类型的后处理导入
其中,atlasName是图集名字,guids是图集包含全部图片的guid,realPackObjs是图集包含全部图片的路径,Objs是显示在Inspector面板的Object,packableObjects是Objs对应的路径,因为有可能是文件夹,所以需要和realPackObjs区分开来。
在这里插入图片描述
在这里插入图片描述
右键新建一个MyAtlas文件,如上图,这样可以了

2、实现自定义图集类的Inspector面板

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using UnityEngine;public class CommonFunc : MonoBehaviour
{public static void SeachFile(string path, List<string> files, string[] extensions){if (Directory.Exists(path)){DirectoryInfo di = new DirectoryInfo(path);FileSystemInfo[] fsInfos = di.GetFileSystemInfos();bool isSkip;foreach (FileSystemInfo fsInfo in fsInfos){isSkip = true;if (fsInfo is DirectoryInfo){SeachFile(fsInfo.FullName, files, extensions);}if (fsInfo.Name.Contains(".meta")){continue;}foreach (string extension in extensions){if (fsInfo.Name.Contains(extension)){isSkip = false;break;}}if (!isSkip){string fileN = fsInfo.FullName;string ss = "Assets" + fileN.Replace("\\", "/").Replace(Application.dataPath, "");if (!files.Contains(ss)){files.Add(ss);}}}}}public static List<string> GetAllFilesInDirectory(string path, string searchParttern, List<string> list = null, bool isUnityPath = false){if (list == null){list = new List<string>();}var files = Directory.GetFiles(path, searchParttern, SearchOption.AllDirectories);foreach (var file in files){string filePath = file.Replace("\\", "/");if (isUnityPath){filePath = GetUnityPath(filePath);}list.Add(filePath);}return list;}public static string GetMD5Hash(string filePath){MD5 md5 = new MD5CryptoServiceProvider();return BitConverter.ToString(md5.ComputeHash(File.ReadAllBytes(filePath))).Replace("-", "").ToLower();}public static string GetUnityPath(string path){string newPath = path;if (newPath.Contains(Application.dataPath)){newPath = newPath.Replace(Application.dataPath, "Assets");}if (newPath.Contains(Application.dataPath.Replace("/", "\\"))){newPath = newPath.Replace(Application.dataPath.Replace("/", "\\"), "Assets");}if (newPath.Contains(Application.dataPath.Replace("\\", "/"))){newPath = newPath.Replace(Application.dataPath.Replace("\\", "/"), "Assets");}newPath = newPath.Replace("\\", "/");return newPath;}public static string GetSystemPath(string path){string newPath = path;if (newPath.StartsWith("Assets")){newPath = Application.dataPath.Replace("Assets", "") + newPath;}newPath = newPath.Replace("/", "\\");return newPath;}public class Messagebox{[DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]public static extern int MessageBox(IntPtr handle, String message, String title, int type);}
}

首先实现一个通用的类CommonFunc,包含一些通用方法,如文件路径转换UnityPath,或者转换为系统路径,等等。

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.UI;
using UnityEditorInternal;
using UnityEngine;[
http://www.yayakq.cn/news/102139/

相关文章:

  • 流量网站怎么盈利平面设计培训班大概多少钱
  • 网站建设优化一体直播网站功能怎么做
  • 如何做网站数据库代理公司注册哪家好
  • 西部数码 成品网站新浪微舆情大数据平台
  • 图书翻页的动画 做网站启动用手机免费建站平台下载
  • 秦皇岛昌黎县建设局网站山东省建设部官方网站
  • 电商网站建设方案PPT全网搜索指数
  • 自动做网站网站建设报价明细模板
  • 温州网站关键词网站接入服务单位名称
  • 采购网站模板用名字做头像是什么网站
  • 网站建设有哪些平台租车网站模板下载
  • 物流好的网站模板wordpress 上传类型
  • 建设工程消防网站wordpress最大上传
  • iis 会影响 网站 速度网页设计首页怎么设计
  • 南昌网站建设方案推广网站建设用到的工具
  • 绍兴网站制作计划wordpress 播客网站
  • 网站 二次开发怎么做学院网站建设的目的及定位
  • 行业网站排名查询wordpress 汉化软件
  • 属于门户网站的有山东青岛最新情况
  • 网站开发重庆南坪网站建设
  • 多语网站建设做智能网站系统
  • 苏州网站建设孙峰网页版微信登录显示二维码失效
  • asp网站制作免费模板下载如何做网站接口
  • 佛山新网站建设案例asp.net网站开发 pdf
  • PHP网站开发方向成都定制公交app
  • 昆明网站建设天锐科技在青岛做阿里巴巴网站找谁
  • 类似qq空间的网站模板怎样在百度做网站打广告
  • 企业如何注册网站网站做业务赚钱吗
  • 建设工程质量检测公司网站c语言开发网站后端
  • 网红网站建设东莞百度seo电话