PlazaRoom.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 = ManaReso.Get("PlazaRoomStar", Folder.Scene, false, ManaReso.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 StarCreater StarCreaterA;
  42. private static StarCreater StarCreaterB;
  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. StarCreaterA = new StarCreater();
  56. StarCreaterB = new StarCreater();
  57. Transform tra = ManaReso.Get("PlazaRoom", Folder.Scene, true, null, true);
  58. tra.AddComponent<PlazaRoom>();
  59. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("PhonoGraph_ske", Folder.Config));
  60. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("PhonoGraph_tex", Folder.Config), "PhonoGraph_texture");
  61. UnityArmatureComponent uac = UnityFactory.factory.BuildArmatureComponent("PhonoGraph");
  62. uac.transform.parent = ManaReso.Get("PhonoGraph");
  63. uac.anim.Play("newAnimation");
  64. uac.transform.localPosition = new Vector3();
  65. }
  66. private static void SetCloud()
  67. {
  68. #region Cloud1
  69. Transform tra = ManaReso.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 = ManaReso.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 = ManaReso.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. StarCreaterA.Update();
  98. StarCreaterB.Update();
  99. }
  100. public void DepthThread()
  101. {
  102. foreach (var v in SFSManager.GardenSmartFox.PlazaRoomManager.UserInstanceDictionary.Values)
  103. {
  104. if (v.Player.transform.hasChanged)
  105. {
  106. ResetDepth();
  107. break;
  108. }
  109. }
  110. }
  111. public static Dictionary<Transform, List<Transform>> DepthDictionary = new Dictionary<Transform, List<Transform>>();
  112. public void ResetDepth()
  113. {
  114. Dictionary<Transform, List<Transform>> tempDictionary = new Dictionary<Transform, List<Transform>>();
  115. foreach (var plazaRoomPlayer in SFSManager.GardenSmartFox.PlazaRoomManager.UserInstanceDictionary.Values)
  116. {
  117. tempDictionary.Add(plazaRoomPlayer.Player.transform, new List<Transform> {plazaRoomPlayer.MessageBox, plazaRoomPlayer.NickNameTransform});
  118. }
  119. foreach (var kv in DepthDictionary)
  120. {
  121. tempDictionary.Add(kv.Key, kv.Value);
  122. }
  123. List<Transform> transforms = tempDictionary.Keys.ToList();
  124. transforms.MySort((transform0, transform1) => transform0.position.z > transform1.position.z);
  125. for (int i = 0; i < transforms.Count; i++)
  126. {
  127. for (int j = 0; j < tempDictionary[transforms[i]].Count; j++)
  128. {
  129. tempDictionary[transforms[i]][j].SetAsLastSibling();
  130. }
  131. }
  132. }
  133. public void OnPointerClick(PointerEventData eventData)
  134. {
  135. SFSManager.GardenSmartFox.PlazaRoomManager.MoveTo(HitPositionToDestination(eventData.pointerCurrentRaycast.worldPosition));
  136. }
  137. private static Vector3 Offset = new Vector3(0, 0, -3);
  138. public static Vector3 HitPositionToDestination(Vector3 hitPosition)
  139. {
  140. return hitPosition + Offset;
  141. }
  142. }