SFSPlazaRoomManager.cs 22 KB

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