ET框架之SceneChangeComponent
初始化事件
using ETModel; namespace ETHotfix
{
[Event(EventIdType.InitSceneStart)]
public class InitSceneStartEvent:AEvent
{
public override void Run()
{
Game.Scene.GetComponent<TKComponent>().Create(TKType.Boot, "TK");
Game.Scene.GetComponent<UIComponent>().Create(UIType.UILoading);
}
}
}
UILoading组件
using System;
using ETModel;
using UnityEngine;
using UnityEngine.UI; namespace ETHotfix
{
[ObjectSystem]
public class UILoadingAwakeSystem: AwakeSystem<UILoadingComponent>
{
public override void Awake(UILoadingComponent self)
{
self.Awake();
}
} [ObjectSystem]
public class UILoadingUpdateSystem: UpdateSystem<UILoadingComponent>
{
public override void Update(UILoadingComponent self)
{
self.Update();
}
} [UIFactory(UIType.UILoading)]
public class UILoadingFactory: IUIFactory
{
public UI Create(Scene scene, string type, GameObject parent)
{
try
{
ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent<ResourcesComponent>();
resourcesComponent.LoadBundle($"{type}.unity3d");
GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset($"{type}.unity3d", $"{type}");
GameObject inst = UnityEngine.Object.Instantiate(bundleGameObject);
UI ui = ComponentFactory.Create<UI, GameObject>(inst); ui.AddComponent<UILoadingComponent>();
return ui;
}
catch (Exception e)
{
Log.Error(e);
return null;
}
} public void Remove(string type)
{
ETModel.Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"{type}.unity3d");
}
} public class UILoadingComponent: Component
{
private Text text;
private SceneChangeComponent scc; public void Awake()
{
ReferenceCollector rc = this.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
var obj = rc.Get<GameObject>("Text");
this.text = obj.GetComponent<Text>();
this.GetParent<UI>().GameObject.SetActive(false);
} public void Update()
{
if (scc != null) this.text.text = scc.Process.ToString();
} public void Loading(SceneChangeComponent pscc)
{
this.scc = pscc;
this.GetParent<UI>().GameObject.SetActive(true);
} public void LoadCompleted()
{
this.GetParent<UI>().GameObject.SetActive(false);
}
}
}
tkBootComponent中的场景切换代码
using (SceneChangeComponent scc = ETModel.ComponentFactory.Create<SceneChangeComponent>())
{
Game.Scene.GetComponent<UIComponent>().Get(UIType.UILoading).GetComponent<UILoadingComponent>().Loading(scc);
await scc.ChangeSceneAsync(ETModel.SceneType.main);
scc.tcs.Task.GetAwaiter().OnCompleted(() => Game.Scene.GetComponent<UIComponent>().Get(UIType.UILoading).GetComponent<UILoadingComponent>().LoadCompleted());
}
Game.EventSystem.Run(EventIdType.MainSceneStart);
tkBootComponent
using System;
using System.Threading.Tasks;
using DG.Tweening;
using ETModel;
using UnityEngine;
using UnityEngine.UI; namespace ETHotfix
{
[ObjectSystem]
public class tkBootComponentAwakeSystem: AwakeSystem<tkBootComponent>
{
public override void Awake(tkBootComponent self)
{
self.Awake();
}
} [TKFactory(TKType.Boot)]
public class tkBootComponentFactory: ITKFactory
{
public TK Create(Scene scene, string type, GameObject parent)
{
try
{
ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent<ResourcesComponent>();
resourcesComponent.LoadBundle($"{type}.unity3d");
GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset($"{type}.unity3d", $"{type}");
GameObject inst = UnityEngine.Object.Instantiate(bundleGameObject);
TK tk = ComponentFactory.Create<TK, GameObject>(inst); tk.AddComponent<tkBootComponent>();
return tk;
}
catch (Exception e)
{
Log.Error(e);
return null;
}
} public void Remove(string type)
{
ETModel.Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"{type}.unity3d");
}
} public class tkBootComponent: Component
{
private GameObject bright;
private GameObject info;
private GameObject vsn;
private GameObject vmn;
private GameObject vver;
private GameObject date; public async void Awake()
{
ReferenceCollector rc = this.GetParent<TK>().gameObject.GetComponent<ReferenceCollector>();
// 测试动态添加Mono
//this.GetParent<TK>().gameObject.AddComponent<ScrollBackground>(); this.bright = rc.Get<GameObject>("bright");
this.info = rc.Get<GameObject>("Info");
this.vsn = rc.Get<GameObject>("vsn");
this.vmn = rc.Get<GameObject>("vmn");
this.vver = rc.Get<GameObject>("vver");
this.date = rc.Get<GameObject>("date"); Image brightImage = this.bright.GetComponent<Image>();
// Logo图片亮起来
brightImage.DOFade(1f, 3f).SetEase(Ease.Linear);
await Task.Delay();
this.bright.transform.parent.gameObject.SetActive(false); this.info.SetActive(true);
await Task.Delay(); // 测试访问
Log.Info(Game.Scene.GetComponent<TKComponent>().Get(TKType.Boot).gameObject.name);
Log.Info(Game.Scene.GetComponent<TKComponent>().Get(TKType.Boot).GetComponent<tkBootComponent>().InstanceId.ToString()); // 销毁GameObject
//this.GetParent<TK>().Dispose();
// 切换场景到main
using (SceneChangeComponent scc = ETModel.ComponentFactory.Create<SceneChangeComponent>())
{
Game.Scene.GetComponent<UIComponent>().Get(UIType.UILoading).GetComponent<UILoadingComponent>().Loading(scc);
await scc.ChangeSceneAsync(ETModel.SceneType.main);
scc.tcs.Task.GetAwaiter().OnCompleted(() => Game.Scene.GetComponent<UIComponent>().Get(UIType.UILoading).GetComponent<UILoadingComponent>().LoadCompleted());
}
Game.EventSystem.Run(EventIdType.MainSceneStart);
}
}
}
MainSceneStartEvent
using ETModel; namespace ETHotfix
{
[Event(EventIdType.MainSceneStart)]
public class MainSceneStartEvent: AEvent
{
public override void Run()
{
Game.Scene.GetComponent<TKComponent>().Create(TKType.ScrollBackground, "TK");
}
}
}
tkScrollBackgroundComponent
using System;
using ETModel;
using UnityEngine;
using UnityEngine.UI; namespace ETHotfix
{
[ObjectSystem]
public class tkScrollBackgroundComponentAwakeSystem: AwakeSystem<tkScrollBackgroundComponent>
{
public override void Awake(tkScrollBackgroundComponent self)
{
self.Awake();
}
} [TKFactory(TKType.ScrollBackground)]
public class tkScrollBackgroundComponentFactory: ITKFactory
{
public TK Create(Scene scene, string type, GameObject parent)
{
try
{
ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent<ResourcesComponent>();
resourcesComponent.LoadBundle($"{type}.unity3d");
GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset($"{type}.unity3d", $"{type}");
GameObject inst = UnityEngine.Object.Instantiate(bundleGameObject);
TK tk = ComponentFactory.Create<TK, GameObject>(inst); tk.AddComponent<tkScrollBackgroundComponent>();
return tk;
}
catch (Exception e)
{
Log.Error(e);
return null;
}
} public void Remove(string type)
{
ETModel.Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"{type}.unity3d");
}
} public class tkScrollBackgroundComponent: Component
{
public void Awake()
{ }
}
}
通过熊猫的指导,代码有两处地方更改,同时对ComponentFactory理明了了:
// 切换场景到main
using (SceneChangeComponent scc = ETModel.ComponentFactory.Create<SceneChangeComponent>())
{
ETModel.Game.Scene.AddComponent(scc);
Game.Scene.GetComponent<UIComponent>().Get(UIType.UILoading).GetComponent<UILoadingComponent>().Loading();
await scc.ChangeSceneAsync(ETModel.SceneType.main);
scc.tcs.Task.GetAwaiter().OnCompleted(() =>
{
Game.Scene.GetComponent<UIComponent>().Get(UIType.UILoading)
.GetComponent<UILoadingComponent>().LoadCompleted();
// Mian场景启动事件
Game.EventSystem.Run(EventIdType.MainSceneStart);
});
}
//public void Loading(SceneChangeComponent pscc)
public void Loading()
{
//this.scc = pscc;
this.scc = ETModel.Game.Scene.GetComponent<SceneChangeComponent>();
this.GetParent<UI>().GameObject.SetActive(true);
} public void LoadCompleted()
{
this.GetParent<UI>().GameObject.SetActive(false);
ETModel.Game.Scene.RemoveComponent<SceneChangeComponent>();
}
ps:可能存在理解不当的地方,欢迎留言指正!
ET框架之SceneChangeComponent的更多相关文章
- 避免重复造轮子的UI自动化测试框架开发
一懒起来就好久没更新文章了,其实懒也还是因为忙,今年上半年的加班赶上了去年一年的加班,加班不息啊,好了吐槽完就写写一直打算继续的自动化开发 目前各种UI测试框架层出不穷,但是万变不离其宗,驱动PC浏览 ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- 旺财速啃H5框架之Bootstrap(五)
在上一篇<<旺财速啃H5框架之Bootstrap(四)>>做了基本的框架,<<旺财速啃H5框架之Bootstrap(二)>>篇里也大体认识了bootst ...
- Angular企业级开发(5)-项目框架搭建
1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...
- Scrapy框架爬虫初探——中关村在线手机参数数据爬取
关于Scrapy如何安装部署的文章已经相当多了,但是网上实战的例子还不是很多,近来正好在学习该爬虫框架,就简单写了个Spider Demo来实践.作为硬件数码控,我选择了经常光顾的中关村在线的手机页面 ...
- 制作类似ThinkPHP框架中的PATHINFO模式功能
一.PATHINFO功能简述 搞PHP的都知道ThinkPHP是一个免费开源的轻量级PHP框架,虽说轻量但它的功能却很强大.这也是我接触学习的第一个框架.TP框架中的URL默认模式即是PathInfo ...
- 旺财速啃H5框架之Bootstrap(四)
上一篇<<旺财速啃H5框架之Bootstrap(三)>>已经把导航做了,接下来搭建内容框架.... 对于不规整的网页,要做成自适应就有点玩大了.... 例如下面这种版式的页面. ...
- 一起学 Java(三) 集合框架、数据结构、泛型
一.Java 集合框架 集合框架是一个用来代表和操纵集合的统一架构.所有的集合框架都包含如下内容: 接口:是代表集合的抽象数据类型.接口允许集合独立操纵其代表的细节.在面向对象的语言,接口通常形成一个 ...
- Hibernatel框架关联映射
Hibernatel框架关联映射 Hibernate程序执行流程: 1.集合映射 需求:网络购物时,用户购买商品,填写地址 每个用户会有不确定的地址数目,或者只有一个或者有很多.这个时候不能把每条地址 ...
随机推荐
- 位运算基础知识及简单例题(待补全Hamilton)
位运算 +++ 1 : 0000000000...01 2 : 0000000000...10 3 : 0000000000...11 补码 1 + x = 0000000000...00 1 + 1 ...
- dubbo的使用
dubbo现在用的也不多,基本都在用spring cloud那一套,所以不详细写这个dubbo了. 1.zookeeper的安装 2.demo示例 我们需要把提供者注册到dubbo注册中心,消费者去订 ...
- USB闪存驱动器未显示在MacOS的Finder或磁盘工具上?为什么Mac无法识别USB该如何解决?
您可能会在Mac上无法显示的闪存驱动器上形成困扰.您确定驱动器正常,但Mac计算机无法检测到. 阅读这篇文章,闪存驱动器未显示在MacOS的Finder或磁盘工具上?为什么Mac无法识别USB该如何 ...
- openlayers编辑区域
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- NOI Online能力测试游记:退役选手的自娱自乐
2020年2月17日早上8点,CCF发布了关于举办NOI Online能力测试的通知. 为给选手提供一个锻炼的机会,CCF拟举办一场NOI Online能力测试.测试分为入门组和提高组,每组限额报名3 ...
- AI 数学基础 : 熵
什么是熵(entropy)? 1.1 熵的引入 事实上,熵的英文原文为entropy,最初由德国物理学家鲁道夫·克劳修斯提出,其表达式为: 它表示一个系系统在不受外部干扰时,其内部最稳定的状态.后来一 ...
- os常用讲解
os.mkdir()创建单个不存在的空目录,无法创建多个或者已经存在的含有文件的同名目录 os.makedirs() 能够递归创建多个目录,如果目录已经存在即使都是空的或者目录已经存在且含有文件,则引 ...
- Spring-Cache手动清缓存
Spring Cache 手动清Redis缓存 注册cacheRedisTemplate 将 cache 的 RedisTemplate 注册为Bean @Bean(name = "cach ...
- Python中io的open()在PyCharm环境下报错和路劲的问题
PS:我也是初学者,上班空闲时间学习学习Python.今天学到io的时候,遇到了两个用PyCharm环境编写代码的小白错误,如下: 两个问题都是如下代码: 1. 第一个问题:当写好代码之后,点击运行报 ...
- R语言读写数据
R语言读写数据 一般做模型的时候,从外部的excel中读入数据,我现在常用的比较多的是read_csv(file) 读入之前先把excel数据转化成.csv格式 同样的把结果输出来的时候用的是writ ...