Unity3D多线程之页面和窗口管理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3D多线程之页面和窗口管理相关的知识,希望对你有一定的参考价值。
参考技术A 先附上git地址https://github.com/huqiang0204/huqiang.UnitySubThreadUI
主要基类UIbase
public ModelElement Parent get; protected set; //当前UI的父元素
public ModelElement model get; protected set; //当前模型
public T LoadUI<T>(string asset, string name)//从asset中载入UI模型
UI模型需要先注册
class ModelManagerUI
/// 载入模型数据
/// <param name="buff">模型二进制数据</param>
/// <param name="name">注册asset名</param>
/// <returns></returns>
public unsafe static PrefabAsset LoadModels(byte[] buff, string name)
使用示例
public TextAsset baseUI;
// Start is called before the first frame update
void Start()
App.Initial(transform as RectTransform);
ModelManagerUI.LoadModels(baseUI.bytes, "baseUI");
#if UNITY_EDITOR
AssetBundle.UnloadAllAssetBundles(true);
#endif
ElementAsset.LoadAssetsAsync("base.unity3d").PlayOver = (o, e) =>
UIPage.LoadPage<TestPage>();
;
UIpage之间的相互切换,UIpage继承于UIbase
示例页面之间切换
A页面
class A:UIPage
class View
public EventCallBack Last;
public EventCallBack Next;
View view;
public override void Initial(ModelElement parent, object dat = null)
view = LoadUI<View>("baseUI","a");
base.Initial(parent, dat);
view.Last.Click = (o, e) => LoadPage<B>(); ;
view.Next.Click = (o, e) => LoadPage<B>(); ;
B页面
class A:UIPage
class View
public EventCallBack Last;
public EventCallBack Next;
View view;
public override void Initial(ModelElement parent, object dat = null)
view = LoadUI<View>("baseUI","b");
base.Initial(parent, dat);
view.Last.Click = (o, e) => LoadPage<A> (); ;
view.Next.Click = (o, e) => LoadPage<A>(); ;
在UIPage中弹一个窗口,当再次调用时会隐藏当前窗口,显示新窗口
protected T ShowPopWindow<T>(object obj = null, huqiang.UI.ModelElement parent = null) where T : PopWindow, new()
public PopWindow currentPop get; private set; //当前窗口
public void HidePopWindow()//隐藏当前窗口,如果存在
public void ReleasePopWindow()//释放掉当前未激活的弹窗
public void ReleasePopWindow<T>()//释放掉该类型的窗口
public void ReleasePopWindow(PopWindow window)//释放掉改实例窗口
public T GetPopWindow<T>() where T : PopWindow//获取该类型的窗口
想要显示多个窗口请自行管理,List<PopWindow> pops;
Selenium-测试对象操作之:多窗口内嵌frame
操作策略:通过selenium提供的方法切换后进行操作
窗口切换:switch_to_window()
frame切换:switch_to_frame
窗口切换注意:窗口打开顺序和窗口句柄列表索引的关系
页面打开顺序:1 2 3
窗口句柄索引:0 2 1
多窗口案例:
#coding=utf-8
from selenium import webdriver
import time,os
driver = webdriver.Chrome()
driver.get("https://www.hao123.com/")
driver.maximize_window()
#进入"凤 凰 网",“优酷网”
driver.find_element_by_link_text("凤 凰 网").click()
time.sleep(3)
driver.find_element_by_link_text("优 酷 网").click()
time.sleep(3)
#获取所有窗口的窗口句柄
all_handle=driver.window_handles
print all_handle
#切换到“优酷网”
driver.switch_to_window(all_handle[1])
time.sleep(3)
#在“优酷网”继续操作
driver.find_element_by_link_text("发现").click()
‘‘‘页面打开顺序和窗口句柄列表索引的关系
1 2 3
0 2 1
‘‘‘
内嵌frame案例:
Pyhon代码
#coding=utf-8
from selenium import webdriver
import time
import os
driver = webdriver.Chrome()
file_path =os.path.abspath(‘frame.html‘)
driver.get(file_path)
#先找到到 ifrome1(id = f1)
driver.switch_to_frame("f1")
#再找到其下面的 ifrome2(id =f2)
driver.switch_to_frame("f2")
#下面就可以正常的操作元素了
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(3)
driver.quit()
内嵌frame HTML代码
frame.html
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>frame</title>
</head>
<body>
<div class="row-fluid">
<div class="span10 well">
<h3>frame</h3>
<iframe id="f1" src="inner.html" width="800" height="600"></iframe>
</div>
</div>
</body>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
</html>
inner.html
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>inner</title>
</head>
<body>
<div class="row-fluid">
<div class="span6 well">
<h3>inner</h3>
<iframe id="f2" src="http://www.baidu.com" width="700" height="400">
</iframe>
</div>
</div>
</body>
</html>
以上是关于Unity3D多线程之页面和窗口管理的主要内容,如果未能解决你的问题,请参考以下文章
如何创建VCL窗口应用程序之创建多线程应用(定义与初始化线程)