@@ -56,7 +56,7 @@ private void Awake()
56
56
/// 透過對應名稱查找物件, 並且設置與檢查是否有匹配的 UICanvas 環境
57
57
/// </summary>
58
58
/// <param name="canvasName"></param>
59
- private bool _SetupAndCheckUICanvas ( string canvasName )
59
+ public bool SetupAndCheckUICanvas ( string canvasName )
60
60
{
61
61
if ( this . _dictUICanvas . ContainsKey ( canvasName ) ) return true ;
62
62
@@ -205,7 +205,7 @@ protected override UIBase Instantiate(UIBase uiBase, string assetName, AddIntoCa
205
205
if ( uiBase != null )
206
206
{
207
207
// 先檢查與設置 UICanvas 環境
208
- if ( this . _SetupAndCheckUICanvas ( uiBase . uiSetting . canvasName ) )
208
+ if ( this . SetupAndCheckUICanvas ( uiBase . uiSetting . canvasName ) )
209
209
{
210
210
uiCanvas = this . GetUICanvas ( uiBase . uiSetting . canvasName ) ;
211
211
}
@@ -506,6 +506,7 @@ public int GetStackByStackCount(int groupId, string canvasName)
506
506
{
507
507
if ( this . _dictStackByStack . Count == 0 ) return 0 ;
508
508
string key = $ "{ groupId } { canvasName } ";
509
+ if ( ! this . _dictStackByStack . ContainsKey ( key ) ) return 0 ;
509
510
return this . _dictStackByStack [ key ] . Count ;
510
511
}
511
512
@@ -609,7 +610,7 @@ public override void Close(string assetName, bool disabledPreClose = false, bool
609
610
this . _Close ( assetName , disabledPreClose , forceDestroy , false ) ;
610
611
}
611
612
612
- public override void CloseAll ( bool disabledPreClose = false , bool forceDestroy = false , params string [ ] withoutAssetNames )
613
+ public override void CloseAll ( bool disabledPreClose = false , bool forceDestroy = false , bool forceCloseExcluded = false , params string [ ] withoutAssetNames )
613
614
{
614
615
if ( this . _dictAllCache . Count == 0 ) return ;
615
616
@@ -643,13 +644,13 @@ public override void CloseAll(bool disabledPreClose = false, bool forceDestroy =
643
644
if ( ! forceDestroy && ! this . CheckIsShowing ( uiBase ) && ! uiBase . allowInstantiate ) continue ;
644
645
645
646
// 如有啟用 CloseAll 需跳過開關, 則不列入關閉執行
646
- if ( uiBase . uiSetting . whenCloseAllToSkip ) continue ;
647
+ if ( ! forceCloseExcluded && uiBase . uiSetting . whenCloseAllToSkip ) continue ;
647
648
648
649
this . _Close ( assetName , disabledPreClose , forceDestroy , true ) ;
649
650
}
650
651
}
651
652
652
- public override void CloseAll ( int groupId , bool disabledPreClose = false , bool forceDestroy = false , params string [ ] withoutAssetNames )
653
+ public override void CloseAll ( int groupId , bool disabledPreClose = false , bool forceDestroy = false , bool forceCloseExcluded = false , params string [ ] withoutAssetNames )
653
654
{
654
655
if ( this . _dictAllCache . Count == 0 ) return ;
655
656
@@ -685,7 +686,7 @@ public override void CloseAll(int groupId, bool disabledPreClose = false, bool f
685
686
if ( ! forceDestroy && ! this . CheckIsShowing ( uiBase ) && ! uiBase . allowInstantiate ) continue ;
686
687
687
688
// 如有啟用 CloseAll 需跳過開關, 則不列入關閉執行
688
- if ( uiBase . uiSetting . whenCloseAllToSkip ) continue ;
689
+ if ( ! forceCloseExcluded && uiBase . uiSetting . whenCloseAllToSkip ) continue ;
689
690
690
691
this . _Close ( assetName , disabledPreClose , forceDestroy , true ) ;
691
692
}
@@ -994,20 +995,23 @@ protected void ExitAndHideReverse(UIBase uiBase, bool doReverse = true)
994
995
{
995
996
// 使用 GroupId + CanvasName 作為 Reverse 緩存的 Key (主要是獨立切出不同 Canvas 的反切緩存)
996
997
var key = $ "{ uiBase . groupId } { uiBase . uiSetting . canvasName } ";
997
- if ( this . _dictReverse [ key ] . Count > 1 )
998
- {
999
- // 如果當前 UI 是 Reverse 模式, 將會直接移除最上層的緩存
1000
- this . _dictReverse [ key ] . RemoveAt ( this . _dictReverse [ key ] . Count - 1 ) ;
1001
- // 移除最上層後, 再取一次最上層 (等於是倒數第二變成最 Top)
1002
- var top = this . _dictReverse [ key ] [ this . _dictReverse [ key ] . Count - 1 ] ;
1003
- // 開啟最上層的 UI (堆疊的緩存中後出的會有 isHidden = false 參考問題, 所以需要強制 doStack = false, 避免影響堆疊計數)
1004
- // ※備註: 另外就是如果 allowInstantiate = false, 會有 Data Reference 問題, 所以會需要儲存上一次的數據進行還原 (需注意在同參考的情況下, 當 Second Last 被關閉時, Hidden = true 剛好不用數據還原)
1005
- this . LoadAndDisplay ( top . uiBase , top . data , false ) . Forget ( ) ;
1006
- }
1007
- else if ( this . _dictReverse [ key ] . Count > 0 && this . _dictReverse [ key ] . Count < 2 )
998
+ if ( this . _dictReverse . ContainsKey ( key ) )
1008
999
{
1009
- this . _dictReverse [ key ] . RemoveAt ( this . _dictReverse [ key ] . Count - 1 ) ;
1010
- this . _dictReverse . Remove ( key ) ;
1000
+ if ( this . _dictReverse [ key ] . Count > 1 )
1001
+ {
1002
+ // 如果當前 UI 是 Reverse 模式, 將會直接移除最上層的緩存
1003
+ this . _dictReverse [ key ] . RemoveAt ( this . _dictReverse [ key ] . Count - 1 ) ;
1004
+ // 移除最上層後, 再取一次最上層 (等於是倒數第二變成最 Top)
1005
+ var top = this . _dictReverse [ key ] [ this . _dictReverse [ key ] . Count - 1 ] ;
1006
+ // 開啟最上層的 UI (堆疊的緩存中後出的會有 isHidden = false 參考問題, 所以需要強制 doStack = false, 避免影響堆疊計數)
1007
+ // ※備註: 另外就是如果 allowInstantiate = false, 會有 Data Reference 問題, 所以會需要儲存上一次的數據進行還原 (需注意在同參考的情況下, 當 Second Last 被關閉時, Hidden = true 剛好不用數據還原)
1008
+ this . LoadAndDisplay ( top . uiBase , top . data , false ) . Forget ( ) ;
1009
+ }
1010
+ else if ( this . _dictReverse [ key ] . Count > 0 && this . _dictReverse [ key ] . Count < 2 )
1011
+ {
1012
+ this . _dictReverse [ key ] . RemoveAt ( this . _dictReverse [ key ] . Count - 1 ) ;
1013
+ this . _dictReverse . Remove ( key ) ;
1014
+ }
1011
1015
}
1012
1016
}
1013
1017
}
@@ -1044,25 +1048,28 @@ protected void PopStackByStack(UIBase uiBase)
1044
1048
// 以 GroupId + CanvasName 作為 key
1045
1049
var key = $ "{ uiBase . groupId } { uiBase . uiSetting . canvasName } ";
1046
1050
string currentAssetName = uiBase . assetName ;
1047
- if ( this . _dictStackByStack [ key ] . Count > 1 )
1051
+ if ( this . _dictStackByStack . ContainsKey ( key ) )
1048
1052
{
1049
- int count = 1 ;
1050
- string assetName = this . _dictStackByStack [ key ] [ this . _dictStackByStack [ key ] . Count - count ] ;
1051
- // 如果 currentAssetName != assetName 表示被特別關閉
1052
- while ( currentAssetName != assetName )
1053
+ if ( this . _dictStackByStack [ key ] . Count > 1 )
1053
1054
{
1054
- // 往下查找直到匹配
1055
- ++ count ;
1056
- if ( count > this . _dictStackByStack [ key ] . Count ) break ;
1057
- assetName = this . _dictStackByStack [ key ] [ this . _dictStackByStack [ key ] . Count - count ] ;
1055
+ int count = 1 ;
1056
+ string assetName = this . _dictStackByStack [ key ] [ this . _dictStackByStack [ key ] . Count - count ] ;
1057
+ // 如果 currentAssetName != assetName 表示被特別關閉
1058
+ while ( currentAssetName != assetName )
1059
+ {
1060
+ // 往下查找直到匹配
1061
+ ++ count ;
1062
+ if ( count > this . _dictStackByStack [ key ] . Count ) break ;
1063
+ assetName = this . _dictStackByStack [ key ] [ this . _dictStackByStack [ key ] . Count - count ] ;
1064
+ }
1065
+ // 如果當前 UI 是 StackByStack 模式, 將會直接移除最上層的緩存
1066
+ this . _dictStackByStack [ key ] . RemoveAt ( this . _dictStackByStack [ key ] . Count - count ) ;
1067
+ }
1068
+ else if ( this . _dictStackByStack [ key ] . Count > 0 && this . _dictStackByStack [ key ] . Count < 2 )
1069
+ {
1070
+ this . _dictStackByStack [ key ] . RemoveAt ( this . _dictStackByStack [ key ] . Count - 1 ) ;
1071
+ this . _dictStackByStack . Remove ( key ) ;
1058
1072
}
1059
- // 如果當前 UI 是 StackByStack 模式, 將會直接移除最上層的緩存
1060
- this . _dictStackByStack [ key ] . RemoveAt ( this . _dictStackByStack [ key ] . Count - count ) ;
1061
- }
1062
- else if ( this . _dictStackByStack [ key ] . Count > 0 && this . _dictStackByStack [ key ] . Count < 2 )
1063
- {
1064
- this . _dictStackByStack [ key ] . RemoveAt ( this . _dictStackByStack [ key ] . Count - 1 ) ;
1065
- this . _dictStackByStack . Remove ( key ) ;
1066
1073
}
1067
1074
}
1068
1075
}
0 commit comments