PlazaRoom.cs 6.8 KB

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