初始化事件

 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的更多相关文章

  1. 避免重复造轮子的UI自动化测试框架开发

    一懒起来就好久没更新文章了,其实懒也还是因为忙,今年上半年的加班赶上了去年一年的加班,加班不息啊,好了吐槽完就写写一直打算继续的自动化开发 目前各种UI测试框架层出不穷,但是万变不离其宗,驱动PC浏览 ...

  2. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  3. 旺财速啃H5框架之Bootstrap(五)

    在上一篇<<旺财速啃H5框架之Bootstrap(四)>>做了基本的框架,<<旺财速啃H5框架之Bootstrap(二)>>篇里也大体认识了bootst ...

  4. Angular企业级开发(5)-项目框架搭建

    1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...

  5. Scrapy框架爬虫初探——中关村在线手机参数数据爬取

    关于Scrapy如何安装部署的文章已经相当多了,但是网上实战的例子还不是很多,近来正好在学习该爬虫框架,就简单写了个Spider Demo来实践.作为硬件数码控,我选择了经常光顾的中关村在线的手机页面 ...

  6. 制作类似ThinkPHP框架中的PATHINFO模式功能

    一.PATHINFO功能简述 搞PHP的都知道ThinkPHP是一个免费开源的轻量级PHP框架,虽说轻量但它的功能却很强大.这也是我接触学习的第一个框架.TP框架中的URL默认模式即是PathInfo ...

  7. 旺财速啃H5框架之Bootstrap(四)

    上一篇<<旺财速啃H5框架之Bootstrap(三)>>已经把导航做了,接下来搭建内容框架.... 对于不规整的网页,要做成自适应就有点玩大了.... 例如下面这种版式的页面. ...

  8. 一起学 Java(三) 集合框架、数据结构、泛型

    一.Java 集合框架 集合框架是一个用来代表和操纵集合的统一架构.所有的集合框架都包含如下内容: 接口:是代表集合的抽象数据类型.接口允许集合独立操纵其代表的细节.在面向对象的语言,接口通常形成一个 ...

  9. Hibernatel框架关联映射

    Hibernatel框架关联映射 Hibernate程序执行流程: 1.集合映射 需求:网络购物时,用户购买商品,填写地址 每个用户会有不确定的地址数目,或者只有一个或者有很多.这个时候不能把每条地址 ...

随机推荐

  1. 数据结构(集合)学习之Map(二)

    集合 框架关系图 补充:HashTable父类是Dictionary,不是AbstractMap. 一:HashMap中的链循环: 一般来说HashMap中的链循环会发生在多线程操作时(虽然HashM ...

  2. sql多字段分组排序显示全部数据

    建表sql CREATE TABLE `tbl_demo` ( `id` ) COLLATE utf8_bin NOT NULL, `payer_name` ) COLLATE utf8_bin DE ...

  3. 【sklearn朴素贝叶斯算法】高斯分布/多项式/伯努利贝叶斯算法以及代码实例

    朴素贝叶斯 朴素贝叶斯方法是一组基于贝叶斯定理的监督学习算法,其"朴素"假设是:给定类别变量的每一对特征之间条件独立.贝叶斯定理描述了如下关系: 给定类别变量\(y\)以及属性值向 ...

  4. Eclipse使用Alibaba Cloud Toolkit极速部署项目

    个人博客 地址:https://www.wenhaofan.com/a/20190716205809 什么是Alibaba Cloud Toolkit Cloud Toolkit 是针对 IDE 平台 ...

  5. 【Jmeter】jmeter提取response中的返回值,并保存到本地文件--BeanShell后置处理器

    有个需求,需要在压测环境中,创建几十万的账号数据,然后再根据创建结果,查询到某些账号信息. 按照之前我的做法,直接Python调用API,然后再数据库查询: 但是近期所有开发人员的数据库访问权限被限制 ...

  6. babel环境安装与编译

    babel:将浏览器不支持的ES6语法转为javascript 查看node是否安装: npm -v node -v 实例演示:在桌面新建part5目录在cmd命令行中 cd desktop cd p ...

  7. css样式的兼容性

    浏览器                 前缀 IE和safari             -webkit- Chrome                -ms- Firefox            ...

  8. Pair类模板

    >Pair的实现是一个结构体而不是一个类< 1.标准头文件 #include<utility> 似乎无需引入该文件,在std命名空间内也有pair类型 2.格式为:templa ...

  9. Java知识点题集

    一.红黑树的特性 (1)每个节点或者是黑色,或者是红色. (2)根节点是黑色. (3)每个叶子节点(NIL)是黑色. [注意:这里叶子节点,是指为空(NIL或NULL)的叶子节点!] (4)如果一个节 ...

  10. PTA-德州扑克 题解

    于2020/02/24记录. 德州扑克属实是个带难题.本题解简单易懂,命名合理,应该比较好理解. 题目如下: 最近,阿夸迷于德州扑克.所以她找到了很多人和她一起玩.由于人数众多,阿夸必须更改游戏规则: ...