源战役客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

91 строка
2.7 KiB

1 месяц назад
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace U3DExtends
  4. {
  5. public class ReopenLayoutOnExitGame : MonoBehaviour
  6. {
  7. #if UNITY_EDITOR
  8. // class ReopenInfo
  9. // {
  10. // string path;
  11. // Vector3 pos;
  12. // }
  13. private static ReopenLayoutOnExitGame Instance;
  14. private static Dictionary<string, Vector3> layout_open_in_playmode = new Dictionary<string, Vector3>();
  15. private bool isRunningGame = false;
  16. public static void RecordOpenLayout(string path, Vector3 pos)
  17. {
  18. Debug.Log("record : "+path+" pos:"+pos.ToString());
  19. if (Instance != null && Instance.isRunningGame && path!="")
  20. {
  21. layout_open_in_playmode.Add(path, pos);
  22. }
  23. }
  24. private void Start()
  25. {
  26. Instance = this;
  27. // hadSaveOnRunTime = false;
  28. Debug.Log("Start");
  29. isRunningGame = true;
  30. }
  31. private void OnDisable() {
  32. // Debug.Log("disable");
  33. Instance = null;
  34. }
  35. private void OnTransformChildrenChanged() {
  36. Debug.Log("OnTransformChildrenChanged");
  37. List<string> wait_delete_key = new List<string>();
  38. foreach (var item in layout_open_in_playmode)
  39. {
  40. bool had_find = false;
  41. for (int i = 0; i < transform.childCount; i++)
  42. {
  43. LayoutInfo info = transform.GetChild(i).GetComponent<LayoutInfo>();
  44. if (info && info.LayoutPath == item.Key)
  45. {
  46. had_find = true;
  47. break;
  48. }
  49. }
  50. if (!had_find)
  51. {
  52. wait_delete_key.Add(item.Key);
  53. }
  54. }
  55. foreach (var item in wait_delete_key)
  56. {
  57. layout_open_in_playmode.Remove(item);
  58. }
  59. }
  60. private void OnApplicationQuit()
  61. {
  62. Debug.Log("OnApplicationQuit");
  63. isRunningGame = false;
  64. if (layout_open_in_playmode.Count>0 && U3DExtends.Configure.ReloadLayoutOnExitGame)
  65. {
  66. System.Action<UnityEditor.PlayModeStateChange> p = null;
  67. p = new System.Action<UnityEditor.PlayModeStateChange>((UnityEditor.PlayModeStateChange c) => {
  68. foreach (var item in layout_open_in_playmode)
  69. {
  70. // Debug.Log("item.Key : "+item.Key);
  71. Transform layout = UIEditorHelper.LoadLayoutByPath(item.Key);
  72. if (layout != null)
  73. {
  74. layout.localPosition = item.Value;
  75. }
  76. }
  77. layout_open_in_playmode.Clear();
  78. UnityEditor.EditorApplication.playModeStateChanged -= p;
  79. });
  80. UnityEditor.EditorApplication.playModeStateChanged += p;
  81. }
  82. }
  83. #endif
  84. }
  85. }