PlazaRoomController.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. using System;
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using LitJson;
  6. using Sfs2X.Core;
  7. using Sfs2X.Entities;
  8. using Sfs2X.Entities.Data;
  9. using Sfs2X.Requests;
  10. using Sfs2X.Entities.Variables;
  11. using UnityEngine.UI;
  12. using Random = UnityEngine.Random;
  13. public enum JoinRoomResult
  14. {
  15. RoomFullError = 0,
  16. RoomExpireError = 1,
  17. Unknown = 2,
  18. Succeed = 3,
  19. Pending = 4,
  20. }
  21. public class PlazaRoomController
  22. {
  23. private static int MinMessageFontSize = 12;
  24. private static int MaxMessageFontSize = 20;
  25. private static Vector3 PlazaRoomPlayerScale = new Vector3(0.525f, 0.525f, 0.525f);
  26. public class PlazaRoomPlayer
  27. {
  28. #region Config
  29. public string NickName;
  30. public Player Player;
  31. public Transform NickNameTransform;
  32. public List<TweenRoot> TweenRoots;
  33. public BestfitText MessageLab;
  34. public Transform MessageBox;
  35. #endregion
  36. public PlazaRoomPlayer(Player player, string nickname)
  37. {
  38. Player = player;
  39. TweenRoots = new List<TweenRoot>();
  40. NickNameTransform = ResourceManager.Get(ResourceLabel.NickName, Folder.UI, false, ResourceManager.Get(ObjectLabel.W_HudParent), false, ObjType.NickName);
  41. HudTarget hudTarget = NickNameTransform.GetComponent<HudTarget>();
  42. if (hudTarget == null)
  43. {
  44. hudTarget = NickNameTransform.AddComponent<HudTarget>();
  45. }
  46. hudTarget.PosTra = Player.ChildDic["NickName"];
  47. hudTarget.SetPosition();
  48. NickName = string.IsNullOrEmpty(nickname) ? Language.GetStr(LanguageLabel.UI__Unnamed) : nickname;
  49. NickNameTransform.GetComponent<Text>().text = NickName;
  50. MessageBox = ResourceManager.Get(ResourceLabel.MessageBox, Folder.UI, false, ResourceManager.Get(ObjectLabel.W_HudParent), false, ObjType.MessageBox);
  51. MessageLab = MessageBox.GetComponentInChildren<BestfitText>();
  52. MessageLab.VerticalMinSize = MinMessageFontSize;
  53. MessageLab.VerticalMaxSize = MaxMessageFontSize;
  54. hudTarget = MessageBox.GetComponent<HudTarget>();
  55. if (hudTarget == null)
  56. {
  57. hudTarget = MessageBox.AddComponent<HudTarget>();
  58. }
  59. hudTarget.PosTra = Player.ChildDic["MessageBox"];
  60. MessageBox.CreateTweenCG(0, 1, 0.25f, true, true, Curve.EaseOutQuad).InOrigin = true;
  61. }
  62. public void Save()
  63. {
  64. foreach (var tweenRoot in TweenRoots)
  65. {
  66. tweenRoot.Pause();
  67. }
  68. ResourceManager.Save(Player);
  69. ResourceManager.Save(NickNameTransform);
  70. ResourceManager.Save(MessageBox);
  71. Player.PlayAnim(Player.IdleAnimationName);
  72. Player.DeactiveShadow();
  73. Player.Shadow.SetLZ(0);
  74. Player.ExpressionMeshFilter.transform.parent = Player.transform;
  75. }
  76. public bool IsMoving;
  77. public float Speed = 1f;
  78. public Vector3 Destination;
  79. public TweenVec MoveTween;
  80. public void MoveTo(Vector3 destination)
  81. {
  82. if (destination.Equal(Player.transform.position))
  83. {
  84. return;
  85. }
  86. if (destination.x > Player.transform.position.x)
  87. {
  88. Player.Flip(PlayerDirection.Right);
  89. }
  90. else
  91. {
  92. Player.Flip(PlayerDirection.Left);
  93. }
  94. float offsetX = Mathf.Abs(destination.x - Player.transform.position.x);
  95. float offsetY = Mathf.Abs(destination.y - Player.transform.position.y);
  96. float offset = Mathf.Sqrt(offsetX*offsetX + offsetY*offsetY);
  97. float duration = Mathf.Clamp(offset/1.5f, 0.25f, 100f)/Speed;
  98. MoveTween = Player.transform.CreateTweenVec3D(destination, duration, false, true, true, Curve.EaseOutQuad);
  99. MoveTween.StartForward();
  100. MoveTween.AddEventOnetime(EventType.ForwardFinish, StopMove);
  101. TweenRoots.Add(MoveTween);
  102. IsMoving = true;
  103. Destination = destination;
  104. Player.PlayAnim(Player.WalkAnimationName);
  105. }
  106. public void StopMove()
  107. {
  108. IsMoving = false;
  109. Player.PlayAnim(Player.IdleAnimationName);
  110. }
  111. public float MessgeTime = 3f;
  112. public Coroutine MessgeCoroutine;
  113. public void ShowMessage(Color color, string message)
  114. {
  115. if (MessgeCoroutine != null)
  116. {
  117. Auxiliary.Instance.StopCoroutine(MessgeCoroutine);
  118. }
  119. MessageLab.text = message;
  120. MessageLab.color = color;
  121. MessageBox.TweenForCG();
  122. MessgeCoroutine = Auxiliary.Instance.DelayCall(() => { MessageBox.TweenBacCG(); }, MessgeTime);
  123. }
  124. }
  125. #region Config
  126. public GardenSmartFox GardenSmartFox;
  127. public PlazaRoomPlayer SelfInstance;
  128. public Room CurrentPlazaRoom;
  129. public RoomData CurrentRoomData;
  130. public bool JoinedPlazaRoom
  131. {
  132. get { return CurrentPlazaRoom != null; }
  133. }
  134. public bool InPlazaRoom;
  135. public bool IsBlackMaskFinish;
  136. public JoinRoomResult JoinRoomResult = JoinRoomResult.Pending;
  137. public Dictionary<int, PlazaRoomPlayer> UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
  138. #endregion
  139. private Coroutine JoinRoomCoroutine;
  140. public void BeginEnterPlazaRoom(RoomData roomData)
  141. {
  142. CurrentRoomData = roomData;
  143. IsBlackMaskFinish = false;
  144. JoinRoomResult = JoinRoomResult.Pending;
  145. AudioManager.MusicTheme.TweenBacAudio();
  146. ResourceManager.Get(ObjectLabel.B_SignIn0).TweenBacCG();
  147. ResourceManager.Get(ObjectLabel.T_NickName).TweenBacCG();
  148. Manager.SceneSwitchLock = true;
  149. TweenRoot tweenRoot = ResourceManager.Get(ObjectLabel.V_BlackMask).TweenBacCG();
  150. tweenRoot.AddEventOnetime
  151. (
  152. EventType.BackwardFinish, () =>
  153. {
  154. IsBlackMaskFinish = true;
  155. TryEnterPlazaRoom();
  156. }
  157. );
  158. GardenSmartFox.ExecuteAfterCheckConection
  159. (
  160. null,
  161. (succeed, baseEvent) =>
  162. {
  163. if (!succeed)
  164. {
  165. JoinRoomResult = JoinRoomResult.Unknown;
  166. TryEnterPlazaRoom();
  167. }
  168. },
  169. (succeed, baseEvent) =>
  170. {
  171. if (!succeed)
  172. {
  173. JoinRoomResult = JoinRoomResult.Unknown;
  174. TryEnterPlazaRoom();
  175. }
  176. }
  177. );
  178. JoinRoomCoroutine = DelayCall.Call(5f, () => { OnJoinPlazaRoomError(JoinRoomResult.Unknown); });
  179. }
  180. public void TryEnterPlazaRoom()
  181. {
  182. if (!GardenSmartFox.PlazaRoomController.IsBlackMaskFinish)
  183. return;
  184. if (JoinRoomResult == JoinRoomResult.Pending)
  185. return;
  186. if (JoinRoomResult == JoinRoomResult.Succeed)
  187. {
  188. EnterPlazaRoom();
  189. }
  190. else
  191. {
  192. QuitPlazaRoom();
  193. if (JoinRoomResult == JoinRoomResult.RoomFullError)
  194. {
  195. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Z_RoomFull), null, null, () => { ResourceManager.Get(ObjectLabel.V_BlackMask).TweenForCG(); AudioManager.MusicTheme.TweenForAudio(); }, null, false);
  196. }
  197. else if (JoinRoomResult == JoinRoomResult.RoomExpireError)
  198. {
  199. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Z_RoomExpire), null, null, () => { ResourceManager.Get(ObjectLabel.V_BlackMask).TweenForCG(); AudioManager.MusicTheme.TweenForAudio(); }, null, false);
  200. }
  201. else
  202. {
  203. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Z_Unknown), null, null, () => { ResourceManager.Get(ObjectLabel.V_BlackMask).TweenForCG(); AudioManager.MusicTheme.TweenForAudio(); }, null, false);
  204. }
  205. }
  206. }
  207. private Vector3 PlayerDefaultPosition;
  208. public void EnterPlazaRoom()
  209. {
  210. GardenSmartFox.EventManager.PlazaRoomEvent.GetAllChestData(CurrentRoomData.ID);
  211. foreach (var kv in UserInstanceDictionary)
  212. {
  213. if (kv.Value.Player.transform.parent == null)
  214. {
  215. kv.Value.Player.transform.parent = ResourceManager.Get("PlazaRoom");
  216. kv.Value.Player.transform.localScale = PlazaRoomPlayerScale;
  217. }
  218. }
  219. AudioManager.MusicPartyTheme.TweenForAudio();
  220. InPlazaRoom = true;
  221. PlazaRoomManager.ClosePanel();
  222. GardenManager.RetrieveAllElf();
  223. IAPManager.RetrieveADChest();
  224. GardenSmartFox.PlazaRoomController.PlazaRoomSky = ResourceManager.Get("PlazaRoomSky");
  225. SkyOriginPosition = GardenSmartFox.PlazaRoomController.PlazaRoomSky.position;
  226. GardenSmartFox.PlazaRoomController.PlazaRoomCamera = ResourceManager.Get<Camera>("MainCamera");
  227. GardenSmartFox.PlazaRoomController.CameraOriginPosition = GardenSmartFox.PlazaRoomController.PlazaRoomCamera.transform.position;
  228. GardenSmartFox.PlazaRoomController.CameraLeftBorder = ResourceManager.Get("PlazaRoomCameraLeftBorder").position.x;
  229. GardenSmartFox.PlazaRoomController.CameraRightBorder = ResourceManager.Get("PlazaRoomCameraRightBorder").position.x;
  230. GardenSmartFox.PlazaRoomController.PlazaRoomCamera.transform.SetX(GardenSmartFox.PlazaRoomController.CameraLeftBorder);
  231. ResourceManager.Get(ObjectLabel.V_BlackMask).TweenForCG();
  232. ResourceManager.SetActive(ObjectLabel.C_Main2, false);
  233. ResourceManager.SetActive(ResourceLabel.Garden, false);
  234. ResourceManager.SetActive("PlazaRoom", true);
  235. ResourceManager.SetActive(ObjectLabel.W_HudParent, true);
  236. ResourceManager.SetActive(ObjectLabel.X_PlazaRoom, true);
  237. }
  238. public void ExitPlazaRoom()
  239. {
  240. QuitPlazaRoom();
  241. TweenRoot tweenRoot = ResourceManager.Get(ObjectLabel.V_BlackMask).TweenBacCG();
  242. tweenRoot.AddEventOnetime
  243. (
  244. EventType.BackwardFinish,
  245. () =>
  246. {
  247. ChestManager.RetrieveAllChest();
  248. InPlazaRoom = false;
  249. AudioManager.MusicTheme.TweenForAudio();
  250. PlazaRoomSky.position = SkyOriginPosition;
  251. PlazaRoomCamera.transform.position = CameraOriginPosition;
  252. ResourceManager.SetActive(ObjectLabel.C_Main2, true);
  253. ResourceManager.SetActive(ResourceLabel.Garden, true);
  254. ResourceManager.SetActive("PlazaRoom", false);
  255. ResourceManager.SetActive(ObjectLabel.W_HudParent, false);
  256. ResourceManager.SetActive(ObjectLabel.X_PlazaRoom, false);
  257. ResourceManager.Get(ObjectLabel.V_BlackMask).TweenForCG();
  258. ResourceManager.Get(ObjectLabel.B_SignIn0).TweenForCG();
  259. ResourceManager.Get(ObjectLabel.T_NickName).TweenForCG();
  260. ResourceManager.Get<Text>(ObjectLabel.X_CurrentInfoLab).text = "";
  261. Transform tra = ResourceManager.Get(ObjectLabel.X_Info);
  262. while (tra.childCount > 0)
  263. {
  264. ResourceManager.Save(tra.GetChild(0));
  265. }
  266. foreach (var kv in UserInstanceDictionary)
  267. {
  268. kv.Value.Save();
  269. }
  270. UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
  271. RobotManager.DeactivateAllRobots(true);
  272. }
  273. );
  274. tweenRoot.AddEventOnetime
  275. (
  276. EventType.ForwardFinish,
  277. () =>
  278. {
  279. PlazaRoomManager.OpenPanel();
  280. }
  281. );
  282. }
  283. public void QuitPlazaRoom()
  284. {
  285. PlazaRoomChest.SystemChest = null;
  286. Manager.SceneSwitchLock = false;
  287. GardenSmartFox.SmartFox.Send(new LeaveRoomRequest(CurrentPlazaRoom));
  288. GardenSmartFox.PlazaRoomController.CurrentPlazaRoom = null;
  289. }
  290. public PlazaRoomController(GardenSmartFox gardenSmartFox)
  291. {
  292. GardenSmartFox = gardenSmartFox;
  293. gardenSmartFox.Connector.onConnectionLost += OnConectionLost;
  294. }
  295. public void Update()
  296. {
  297. if (!JoinedPlazaRoom)
  298. return;
  299. if (!InPlazaRoom)
  300. return;
  301. //KeepAliveThread();
  302. //CheckDefautChestThread();
  303. CameraControllThread();
  304. }
  305. public float KeepAliveTime = 30;
  306. public float KeepAliveTimer;
  307. public void KeepAliveThread()
  308. {
  309. KeepAliveTimer += Time.deltaTime;
  310. if (KeepAliveTimer > KeepAliveTime)
  311. {
  312. KeepAliveTimer = 0;
  313. SFSObject parameter = new SFSObject();
  314. parameter.PutInt(SFSLabel.CommandID, PlazaRoomReq.KeepAlive.GetHashCode());
  315. GardenSmartFox.AddRequest(parameter, RequestType.Immediate);
  316. }
  317. }
  318. public float CameraLeftBorder;
  319. public float CameraRightBorder;
  320. public Vector3 CameraOriginPosition;
  321. public Camera PlazaRoomCamera;
  322. public void CameraControllThread()
  323. {
  324. float x;
  325. if (SelfInstance.Player.transform.position.x <= CameraLeftBorder)
  326. {
  327. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraLeftBorder, Time.deltaTime);
  328. if (SkyTween != null)
  329. SkyTween.Pause();
  330. }
  331. else if (SelfInstance.Player.transform.position.x >= CameraRightBorder)
  332. {
  333. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraRightBorder, Time.deltaTime);
  334. if (SkyTween != null)
  335. SkyTween.Pause();
  336. }
  337. else
  338. {
  339. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, SelfInstance.Player.transform.position.x, Time.deltaTime);
  340. }
  341. PlazaRoomCamera.transform.SetX(x);
  342. }
  343. private float CheckTime = 10;
  344. private float CheckTimer;
  345. public void CheckDefautChestThread()
  346. {
  347. CheckTimer += Time.deltaTime;
  348. if (CheckTimer >= CheckTime)
  349. {
  350. CheckTimer = 0;
  351. GardenSmartFox.EventManager.PlazaRoomEvent.CheckDefaultChestStatus(CurrentRoomData.ID);
  352. }
  353. }
  354. public void MoveTo(Vector3 destination)
  355. {
  356. SFSManager.GardenSmartFox.PlazaRoomController.SelfInstance.MoveTo(destination);
  357. SFSManager.GardenSmartFox.PlazaRoomController.SendSynchronizeDestination(destination);
  358. MoveSky(SelfInstance.MoveTween.Duration, SelfInstance.MoveTween.Delta);
  359. }
  360. private float SkyMoveRatio = 0.1f;
  361. private Vector3 SkyOriginPosition;
  362. private TweenRoot SkyTween;
  363. public Transform PlazaRoomSky;
  364. private void MoveSky(float duration, Vector3 offset)
  365. {
  366. offset *= -SkyMoveRatio;
  367. offset.y = 0;
  368. offset.z = 0;
  369. SkyTween = PlazaRoomSky.transform.CreateTweenVecOffset2D(offset, duration, false, true, true, Curve.Linear);
  370. SkyTween.StartForward();
  371. }
  372. public void OnConectionLost(BaseEvent baseEvent)
  373. {
  374. if (JoinedPlazaRoom)
  375. {
  376. OnExitPlazaRoom();
  377. }
  378. }
  379. public void OnExitPlazaRoom()
  380. {
  381. AudioManager.MusicPartyTheme.TweenBacAudio();
  382. ExitPlazaRoom();
  383. }
  384. private float SelfInstanceOffset = 0.001f;
  385. public void OnJoinPlazaRoom(Room room)
  386. {
  387. if (JoinRoomResult == JoinRoomResult.Pending)
  388. {
  389. GardenSmartFox.PlazaRoomController.CurrentPlazaRoom = room;
  390. PlazaRoom.Initialize();
  391. PlayerDefaultPosition = GetDefaultPosition();
  392. SelfInstance = InstantiatePlayer(NickNameManager.NickName, PlayerDefaultPosition, PlayerDirection.Left, ConfigManager.GetDressDataIDs(PlayerManager.Player));
  393. UserInstanceDictionary.Add(SFSManager.GardenSmartFox.User.Id, SelfInstance);
  394. SendInstantiateRequset(-1);
  395. SelfInstance.Player.transform.SetLZ(SelfInstance.Player.transform.localPosition.z - SelfInstanceOffset);
  396. JoinRoomResult = JoinRoomResult.Succeed;
  397. TryEnterPlazaRoom();
  398. DelayCall.stopCoroutine(JoinRoomCoroutine);
  399. }
  400. }
  401. public void OnJoinPlazaRoomError(JoinRoomResult joinRoomResult)
  402. {
  403. if (JoinRoomResult == JoinRoomResult.Pending)
  404. {
  405. JoinRoomResult = joinRoomResult;
  406. TryEnterPlazaRoom();
  407. DelayCall.stopCoroutine(JoinRoomCoroutine);
  408. }
  409. }
  410. public void OnUserExitPlazaRoom(int userID)
  411. {
  412. UserInstanceDictionary[userID].Save();
  413. UserInstanceDictionary.Remove(userID);
  414. }
  415. public void OnUserEnterPlazaRoom(int senderID)
  416. {
  417. SendInstantiateRequset(senderID);
  418. }
  419. public void Synchronize(int senderID, ISFSObject parameter)
  420. {
  421. if (!UserInstanceDictionary.ContainsKey(senderID))
  422. return;
  423. if (SFSManager.GardenSmartFox.User.Id == senderID)
  424. return;
  425. if (parameter.ContainsKey(InfoLabel.Destination.GetHashString()))
  426. {
  427. Vector3 destination = parameter.GetUtfString(InfoLabel.Destination.GetHashString()).ToVector();
  428. SynchronizeDestination(destination, senderID);
  429. }
  430. if (parameter.ContainsKey(InfoLabel.Close.GetHashString()))
  431. {
  432. List<int> closeIDs = parameter.GetIntArray(InfoLabel.Destination.GetHashString()).ToList();
  433. SynchronizeClose(closeIDs, senderID);
  434. }
  435. }
  436. public void SynchronizeClose(List<int> closeIDs, int senderID)
  437. {
  438. Player player = UserInstanceDictionary[senderID].Player;
  439. foreach (var closeID in closeIDs)
  440. {
  441. CloseItem closeItem = PlayerManager.CloseItemDic[closeID];
  442. player.ChangeClose(closeItem.BodyPart, closeItem.ArmatureName);
  443. }
  444. }
  445. public void SynchronizeDestination(Vector3 destination, int senderID)
  446. {
  447. UserInstanceDictionary[senderID].MoveTo(destination);
  448. }
  449. private float ExpressionDuration = 1;
  450. public void ReceiveExpression(int expressionID, int senderID)
  451. {
  452. PlazaRoomPlayer plazaRoomPlayer = UserInstanceDictionary[senderID];
  453. string expressionName = Enum.GetName(typeof(ExpressionID), expressionID);
  454. plazaRoomPlayer.Player.ChangeExpression(expressionName, ExpressionDuration);
  455. string senderName = senderID == SFSManager.GardenSmartFox.User.Id ? Language.GetStr(LanguageLabel.UI__X_Self) : plazaRoomPlayer.NickName;
  456. string message = $"{senderName}:\u3000<({expressionName}按钮)>";
  457. Color textColor = senderID == SFSManager.GardenSmartFox.User.Id ? Lib.SelfMessage : Lib.OtherMessage;
  458. InfoBoxManager.PlazaRoomInfoBox.Show(message, Mathf.Infinity, textColor, ResourceManager.LoadSprite(ResourceLabel.Expression, Folder.Scene));
  459. Text text = ResourceManager.Get<Text>(ObjectLabel.X_CurrentInfoLab);
  460. text.color = textColor;
  461. text.text = message;
  462. }
  463. public void ReceivePublicMessage(string message, int senderID)
  464. {
  465. Color textColor = senderID == SFSManager.GardenSmartFox.User.Id ? Lib.SelfMessage : Lib.OtherMessage;
  466. PlazaRoomPlayer plazaRoomPlayer = UserInstanceDictionary[senderID];
  467. plazaRoomPlayer.ShowMessage(textColor, message);
  468. string senderName = senderID == SFSManager.GardenSmartFox.User.Id ? Language.GetStr(LanguageLabel.UI__X_Self) : plazaRoomPlayer.NickName;
  469. message = $"{senderName}:\u3000{message}";
  470. InfoBoxManager.PlazaRoomInfoBox.Show(message, Mathf.Infinity, textColor, ResourceManager.LoadSprite(ResourceLabel.Expression, Folder.Scene));
  471. ResourceManager.SetText(ObjectLabel.X_CurrentInfoLab, message);
  472. Text text = ResourceManager.Get<Text>(ObjectLabel.X_CurrentInfoLab);
  473. text.color = textColor;
  474. text.text = message;
  475. }
  476. public void OnInstantiate(int senderID, ISFSObject parameter)
  477. {
  478. if (SFSManager.GardenSmartFox.User.Id == senderID)
  479. return;
  480. UserInstanceDictionary.Add(senderID, InstantiatePlayer(parameter));
  481. }
  482. public void SendExpression(ExpressionID expressionID)
  483. {
  484. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendExpression(expressionID);
  485. }
  486. public bool SendPublicMessage(string message)
  487. {
  488. if (string.IsNullOrEmpty(message))
  489. {
  490. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__CannotEmpty));
  491. return false;
  492. }
  493. else
  494. {
  495. message = StringFilter.GetFilteredString(message);
  496. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendPublicMessage(message);
  497. return true;
  498. }
  499. }
  500. public void SendInstantiateRequset(int receiverID)
  501. {
  502. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendInstantiateRequset(GardenSmartFox.User.Id, ConfigManager.GetDressDataIDs(SelfInstance.Player).ToArray(), SelfInstance.Player.transform.position, SelfInstance.Player.PlayerDirection, NickNameManager.NickName, receiverID);
  503. if (SelfInstance.IsMoving)
  504. {
  505. SendSynchronizeDestination(SelfInstance.Destination);
  506. }
  507. }
  508. public void SendSynchronizeDestination(Vector3 destination)
  509. {
  510. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendSynchronizeDestination(GardenSmartFox.User.Id, destination);
  511. }
  512. private float ShaowLocalZ = 3;
  513. public PlazaRoomPlayer InstantiatePlayer(string nickName, Vector3 position, PlayerDirection direction, List<int> dressDataIDs)
  514. {
  515. Transform parent = ResourceManager.Get("PlazaRoom", false);
  516. Transform tra = ResourceManager.Get("Player", Folder.Scene, false, parent, false, ObjType.Player);
  517. Player player = tra.GetComponent<Player>();
  518. if (player == null)
  519. {
  520. player = tra.AddScript<Player>();
  521. player.Build();
  522. }
  523. foreach (var id in dressDataIDs)
  524. {
  525. CloseItem closeItem = PlayerManager.CloseItemDic[id];
  526. closeItem.ChangeDress(player);
  527. }
  528. player.SetAllCollider(false);
  529. player.transform.position = position;
  530. player.Flip(direction);
  531. player.ActiveShadow();
  532. player.Shadow.SetLZ(ShaowLocalZ);
  533. tra.localScale = PlazaRoomPlayerScale;
  534. return new PlazaRoomPlayer(player, nickName);
  535. }
  536. public PlazaRoomPlayer InstantiatePlayer(ISFSObject parameter)
  537. {
  538. List<int> dressDatas = ConfigManager.GetDressDataIDs(parameter);
  539. Vector3 position = parameter.GetUtfString(InfoLabel.Position.GetHashString()).ToVector();
  540. PlayerDirection direction = (PlayerDirection) parameter.GetInt(InfoLabel.PlayerDirection.GetHashString());
  541. string nickName = parameter.GetUtfString(InfoLabel.NickName.GetHashString());
  542. PlazaRoomPlayer plazaRoomPlayer = InstantiatePlayer(nickName, position, direction, dressDatas);
  543. return plazaRoomPlayer;
  544. }
  545. private static float MinZOffset = 0.0001f;
  546. private static float MaxZOffset = 0.001f;
  547. public static PlayerDirection DefaultDirection = PlayerDirection.Left;
  548. public static Vector3 GetDefaultPosition()
  549. {
  550. float zOffset = Random.Range(MinZOffset, MaxZOffset);
  551. Vector3 position = ResourceManager.Get("PlazaRoomDefaultPosition").position;
  552. position.z += zOffset;
  553. return position;
  554. }
  555. }