SFSPlazaRoomManager.cs 21 KB

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