1.崩溃和报错
Application.logMessageReceived += unityLogHander;
private unityLogHander(string log_, string stackInfo_, LogType type_){
if (
type_ == LogType.Assert ||
type_ == LogType.Error ||
type_ == LogType.Exception
){
//Editor + Debug 下弹出提示框
//非 Editor + Debug 下报bugly
}
}
2.运行时,跨环境调用
2 - 1 - IOS 交互
2 - 2 - Android 交互
2 - 3 - lua 交互
3.AssetsBundle相关
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
/*
工程目录 的 Assets 目录
Application.dataPath
AB包构建需要的一些文件操作,详细操作方式查阅以下类的文档。
File、FileInfo、Directory、DirectoryInfo
*/
//获取工程相某个文件夹下的文件列表的相对路径
public static List<string> getRelativeFilePathList( string relativeFolder_ , List<string> filterList_ = null ){
string _targetRelativeFolderPath = System.IO.Path.Combine( Application.dataPath , relativeFolder_ );
List<string> _fileRelativePathList = new List<string>();
DirectoryInfo _targetDirInfo = new DirectoryInfo( _targetRelativeFolderPath );//文件夹信息
for (int _idx = 0; _idx < filterList_.Count; _idx++) {
FileInfo[] _targetFileInfos = _targetDirInfo.GetFiles( filterList_[_idx] , SearchOption.AllDirectories );//满足后缀的文件信息列表
for (int _j = 0; _j < _targetFileInfos.Length; _j++) {
string _filePath = _targetFileInfos[ _j ].FullName;//绝对路径
string _relativePath = _filePath.Substring( _filePath.IndexOf("Assets") );//相对路径
_fileRelativePathList.Add(_relativePath);
}
}
return _fileRelativePathList;
}
//获取其所依赖的文件列表
public static string[] getDependencies( string[] filePathList_, List<string> filterList_ = null ){
string[] _filePathList = AssetDatabase.GetDependencies(filePathList_, true);
if(filterList_ == null) {
return _filePathList;
}else{
return _filePathList.Where( _filePath => filterList_.Contains( System.IO.Path.GetExtension( _filePath ).ToLower() ) ).ToArray();
}
}
// ab资源的文件列表
string[] _abResFilePathList = getRelativeFilePathList("ToLua/Examples" , new List<string>{ "*.lua.bytes" });
// 资源的依赖列表
string[] _dependenciesList = getDependencies(_abResFilePathList);
3 - 1 - 依赖关系
3 - 2 - 去重
3 - 3 - 下载,解压
4.ShaderVariant 收集 + 剔除
4 - 1 - 收集
4 - 2 - 剔除
5.Editor拓展
5 - 1 - 导入时,修改参数
5 - 2 - 校验资源
5 - 3 - 编辑器
5 - 3 - 1 - 组件依赖
using UnityEngine;
using UnityEditor;
//TarClass 注册到gameObject的同时,DependOnTarClass也要注册到gameObject上
[CustomEditor(typeof(TarClass))]
public class TarClassAutoBind : Editor {
public void OnEnable() {
TarClass _obj = target as TarClass;
if(_obj == null){
return;
}
TarClass _component = _obj.GetComponent<TarClass>();
DependOnTarClass extensions = _obj.GetComponent<DependOnTarClass>();
if (_component != null && _component.GetComponent<DependOnTarClass>() == null){
_component.gameObject.AddComponent<DependOnTarClass>();
}
}
}
|