PlazaRoom.cs 5.9 KB

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