Chinar 坚持将简单的生活方式,带给世人! (拥有更好的阅读体验 —— 高分辨率用户请根据需求调整网页缩放比例) |
助力快速完成 Unity 对系统类进行扩展,添加函数便于调用 为新手节省宝贵的时间,避免采坑! |
Chinar 教程效果:javascript
新建一个脚本,名称随意html
类必须设为静态 Static ,函数一样(这样才能经过其余类,直接访问到扩展函数)java
形参为 this + 须要扩展的类服务器
依照下列各式
函数
// ========================================================
// 描述:对系统类进行扩展,添加函数
// 做者:Chinar
// 建立时间:2018-08-28 00:03:03
// 版 本:1.0
// ========================================================
using UnityEngine;
#region Chinar Icon
/*
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
##########################################################@$@#############################################################$ #######################################################&: :&##########################################################$
#####################################################| !########################################################$ ##################################################@; :@#####################################################$
################################################@; ;@###################################################$ ###############################################| |##################################################$
#############################################@: '&################################################$ ############################################$` .$###############################################$
###########################################%. .%##############################################$
##########################################$` `$#############################################$ #########################################&' '&############################################$
##########################$. :&#######! !#######&: .%#############################$
##########################&' |####&' '&####| '&#############################$
###########################%. :@##%. .%##@: .%##############################$ ############################&' ;##| |##; '&###############################$
##############################@: `$#| |#&` :@#################################$ ###################################@&&##%. |##&&@######################################$
################$:. '|@#$` `$#@|' .;$###################$ ###############! !##################$
###############&' '&##################$ ################%. %###################$
#################! !####################$ ##################! !#####################$
###################| |######################$
####################&' '&#######################$
######################| |#########################$ ########################! ;###########################$
##########################%. .|#############################$
############################@; ;@###############################$ ####################@; `$#$` `%#$` ;@#######################$
####################%. !#&' `;` `$#| .%#######################$
#############################%. '&#&' .%################################$ ###########################&' !#####! '&##############################$
##########################%. :@#$%%%$#@; .%#############################$
#########################| !###&' '&###! |############################$
##########################@; .|######&' '&######|. ;@#############################$
###############################$;` '!&##########&' '&##########&|' `;&##################################$
########################################################&' '&###########################################################$
########################################################&' '&###########################################################$
########################################################&' '&###########################################################$
########################################################&' '&###########################################################$
########################################################&' '&###########################################################$
########################################################&' '&###########################################################$
########################################################&' '&###########################################################$
#########################################################&$$$&############################################################$ ##########################################################@@@#############################################################$
####################&$$$$$&######&;`%###################&' '&###########################################################$
###############|. %#####$` !###################&' '&###########################################################$
#############; .|###############$` !#####################################################################################$
###########&' `$#################$` !#####################################################################################$
###########; '&##################$` :@########@: ;#########$` .|########| ;@#####@: `$#########$ ##########$` !###################$` ;########@: .%#######@: ;#######@: !####|. '&##############@: `$###$` :@#############$
##########$` |###################$` ;#########%. |#######@: ;#######! `$######$` !#######|. %###% .%##############$
###########; '&##################$` ;#########%. |#######@: ;#######; '&######&' !#####%. .%#####% %###% .%##############$
###########@: `$#################$` ;#########%. |#######@: ;#######; '&######&' !#####; :@######% %###% .%##############$
#############! !###############$` ;#########%. |#######@: ;#######; '&######&' !#####| .%######% %###% .%##############$
###############%` %#####$` ;#########%. |#######@: ;#######; '&######&' !######%. %###% .%##############$
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
##########################################################################################################################$
*/
#endregion
/// <summary> /// 扩展Vector3
/// </summary> public static class Vctor3Ex { /// <summary>
/// 调用 transform.position.GetVector2,可直接获得 x,y 平面坐标的信息,并对坐标直接取整 /// </summary>
/// <returns>二维坐标</returns> public static Vector2 GetVector2(this Vector3 v) { int x = Mathf.RoundToInt(v.x); int y = Mathf.RoundToInt(v.y); return new Vector2(x, y); } /// <summary>
/// 经过 gameobject.SetOff,可直接关闭当前游戏对象 /// </summary>
public static void SetOff(this GameObject go)
{
go.SetActive(false);
}
}
此时,咱们经过 transform.position.GetVector2
就能够调用到扩展后的函数测试
gameobject.SetOff
就能够调用到扩展后的函数
this
/// <summary>
/// 每帧刷新
/// </summary>
void Update()
{
gameObject.SetOff();//是否是很方便,代码很整洁呢!?
Vector2 v = gameObject.transform.position.GetVector2();
}
Chinar 提供一站式教程,闭眼式建立! 为新手节省宝贵时间,避免采坑! |
先点击领取 —— 阿里全产品优惠券 (享受最低优惠)
1 —— 云服务器超全购买流程 (新手必备!)
2 —— 阿里ECS云服务器自定义配置 - 购买教程(新手必备!)
3—— Windows 服务器配置、运行、建站一条龙 !
4 —— Linux 服务器配置、运行、建站一条龙 !spa
本博客为非营利性我的原创,除部分有明确署名的做品外,所刊登的全部做品的著做权均为本人所拥有,本人保留全部法定权利。违者必究
对于须要复制、转载、连接和传播博客文章或内容的,请及时和本博主进行联系,留言,Email: ichinar@icloud.com
对于经本博主明确受权和许可以使用文章及内容的,使用时请注明文章或内容出处并注明网址.net