初始化事件

 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. Kemaswill 机器学习 数据挖掘 推荐系统 Python optparser模块简介

      Python optparser模块简介

  2. 使用phpstudy向mysql中导入数据

  3. idea 阿波罗(apollo)设置

    项目启动时需要配置环境

  4. STL-set&&multiset 集合

    #include <iostream> #include <cstdio> #include <set> // 仿函数的原型 //struct greaters / ...

  5. 免费生成二维码接口,可直接嵌入到web项目中,附带嵌入方法,任意颜色二维码,任意大小二维码!

    在线体验连接:http://www.zhaimaojun.top/qrcode/ 你是否在项目中寻找方便而且免费的可以直接嵌入到项目中的二维码生成工具呢?你找到了这里,说明你已经找到了!不要犹豫直接拿 ...

  6. (int)、int.Parse()、int.TryParse()、Convert.ToInt32()区别

    请看代码: //1.null. //int i1 = (int)null;//编译时报错:无法将“null”转换为“int”,因为后者是不可以为“null”的值类型. //int i2 = int.P ...

  7. 移动Web开发-WebApp(flex布局+移动端导航案例)

    实际开发中的像素:css像素设备像素比dpr=设备像素/css像素标清屏dpr=1 高清屏dpr=2缩放改变的是css像素大小PPI(每英寸的物理像素点)=根号(屏幕横向分辨率²+屏幕纵向分辨率²)/ ...

  8. gulp常用插件之gulp-postcss使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 ** gulp-postcss**这是一款通过多个插件通过管道传递CSS,但是仅解析一次CSS. 更多使用文档请点击访问gulp-postcss工 ...

  9. 【剑指Offer】60、按之字形顺序打印二叉树

    题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 题解:BFS 主要的方法与BFS写法没什么区 ...

  10. linux 搭建python虚拟环境

    requirements.txt 包含paramiko,pysfp.setuptools,适用python版本3.6.6+ 前提编译安装python wget wget https://www.pyt ...