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.集合映射 需求:网络购物时,用户购买商品,填写地址 每个用户会有不确定的地址数目,或者只有一个或者有很多.这个时候不能把每条地址 ...
随机推荐
- React网络请求跨域代理设置
之前的之所以可以请求其他域名下的网络数据,是因为我们在服务端设置了相关配置,如下所示 如果将其注释掉,再次测试,如下所示 此时便无法跨域操作,接下来介绍下React如何实现跨域代理 (1)分析 Rea ...
- github访问过慢
转:https://baijiahao.baidu.com/s?id=1608100091125662190&wfr=spider&for=pc https://www.cnblogs ...
- 深入浅出Mybatis系列十-SQL执行流程分析(源码篇)
注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 最近太忙了,一直没时间继续更新博客,今天忙里偷闲继续我的Mybatis学习之旅.在前 ...
- js获取页面缩放比例
今天在网上看到一位大神写的一篇文章,出处记不得了,只是因为我在做项目的时候需要用到所以看了一眼. 经理要求我把两张图表上下排列(非响应式的)改成可以适配浏览器的,刚开始只是想改样式,看到代码才发现原来 ...
- gulp常用插件之gulp-rev-format使用
更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-rev-format这是一款提供静态资产的哈希格式选项(前缀,后缀,最后扩展名). 更多使用文档请点击访问gulp-rev-format ...
- pygame 运行心理学问卷
import pygame import sys from pygame.locals import * # wait for keys to putdown def waitForKeys(keys ...
- Linux网络课程学习第一天
第一天上课主要介绍了LINUX系统和Linux课程的情况.了解了开源系统的四大优势,六大特点. 最具有心得的一句话: 学习是件苦差事: 稻盛和夫先生的话也深深激励着我:“工作马马虎虎,只想在兴趣和游戏 ...
- 使用vue/cli 创建一个简单的项目
首先,电脑安装了node.js官方要求8.9 或更高版本 (推荐 8.11.0+) npm install -g @vue/cli # OR yarn global add @vue/cli 全局安装 ...
- 实现字符串和从0到n-1范围内的数字串的一一对应---->poj1200
#include<iostream> using namespace std; ; int num[maxn]; string s; int main() { int nc;//字符串s中 ...
- C语言库函数strstr、strch比较
该库函数包含在<string.h>头文件中,函数原型:extern char *strstr(char *str1, const char *str2);使用方法 char *strstr ...