C#中级编程——C#扩展方法,基于Unity(二)
2021/7/9 17:14:22
本文主要是介绍C#中级编程——C#扩展方法,基于Unity(二),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
C#中级编程——C#扩展方法,基于Unity(二)
之前学习了扩展方法,今天看了DoTween的源码,豁然开朗,极致的运用了扩展方法
先上代码
/// <summary>Tweens a Material's named color property to the given value. /// Also stores the material as the tween's target so it can be used for filtered operations</summary> /// <param name="endValue">The end value to reach</param> /// <param name="property">The name of the material property to tween (like _Tint or _SpecColor)</param> /// <param name="duration">The duration of the tween</param> public static TweenerCore<Color, Color, ColorOptions> DOColor( this Material target, Color endValue, string property, float duration) { if (!target.HasProperty(property)) { if (Debugger.logPriority > 0) Debugger.LogMissingMaterialProperty(property); return (TweenerCore<Color, Color, ColorOptions>) null; } TweenerCore<Color, Color, ColorOptions> t = DOTween.To((DOGetter<Color>) (() => target.GetColor(property)), (DOSetter<Color>) (x => target.SetColor(property, x)), endValue, duration); t.SetTarget<TweenerCore<Color, Color, ColorOptions>>((object) target); return t; }
当然这只是众多重载其中的一个,我们就拿出一个来一起看下。
1.首先必须是静态static方法
2.第一个参数要用this关键字,是作用的目标类
3.后面的参数就比较随意了,就看你要用啥了,比如上面代码中,又用到了3个参数,就照这种写法是没问题的。
# 总结 欢迎大佬多多来给萌新指正,欢迎大家来共同探讨。 **如果各位看官觉得文章有点点帮助,跪求各位给点个“一键三连”,谢啦~**
装模作样的声明一下:本博文章若非特殊注明皆为原创,若需转载请保留原文链接
https://blog.csdn.net/Wrinkle2017/article/details/118608863
及作者信息
这篇关于C#中级编程——C#扩展方法,基于Unity(二)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#
- 2024-01-24Advanced .Net Debugging 1:你必须知道的调试工具
- 2024-01-24.NET集成IdGenerator生成分布式全局唯一ID
- 2024-01-23用CI/CD工具Vela部署Elasticsearch + C# 如何使用
- 2024-01-23.NET开源的简单、快速、强大的前后端分离后台权限管理系统