SFSPlazaRoomManager.cs 22 KB

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