PlazaRoom.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using DragonBones;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. using Debug = UnityEngine.Debug;
  9. using Transform = UnityEngine.Transform;
  10. public class PlazaRoomLabel
  11. {
  12. public static string PlayerLeftDownBorder = "PlayerLeftDownBorder";
  13. public static string PlayerRightTopBorder = "PlayerRightTopBorder";
  14. public static string PlazaRoomDefaultPosition = "PlazaRoomDefaultPosition";
  15. public static string PlazaRoomSky = "PlazaRoomSky";
  16. public static string PlazaRoomCameraLeftBorder = "PlazaRoomCameraLeftBorder";
  17. public static string PlazaRoomCameraRightBorder = "PlazaRoomCameraRightBorder";
  18. public static string PlazaRoomChestPos = "PlazaRoomChestPos";
  19. public static string PlazaRoom = "PlazaRoom";
  20. public static string HeartSprite = "HeartSprite";
  21. public static string WelcomeSprite = "WelcomeSprite";
  22. public static string PhonoGraph = "PhonoGraph";
  23. public static string PlazaRoomCloud1 = "PlazaRoomCloud1";
  24. public static string PlazaRoomCloud2 = "PlazaRoomCloud2";
  25. public static string PlazaRoomCloud3 = "PlazaRoomCloud3";
  26. }
  27. public class PlazaRoom : MonoBehaviour, IPointerClickHandler
  28. {
  29. private class StarCreater
  30. {
  31. public float StarSpawnTime = 0;
  32. public float StarSpawnTimer = 0;
  33. public float MinStarSpawnTime = 0.1f;
  34. public float MaxStarSpawnTime = 0.3f;
  35. public float LeftStarBorder = 0;
  36. public float RightStarBorder = 16;
  37. public float UpStarBorder = 4.6f;
  38. public float DownStarBorder = 0;
  39. public Vector3 MinStarScale = new Vector3(0.5f, 0.5f, 0.5f);
  40. public Vector3 MaxStarScale = new Vector3(1, 1, 1);
  41. public void Update()
  42. {
  43. StarSpawnTimer += Time.deltaTime;
  44. if (StarSpawnTimer >= StarSpawnTime)
  45. {
  46. StarSpawnTime = Random.Range(MinStarSpawnTime, MaxStarSpawnTime);
  47. StarSpawnTimer = 0;
  48. Transform star = ResourceManager.Get(ResourceLabel.PlazaRoomStar, Folder.Scene, false, ResourceManager.Get(PlazaRoomLabel.PlazaRoom), false, ObjType.PlazaRoomStar, typeof(PlazaRoomStar));
  49. star.GetComponent<PlazaRoomStar>().Show();
  50. star.localScale = Vector3.Lerp(MinStarScale, MaxStarScale, Random.Range(0f, 1f));
  51. star.SetX(Random.Range(LeftStarBorder, RightStarBorder));
  52. star.SetY(Random.Range(DownStarBorder, UpStarBorder));
  53. }
  54. }
  55. }
  56. #region Config
  57. public static bool Initialized;
  58. private static string PhonoGraphAnimName = "newAnimation";
  59. private static Vector3 HitPosOffset = new Vector3(0, 0, -3);
  60. private static List<StarCreater> StarCreaters = new List<StarCreater>();
  61. public static Dictionary<Transform, List<Transform>> ControllDepthDictionary = new Dictionary<Transform, List<Transform>>();
  62. #endregion
  63. public static void Initialize()
  64. {
  65. if (Initialized)
  66. return;
  67. else
  68. Initialized = true;
  69. LoadScene();
  70. InitCloud();
  71. }
  72. private static void InitCloud()
  73. {
  74. #region Cloud1
  75. Transform tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoomCloud1);
  76. //tra.GetComponent<SpriteRenderer>().sprite = ManaReso.LoadSprite("云朵", Folder.Scene);
  77. TweenRoot tween = tra.CreateTweenVec2D(new Vector3(-21, tra.localPosition.y, tra.localPosition.z), 115f, true, false, true, Curve.Linear);
  78. tween.Repeat = true;
  79. tween.StartForward();
  80. #endregion
  81. #region Cloud2
  82. tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoomCloud2);
  83. //tra.GetComponent<SpriteRenderer>().sprite = ManaReso.LoadSprite("云朵", Folder.Scene);
  84. tween = tra.CreateTweenVec2D(new Vector3(-21, tra.localPosition.y, tra.localPosition.z), 157.5f, true, false, true, Curve.Linear);
  85. tween.Repeat = true;
  86. tween.StartForward();
  87. #endregion
  88. #region Cloud3
  89. tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoomCloud3);
  90. //tra.GetComponent<SpriteRenderer>().sprite = ManaReso.LoadSprite("云朵", Folder.Scene);
  91. tween = tra.CreateTweenVec2D(new Vector3(-21, tra.localPosition.y, tra.localPosition.z), 200f, true, false, true, Curve.Linear);
  92. tween.Repeat = true;
  93. tween.StartForward();
  94. #endregion
  95. }
  96. private static void LoadScene()
  97. {
  98. StarCreaters.Add(new StarCreater());
  99. StarCreaters.Add(new StarCreater());
  100. Transform tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoom, Folder.Scene, true, null, true);
  101. tra.AddComponent<PlazaRoom>();
  102. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.PhonoGraphSke, Folder.Config));
  103. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.PhonoGraphTex, Folder.Config), ResourceLabel.PhonoGraphTexture);
  104. UnityArmatureComponent uac = UnityFactory.factory.BuildArmatureComponent(PlazaRoomLabel.PhonoGraph);
  105. uac.transform.parent = ResourceManager.Get(PlazaRoomLabel.PhonoGraph);
  106. uac.anim.Play(PhonoGraphAnimName);
  107. uac.transform.localPosition = new Vector3();
  108. LanguageManager.OnLanguageChange += OnLanguageChange;
  109. OnLanguageChange(CurrentLanguage.Default, LanguageManager.CurrentLanguage);
  110. }
  111. public void Update()
  112. {
  113. CreateStarThread();
  114. ControllDepthThread();
  115. }
  116. public void CreateStarThread()
  117. {
  118. foreach (var starCreater in StarCreaters)
  119. {
  120. starCreater.Update();
  121. }
  122. }
  123. public void ControllDepthThread()
  124. {
  125. foreach (var v in SFSManager.GardenSmartFox.PlazaRoomController.UserInstanceDictionary.Values)
  126. {
  127. if (v.Player.transform.hasChanged)
  128. {
  129. ResetDepth();
  130. break;
  131. }
  132. }
  133. }
  134. public void ResetDepth()
  135. {
  136. Dictionary<Transform, List<Transform>> tempDictionary = new Dictionary<Transform, List<Transform>>();
  137. foreach (var plazaRoomPlayer in SFSManager.GardenSmartFox.PlazaRoomController.UserInstanceDictionary.Values)
  138. {
  139. tempDictionary.Add(plazaRoomPlayer.Player.transform, new List<Transform> {plazaRoomPlayer.MessageBox, plazaRoomPlayer.NickNameTransform});
  140. }
  141. foreach (var kv in ControllDepthDictionary)
  142. {
  143. tempDictionary.Add(kv.Key, kv.Value);
  144. }
  145. List<Transform> transforms = tempDictionary.Keys.ToList();
  146. transforms.MySort((transform0, transform1) => transform0.position.z > transform1.position.z);
  147. for (int i = 0; i < transforms.Count; i++)
  148. {
  149. for (int j = 0; j < tempDictionary[transforms[i]].Count; j++)
  150. {
  151. tempDictionary[transforms[i]][j].SetAsLastSibling();
  152. }
  153. }
  154. }
  155. private static void OnLanguageChange(CurrentLanguage fromLanguage, CurrentLanguage toLanguage)
  156. {
  157. if (toLanguage == CurrentLanguage.ChineseSimplified)
  158. {
  159. ResourceManager.SetActive(PlazaRoomLabel.WelcomeSprite, false);
  160. ResourceManager.SetActive(PlazaRoomLabel.HeartSprite, true);
  161. }
  162. else
  163. {
  164. ResourceManager.SetActive(PlazaRoomLabel.WelcomeSprite, true);
  165. ResourceManager.SetActive(PlazaRoomLabel.HeartSprite, false);
  166. }
  167. }
  168. public void OnPointerClick(PointerEventData eventData)
  169. {
  170. SFSManager.GardenSmartFox.PlazaRoomController.MoveTo(HitPositionToDestination(eventData.pointerCurrentRaycast.worldPosition));
  171. }
  172. public static Vector3 HitPositionToDestination(Vector3 hitPosition)
  173. {
  174. return hitPosition + HitPosOffset;
  175. }
  176. }