SFSPlazaRoomManager.cs 21 KB

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