SFSPlazaRoomManager.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. using Random = UnityEngine.Random;
  13. public enum JoinRoomResult
  14. {
  15. RoomFullError = 0,
  16. RoomExpireError = 1,
  17. Unknown = 2,
  18. Succeed = 3,
  19. Pending = 4,
  20. }
  21. public class SFSPlazaRoomManager
  22. {
  23. private static Vector3 PlazaRoomPlayerScale = new Vector3(0.525f, 0.525f, 0.525f);
  24. public class PlazaRoomPlayer
  25. {
  26. #region Config
  27. public string NickName;
  28. public Player Player;
  29. public Transform NickNameTransform;
  30. public List<TweenRoot> TweenRoots;
  31. public BestfitText MessageLab;
  32. public Transform MessageBox;
  33. #endregion
  34. public PlazaRoomPlayer(Player player, string nickname)
  35. {
  36. Player = player;
  37. TweenRoots = new List<TweenRoot>();
  38. NickNameTransform = ManaReso.Get("NickName", Folder.UI, false, ManaReso.Get("W_HudParent"), false, ObjType.NickName);
  39. HudTarget hudTarget = NickNameTransform.GetComponent<HudTarget>();
  40. if (hudTarget == null)
  41. {
  42. hudTarget = NickNameTransform.AddComponent<HudTarget>();
  43. }
  44. hudTarget.PosTra = Player.ChildDic["NickName"];
  45. hudTarget.SetPosition();
  46. NickName = string.IsNullOrEmpty(nickname) ? Language.GetStr("UI", "未命名") : nickname;
  47. NickNameTransform.GetComponent<Text>().text = NickName;
  48. MessageBox = ManaReso.Get("MessageBox", Folder.UI, false, ManaReso.Get("W_HudParent"), false, ObjType.MessageBox);
  49. MessageLab = MessageBox.GetComponentInChildren<BestfitText>();
  50. MessageLab.VerticalMinSize = 12;
  51. MessageLab.VerticalMaxSize = 20;
  52. hudTarget = MessageBox.GetComponent<HudTarget>();
  53. if (hudTarget == null)
  54. {
  55. hudTarget = MessageBox.AddComponent<HudTarget>();
  56. }
  57. hudTarget.PosTra = Player.ChildDic["MessageBox"];
  58. MessageBox.CreateTweenCG(0, 1, 0.25f, true, true, Curve.EaseOutQuad).InOrigin = true;
  59. }
  60. public void Save()
  61. {
  62. foreach (var tweenRoot in TweenRoots)
  63. {
  64. tweenRoot.Pause();
  65. }
  66. ManaReso.Save(Player);
  67. ManaReso.Save(NickNameTransform);
  68. ManaReso.Save(MessageBox);
  69. Player.PlayAnim(Player.IdleAnimationName);
  70. Player.DeactiveShadow();
  71. Player.Shadow.SetLZ(0);
  72. Player.ExpressionMeshFilter.transform.parent = Player.transform;
  73. }
  74. public bool IsMoving;
  75. public float Speed = 1f;
  76. public Vector3 Destination;
  77. public TweenVec MoveTween;
  78. public void MoveTo(Vector3 destination)
  79. {
  80. if (destination.Equal(Player.transform.position))
  81. {
  82. return;
  83. }
  84. if (destination.x > Player.transform.position.x)
  85. {
  86. Player.Flip(PlayerDirection.Right);
  87. }
  88. else
  89. {
  90. Player.Flip(PlayerDirection.Left);
  91. }
  92. float duration = Mathf.Clamp(Vector3.Magnitude(destination - Player.transform.position) / 1.5f, 0.25f, 10f) / Speed;
  93. MoveTween = Player.transform.CreateTweenVec3D(destination, duration, false, true, true, Curve.EaseOutQuad);
  94. MoveTween.StartForward();
  95. MoveTween.AddEventOnetime(EventType.ForwardFinish, StopMove);
  96. TweenRoots.Add(MoveTween);
  97. IsMoving = true;
  98. Destination = destination;
  99. Player.PlayAnim(Player.WalkAnimationName);
  100. }
  101. public void StopMove()
  102. {
  103. IsMoving = false;
  104. Player.PlayAnim(Player.IdleAnimationName);
  105. }
  106. public float MessgeTime = 3f;
  107. public Coroutine MessgeCoroutine;
  108. public void ShowMessage(Color color, string message)
  109. {
  110. if (MessgeCoroutine != null)
  111. {
  112. Auxiliary.Instance.StopCoroutine(MessgeCoroutine);
  113. }
  114. MessageLab.text = message;
  115. MessageLab.color = color;
  116. MessageBox.TweenForCG();
  117. MessgeCoroutine = Auxiliary.Instance.DelayCall(() => { MessageBox.TweenBacCG(); }, MessgeTime);
  118. }
  119. }
  120. #region Variable
  121. public GardenSmartFox GardenSmartFox;
  122. public PlazaRoomPlayer SelfInstance;
  123. public Room CurrentPlazaRoom;
  124. public RoomData CurrentRoomData;
  125. public bool JoinedPlazaRoom
  126. {
  127. get { return CurrentPlazaRoom != null; }
  128. }
  129. public bool InPlazaRoom;
  130. public bool IsBlackMaskFinish;
  131. public JoinRoomResult JoinRoomResult = JoinRoomResult.Pending;
  132. public Dictionary<int, PlazaRoomPlayer> UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
  133. #endregion
  134. private Coroutine JoinRoomCoroutine;
  135. public void BeginEnterPlazaRoom(RoomData roomData)
  136. {
  137. CurrentRoomData = roomData;
  138. IsBlackMaskFinish = false;
  139. JoinRoomResult = JoinRoomResult.Pending;
  140. ManaAudio.MusicTheme.TweenBacAudio();
  141. ManaReso.Get("B_SignIn0").TweenBacCG();
  142. ManaReso.Get("T_NickName").TweenBacCG();
  143. ManaCenter.SceneSwitchLock = true;
  144. TweenRoot tweenRoot = ManaReso.Get("V_BlackMask").TweenBacCG();
  145. tweenRoot.AddEventOnetime
  146. (
  147. EventType.BackwardFinish, () =>
  148. {
  149. IsBlackMaskFinish = true;
  150. TryEnterPlazaRoom();
  151. }
  152. );
  153. GardenSmartFox.ExecuteAfterCheckConection
  154. (
  155. null,
  156. (succeed, baseEvent) =>
  157. {
  158. if (!succeed)
  159. {
  160. JoinRoomResult = JoinRoomResult.Unknown;
  161. TryEnterPlazaRoom();
  162. }
  163. },
  164. (succeed, baseEvent) =>
  165. {
  166. if (!succeed)
  167. {
  168. JoinRoomResult = JoinRoomResult.Unknown;
  169. TryEnterPlazaRoom();
  170. }
  171. }
  172. );
  173. JoinRoomCoroutine = DelayCall.Call(20f, () => { OnJoinPlazaRoomError(JoinRoomResult.Unknown); });
  174. }
  175. public void TryEnterPlazaRoom()
  176. {
  177. if (!GardenSmartFox.PlazaRoomManager.IsBlackMaskFinish)
  178. return;
  179. if (JoinRoomResult == JoinRoomResult.Pending)
  180. return;
  181. if (JoinRoomResult == JoinRoomResult.Succeed)
  182. {
  183. EnterPlazaRoom();
  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. }
  201. }
  202. private Vector3 PlayerDefaultPosition;
  203. public void EnterPlazaRoom()
  204. {
  205. PlazaRoom.Initialize();
  206. GardenSmartFox.EventManager.PlazaRoomEvent.GetAllChestData(CurrentRoomData.ID);
  207. foreach (var kv in UserInstanceDictionary)
  208. {
  209. if (kv.Value.Player.transform.parent == null)
  210. {
  211. kv.Value.Player.transform.parent = ManaReso.Get("PlazaRoom");
  212. kv.Value.Player.transform.localScale = PlazaRoomPlayerScale;
  213. }
  214. }
  215. ManaAudio.MusicPartyTheme.TweenForAudio();
  216. InPlazaRoom = true;
  217. PlazaRoomMge.ClosePanel();
  218. ManaGarden.RetrieveAllElf();
  219. ManaIAP.RetrieveADChest();
  220. GardenSmartFox.PlazaRoomManager.PlazaRoomSky = ManaReso.Get("PlazaRoomSky");
  221. SkyOriginPosition = GardenSmartFox.PlazaRoomManager.PlazaRoomSky.position;
  222. GardenSmartFox.PlazaRoomManager.PlazaRoomCamera = ManaReso.Get<Camera>("MainCamera");
  223. GardenSmartFox.PlazaRoomManager.CameraOriginPosition = GardenSmartFox.PlazaRoomManager.PlazaRoomCamera.transform.position;
  224. PlayerDefaultPosition = GetDefaultPosition();
  225. SelfInstance = InstantiatePlayer(ManaNickName.NickName, PlayerDefaultPosition, PlayerDirection.Left, ManaData.GetDressDataIDs(ManaPlayer.Player));
  226. SelfInstance.Player.transform.SetZ(SelfInstance.Player.transform.position.z - 0.1f);
  227. UserInstanceDictionary.Add(SFSManager.GardenSmartFox.User.Id, SelfInstance);
  228. SendInstantiateRequset(-1);
  229. GardenSmartFox.PlazaRoomManager.CameraLeftBorder = ManaReso.Get("PlazaRoomCameraLeftBorder").position.x;
  230. GardenSmartFox.PlazaRoomManager.CameraRightBorder = ManaReso.Get("PlazaRoomCameraRightBorder").position.x;
  231. GardenSmartFox.PlazaRoomManager.PlazaRoomCamera.transform.SetX(GardenSmartFox.PlazaRoomManager.CameraLeftBorder);
  232. ManaReso.Get("V_BlackMask").TweenForCG();
  233. ManaReso.SetActive("C_Main2", false);
  234. ManaReso.SetActive("Garden", false);
  235. ManaReso.SetActive("PlazaRoom", true);
  236. ManaReso.SetActive("W_HudParent", true);
  237. ManaReso.SetActive("X_PlazaRoom", true);
  238. }
  239. public void ExitPlazaRoom()
  240. {
  241. QuitPlazaRoom();
  242. TweenRoot tweenRoot = ManaReso.Get("V_BlackMask").TweenBacCG();
  243. tweenRoot.AddEventOnetime
  244. (
  245. EventType.BackwardFinish,
  246. () =>
  247. {
  248. ChestMge.RetrieveAllChest();
  249. InPlazaRoom = false;
  250. ManaAudio.MusicTheme.TweenForAudio();
  251. PlazaRoomSky.position = SkyOriginPosition;
  252. PlazaRoomCamera.transform.position = CameraOriginPosition;
  253. ManaReso.SetActive("C_Main2", true);
  254. ManaReso.SetActive("Garden", true);
  255. ManaReso.SetActive("PlazaRoom", false);
  256. ManaReso.SetActive("W_HudParent", false);
  257. ManaReso.SetActive("X_PlazaRoom", false);
  258. ManaReso.Get("V_BlackMask").TweenForCG();
  259. ManaReso.Get("B_SignIn0").TweenForCG();
  260. ManaReso.Get("T_NickName").TweenForCG();
  261. ManaReso.Get<Text>("X_CurrentInfoLab").text = "";
  262. Transform tra = ManaReso.Get("X_Info");
  263. while (tra.childCount > 0)
  264. {
  265. ManaReso.Save(tra.GetChild(0));
  266. }
  267. foreach (var kv in UserInstanceDictionary)
  268. {
  269. kv.Value.Save();
  270. }
  271. UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
  272. RobotManager.DeactivateAllRobots(true);
  273. }
  274. );
  275. tweenRoot.AddEventOnetime
  276. (
  277. EventType.ForwardFinish,
  278. () =>
  279. {
  280. PlazaRoomMge.OpenPanel();
  281. }
  282. );
  283. }
  284. public void QuitPlazaRoom()
  285. {
  286. PlazaRoomChest.SystemChest = null;
  287. ManaCenter.SceneSwitchLock = false;
  288. GardenSmartFox.SmartFox.Send(new LeaveRoomRequest(CurrentPlazaRoom));
  289. GardenSmartFox.PlazaRoomManager.CurrentPlazaRoom = null;
  290. }
  291. public SFSPlazaRoomManager(GardenSmartFox gardenSmartFox)
  292. {
  293. GardenSmartFox = gardenSmartFox;
  294. gardenSmartFox.Connector.onConnectionLost += OnConectionLost;
  295. }
  296. public void Update()
  297. {
  298. if (!JoinedPlazaRoom)
  299. return;
  300. if (!InPlazaRoom)
  301. return;
  302. //KeepAliveThread();
  303. //CheckDefautChestThread();
  304. RobotThread();
  305. CameraControllThread();
  306. }
  307. public float KeepAliveTime = 30;
  308. public float KeepAliveTimer;
  309. public void KeepAliveThread()
  310. {
  311. KeepAliveTimer += Time.deltaTime;
  312. if (KeepAliveTimer > KeepAliveTime)
  313. {
  314. KeepAliveTimer = 0;
  315. SFSObject parameter = new SFSObject();
  316. parameter.PutInt(Label.CommandID, PlazaRoomReq.KeepAlive.GetHashCode());
  317. GardenSmartFox.AddRequest(parameter, RequestType.Immediate);
  318. }
  319. }
  320. public float CameraLeftBorder;
  321. public float CameraRightBorder;
  322. public Vector3 CameraOriginPosition;
  323. public Camera PlazaRoomCamera;
  324. public void CameraControllThread()
  325. {
  326. float x;
  327. if (SelfInstance.Player.transform.position.x <= CameraLeftBorder)
  328. {
  329. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraLeftBorder, Time.deltaTime);
  330. if (SkyTween != null)
  331. SkyTween.Pause();
  332. }
  333. else if (SelfInstance.Player.transform.position.x >= CameraRightBorder)
  334. {
  335. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, CameraRightBorder, Time.deltaTime);
  336. if (SkyTween != null)
  337. SkyTween.Pause();
  338. }
  339. else
  340. {
  341. x = Mathf.Lerp(PlazaRoomCamera.transform.position.x, SelfInstance.Player.transform.position.x, Time.deltaTime);
  342. }
  343. PlazaRoomCamera.transform.SetX(x);
  344. }
  345. public void RobotThread()
  346. {
  347. RobotManager.Update();
  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. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendInstantiateRequset(GardenSmartFox.User.Id, ManaData.GetDressDataIDs(SelfInstance.Player).ToArray(), SelfInstance.Player.transform.position, SelfInstance.Player.PlayerDirection, ManaNickName.NickName, receiverID);
  502. if (SelfInstance.IsMoving)
  503. {
  504. SendSynchronizeDestination(SelfInstance.Destination);
  505. }
  506. }
  507. public void SendSynchronizeDestination(Vector3 destination)
  508. {
  509. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendSynchronizeDestination(GardenSmartFox.User.Id, destination);
  510. }
  511. public PlazaRoomPlayer InstantiatePlayer(string nickName, Vector3 position, PlayerDirection direction, List<int> dressDataIDs)
  512. {
  513. Transform parent = ManaReso.Get("PlazaRoom", false);
  514. Transform tra = ManaReso.Get("Player", Folder.Scene, false, parent, false, ObjType.Player);
  515. Player player = tra.GetComponent<Player>();
  516. if (player == null)
  517. {
  518. player = tra.AddScript<Player>();
  519. player.Build();
  520. }
  521. foreach (var id in dressDataIDs)
  522. {
  523. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[id];
  524. closeUnit.ChangeDress(player);
  525. }
  526. player.SetAllCollider(false);
  527. player.transform.position = position;
  528. player.Flip(direction);
  529. player.ActiveShadow();
  530. player.Shadow.SetLZ(3);
  531. tra.localScale = PlazaRoomPlayerScale;
  532. return new PlazaRoomPlayer(player, nickName);
  533. }
  534. public PlazaRoomPlayer InstantiatePlayer(ISFSObject parameter)
  535. {
  536. List<int> dressDatas = ManaData.GetDressDataIDs(parameter);
  537. Vector3 position = parameter.GetUtfString(InfoLabel.Position.GetHashString()).StringToVector();
  538. PlayerDirection direction = (PlayerDirection) parameter.GetInt(InfoLabel.PlayerDirection.GetHashString());
  539. string nickName = parameter.GetUtfString(InfoLabel.NickName.GetHashString());
  540. PlazaRoomPlayer plazaRoomPlayer = InstantiatePlayer(nickName, position, direction, dressDatas);
  541. return plazaRoomPlayer;
  542. }
  543. private static float minZOffset = 0.01f;
  544. private static float maxZOffset = 0.1f;
  545. public static Vector3 GetDefaultPosition() //todo
  546. {
  547. float zOffset = Random.Range(minZOffset, maxZOffset);
  548. Vector3 position = ManaReso.Get("PlazaRoomDefaultPosition").position;
  549. position.z += zOffset;
  550. return position;
  551. }
  552. }