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

上海金融网站建设厦门网站搜索引擎优化

上海金融网站建设,厦门网站搜索引擎优化,网站如何做导航,wordpress avada 加速主要学习内容TypeEventSystemActionKitTimer类1、TypeEventSystem-适用于一个条件触发,多个组件响应的情况例如:动物园系统中,点击肉食动物按钮,动物园中有肉食属性的动物都进行显示。步骤:1、动物自身脚本上进行判断是…

主要学习内容

  1. TypeEventSystem

  1. ActionKit

  1. Timer类

1、TypeEventSystem-适用于一个条件触发,多个组件响应的情况

例如:动物园系统中,点击肉食动物按钮,动物园中有肉食属性的动物都进行显示。

步骤:

1、动物自身脚本上进行判断是否有肉食属性,有则注册事件

2、事件发送方:按钮点击,发送通知事件

3、事件接收方:动物,执行处理事件的操作

①单事件触发

代码学习

using System;
using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;// namespace QFramework.Example//在类的外面嵌套上命名空间
// {public class TypeEventSystemController : MonoBehaviour{//用结构体定义一个事件,适合一对多的情况,一触发,多响应public struct EventA{//参数public int Count;}//在start中监听事件void Start(){//注册并回调,简单写法TypeEventSystem.Global.Register<EventA>(e => //输入e点击Tab{Debug.Log(e.Count);}).UnRegisterWhenGameObjectDestroyed(gameObject);//注销,与当前的gameobject进行关联//传统事件机制的用法①②③//①TypeEventSystem.Global.Register<EventA>(onEventA);}//②//void onEventA(Event e)//{//}//③销毁//private void OnDestroy()//{//    TypeEventSystem.Global.UnRegister<EventA>(onEventA);// }// Update is called once per framevoid Update(){//发送事件if (Input.GetMouseButtonDown(0)){//第一种写法:自动new一个A,但是无法传参//TypeEventSystem.Global.Send<EventA>();//第二种写法TypeEventSystem.Global.Send(new EventA(){Count = 10});}}}
// }

②多事件触发

using System.Collections;
using System.Collections.Generic;
using QFramework;
using SnakeGame;
using Unity.VisualScripting;
using UnityEngine;public class MutiEvent : MonoBehaviour//添加// IOnEvent<MutiEvent.IEventA>, //     IOnEvent<MutiEvent.EventB>//报错可进行点击自动生成代码
{public interface IEventA//接口形式{public abstract void Function();}public struct EventB: IEventA{public void Function(){print("从管道B中流出");}}public struct EventC: IEventA{public void Function(){print("从管道C中流出");}}void Start(){TypeEventSystem.Global.Register<IEventA>(a => {Debug.Log(a.GetType().Name);}).UnRegisterWhenGameObjectDestroyed(gameObject); //输出名字}// Update is called once per framevoid Update(){if (Input.GetMouseButtonDown(0)){TypeEventSystem.Global.Send<IEventA>(new EventB());}if (Input.GetMouseButtonDown(1)){TypeEventSystem.Global.Send<IEventA>(new EventC());}}}

2、ActionKit

①单独使用时

1)延时功能
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using QFramework;public class ActionKitExample : MonoBehaviour
{void Start(){//调用延时功能DelayTime();}/// <summary>/// 实现延时功能/// </summary>void DelayTime(){print("开始时间 "+Time.time);ActionKit.Delay(1.0f, () =>{print("延迟时间:" + Time.time);}).Start(this);//底层使用的是MonoBehaviour中的东西,所以需要关联一下gameObject}}

运行结果:大约延迟1s

 /// <summary>/// 序列和完成回调/// </summary>void SequenceAndCallBack(){print("序列开始:"+Time.time);ActionKit.Sequence().Callback(() => print("DelayStart延时开始:"+Time.time))//回调函数.Delay(1.0f)//延时一秒.Callback(()=>Debug.Log("Delay Finish延时结束:"+Time.time)).Start(this,_=>{print("Sequence Finish序列结束:"+Time.time);});}

运行结果:sequence从上到下执行

  /// <summary>/// 帧延时/// </summary>void DelayFrameExample(){//延时一帧后回调print("帧延时开始帧率数"+Time.frameCount);ActionKit.DelayFrame(1, () =>{print("帧延时结束帧率数" + Time.frameCount);}).Start(this);//序列延时10帧后回调ActionKit.Sequence().DelayFrame(10).Callback(() => print("序列延时帧率数" + Time.frameCount)).Start(this);//下一帧做什么ActionKit.NextFrame(() => { }).Start(this);}

运行结果

   /// <summary>/// 支持协程的方式/// </summary>void CoroutineExample(){//第一种:普通//ActionKit.Coroutine(() => SomeCoroutine()).Start(this);//ActionKit.Coroutine(SomeCoroutine).Start(this);//第二种:将协程转换为动作//SomeCoroutine().ToAction().Start(this);//第三种:序列的方式执行ActionKit.Sequence().Coroutine(()=>SomeCoroutine()).Callback(()=>print("结束"))//如果是多个:使用delegte.Start(this);}IEnumerator SomeCoroutine(){yield  return new WaitForSeconds(1.0f);print("你好"+Time.time);}

运行结果:我感觉跟上面序列完成回调的Delay(1.0f)方法是一样的,且不如上面的简单,这个方法可以弃用了

2)条件执行
    /// <summary>/// 条件执行(仅执行一次)/// </summary>void ConditionExample(){ActionKit.Sequence().Callback(() => print("条件发生之前")).Condition(() => Input.GetMouseButtonDown(0))//每帧调用后面的委托,直到委托返回为true,执行下一步.Callback(() => print("鼠标点击")).Start(this);}

运行结果:一直在等待条件的执行

   /// <summary>/// 重复执行/// </summary>void RepeatExample(){print("点击五次鼠标右键,输出信息");ActionKit.Repeat(5)//改为关键字repeat.Condition(() => Input.GetMouseButtonDown(1))//每帧调用后面的委托,直到委托返回为true,执行下一步.Callback(() => print("鼠标点击")).Start(this, () =>{print("5次右键点击完成");});}

运行结果:条件重复5次后输出

  /// <summary>/// 并行执行,同时执行动作,动作全部完成执行最后finish函数/// </summary>void ParallelExample(){print("并行开始");ActionKit.Parallel().Delay(1.0f, () => { print(Time.time); }).Delay(2.0f, () => { print(Time.time); }).Delay(3.0f, () => { print(Time.time); }).Start(this, () =>{print("并行结束" + Time.time);});}

运行结果

3)自定义动作执行
    /// <summary>///自定义动作/// </summary>void CutomExample(){ActionKit.Custom(a =>{a.OnStart(() => { print("OnStart"); }).OnExecute(dt =>{print("OnExecute");if (Time.frameCount > 5){a.Finish();//注意这里是Finish}}).OnFinish(() => { print("OnFinish"); });}).Start(this);}

运行结果:事件开始,执行,结束

  //传数据的自定义事件public class ActionData{public  int FrameCount;//公有,其他函数可以访问}/// <summary>///自定义动作,含参数/// </summary>void CutomExampleWithParameter(){ActionKit.Custom<ActionData>(a =>//传一个自定义的数据类型{a.OnStart(() =>{a.Data = new ActionData(){FrameCount=0};print("OnStart");}).OnExecute(dt =>{print("OnExecute");a.Data.FrameCount++;if (a.Data.FrameCount > 5){a.Finish();//注意这里是Finish}}).OnFinish(() => { print("OnFinish"); });}).Start(this);}

运行结果:开始的时候定义参数值,执行时进行判断,符合条件结束

②与DoTween插件集成

集成步骤:

查找-双击-导入

代码

    /// <summary>/// DoTween的集成,Dotween和ActionKit组合使用/// </summary>void DotweenExample(){ActionKit.Sequence().DOTween(() => transform.DOMoveX(5, 1)).Start(this);}

运行结果:挂在脚本的物体在一秒钟,x变为5

3、Timer计时器

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using QFramework;
using QFramework.TimeExtend;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using Timer = QFramework.TimeExtend.Timer;public class Test : MonoBehaviour
{private Timer timer1;private Timer timer2;public Text timeText;void Start(){ActionKit.Sequence().Callback(() => print("按下F1新建一个计时器")).Condition(() => Input.GetKey(KeyCode.F1)) .Callback(() => timer1 = Timer.AddTimer(10, "Timer1", false, true).OnUpdated(a =>{timeText.text = ((1 - a) * 10).ToString();}).OnCompleted(() => //十秒完成后{print("Timer1计时10秒结束");})).Condition(()=> Input.GetKey(KeyCode.D)).Callback(delegate{Timer.DelTimer("Timer1");print("删除-计时器1");}).Condition(()=>  Input.GetKey(KeyCode.A)).Callback(delegate{if (!Timer.Exist(timer2)){timer2 = Timer.AddTimer(10, "Timer2", false, true).OnUpdated(a =>{timeText.text = (a*10).ToString();}).OnCompleted(()=>//十秒完成后{print("Timer2计时10秒结束");});print("新建-计时器2");}})   .Condition(() => Input.GetKey(KeyCode.S)) .Callback(delegate{if (Timer.Exist(timer2)){Timer.Pause(timer2);print("暂停-计时器2");}})   .Condition(() => Input.GetKey(KeyCode.F)) .Callback(delegate{if (Timer.Exist(timer2)){Timer.Resum(timer2);print("计时器恢复");}})   .Start(this);}}
}


文章转载自:
http://ermentrude.przc.cn
http://dey.przc.cn
http://clannishly.przc.cn
http://horticulture.przc.cn
http://chasmophyte.przc.cn
http://maladaptation.przc.cn
http://duniewassal.przc.cn
http://ledger.przc.cn
http://cicerone.przc.cn
http://grant.przc.cn
http://whorehouse.przc.cn
http://airworthy.przc.cn
http://giddily.przc.cn
http://dlitt.przc.cn
http://prebiological.przc.cn
http://metafemale.przc.cn
http://autocycle.przc.cn
http://bacillin.przc.cn
http://infamatory.przc.cn
http://erysipeloid.przc.cn
http://haematic.przc.cn
http://hematopoietic.przc.cn
http://tacoma.przc.cn
http://poacher.przc.cn
http://tricuspidal.przc.cn
http://intuitionist.przc.cn
http://catalpa.przc.cn
http://there.przc.cn
http://munch.przc.cn
http://causal.przc.cn
http://circumstellar.przc.cn
http://confederative.przc.cn
http://scrimshander.przc.cn
http://baldwin.przc.cn
http://faggoty.przc.cn
http://conceitedly.przc.cn
http://accessorial.przc.cn
http://mammonite.przc.cn
http://insanely.przc.cn
http://subaltern.przc.cn
http://bantling.przc.cn
http://barbed.przc.cn
http://hypochondriasis.przc.cn
http://rheogoniometry.przc.cn
http://wearable.przc.cn
http://unbiased.przc.cn
http://butterscotch.przc.cn
http://bottleneck.przc.cn
http://endostea.przc.cn
http://fledgeless.przc.cn
http://biplane.przc.cn
http://internal.przc.cn
http://diacid.przc.cn
http://abrader.przc.cn
http://primatology.przc.cn
http://yamato.przc.cn
http://picket.przc.cn
http://fireproof.przc.cn
http://frothy.przc.cn
http://spiritedly.przc.cn
http://thermoluminescence.przc.cn
http://icc.przc.cn
http://axite.przc.cn
http://saviour.przc.cn
http://zygosis.przc.cn
http://decompose.przc.cn
http://monthlong.przc.cn
http://biopoiesis.przc.cn
http://alkali.przc.cn
http://amidol.przc.cn
http://matriarchate.przc.cn
http://catholically.przc.cn
http://palmyra.przc.cn
http://dragrope.przc.cn
http://miolithic.przc.cn
http://obpyriform.przc.cn
http://examinatorial.przc.cn
http://fore.przc.cn
http://stoneware.przc.cn
http://stearate.przc.cn
http://scurviness.przc.cn
http://amie.przc.cn
http://chiromancy.przc.cn
http://boisterous.przc.cn
http://subcortex.przc.cn
http://pepperbox.przc.cn
http://teletransportation.przc.cn
http://prodigal.przc.cn
http://blastocoele.przc.cn
http://approx.przc.cn
http://worriment.przc.cn
http://metralgia.przc.cn
http://violetta.przc.cn
http://acnemia.przc.cn
http://elul.przc.cn
http://verisimilitude.przc.cn
http://ferropseudobrookite.przc.cn
http://bantling.przc.cn
http://prankster.przc.cn
http://incrustation.przc.cn
http://www.15wanjia.com/news/60071.html

相关文章:

  • 网站产品要如何做详情代运营公司可靠吗
  • 58同城商业后台如何做网站哈尔滨最新信息
  • 建设项目查询网站百度智能云建站
  • 做视频网站用什么服务器配置西安的网络优化公司
  • 丹阳房产网二手房seo关键词优化软件app
  • 自己做网站需要学什么东西万网域名查询接口
  • 丽水市住房和城乡建设局网站百度关键词seo优化
  • 网站后台管理默认密码sem是什么分析方法
  • 佛山网站建设维护深圳做网站
  • 网站seo内部优化网站推广优化的方法
  • 网站后台内容编辑器下载免费的网站域名查询app
  • 广东网站建设哪家好最好的推广平台排名
  • 怎么看网站备案芜湖网络营销公司
  • 设计深圳seo技术
  • 伊川县住房和城乡建设厅网站深圳市seo网络推广哪家好
  • 网站做数据统计上海专业优化排名工具
  • php网站建设方案什么都能搜的浏览器
  • 做字幕模板下载网站有哪些sem代运营推广公司
  • 网站建设导航栏设计代刷网站推广链接免费
  • 英文商务网站制作兰州做网站的公司
  • 营销网站建设流程图seo内容优化心得
  • 线上设计师招聘临沂seo公司
  • 高校廉洁文化建设网站宁波seo整站优化软件
  • 做网站做那一网站好建设优化网站
  • 过界女主个人做网站的绍兴seo外包
  • gps建站教程网络营销策略名词解释
  • 做app还是网站semiconductor是什么意思
  • 安装网站程序的流程搜索引擎优化seo名词解释
  • 穷游网站 做行程 封面2021年十大热点事件
  • 上海做企业网站网络推广需要多少钱