SFSPlazaRoomManager.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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.ExpressionMeshFilter.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. foreach (var kv in UserInstanceDictionary)
  207. {
  208. if (kv.Value.Player.transform.parent == null)
  209. kv.Value.Player.transform.parent = ManaReso.Get("PlazaRoom");
  210. }
  211. ManaAudio.MusicPartyTheme.TweenForAudio();
  212. InPlazaRoom = true;
  213. PlazaRoomMge.ClosePanel();
  214. ManaGarden.RetrieveAllElf();
  215. ManaIAP.RetrieveADChest();
  216. GardenSmartFox.PlazaRoomManager.PlazaRoomSky = ManaReso.Get("PlazaRoomSky");
  217. SkyOriginPosition = GardenSmartFox.PlazaRoomManager.PlazaRoomSky.position;
  218. GardenSmartFox.PlazaRoomManager.PlazaRoomCamera = ManaReso.Get<Camera>("MainCamera");
  219. GardenSmartFox.PlazaRoomManager.CameraOriginPosition = GardenSmartFox.PlazaRoomManager.PlazaRoomCamera.transform.position;
  220. PlayerDefaultPosition = ManaReso.Get("PlazaRoomDefaultPosition").position;
  221. SelfInstance = InstantiatePlayer(ManaNickName.NickName, PlayerDefaultPosition, PlayerDirection.Left, ManaData.GetDressDataIDs(ManaPlayer.Player));
  222. SelfInstance.Player.transform.position += new Vector3(0, 0, -0.001f);
  223. UserInstanceDictionary.Add(SFSManager.GardenSmartFox.User.Id, SelfInstance);
  224. SendInstantiateRequset(-1);
  225. GardenSmartFox.PlazaRoomManager.CameraLeftBorder = ManaReso.Get("PlazaRoomCameraLeftBorder").position.x;
  226. GardenSmartFox.PlazaRoomManager.CameraRightBorder = ManaReso.Get("PlazaRoomCameraRightBorder").position.x;
  227. GardenSmartFox.PlazaRoomManager.PlazaRoomCamera.transform.SetX(GardenSmartFox.PlazaRoomManager.CameraLeftBorder);
  228. ManaReso.Get("V_BlackMask").TweenForCG();
  229. ManaReso.SetActive("C_Main2", false);
  230. ManaReso.SetActive("Garden", false);
  231. ManaReso.SetActive("PlazaRoom", true);
  232. ManaReso.SetActive("W_HudParent", true);
  233. ManaReso.SetActive("X_PlazaRoom", true);
  234. }
  235. public void ExitPlazaRoom()
  236. {
  237. QuitPlazaRoom();
  238. TweenRoot tweenRoot = ManaReso.Get("V_BlackMask").TweenBacCG();
  239. tweenRoot.AddEventOnetime
  240. (
  241. EventType.BackwardFinish,
  242. () =>
  243. {
  244. ChestMge.RetrieveAllChest();
  245. InPlazaRoom = false;
  246. ManaAudio.MusicTheme.TweenForAudio();
  247. PlazaRoomSky.position = SkyOriginPosition;
  248. PlazaRoomCamera.transform.position = CameraOriginPosition;
  249. ManaReso.SetActive("C_Main2", true);
  250. ManaReso.SetActive("Garden", true);
  251. ManaReso.SetActive("PlazaRoom", false);
  252. ManaReso.SetActive("W_HudParent", false);
  253. ManaReso.SetActive("X_PlazaRoom", false);
  254. ManaReso.Get("V_BlackMask").TweenForCG();
  255. ManaReso.Get("B_SignIn0").TweenForCG();
  256. ManaReso.Get("T_NickName").TweenForCG();
  257. foreach (var kv in UserInstanceDictionary)
  258. {
  259. kv.Value.Save();
  260. }
  261. UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
  262. }
  263. );
  264. tweenRoot.AddEventOnetime
  265. (
  266. EventType.ForwardFinish,
  267. () =>
  268. {
  269. PlazaRoomMge.OpenPanel();
  270. }
  271. );
  272. }
  273. public void QuitPlazaRoom()
  274. {
  275. PlazaRoomChest.SystemChest = null;
  276. ManaCenter.SceneSwitchLock = false;
  277. GardenSmartFox.SmartFox.Send(new LeaveRoomRequest(CurrentPlazaRoom));
  278. GardenSmartFox.PlazaRoomManager.CurrentPlazaRoom = null;
  279. }
  280. public SFSPlazaRoomManager(GardenSmartFox gardenSmartFox)
  281. {
  282. GardenSmartFox = gardenSmartFox;
  283. gardenSmartFox.Connector.onConnectionLost += OnConectionLost;
  284. }
  285. public void Update()
  286. {
  287. if (!JoinedPlazaRoom)
  288. return;
  289. if (EnteringPlazaRoom)
  290. return;
  291. //KeepAliveThread();
  292. //CheckDefautChestThread();
  293. CameraControllThread();
  294. }
  295. public float KeepAliveTime = 30;
  296. public float KeepAliveTimer;
  297. public void KeepAliveThread()
  298. {
  299. KeepAliveTimer += Time.deltaTime;
  300. if (KeepAliveTimer > KeepAliveTime)
  301. {
  302. KeepAliveTimer = 0;
  303. SFSObject parameter = new SFSObject();
  304. parameter.PutInt(Label.CommandID, PlazaRoomReq.KeepAlive.GetHashCode());
  305. GardenSmartFox.AddRequest(parameter, RequestType.Immediate);
  306. }
  307. }
  308. public float CameraLeftBorder;
  309. public float CameraRightBorder;
  310. public Vector3 CameraOriginPosition;
  311. public Camera PlazaRoomCamera;
  312. public void CameraControllThread()
  313. {
  314. if (PlazaRoomCamera == null)
  315. {
  316. return;
  317. }
  318. if (!InPlazaRoom)
  319. {
  320. return;
  321. }
  322. float x;
  323. if (SelfInstance.Player.transform.position.x <= CameraLeftBorder)
  324. {
  325. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraLeftBorder, Time.deltaTime);
  326. if (SkyTween != null)
  327. SkyTween.Pause();
  328. }
  329. else if (SelfInstance.Player.transform.position.x >= CameraRightBorder)
  330. {
  331. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraRightBorder, Time.deltaTime);
  332. if (SkyTween != null)
  333. SkyTween.Pause();
  334. }
  335. else
  336. {
  337. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, SelfInstance.Player.transform.position.x, Time.deltaTime);
  338. }
  339. PlazaRoomCamera.transform.SetX(x);
  340. }
  341. private float CheckTime = 10;
  342. private float CheckTimer;
  343. public void CheckDefautChestThread()
  344. {
  345. CheckTimer += Time.deltaTime;
  346. if (CheckTimer >= CheckTime)
  347. {
  348. CheckTimer = 0;
  349. GardenSmartFox.EventManager.PlazaRoomEvent.CheckDefaultChestStatus(CurrentRoomData.ID);
  350. }
  351. }
  352. public void MoveTo(Vector3 destination)
  353. {
  354. SFSManager.GardenSmartFox.PlazaRoomManager.SelfInstance.MoveTo(destination);
  355. SFSManager.GardenSmartFox.PlazaRoomManager.SendSynchronizeDestination(destination);
  356. MoveSky(SelfInstance.MoveTween.Duration, SelfInstance.MoveTween.Delta);
  357. }
  358. private float SkyMoveRatio = 0.1f;
  359. private Vector3 SkyOriginPosition;
  360. private TweenRoot SkyTween;
  361. public Transform PlazaRoomSky;
  362. private void MoveSky(float duration, Vector3 offset)
  363. {
  364. offset *= -SkyMoveRatio;
  365. offset.y = 0;
  366. offset.z = 0;
  367. SkyTween = PlazaRoomSky.transform.CreateTweenVecOffset2D(offset, duration, false, true, true, Curve.Linear);
  368. SkyTween.StartForward();
  369. }
  370. public void OnConectionLost(BaseEvent baseEvent)
  371. {
  372. if (JoinedPlazaRoom)
  373. {
  374. OnExitPlazaRoom();
  375. }
  376. }
  377. public void OnExitPlazaRoom()
  378. {
  379. ManaAudio.MusicPartyTheme.TweenBacAudio();
  380. ExitPlazaRoom();
  381. }
  382. public void OnJoinPlazaRoom(Room room)
  383. {
  384. GardenSmartFox.PlazaRoomManager.CurrentPlazaRoom = room;
  385. JoinRoomResult = JoinRoomResult.Succeed;
  386. TryEnterPlazaRoom();
  387. }
  388. public void OnJoinPlazaRoomError(JoinRoomResult joinRoomResult)
  389. {
  390. this.JoinRoomResult = joinRoomResult;
  391. TryEnterPlazaRoom();
  392. }
  393. public void OnUserExitPlazaRoom(int userID)
  394. {
  395. UserInstanceDictionary[userID].Save();
  396. UserInstanceDictionary.Remove(userID);
  397. }
  398. public void OnUserEnterPlazaRoom(int senderID)
  399. {
  400. SendInstantiateRequset(senderID);
  401. }
  402. public void Synchronize(int senderID, ISFSObject parameter)
  403. {
  404. if (!UserInstanceDictionary.ContainsKey(senderID))
  405. return;
  406. if (SFSManager.GardenSmartFox.User.Id == senderID)
  407. return;
  408. if (parameter.ContainsKey(InfoLabel.Destination.GetHashString()))
  409. {
  410. Vector3 destination = parameter.GetUtfString(InfoLabel.Destination.GetHashString()).StringToVector();
  411. SynchronizeDestination(destination, senderID);
  412. }
  413. if (parameter.ContainsKey(InfoLabel.Close.GetHashString()))
  414. {
  415. List<int> closeIDs = parameter.GetIntArray(InfoLabel.Destination.GetHashString()).ToList();
  416. SynchronizeClose(closeIDs, senderID);
  417. }
  418. }
  419. public void SynchronizeClose(List<int> closeIDs, int senderID)
  420. {
  421. Player player = UserInstanceDictionary[senderID].Player;
  422. foreach (var closeID in closeIDs)
  423. {
  424. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[closeID];
  425. player.ChangeClose(closeUnit.BodyPart, closeUnit.ArmatureName);
  426. }
  427. }
  428. public void SynchronizeDestination(Vector3 destination, int senderID)
  429. {
  430. UserInstanceDictionary[senderID].MoveTo(destination);
  431. }
  432. private float ExpressionDuration = 1;
  433. public void ReceiveExpression(int expressionID, int senderID)
  434. {
  435. PlazaRoomPlayer plazaRoomPlayer = UserInstanceDictionary[senderID];
  436. string expressionName = Enum.GetName(typeof(ExpressionID), expressionID);
  437. plazaRoomPlayer.Player.ChangeExpression(expressionName, ExpressionDuration);
  438. string senderName = senderID == SFSManager.GardenSmartFox.User.Id ? Language.GetStr("UI", "X_Self") : plazaRoomPlayer.NickName;
  439. string message = $"{senderName}:\u3000<({expressionName}按钮)>";
  440. Color textColor = senderID == SFSManager.GardenSmartFox.User.Id ? Lib.SelfMessage : Lib.OtherMessage;
  441. ManaInfoBox.Show(InfoCategory.PlazaRoom, message, Mathf.Infinity, textColor, ManaReso.LoadSprite("Expression", Folder.Scene));
  442. Text text = ManaReso.Get<Text>("X_CurrentInfoLab");
  443. text.color = textColor;
  444. text.text = message;
  445. }
  446. public void ReceivePublicMessage(string message, int senderID)
  447. {
  448. Color textColor = senderID == SFSManager.GardenSmartFox.User.Id ? Lib.SelfMessage : Lib.OtherMessage;
  449. PlazaRoomPlayer plazaRoomPlayer = UserInstanceDictionary[senderID];
  450. plazaRoomPlayer.ShowMessage(textColor, message);
  451. string senderName = senderID == SFSManager.GardenSmartFox.User.Id ? Language.GetStr("UI", "X_Self") : plazaRoomPlayer.NickName;
  452. message = $"{senderName}:\u3000{message}";
  453. ManaInfoBox.Show(InfoCategory.PlazaRoom, message, Mathf.Infinity, textColor, ManaReso.LoadSprite("Expression", Folder.Scene));
  454. ManaReso.SetText("X_CurrentInfoLab", message);
  455. Text text = ManaReso.Get<Text>("X_CurrentInfoLab");
  456. text.color = textColor;
  457. text.text = message;
  458. }
  459. public void OnInstantiate(int senderID, ISFSObject parameter)
  460. {
  461. if (SFSManager.GardenSmartFox.User.Id == senderID)
  462. return;
  463. UserInstanceDictionary.Add(senderID, InstantiatePlayer(parameter));
  464. }
  465. public void SendExpression(ExpressionID expressionID)
  466. {
  467. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendExpression(expressionID);
  468. }
  469. public bool SendPublicMessage(string message)
  470. {
  471. if (string.IsNullOrEmpty(message))
  472. {
  473. Bubble.Show(null, Language.GetStr("UI", "内容不能为空"));
  474. return false;
  475. }
  476. else
  477. {
  478. message = StringFilter.GetFilteredString(message);
  479. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendPublicMessage(message);
  480. return true;
  481. }
  482. }
  483. public void SendInstantiateRequset(int receiverID)
  484. {
  485. SFSObject parameter = new SFSObject();
  486. parameter.PutInt(InfoLabel.SenderID.GetHashString(), GardenSmartFox.User.Id);
  487. parameter.PutIntArray(InfoLabel.Close.GetHashString(), ManaData.GetDressDataIDs(SelfInstance.Player).ToArray());
  488. parameter.PutUtfString(InfoLabel.Position.GetHashString(), SelfInstance.Player.transform.position.VectorToString());
  489. parameter.PutInt(InfoLabel.PlayerDirection.GetHashString(), SelfInstance.Player.PlayerDirection.GetHashCode());
  490. parameter.PutUtfString(InfoLabel.NickName.GetHashString(), ManaNickName.NickName);
  491. GardenSmartFox.AddRequest(PlazaRoomEvent.WrapInfoRequest(CurrentPlazaRoom.Id, receiverID, InfoID.Instantiate, parameter), RequestType.Immediate);
  492. if (SelfInstance.IsMoving)
  493. {
  494. SendSynchronizeDestination(SelfInstance.Destination);
  495. }
  496. }
  497. public void SendSynchronizeDestination(Vector3 destination)
  498. {
  499. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendSynchronizeDestination(destination);
  500. }
  501. public PlazaRoomPlayer InstantiatePlayer(string nickName, Vector3 position, PlayerDirection direction, List<int> dressDataIDs)
  502. {
  503. Transform parent = ManaReso.Get("PlazaRoom", false);
  504. Transform tra = ManaReso.Get("Player", Folder.Scene, false, parent, false, ObjType.Player);
  505. Player player = tra.GetComponent<Player>();
  506. if (player == null)
  507. {
  508. player = tra.AddScript<Player>();
  509. player.Build();
  510. }
  511. foreach (var id in dressDataIDs)
  512. {
  513. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[id];
  514. closeUnit.ChangeDress(player);
  515. }
  516. player.SetAllCollider(false);
  517. player.transform.position = position;
  518. player.Flip(direction);
  519. player.ActiveShadow();
  520. player.Shadow.SetLZ(3);
  521. tra.localScale = new Vector3(0.525f, 0.525f, 0.525f);
  522. return new PlazaRoomPlayer(player, nickName);
  523. }
  524. public PlazaRoomPlayer InstantiatePlayer(ISFSObject parameter)
  525. {
  526. List<int> dressDatas = ManaData.GetDressDataIDs(parameter);
  527. Vector3 position = parameter.GetUtfString(InfoLabel.Position.GetHashString()).StringToVector();
  528. PlayerDirection direction = (PlayerDirection) parameter.GetInt(InfoLabel.PlayerDirection.GetHashString());
  529. string nickName = parameter.GetUtfString(InfoLabel.NickName.GetHashString());
  530. PlazaRoomPlayer plazaRoomPlayer = InstantiatePlayer(nickName, position, direction, dressDatas);
  531. return plazaRoomPlayer;
  532. }
  533. }