static int DestroyWnd(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(WndManage), typeof(Wnd))) { WndManage obj = (WndManage)ToLua.ToObject(L, 1); Wnd arg0 = (Wnd)ToLua.ToObject(L, 2); obj.DestroyWnd(arg0); return(0); } else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(WndManage), typeof(string), typeof(float))) { WndManage obj = (WndManage)ToLua.ToObject(L, 1); string arg0 = ToLua.ToString(L, 2); float arg1 = (float)LuaDLL.lua_tonumber(L, 3); obj.DestroyWnd(arg0, arg1); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: WndManage.DestroyWnd")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int _CreateWnd(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 3) { UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 1, typeof(UnityEngine.GameObject)); UnityEngine.GameObject arg1 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 2, typeof(UnityEngine.GameObject)); wndInfo arg2 = (wndInfo)ToLua.CheckObject(L, 3, typeof(wndInfo)); Wnd obj = new Wnd(arg0, arg1, arg2); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: Wnd.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void DestroyWnd(Wnd wnd) { if (OnWndDestroy != null) { try { OnWndDestroy(wnd); } catch (Exception ex) { Debug.LogError(ex); } } wnd.Dispose(); //卸载窗体对象 m_wndInstances.Remove(wnd.Name); //从管理器移除引用 //引用计数减少 { wndInfo wInfo = m_wndInfos[wnd.Name]; foreach (string packet in wInfo.dependPackets) { ResourceRefManage.Single.SubRef(packet); } } }
/// <summary> /// 定期检查过期UI /// </summary> void CheckRedundantUI_CallBack() { DateTime now = DateTime.Now; //检查冗余窗体 Dictionary <string, DateTime> newList = new Dictionary <string, DateTime>(); foreach (KeyValuePair <string, DateTime> curr in m_wndLastHideTime) { string wndname = curr.Key; Wnd wnd = m_wndInstances[wndname]; wndInfo wInfo = m_wndInfos[wndname]; if ( (now - curr.Value).TotalSeconds > wInfo.cacheTime//超时 ) { DestroyWnd(wnd); } else { newList.Add(curr.Key, curr.Value); } } m_wndLastHideTime = newList; //继续定时 { new MonoEX.Timer(15.0f).Play().OnComplete(CheckRedundantUI_CallBack); } }
void OnWndDestroy(Wnd wnd) { if (wnd == m_instance) { OnLostInstance(); m_instance = null; } }
/// <summary> /// Registers the hotkey. You have to keep a reference to the returned object. /// </summary> /// <param name="keys">The keys that will work as the global hotkey.</param> /// <returns>The registered hotkey.</returns> public static HotKey Register(Keys keys) { HotKey hotKey = new HotKey { _keys = keys }; Wnd.HotKeyRegister(hotKey); return(hotKey); }
/// <summary> /// Unregisters the Hotkey /// </summary> public void Dispose() { if (this._disposed) { return; } this._disposed = true; Wnd.HotKeyUnRegister(this); }
//强制清除已经被隐藏的窗体,以立即回收内存 public void DestroyHideWnds() { foreach (KeyValuePair <string, DateTime> curr in m_wndLastHideTime) { string wndname = curr.Key; Wnd wnd = m_wndInstances[wndname]; DestroyWnd(wnd); DestroyWnd(wndname, 0); } m_wndLastHideTime.Clear(); }
static int Dispose(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); Wnd obj = (Wnd)ToLua.CheckObject(L, 1, typeof(Wnd)); obj.Dispose(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int _Show(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); Wnd obj = (Wnd)ToLua.CheckObject(L, 1, typeof(Wnd)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); obj._Show(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int GetGameObject(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); Wnd obj = (Wnd)ToLua.CheckObject(L, 1, typeof(Wnd)); UnityEngine.GameObject o = obj.GetGameObject(); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int FindWidget(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); Wnd obj = (Wnd)ToLua.CheckObject(L, 1, typeof(Wnd)); string arg0 = ToLua.CheckString(L, 2); UnityEngine.GameObject o = obj.FindWidget(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int _GetWnd(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); WndManage obj = (WndManage)ToLua.CheckObject(L, 1, typeof(WndManage)); string arg0 = ToLua.CheckString(L, 2); Wnd o = obj._GetWnd(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int set_m_baffleObj(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); Wnd obj = (Wnd)o; UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 2, typeof(UnityEngine.GameObject)); obj.m_baffleObj = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index m_baffleObj on a nil value" : e.Message)); } }
static int get_IsVisible(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); Wnd obj = (Wnd)o; bool ret = obj.IsVisible; LuaDLL.lua_pushboolean(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index IsVisible on a nil value" : e.Message)); } }
static int get_Name(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); Wnd obj = (Wnd)o; string ret = obj.Name; LuaDLL.lua_pushstring(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index Name on a nil value" : e.Message)); } }
static int get_m_baffleObj(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); Wnd obj = (Wnd)o; UnityEngine.GameObject ret = obj.m_baffleObj; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index m_baffleObj on a nil value" : e.Message)); } }
static int _Hide(IntPtr L) { try { ToLua.CheckArgsCount(L, 4); Wnd obj = (Wnd)ToLua.CheckObject(L, 1, typeof(Wnd)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); WShowType arg1 = (WShowType)ToLua.CheckObject(L, 3, typeof(WShowType)); int arg2 = (int)LuaDLL.luaL_checknumber(L, 4); obj._Hide(arg0, arg1, arg2); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public override void Update() { if (!Wnd.IsShow) { return; } if (TargetObject == null) { Wnd.ResetGuideStep(); Wnd.Close(); return; } CheckTargetObjPosChange(); UpdateGuideObjPos(); CheckTargetObjVisibility(); }
/// <summary> /// Target的位置发生变化时,更新引导的箭头 /// </summary> private void CheckTargetObjPosChange() { var new_pos = TargetTrans.position; var new_scale = TargetTrans.localScale; if (Mathf.Abs(new_pos.x - TargetObjOldPosX) < MIN_DIFF && Mathf.Abs(new_pos.y - TargetObjOldPosY) <= MIN_DIFF && Mathf.Abs(new_scale.x - TargetObjOldScaleX) < MIN_DIFF && Mathf.Abs(new_scale.y - TargetObjOldScaleY) <= MIN_DIFF) { return; } Bounds = UGUIMath.CalculateAbsoluteBounds(TargetTrans.GetComponent <RectTransform>()); TargetObjOldPosX = new_pos.x; TargetObjOldPosY = new_pos.y; TargetObjOldScaleX = new_scale.x; TargetObjOldScaleY = new_scale.y; if (CopyObj != null) { // 可能traget_trans的父亲节点有缩放 var rect_corner = new Vector3[4]; CopyTrans.GetComponent <RectTransform>().GetWorldCorners(rect_corner); float copy_rect_size_x = rect_corner[2].x - rect_corner[0].x; TargetTrans.GetComponent <RectTransform>().GetWorldCorners(rect_corner); float target_size_x = rect_corner[2].x - rect_corner[0].x; float scale = 1; if (copy_rect_size_x != 0) { scale = target_size_x / copy_rect_size_x; } Vector3 ori_scale = CopyTrans.localScale; CopyTrans.localScale = new Vector3(ori_scale.x * scale, ori_scale.y * scale, ori_scale.z * scale); } Wnd.ResetArrowTips(); }
//string TTKFileName = null; //public void GenerateMapping() //{ // Logger NewLogObj = new Logger(); // string LogFilePath = NewLogObj.GetLogFilePath(); // string TTKFileName=CheckIfProductLocalizedForCurrentLocale(); // if (TTKFileName == null) // { // NewLogObj.WriteLogFile(LogFilePath, TTKFileName + " TTKFileName is null, Cannot genertae mapping", "fail"); // } // string[] Temp = TTKFileName.Split('-'); // TTKFileName = Temp[0]; // string CurrentDir = Directory.GetCurrentDirectory(); // string MappedFile = CurrentDir + "//Inputs//Mapped.txt"; // //if (File.Exists(MappedFile)) // //{ // // File.Delete(MappedFile); // //} // // File.Create(MappedFile); // //Introducing timeout of 1 min for attempting multiple times for perl script to start // int timer = 0; int PerlStartTimeout=60000; // 1 min // while (timer < PerlStartTimeout) // { // try // { // string PerlFilePath = CurrentDir + "//Inputs//" + TTKFileName; // Process myProcess = new Process(); // ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("perl.exe"); // //myProcessStartInfo.Arguments = "GenerateMapping.pl " + TTKFileName; // NewLogObj.WriteLogFile(LogFilePath, "GenerateMapping.pl \"" + PerlFilePath + "\"", "info"); // myProcessStartInfo.Arguments = "GenerateMapping.pl \"" + PerlFilePath + "\""; // myProcessStartInfo.UseShellExecute = false; // myProcessStartInfo.RedirectStandardOutput = true; // myProcess.StartInfo = myProcessStartInfo; // myProcess.Start(); // myProcess.WaitForExit(); // break; // } // catch (Exception Ex) // { // NewLogObj.WriteLogFile(LogFilePath, "Exception while calling GenerateMapping.pl " + Ex.ToString(), "fail"); // timer = timer + 2000; // Thread.Sleep(2000); // } // } // if (timer >= PerlStartTimeout) // { // NewLogObj.WriteLogFile(LogFilePath, "Unable to start GenerateMapping.pl even after retry attempts " , "fail"); // FileOperations FileObj = new FileOperations(); // FileObj.ExitTestEnvironment(); // } //} public void GenerateMapping(string[] TTKFiles) { Logger NewLogObj = new Logger(); FileOperations FileObj = new FileOperations(); Generic NewGenericObj = new Generic(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "GenerateMapping ", "info"); NewLogObj.WriteLogFile(LogFilePath, "============= ", "info"); string[] WindowTitlesInEnglish = null; string FileToConvert = Directory.GetCurrentDirectory() + "\\Inputs\\In.txt"; if (File.Exists(FileToConvert)) { WindowTitlesInEnglish = System.IO.File.ReadAllLines(FileToConvert); } string[] TempWindowTitlesInEnglish = WindowTitlesInEnglish; string SystemLocale = NewGenericObj.GetSystemLocale(); string InputFileName = Directory.GetCurrentDirectory() + "\\Inputs\\Inputs_" + SystemLocale + ".txt"; string TTKHotKeyPatternSpecifier = FileObj.GetInputPattern(InputFileName, "TTKHotKeyPatternSpecifier"); //Replacing special chars for (int i = 0; i < TempWindowTitlesInEnglish.Length; i++) { //if (Regex.IsMatch(TempWindowTitlesInEnglish[i], TTKHotKeyPatternSpecifier, RegexOptions.CultureInvariant)) //{ // TempWindowTitlesInEnglish[i] = Regex.Replace(TempWindowTitlesInEnglish[i], TTKHotKeyPatternSpecifier, ""); //} Regex SpecialCharLookup = new Regex(@"(\(|\)|\*|\+|\?|\.)"); MatchCollection SpecailCharMatchColl = SpecialCharLookup.Matches(TempWindowTitlesInEnglish[i]); if (SpecailCharMatchColl.Count > 0) { string PreviousSpecialCharMatch = null; foreach (Match SpecialCharMatch in SpecailCharMatchColl) { string MatchedString = SpecialCharMatch.ToString(); // string ReplaceWithString = @"\" + MatchedString; if (PreviousSpecialCharMatch != MatchedString) { string ReplaceWithString = "\\" + MatchedString; TempWindowTitlesInEnglish[i] = TempWindowTitlesInEnglish[i].Replace(MatchedString, ReplaceWithString); } PreviousSpecialCharMatch = MatchedString; } } } string OutPutFile = Directory.GetCurrentDirectory() + "\\Inputs\\Mapped.txt"; if (File.Exists(OutPutFile)) { File.Delete(OutPutFile); } StreamWriter outfile = new StreamWriter(@OutPutFile); //string[] TTKFiles=Environment.GetCommandLineArgs(); for (int y = 0; y < TTKFiles.Length; y++) { string TTKFileFullPath = Directory.GetCurrentDirectory() + "\\Inputs\\" + TTKFiles[y]; if (!File.Exists(TTKFileFullPath)) { Console.WriteLine("TTKfile " + TTKFileFullPath + " does not exist"); NewLogObj.WriteLogFile(LogFilePath, TTKFiles[y] + " does not exist ", "fail"); FileObj.ExitTestEnvironment(); } } for (int y = 0; y < TTKFiles.Length; y++) { string TTKFile = TTKFiles[y]; string TTKFileFullPath = Directory.GetCurrentDirectory() + "\\Inputs\\" + TTKFile; string[] InputLines = System.IO.File.ReadAllLines(TTKFileFullPath); foreach (string WindowTitle in TempWindowTitlesInEnglish) { int FirstIterationFlag = 0; foreach (string line in InputLines) { string pattern = "(?<ENStringMatched>^" + WindowTitle + ")(?<UnicodeStringMatched>\t+.*)"; Regex r = new Regex(pattern); Match match = r.Match(line); if (match.Success) { //string EnString = match.Groups[1].Value; //string UnicodeString = match.Groups[2].Value; string EnString = match.Groups["ENStringMatched"].Value; string UnicodeString = match.Groups["UnicodeStringMatched"].Value; string[] TempArray = Regex.Split(UnicodeString, "\t+"); outfile.Write(EnString + "=" + TempArray[1] + "\n"); if (FirstIterationFlag == 0) { //Splice the element List <String> Temp = TempWindowTitlesInEnglish.ToList(); Temp.Remove(WindowTitle); TempWindowTitlesInEnglish = Temp.ToArray(); } FirstIterationFlag = 1; } } } } if (TempWindowTitlesInEnglish.Length > 0) { foreach (string Wnd in TempWindowTitlesInEnglish) { if (!Wnd.StartsWith("#")) { //outfile.Write(Wnd+"\n"); outfile.Write(Wnd + "=" + "" + "\n"); } } } outfile.Close(); }
private void CheckTargetObjVisibility() { var visible = true; if (TargetCanbeHit) { var current_camera = UIMainCtrl.MainCam; if (current_camera == null) { visible = false; } var screen_pos = current_camera.WorldToScreenPoint(Bounds.center); if (pointerData == null) { pointerData = new PointerEventData(EventSystem.current); } var hit_obj = UGUIMath.GetRaycastObj(screen_pos, pointerData); if (hit_obj == Wnd.EventMask) { visible = false; } else if (hit_obj == null) { visible = false; } else { if (CopyObj != null) { if (!UGUIMath.ContainWidget(CopyObj, hit_obj)) { visible = false; } } else if (TargetObject != null) { if (!UGUIMath.ContainWidget(TargetObject, hit_obj)) { visible = false; } } } } else { visible = TargetObject.activeInHierarchy; } if (!visible)// 因为UGUI的Layout有可能并不是在当前帧完成排版,因此对于强制指引,不可见时需要等待一会儿再重置 { if (m_StartInvisible == false) { m_InvisibleTime = Time.time; m_StartInvisible = true; } if (CopyObj == null || Time.time - m_InvisibleTime > m_CloseDelayTime) { Wnd.ResetGuideStep(); Wnd.Close(); } } }
IEnumerator coDoCmd() { while (m_Cmds.Count > 0) { var aInfo = m_Cmds[0]; m_Cmds.RemoveAt(0); var wndName = aInfo.name; var subID = ""; string[] sArray = aInfo.name.Split('&'); if (sArray.Length == 2) { wndName = sArray[0]; subID = '&' + sArray[1]; } if (!m_wndInfos.ContainsKey(aInfo.name)) { if (sArray.Length == 2) { wndInfo wInfo2 = (wndInfo)m_wndInfos[wndName].Clone(); wInfo2.name = aInfo.name; m_wndInfos.Add(wInfo2.name, wInfo2); } else { Debug.LogError("窗体注册信息不存在 " + wndName); continue; } } if (aInfo.needVisible != WShowType.hide && aInfo.needVisible != WShowType.destroy) { //标记是否第一次打开(包括释放后再打开) bool isFirstShow = false; //从最近隐藏记录中清除 if (m_wndLastHideTime.ContainsKey(wndName + subID)) { m_wndLastHideTime.Remove(wndName + subID); } isFirstShow = !m_wndInstances.ContainsKey(wndName + subID); //窗体不存在,则创建 if (isFirstShow) { IEnumerator it = LoadDepend(wndName); while (it.MoveNext()) { yield return(null); } wndInfo wInfo = m_wndInfos[wndName + subID]; //创建一个uipanel GameObject uipanel = new GameObject(wInfo.name + "_panel"); uipanel.transform.parent = UIRootObj.transform; uipanel.transform.localScale = new Vector3(1, 1, 1); uipanel.transform.localRotation = new Quaternion(0, 0, 0, 1); uipanel.transform.localPosition = new Vector3(0, 0, 0); uipanel.layer = LayerMask.NameToLayer("UI");//设置层 UIPanel cmpanel = uipanel.AddComponent <UIPanel>(); GameObject wnd_Obj = GameObjectExtension.InstantiateFromPacket(wInfo.dependPackets[1], wndName + ".prefab", uipanel); if (wnd_Obj == null) { //删除刚创建的uipanel GameObject.Destroy(uipanel); Debug.LogError(String.Format("实例化窗体错误, packet:{0} wndName:{1}", wInfo.dependPackets[1], wInfo.name)); throw new Exception(); } //设置新创建的panel锚点 { UIRect rectCM = uipanel.GetComponent <UIRect>(); rectCM.SetAnchor(UIRootObj, 0, 0, 0, 0); rectCM.updateAnchors = UIRect.AnchorUpdate.OnStart; } //设置预置锚点 const int safev = 1; { UIRect rectCM = wnd_Obj.GetComponent <UIRect>(); rectCM.SetAnchor(uipanel, -safev, -safev, safev, safev); rectCM.updateAnchors = UIRect.AnchorUpdate.OnStart; } //创建挡板 GameObject uibaffle; { uibaffle = new GameObject(wInfo.name + "_baffle"); uibaffle.layer = LayerMask.NameToLayer("UI");//设置层 uibaffle.transform.parent = uipanel.transform; uibaffle.transform.localScale = Vector3.one; uibaffle.transform.localRotation = Quaternion.identity; uibaffle.transform.localPosition = Vector3.zero; //增加碰撞盒 var cl = uibaffle.AddComponent <BoxCollider>(); //增加UIWidget组件 var cmBaffleWidget = uibaffle.AddComponent <UIWidget>(); cl.isTrigger = true; cmBaffleWidget.autoResizeBoxCollider = true; cmBaffleWidget.updateAnchors = UIRect.AnchorUpdate.OnStart; cmBaffleWidget.SetAnchor(uipanel, -safev, -safev, safev, safev);//设置锚点 cmBaffleWidget.depth = -99; } wnd_Obj.name = wndName + subID; wnd_Obj.SetActive(true); uipanel.SetActive(false); m_wndInstances.Add(wndName + subID, new Wnd(uipanel, uibaffle, wInfo)); if (aInfo.isWithBg)//再加一个gameobject的原因是如果做动画底板需要层级高于预制,底板会压在预制上 { //TODODO 图片放到了Resources目录 UITexture ut = NGUITools.AddWidget <UITexture>(uipanel, -99); Texture texure = Resources.Load <Texture>("zanting_jiashenceng"); ut.mainTexture = texure; UIStretch stretch = ut.gameObject.AddComponent <UIStretch>(); stretch.style = UIStretch.Style.Both; // set relative size bigger stretch.relativeSize = new Vector2(3, 3); } } //显示 Wnd wnd = m_wndInstances[wndName + subID]; if (aInfo.needVisible == WShowType.preLoad) { yield return(null); Wnd.OnPreLoadFinish.Call(wnd); } else if (aInfo.needVisible == WShowType.show) { wnd._Show(aInfo.duration); //等待窗体组件准备就绪 yield return(null); if (isFirstShow) { Wnd.OnShowFinish.Call(wnd); } else { Wnd.OnReOpenWnd.Call(wnd); } if (OnWndOpen != null) { OnWndOpen.Call(wndName); } } } else { if (m_wndInstances.ContainsKey(wndName + subID)) { //从最近隐藏记录中清除 if (aInfo.needVisible == WShowType.destroy && m_wndLastHideTime.ContainsKey(wndName + subID)) { m_wndLastHideTime.Remove(wndName + subID); } Wnd wnd = m_wndInstances[wndName + subID]; wnd._Hide(aInfo.duration, aInfo.needVisible, aInfo.PlantfromDetph); if (aInfo.needVisible == WShowType.hide) { Wnd.OnHideFinish.Call(wnd); } else if (aInfo.needVisible == WShowType.destroy) { Wnd.OnDestroyFinish.Call(wnd); } } } yield return(null); } m_coIsRuning = false; }