SFSPlazaRoomManager.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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(10f, () => { 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. Transform tra = ManaReso.Get("X_Info");
  260. while (tra.childCount > 0)
  261. {
  262. ManaReso.Save(tra.GetChild(0));
  263. }
  264. foreach (var kv in UserInstanceDictionary)
  265. {
  266. kv.Value.Save();
  267. }
  268. UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
  269. }
  270. );
  271. tweenRoot.AddEventOnetime
  272. (
  273. EventType.ForwardFinish,
  274. () =>
  275. {
  276. PlazaRoomMge.OpenPanel();
  277. }
  278. );
  279. }
  280. public void QuitPlazaRoom()
  281. {
  282. PlazaRoomChest.SystemChest = null;
  283. ManaCenter.SceneSwitchLock = false;
  284. GardenSmartFox.SmartFox.Send(new LeaveRoomRequest(CurrentPlazaRoom));
  285. GardenSmartFox.PlazaRoomManager.CurrentPlazaRoom = null;
  286. }
  287. public SFSPlazaRoomManager(GardenSmartFox gardenSmartFox)
  288. {
  289. GardenSmartFox = gardenSmartFox;
  290. gardenSmartFox.Connector.onConnectionLost += OnConectionLost;
  291. }
  292. public void Update()
  293. {
  294. if (!JoinedPlazaRoom)
  295. return;
  296. if (EnteringPlazaRoom)
  297. return;
  298. //KeepAliveThread();
  299. //CheckDefautChestThread();
  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. if (PlazaRoomCamera == null)
  322. {
  323. return;
  324. }
  325. if (!InPlazaRoom)
  326. {
  327. return;
  328. }
  329. float x;
  330. if (SelfInstance.Player.transform.position.x <= CameraLeftBorder)
  331. {
  332. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraLeftBorder, Time.deltaTime);
  333. if (SkyTween != null)
  334. SkyTween.Pause();
  335. }
  336. else if (SelfInstance.Player.transform.position.x >= CameraRightBorder)
  337. {
  338. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraRightBorder, Time.deltaTime);
  339. if (SkyTween != null)
  340. SkyTween.Pause();
  341. }
  342. else
  343. {
  344. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, SelfInstance.Player.transform.position.x, Time.deltaTime);
  345. }
  346. PlazaRoomCamera.transform.SetX(x);
  347. }
  348. private float CheckTime = 10;
  349. private float CheckTimer;
  350. public void CheckDefautChestThread()
  351. {
  352. CheckTimer += Time.deltaTime;
  353. if (CheckTimer >= CheckTime)
  354. {
  355. CheckTimer = 0;
  356. GardenSmartFox.EventManager.PlazaRoomEvent.CheckDefaultChestStatus(CurrentRoomData.ID);
  357. }
  358. }
  359. public void MoveTo(Vector3 destination)
  360. {
  361. SFSManager.GardenSmartFox.PlazaRoomManager.SelfInstance.MoveTo(destination);
  362. SFSManager.GardenSmartFox.PlazaRoomManager.SendSynchronizeDestination(destination);
  363. MoveSky(SelfInstance.MoveTween.Duration, SelfInstance.MoveTween.Delta);
  364. }
  365. private float SkyMoveRatio = 0.1f;
  366. private Vector3 SkyOriginPosition;
  367. private TweenRoot SkyTween;
  368. public Transform PlazaRoomSky;
  369. private void MoveSky(float duration, Vector3 offset)
  370. {
  371. offset *= -SkyMoveRatio;
  372. offset.y = 0;
  373. offset.z = 0;
  374. SkyTween = PlazaRoomSky.transform.CreateTweenVecOffset2D(offset, duration, false, true, true, Curve.Linear);
  375. SkyTween.StartForward();
  376. }
  377. public void OnConectionLost(BaseEvent baseEvent)
  378. {
  379. if (JoinedPlazaRoom)
  380. {
  381. OnExitPlazaRoom();
  382. }
  383. }
  384. public void OnExitPlazaRoom()
  385. {
  386. ManaAudio.MusicPartyTheme.TweenBacAudio();
  387. ExitPlazaRoom();
  388. }
  389. public void OnJoinPlazaRoom(Room room)
  390. {
  391. if (JoinRoomResult == JoinRoomResult.Pending)
  392. {
  393. GardenSmartFox.PlazaRoomManager.CurrentPlazaRoom = room;
  394. JoinRoomResult = JoinRoomResult.Succeed;
  395. TryEnterPlazaRoom();
  396. DelayCall.stopCoroutine(JoinRoomCoroutine);
  397. }
  398. }
  399. public void OnJoinPlazaRoomError(JoinRoomResult joinRoomResult)
  400. {
  401. if (JoinRoomResult == JoinRoomResult.Pending)
  402. {
  403. JoinRoomResult = joinRoomResult;
  404. TryEnterPlazaRoom();
  405. }
  406. }
  407. public void OnUserExitPlazaRoom(int userID)
  408. {
  409. UserInstanceDictionary[userID].Save();
  410. UserInstanceDictionary.Remove(userID);
  411. }
  412. public void OnUserEnterPlazaRoom(int senderID)
  413. {
  414. SendInstantiateRequset(senderID);
  415. }
  416. public void Synchronize(int senderID, ISFSObject parameter)
  417. {
  418. if (!UserInstanceDictionary.ContainsKey(senderID))
  419. return;
  420. if (SFSManager.GardenSmartFox.User.Id == senderID)
  421. return;
  422. if (parameter.ContainsKey(InfoLabel.Destination.GetHashString()))
  423. {
  424. Vector3 destination = parameter.GetUtfString(InfoLabel.Destination.GetHashString()).StringToVector();
  425. SynchronizeDestination(destination, senderID);
  426. }
  427. if (parameter.ContainsKey(InfoLabel.Close.GetHashString()))
  428. {
  429. List<int> closeIDs = parameter.GetIntArray(InfoLabel.Destination.GetHashString()).ToList();
  430. SynchronizeClose(closeIDs, senderID);
  431. }
  432. }
  433. public void SynchronizeClose(List<int> closeIDs, int senderID)
  434. {
  435. Player player = UserInstanceDictionary[senderID].Player;
  436. foreach (var closeID in closeIDs)
  437. {
  438. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[closeID];
  439. player.ChangeClose(closeUnit.BodyPart, closeUnit.ArmatureName);
  440. }
  441. }
  442. public void SynchronizeDestination(Vector3 destination, int senderID)
  443. {
  444. UserInstanceDictionary[senderID].MoveTo(destination);
  445. }
  446. private float ExpressionDuration = 1;
  447. public void ReceiveExpression(int expressionID, int senderID)
  448. {
  449. PlazaRoomPlayer plazaRoomPlayer = UserInstanceDictionary[senderID];
  450. string expressionName = Enum.GetName(typeof(ExpressionID), expressionID);
  451. plazaRoomPlayer.Player.ChangeExpression(expressionName, ExpressionDuration);
  452. string senderName = senderID == SFSManager.GardenSmartFox.User.Id ? Language.GetStr("UI", "X_Self") : plazaRoomPlayer.NickName;
  453. string message = $"{senderName}:\u3000<({expressionName}按钮)>";
  454. Color textColor = senderID == SFSManager.GardenSmartFox.User.Id ? Lib.SelfMessage : Lib.OtherMessage;
  455. ManaInfoBox.Show(InfoCategory.PlazaRoom, message, Mathf.Infinity, textColor, ManaReso.LoadSprite("Expression", Folder.Scene));
  456. Text text = ManaReso.Get<Text>("X_CurrentInfoLab");
  457. text.color = textColor;
  458. text.text = message;
  459. }
  460. public void ReceivePublicMessage(string message, int senderID)
  461. {
  462. Color textColor = senderID == SFSManager.GardenSmartFox.User.Id ? Lib.SelfMessage : Lib.OtherMessage;
  463. PlazaRoomPlayer plazaRoomPlayer = UserInstanceDictionary[senderID];
  464. plazaRoomPlayer.ShowMessage(textColor, message);
  465. string senderName = senderID == SFSManager.GardenSmartFox.User.Id ? Language.GetStr("UI", "X_Self") : plazaRoomPlayer.NickName;
  466. message = $"{senderName}:\u3000{message}";
  467. ManaInfoBox.Show(InfoCategory.PlazaRoom, message, Mathf.Infinity, textColor, ManaReso.LoadSprite("Expression", Folder.Scene));
  468. ManaReso.SetText("X_CurrentInfoLab", message);
  469. Text text = ManaReso.Get<Text>("X_CurrentInfoLab");
  470. text.color = textColor;
  471. text.text = message;
  472. }
  473. public void OnInstantiate(int senderID, ISFSObject parameter)
  474. {
  475. if (SFSManager.GardenSmartFox.User.Id == senderID)
  476. return;
  477. UserInstanceDictionary.Add(senderID, InstantiatePlayer(parameter));
  478. }
  479. public void SendExpression(ExpressionID expressionID)
  480. {
  481. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendExpression(expressionID);
  482. }
  483. public bool SendPublicMessage(string message)
  484. {
  485. if (string.IsNullOrEmpty(message))
  486. {
  487. Bubble.Show(null, Language.GetStr("UI", "内容不能为空"));
  488. return false;
  489. }
  490. else
  491. {
  492. message = StringFilter.GetFilteredString(message);
  493. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendPublicMessage(message);
  494. return true;
  495. }
  496. }
  497. public void SendInstantiateRequset(int receiverID)
  498. {
  499. SFSObject parameter = new SFSObject();
  500. parameter.PutInt(InfoLabel.SenderID.GetHashString(), GardenSmartFox.User.Id);
  501. parameter.PutIntArray(InfoLabel.Close.GetHashString(), ManaData.GetDressDataIDs(SelfInstance.Player).ToArray());
  502. parameter.PutUtfString(InfoLabel.Position.GetHashString(), SelfInstance.Player.transform.position.VectorToString());
  503. parameter.PutInt(InfoLabel.PlayerDirection.GetHashString(), SelfInstance.Player.PlayerDirection.GetHashCode());
  504. parameter.PutUtfString(InfoLabel.NickName.GetHashString(), ManaNickName.NickName);
  505. GardenSmartFox.AddRequest(PlazaRoomEvent.WrapInfoRequest(CurrentPlazaRoom.Id, receiverID, InfoID.Instantiate, parameter), RequestType.Immediate);
  506. if (SelfInstance.IsMoving)
  507. {
  508. SendSynchronizeDestination(SelfInstance.Destination);
  509. }
  510. }
  511. public void SendSynchronizeDestination(Vector3 destination)
  512. {
  513. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendSynchronizeDestination(destination);
  514. }
  515. public PlazaRoomPlayer InstantiatePlayer(string nickName, Vector3 position, PlayerDirection direction, List<int> dressDataIDs)
  516. {
  517. Transform parent = ManaReso.Get("PlazaRoom", false);
  518. Transform tra = ManaReso.Get("Player", Folder.Scene, false, parent, false, ObjType.Player);
  519. Player player = tra.GetComponent<Player>();
  520. if (player == null)
  521. {
  522. player = tra.AddScript<Player>();
  523. player.Build();
  524. }
  525. foreach (var id in dressDataIDs)
  526. {
  527. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[id];
  528. closeUnit.ChangeDress(player);
  529. }
  530. player.SetAllCollider(false);
  531. player.transform.position = position;
  532. player.Flip(direction);
  533. player.ActiveShadow();
  534. player.Shadow.SetLZ(3);
  535. tra.localScale = new Vector3(0.525f, 0.525f, 0.525f);
  536. return new PlazaRoomPlayer(player, nickName);
  537. }
  538. public PlazaRoomPlayer InstantiatePlayer(ISFSObject parameter)
  539. {
  540. List<int> dressDatas = ManaData.GetDressDataIDs(parameter);
  541. Vector3 position = parameter.GetUtfString(InfoLabel.Position.GetHashString()).StringToVector();
  542. PlayerDirection direction = (PlayerDirection) parameter.GetInt(InfoLabel.PlayerDirection.GetHashString());
  543. string nickName = parameter.GetUtfString(InfoLabel.NickName.GetHashString());
  544. PlazaRoomPlayer plazaRoomPlayer = InstantiatePlayer(nickName, position, direction, dressDatas);
  545. return plazaRoomPlayer;
  546. }
  547. }