BjMotionControl.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class BjMotionControl : MonoBehaviour
  6. {
  7. public Maid TargetMaid
  8. {
  9. get
  10. {
  11. return this.m_TargetMaid;
  12. }
  13. }
  14. public string nMotionName { get; private set; }
  15. public static BjMotionControl Instance { get; private set; }
  16. public bool IsWait { get; private set; }
  17. public bool DoLeaveMotion
  18. {
  19. get
  20. {
  21. return this.m_DoLeaveMotion;
  22. }
  23. set
  24. {
  25. this.m_DoLeaveMotion = value;
  26. if (value)
  27. {
  28. this.m_WaitCoroutine = this.LeaveMotion();
  29. base.StartCoroutine(this.m_WaitCoroutine);
  30. }
  31. else if (this.m_WaitCoroutine != null)
  32. {
  33. base.StopCoroutine(this.m_WaitCoroutine);
  34. }
  35. }
  36. }
  37. public Transform RightHand
  38. {
  39. get
  40. {
  41. return this.m_RightBone;
  42. }
  43. }
  44. public Transform Lefthand
  45. {
  46. get
  47. {
  48. return this.m_LeftBone;
  49. }
  50. }
  51. private ScriptManager m_ScriptMgr
  52. {
  53. get
  54. {
  55. return GameMain.Instance.ScriptMgr;
  56. }
  57. }
  58. private void Awake()
  59. {
  60. BjMotionControl.Instance = this;
  61. this.m_WaitMotionList.Add(BjMotionControl.WaitType.Normal, this.m_BaseWaitMotion);
  62. this.m_WaitMotionList.Add(BjMotionControl.WaitType.Split1, this.m_StandardChoiseWait);
  63. this.m_WaitMotionList.Add(BjMotionControl.WaitType.Split2, this.m_SplitChoiseWait);
  64. this.m_WaitMotionList.Add(BjMotionControl.WaitType.Muku, this.m_MukuWin);
  65. this.m_WaitMotionList.Add(BjMotionControl.WaitType.Majime, this.m_MajimeWin);
  66. this.m_WaitMotionList.Add(BjMotionControl.WaitType.Rindere, this.m_RindereWin);
  67. }
  68. private void Start()
  69. {
  70. string text = "bjmotion_data.nei";
  71. if (!GameUty.FileSystem.IsExistentFile(text))
  72. {
  73. NDebug.Assert("表がありません。" + text, false);
  74. }
  75. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  76. {
  77. using (CsvParser csvParser = new CsvParser())
  78. {
  79. bool condition = csvParser.Open(afileBase);
  80. NDebug.Assert(condition, text + "\nopen failed.");
  81. for (int i = 1; i < csvParser.max_cell_y; i++)
  82. {
  83. if (csvParser.IsCellToExistData(0, i))
  84. {
  85. this.m_LabelMotpair.Add(csvParser.GetCellAsString(1, i), (csvParser.GetCellAsString(2, i) + ".anm").ToLower());
  86. }
  87. }
  88. }
  89. }
  90. KasaiUtility.CsvReadY("bj_winmotion_data.nei", new Action<CsvParser, int>(this.ReadWinMotion), 1, new Action(this.SetDefaultWinMotion));
  91. }
  92. private void ReadWinMotion(CsvParser csv, int cy)
  93. {
  94. BjMotionControl.WaitType value = (BjMotionControl.WaitType)Enum.Parse(typeof(BjMotionControl.WaitType), csv.GetCellAsString(0, cy));
  95. string[] array = csv.GetCellAsString(1, cy).Split(new char[]
  96. {
  97. '\n'
  98. });
  99. foreach (string key in array)
  100. {
  101. this.m_PersonalWinMotionPair.Add(key, value);
  102. }
  103. }
  104. private void SetDefaultWinMotion()
  105. {
  106. this.m_PersonalWinMotionPair.Add("Muku", BjMotionControl.WaitType.Muku);
  107. this.m_PersonalWinMotionPair.Add("Pure", BjMotionControl.WaitType.Muku);
  108. this.m_PersonalWinMotionPair.Add("Majime", BjMotionControl.WaitType.Majime);
  109. this.m_PersonalWinMotionPair.Add("Pride", BjMotionControl.WaitType.Majime);
  110. this.m_PersonalWinMotionPair.Add("Rindere", BjMotionControl.WaitType.Rindere);
  111. this.m_PersonalWinMotionPair.Add("Cool", BjMotionControl.WaitType.Rindere);
  112. }
  113. private IEnumerator LeaveMotion()
  114. {
  115. float timer = 0f;
  116. int wait_time = UnityEngine.Random.Range(this.m_WaitMinTime, this.m_WaitMaxTime);
  117. Action end_action = delegate()
  118. {
  119. this.m_DoLeaveMotion = true;
  120. };
  121. for (;;)
  122. {
  123. if (this.m_DoLeaveMotion && this.IsWait && !BjVoiceMgr.Instance.isPlay)
  124. {
  125. timer += Time.deltaTime;
  126. if (timer > (float)wait_time)
  127. {
  128. timer = 0f;
  129. this.m_DoLeaveMotion = false;
  130. wait_time = UnityEngine.Random.Range(this.m_WaitMinTime, this.m_WaitMaxTime);
  131. if (!BlackjackGame.Instance.isZoom)
  132. {
  133. this.PlayMotion("*覗き込む", end_action, false, false);
  134. BjVoiceMgr.Instance.PlayVoice("行動選択放置", null, 0f);
  135. }
  136. else
  137. {
  138. BjVoiceMgr.Instance.PlayVoice("行動選択放置", end_action, 0f);
  139. }
  140. }
  141. }
  142. else
  143. {
  144. timer = 0f;
  145. }
  146. yield return null;
  147. }
  148. yield break;
  149. }
  150. private IEnumerator MotionEndCall(string motion_name, Action end_action = null)
  151. {
  152. yield return null;
  153. float last_time = -1f;
  154. while (this.m_IsVoiceWait && this.m_IsVoiceAfter && this.m_TargetMaid.AudioMan.isPlay())
  155. {
  156. yield return null;
  157. }
  158. for (;;)
  159. {
  160. bool motion_end = false;
  161. IEnumerator enumerator = this.m_AnimationChache.GetEnumerator();
  162. try
  163. {
  164. while (enumerator.MoveNext())
  165. {
  166. object obj = enumerator.Current;
  167. AnimationState animationState = (AnimationState)obj;
  168. if (animationState.name == motion_name || animationState.name == "crc_" + motion_name)
  169. {
  170. motion_end = (animationState.normalizedTime < last_time);
  171. last_time = animationState.normalizedTime;
  172. break;
  173. }
  174. }
  175. }
  176. finally
  177. {
  178. IDisposable disposable;
  179. if ((disposable = (enumerator as IDisposable)) != null)
  180. {
  181. disposable.Dispose();
  182. }
  183. }
  184. if (motion_end)
  185. {
  186. break;
  187. }
  188. yield return null;
  189. }
  190. while (this.m_IsVoiceWait && !this.m_IsVoiceAfter && this.m_TargetMaid.AudioMan.isPlay())
  191. {
  192. yield return null;
  193. }
  194. if (end_action != null)
  195. {
  196. end_action();
  197. }
  198. this.IsWait = !this.ForceWaitStop;
  199. yield break;
  200. }
  201. private IEnumerator ToNextMotion(string motion_name, string next_label, Action end_action1 = null, Action end_action2 = null)
  202. {
  203. yield return null;
  204. float last_time = -1f;
  205. for (;;)
  206. {
  207. bool motion_end = false;
  208. IEnumerator enumerator = this.m_AnimationChache.GetEnumerator();
  209. try
  210. {
  211. while (enumerator.MoveNext())
  212. {
  213. object obj = enumerator.Current;
  214. AnimationState animationState = (AnimationState)obj;
  215. if (animationState.name == motion_name || animationState.name == "crc_" + motion_name)
  216. {
  217. motion_end = (animationState.normalizedTime < last_time);
  218. last_time = animationState.normalizedTime;
  219. break;
  220. }
  221. }
  222. }
  223. finally
  224. {
  225. IDisposable disposable;
  226. if ((disposable = (enumerator as IDisposable)) != null)
  227. {
  228. disposable.Dispose();
  229. }
  230. }
  231. if (motion_end)
  232. {
  233. break;
  234. }
  235. yield return null;
  236. }
  237. if (end_action1 != null)
  238. {
  239. end_action1();
  240. }
  241. this.MotionFade(next_label, end_action2);
  242. yield break;
  243. }
  244. private void MotionFade(string label, Action end_action = null)
  245. {
  246. if (!this.m_TargetMaid)
  247. {
  248. return;
  249. }
  250. this.nMotionName = label;
  251. this.m_ScriptMgr.StopMotionScript();
  252. this.m_ScriptMgr.is_motion_blend = this.m_IsMotionBlend;
  253. this.m_ScriptMgr.LoadMotionScript(0, false, "work_002.ks", label, string.Empty, string.Empty, false, true, false, false);
  254. this.m_IsMotionBlend = true;
  255. if (!this.IsWait)
  256. {
  257. if (this.m_nMotionEndCall != null)
  258. {
  259. base.StopCoroutine(this.m_nMotionEndCall);
  260. }
  261. this.m_nMotionEndCall = this.MotionEndCall(this.m_LabelMotpair[label], end_action);
  262. base.StartCoroutine(this.m_nMotionEndCall);
  263. }
  264. BlackjackGame.Instance.SetDealerPos();
  265. }
  266. private void MotionToMotion(string first_label, string next_label, Action action1 = null, Action action2 = null)
  267. {
  268. if (!this.m_TargetMaid)
  269. {
  270. return;
  271. }
  272. this.nMotionName = first_label;
  273. this.m_ScriptMgr.StopMotionScript();
  274. this.m_ScriptMgr.is_motion_blend = this.m_IsMotionBlend;
  275. this.m_ScriptMgr.LoadMotionScript(0, false, "work_002.ks", first_label, string.Empty, string.Empty, false, true, false, false);
  276. this.m_IsMotionBlend = true;
  277. if (!this.IsWait)
  278. {
  279. if (this.m_nToNextMotion != null)
  280. {
  281. base.StopCoroutine(this.m_nToNextMotion);
  282. }
  283. this.m_nToNextMotion = this.ToNextMotion(this.m_LabelMotpair[first_label], next_label, action1, action2);
  284. base.StartCoroutine(this.m_nToNextMotion);
  285. }
  286. BlackjackGame.Instance.SetDealerPos();
  287. }
  288. public void Init()
  289. {
  290. this.m_TargetMaid = GameMain.Instance.CharacterMgr.GetMaid(0);
  291. this.m_TargetMaid.EyeToCamera(Maid.EyeMoveType.無視する, 0f);
  292. this.m_AnimationChache = this.m_TargetMaid.body0.GetAnimation();
  293. this.m_IsMotionBlend = false;
  294. this.PlayWaitMotion(BjMotionControl.WaitType.Normal);
  295. this.m_LeftBone = this.m_TargetMaid.body0.GetBone("_IK_handL");
  296. this.m_RightBone = this.m_TargetMaid.body0.GetBone("_IK_handR");
  297. }
  298. public void PlayMotion(string motion_label, Action end_action = null, bool voice_wait = false, bool voice_after = false)
  299. {
  300. bool isWait = this.IsWait;
  301. this.IsWait = false;
  302. this.m_IsVoiceWait = voice_wait;
  303. this.m_IsVoiceAfter = voice_after;
  304. if (isWait && !this.ForceWaitStop && this.m_WaitMotionList[this.m_WaitMotion].IsStartandEnd)
  305. {
  306. this.MotionToMotion(this.m_WaitMotionList[this.m_WaitMotion].WaitEndLabel, motion_label, null, end_action);
  307. }
  308. else
  309. {
  310. this.MotionFade(motion_label, end_action);
  311. }
  312. }
  313. public void PlayWinMotion(Maid maid)
  314. {
  315. this.PlayWaitMotion(this.m_PersonalWinMotionPair[maid.status.personal.uniqueName]);
  316. }
  317. public void PlayWaitMotion(BjMotionControl.WaitType motion)
  318. {
  319. if (!this.m_TargetMaid)
  320. {
  321. return;
  322. }
  323. if (this.ForceWaitStop)
  324. {
  325. return;
  326. }
  327. this.SetWaitMotion(motion);
  328. this.IsWait = true;
  329. this.MotionFade(this.m_WaitMotionList[motion].WaitStartLabel, null);
  330. }
  331. public void PlayWaitMotion()
  332. {
  333. this.PlayWaitMotion(this.m_WaitMotion);
  334. }
  335. public void SetWaitMotion(BjMotionControl.WaitType motion)
  336. {
  337. this.m_WaitMotion = motion;
  338. this.IsWait = false;
  339. }
  340. public string GetHaihuMotion()
  341. {
  342. if (BjPlayer.Instance.IsSplitGame() && BjPlayer.Instance.IsNowSplitHand)
  343. {
  344. return "*スプリットで配布" + BjPlayer.Instance.splitHand.CardNum.ToString();
  345. }
  346. return "*プレイヤーに配布" + BjPlayer.Instance.standardHand.CardNum.ToString();
  347. }
  348. public Vector3 RightHandPos()
  349. {
  350. return this.m_RightBone.position;
  351. }
  352. public Vector3 LeftHandPos()
  353. {
  354. return this.m_LeftBone.position;
  355. }
  356. private Maid m_TargetMaid;
  357. [HideInInspector]
  358. public bool ForceWaitStop;
  359. private const string m_MotionScriptName = "work_002.ks";
  360. private Animation m_AnimationChache;
  361. [SerializeField]
  362. private int m_WaitMinTime = 5;
  363. [SerializeField]
  364. private int m_WaitMaxTime = 15;
  365. [SerializeField]
  366. private BjMotionControl.Motion3Part m_BaseWaitMotion;
  367. [SerializeField]
  368. private BjMotionControl.Motion3Part m_StandardChoiseWait;
  369. [SerializeField]
  370. private BjMotionControl.Motion3Part m_SplitChoiseWait;
  371. [Header("各性格勝利時モーション")]
  372. [SerializeField]
  373. private BjMotionControl.Motion3Part m_MukuWin;
  374. [SerializeField]
  375. private BjMotionControl.Motion3Part m_MajimeWin;
  376. [SerializeField]
  377. private BjMotionControl.Motion3Part m_RindereWin;
  378. private BjMotionControl.WaitType m_WaitMotion;
  379. private Dictionary<BjMotionControl.WaitType, BjMotionControl.Motion3Part> m_WaitMotionList = new Dictionary<BjMotionControl.WaitType, BjMotionControl.Motion3Part>();
  380. private IEnumerator m_nMotionEndCall;
  381. private IEnumerator m_nToNextMotion;
  382. private IEnumerator m_WaitCoroutine;
  383. private bool m_DoLeaveMotion;
  384. private Transform m_RightBone;
  385. private Transform m_LeftBone;
  386. private Dictionary<string, string> m_LabelMotpair = new Dictionary<string, string>();
  387. private Dictionary<string, BjMotionControl.WaitType> m_PersonalWinMotionPair = new Dictionary<string, BjMotionControl.WaitType>();
  388. private bool m_IsMotionBlend = true;
  389. private bool m_IsVoiceWait;
  390. private bool m_IsVoiceAfter;
  391. public enum WaitType
  392. {
  393. Normal,
  394. Split1,
  395. Split2,
  396. Muku,
  397. Majime,
  398. Rindere
  399. }
  400. [Serializable]
  401. private class Motion3Part
  402. {
  403. public bool IsStartandEnd
  404. {
  405. get
  406. {
  407. return !string.IsNullOrEmpty(this.WaitStartLabel) && !string.IsNullOrEmpty(this.WaitEndLabel);
  408. }
  409. }
  410. public string WaitStartLabel;
  411. public string WaitEndLabel;
  412. }
  413. }