初始化事件

 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. 【spring】(填坑)sql注入攻击 - 持久层参数化

    结果   填坑失败,并没有看懂是如何检测sql攻击的. 只能说的是: 建议都使用参数化传递sql语句参数.(所以,用hibernate.mybatis等框架的真不用太担心sql攻击问题.) 前言 本文 ...

  2. 【巨杉数据库SequoiaDB】社区分享 | SequoiaDB + JanusGraph 实践

    本文来自社区用户投稿,感谢小伙伴的技术分享 项目背景 大家好!在春节这段时间里,由于一直在家,所以花时间捣鼓了一下代码,自己做了 SequoiaDB 和 JanusGraph 的兼容扩展工作. 自己觉 ...

  3. JDBC连接数据库的7个步骤

    1.JDBC所需的四个参数username.password.url.driverClass 2.加载JDBC驱动程序 3.创建数据库连接connection对象conn 4.创建preparedSt ...

  4. ubuntu18.04图形模式切换到命令模式

    命令模式 :Ctrl+Alt+F5 图形模式:Ctrl+Alt+F1

  5. SpringBoot的应运而生

    随着动态语言的流行(Ruby,Groovy,Scala,Node.js),java的开发显得格外的笨重,繁多的配置,低下的效率,复杂的部署流程以及第三方技术集成难度大.springboot应运而生,使 ...

  6. GYCTF 盲注【regexp注入+时间盲注】

    考点:regexp注入+时间盲注 源码: <?php # flag在fl4g里 include 'waf.php'; header("Content-type: text/html; ...

  7. .Net Core 智能提示汉化包

    在.Net Core 2.x 版本,Microsoft 官方没有提供 .Net Core 正式版的多语言安装包.因此,我们在用.Net Core 2.x 版本作为框架目标编写代码时,智能提成是英文的. ...

  8. ubuntu中的Linux安装程序的方法

    Ubuntu: 1.下载.deb文件,下载后,cd到.deb文件目录,然后使用sudo dpkg -i xxx.deb      dpkg=debian packager的缩写  -i=install ...

  9. Nginx配置服务器宕机策略

    Nginx解决服务器宕机问题,Nginx配置服务器宕机策略,如果服务器宕机,会找下一台机器进行访问        配置nginx.cfg配置文件,在映射拦截地址中加入代理地址响应方案 location ...

  10. ReviewBoard使用:添加SVN

    1.登录ReviewBoard,选择“Admin” 2.选择 “Repositores”,点击按钮“Add” 3.填写内容,然后点击按钮“SAVE”保存 Name:仓库名称(自己随意写) Hostin ...