123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- 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 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<PlazaRoomStar>().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 List<StarCreater> StarCreaters;
- #endregion
- public static void Initialize()
- {
- if (Initialized)
- return;
- else
- Initialized = true;
- LoadScene();
- SetCloud();
- }
- 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<PlazaRoom>();
- UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.PhonoGraphSke, Folder.Config));
- UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(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();
- }
- private static void SetCloud()
- {
- #region Cloud1
- Transform tra = ResourceManager.Get(PlazaRoomLabel.PlazaRoomCloud1);
- //tra.GetComponent<SpriteRenderer>().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<SpriteRenderer>().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<SpriteRenderer>().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
- }
- public void Update()
- {
- StarThread();
- DepthThread();
- }
- public void StarThread()
- {
- foreach (var starCreater in StarCreaters)
- {
- starCreater.Update();
- }
- }
- public void DepthThread()
- {
- foreach (var v in SFSManager.GardenSmartFox.PlazaRoomController.UserInstanceDictionary.Values)
- {
- if (v.Player.transform.hasChanged)
- {
- ResetDepth();
- break;
- }
- }
- }
- public static Dictionary<Transform, List<Transform>> DepthDictionary = new Dictionary<Transform, List<Transform>>();
- public void ResetDepth()
- {
- Dictionary<Transform, List<Transform>> tempDictionary = new Dictionary<Transform, List<Transform>>();
- foreach (var plazaRoomPlayer in SFSManager.GardenSmartFox.PlazaRoomController.UserInstanceDictionary.Values)
- {
- tempDictionary.Add(plazaRoomPlayer.Player.transform, new List<Transform> {plazaRoomPlayer.MessageBox, plazaRoomPlayer.NickNameTransform});
- }
- foreach (var kv in DepthDictionary)
- {
- tempDictionary.Add(kv.Key, kv.Value);
- }
- List<Transform> 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();
- }
- }
- }
- public void OnPointerClick(PointerEventData eventData)
- {
- SFSManager.GardenSmartFox.PlazaRoomController.MoveTo(HitPositionToDestination(eventData.pointerCurrentRaycast.worldPosition));
- }
- private static Vector3 Offset = new Vector3(0, 0, -3);
- public static Vector3 HitPositionToDestination(Vector3 hitPosition)
- {
- return hitPosition + Offset;
- }
- }
|