using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using DragonBones; using UnityEngine; using UnityEngine.EventSystems; using Debug = UnityEngine.Debug; using Transform = UnityEngine.Transform; public class PlazaRoomLabel { public static string PlayerLeftDownBorder = "PlayerLeftDownBorder"; public static string PlayerRightTopBorder = "PlayerRightTopBorder"; public static string PlazaRoomDefaultPosition = "PlazaRoomDefaultPosition"; public static string PlazaRoomSky = "PlazaRoomSky"; public static string PlazaRoomCameraLeftBorder = "PlazaRoomCameraLeftBorder"; public static string PlazaRoomCameraRightBorder = "PlazaRoomCameraRightBorder"; public static string PlazaRoomChestPos = "PlazaRoomChestPos"; public static string PlazaRoom = "PlazaRoom"; public static string HeartSprite = "HeartSprite"; public static string WelcomeSprite = "WelcomeSprite"; public static string PhonoGraph = "PhonoGraph"; public static string PlazaRoomCloud1 = "PlazaRoomCloud1"; public static string PlazaRoomCloud2 = "PlazaRoomCloud2"; public static string PlazaRoomCloud3 = "PlazaRoomCloud3"; } public class PlazaRoom : MonoBehaviour, IPointerClickHandler { private class StarCreater { public float StarSpawnTime = 0; public float StarSpawnTimer = 0; public float MinStarSpawnTime = 0.1f; public float MaxStarSpawnTime = 0.3f; public float LeftStarBorder = 0; public float RightStarBorder = 16; public float UpStarBorder = 4.6f; public float DownStarBorder = 0; public Vector3 MinStarScale = new Vector3(0.5f, 0.5f, 0.5f); public Vector3 MaxStarScale = new Vector3(1, 1, 1); public void Update() { StarSpawnTimer += Time.deltaTime; if (StarSpawnTimer >= StarSpawnTime) { StarSpawnTime = Random.Range(MinStarSpawnTime, MaxStarSpawnTime); StarSpawnTimer = 0; Transform star = ResourceManager.Get(ResourceLabel.PlazaRoomStar, Folder.Scene, false, ResourceManager.Get(PlazaRoomLabel.PlazaRoom), false, ObjType.PlazaRoomStar, typeof(PlazaRoomStar)); star.GetComponent().Show(); star.localScale = Vector3.Lerp(MinStarScale, MaxStarScale, Random.Range(0f, 1f)); star.SetX(Random.Range(LeftStarBorder, RightStarBorder)); star.SetY(Random.Range(DownStarBorder, UpStarBorder)); } } } #region Config public static bool Initialized; private static string PhonoGraphAnimName = "newAnimation"; private static Vector3 HitPosOffset = new Vector3(0, 0, -3); private static List StarCreaters = new List(); public static Dictionary> ControllDepthDictionary = new Dictionary>(); #endregion public static void Initialize() { if (Initialized) return; else Initialized = true; LoadScene(); InitCloud(); } private static void InitCloud() { #region Cloud1 Transform tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoomCloud1); //tra.GetComponent().sprite = ManaReso.LoadSprite("云朵", Folder.Scene); TweenRoot tween = tra.CreateTweenVec2D(new Vector3(-21, tra.localPosition.y, tra.localPosition.z), 115f, true, false, true, Curve.Linear); tween.Repeat = true; tween.StartForward(); #endregion #region Cloud2 tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoomCloud2); //tra.GetComponent().sprite = ManaReso.LoadSprite("云朵", Folder.Scene); tween = tra.CreateTweenVec2D(new Vector3(-21, tra.localPosition.y, tra.localPosition.z), 157.5f, true, false, true, Curve.Linear); tween.Repeat = true; tween.StartForward(); #endregion #region Cloud3 tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoomCloud3); //tra.GetComponent().sprite = ManaReso.LoadSprite("云朵", Folder.Scene); tween = tra.CreateTweenVec2D(new Vector3(-21, tra.localPosition.y, tra.localPosition.z), 200f, true, false, true, Curve.Linear); tween.Repeat = true; tween.StartForward(); #endregion } private static void LoadScene() { StarCreaters.Add(new StarCreater()); StarCreaters.Add(new StarCreater()); Transform tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoom, Folder.Scene, true, null, true); tra.AddComponent(); UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load(ResourceLabel.PhonoGraphSke, Folder.Config)); UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load(ResourceLabel.PhonoGraphTex, Folder.Config), ResourceLabel.PhonoGraphTexture); UnityArmatureComponent uac = UnityFactory.factory.BuildArmatureComponent(PlazaRoomLabel.PhonoGraph); uac.transform.parent = ResourceManager.Get(PlazaRoomLabel.PhonoGraph); uac.anim.Play(PhonoGraphAnimName); uac.transform.localPosition = new Vector3(); LanguageManager.OnLanguageChange += OnLanguageChange; OnLanguageChange(CurrentLanguage.Default, LanguageManager.CurrentLanguage); } public void Update() { CreateStarThread(); ControllDepthThread(); } public void CreateStarThread() { foreach (var starCreater in StarCreaters) { starCreater.Update(); } } public void ControllDepthThread() { foreach (var v in SFSManager.GardenSmartFox.PlazaRoomController.UserInstanceDictionary.Values) { if (v.Player.transform.hasChanged) { ResetDepth(); break; } } } public void ResetDepth() { Dictionary> tempDictionary = new Dictionary>(); foreach (var plazaRoomPlayer in SFSManager.GardenSmartFox.PlazaRoomController.UserInstanceDictionary.Values) { tempDictionary.Add(plazaRoomPlayer.Player.transform, new List {plazaRoomPlayer.MessageBox, plazaRoomPlayer.NickNameTransform}); } foreach (var kv in ControllDepthDictionary) { tempDictionary.Add(kv.Key, kv.Value); } List transforms = tempDictionary.Keys.ToList(); transforms.MySort((transform0, transform1) => transform0.position.z > transform1.position.z); for (int i = 0; i < transforms.Count; i++) { for (int j = 0; j < tempDictionary[transforms[i]].Count; j++) { tempDictionary[transforms[i]][j].SetAsLastSibling(); } } } private static void OnLanguageChange(CurrentLanguage fromLanguage, CurrentLanguage toLanguage) { if (toLanguage == CurrentLanguage.ChineseSimplified) { ResourceManager.SetActive(PlazaRoomLabel.WelcomeSprite, false); ResourceManager.SetActive(PlazaRoomLabel.HeartSprite, true); } else { ResourceManager.SetActive(PlazaRoomLabel.WelcomeSprite, true); ResourceManager.SetActive(PlazaRoomLabel.HeartSprite, false); } } public void OnPointerClick(PointerEventData eventData) { SFSManager.GardenSmartFox.PlazaRoomController.MoveTo(HitPositionToDestination(eventData.pointerCurrentRaycast.worldPosition)); } public static Vector3 HitPositionToDestination(Vector3 hitPosition) { return hitPosition + HitPosOffset; } }