MagicaPhysicsManager.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using System;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7. #if MAGICACLOTH_ECS
  8. using Unity.Entities;
  9. #endif
  10. using UnityEngine;
  11. using UnityEngine.LowLevel;
  12. namespace MagicaCloth
  13. {
  14. /// <summary>
  15. /// MagicaCloth物理マネージャ
  16. /// </summary>
  17. [HelpURL("https://magicasoft.jp/magica-cloth-physics-manager/")]
  18. public partial class MagicaPhysicsManager : CreateSingleton<MagicaPhysicsManager>
  19. {
  20. /// <summary>
  21. /// 更新管理
  22. /// </summary>
  23. [SerializeField]
  24. UpdateTimeManager updateTime = new UpdateTimeManager();
  25. /// <summary>
  26. /// パーティクルデータ
  27. /// </summary>
  28. PhysicsManagerParticleData particle = new PhysicsManagerParticleData();
  29. /// <summary>
  30. /// トランスフォームデータ
  31. /// </summary>
  32. PhysicsManagerBoneData bone = new PhysicsManagerBoneData();
  33. /// <summary>
  34. /// メッシュデータ
  35. /// </summary>
  36. PhysicsManagerMeshData mesh = new PhysicsManagerMeshData();
  37. /// <summary>
  38. /// チームデータ
  39. /// </summary>
  40. PhysicsManagerTeamData team = new PhysicsManagerTeamData();
  41. /// <summary>
  42. /// 風データ
  43. /// </summary>
  44. PhysicsManagerWindData wind = new PhysicsManagerWindData();
  45. /// <summary>
  46. /// 全コンポーネントデータ
  47. /// </summary>
  48. PhysicsManagerComponent component = new PhysicsManagerComponent();
  49. /// <summary>
  50. /// 物理計算処理
  51. /// </summary>
  52. PhysicsManagerCompute compute = new PhysicsManagerCompute();
  53. /// <summary>
  54. /// Unity2021.2以降でのGetVertexBuffer()による高速書き込みの利用
  55. /// 実行中は変更できない
  56. /// </summary>
  57. [SerializeField]
  58. private bool useFasterWrite = true;
  59. // コンピュートシェーダー
  60. private ComputeShader meshWriter = null;
  61. //=========================================================================================
  62. /// <summary>
  63. /// シミュレーション計算前イベント
  64. /// Simulation pre-calculation event.
  65. /// </summary>
  66. public PhysicsManagerPreUpdateEvent OnPreUpdate = new PhysicsManagerPreUpdateEvent();
  67. /// <summary>
  68. /// シミュレーション計算後イベント
  69. /// Simulation post-calculation event.
  70. /// </summary>
  71. public PhysicsManagerPostUpdateEvent OnPostUpdate = new PhysicsManagerPostUpdateEvent();
  72. //=========================================================================================
  73. /// <summary>
  74. /// 遅延実行の有無
  75. /// ランタイムで変更できるようにバッファリング
  76. /// </summary>
  77. private bool useDelay = false;
  78. /// <summary>
  79. /// Update()でのPlayerLoopチェック完了フラグ
  80. /// </summary>
  81. private bool updatePlayerLoop = false;
  82. /// <summary>
  83. /// マネージャ全体のアクティブフラグ
  84. /// </summary>
  85. private bool isActive = true;
  86. //=========================================================================================
  87. public UpdateTimeManager UpdateTime
  88. {
  89. get
  90. {
  91. return updateTime;
  92. }
  93. }
  94. public PhysicsManagerParticleData Particle
  95. {
  96. get
  97. {
  98. particle.SetParent(this);
  99. return particle;
  100. }
  101. }
  102. public PhysicsManagerBoneData Bone
  103. {
  104. get
  105. {
  106. bone.SetParent(this);
  107. return bone;
  108. }
  109. }
  110. public PhysicsManagerMeshData Mesh
  111. {
  112. get
  113. {
  114. mesh.SetParent(this);
  115. return mesh;
  116. }
  117. }
  118. public PhysicsManagerTeamData Team
  119. {
  120. get
  121. {
  122. team.SetParent(this);
  123. return team;
  124. }
  125. }
  126. public PhysicsManagerWindData Wind
  127. {
  128. get
  129. {
  130. wind.SetParent(this);
  131. return wind;
  132. }
  133. }
  134. public PhysicsManagerComponent Component
  135. {
  136. get
  137. {
  138. component.SetParent(this);
  139. return component;
  140. }
  141. }
  142. public PhysicsManagerCompute Compute
  143. {
  144. get
  145. {
  146. compute.SetParent(this);
  147. return compute;
  148. }
  149. }
  150. public bool IsDelay
  151. {
  152. get
  153. {
  154. return useDelay;
  155. }
  156. }
  157. public bool IsActive
  158. {
  159. get
  160. {
  161. return isActive;
  162. }
  163. set
  164. {
  165. // アクティブはコンポーネントのenableフラグで行う
  166. this.enabled = value;
  167. }
  168. }
  169. public bool IsFasterWrite
  170. {
  171. get
  172. {
  173. if (useFasterWrite)
  174. {
  175. #if UNITY_2021_2_OR_NEWER
  176. if (MeshWriterShader != null)
  177. {
  178. if (MeshWriterShader.IsSupported(0) && MeshWriterShader.IsSupported(1))
  179. {
  180. return true;
  181. }
  182. }
  183. #endif
  184. }
  185. return false;
  186. }
  187. }
  188. internal ComputeShader MeshWriterShader
  189. {
  190. get
  191. {
  192. if (meshWriter == null)
  193. {
  194. meshWriter = (ComputeShader)Resources.Load("MeshWriter");
  195. }
  196. return meshWriter;
  197. }
  198. }
  199. //=========================================================================================
  200. protected override void Awake()
  201. {
  202. base.Awake();
  203. }
  204. /// <summary>
  205. /// 初期化
  206. /// </summary>
  207. protected override void InitSingleton()
  208. {
  209. Component.Create();
  210. Particle.Create();
  211. Bone.Create();
  212. Mesh.Create();
  213. Team.Create();
  214. Wind.Create();
  215. Compute.Create();
  216. }
  217. /// <summary>
  218. /// 2つ目の破棄されるマネージャの通知
  219. /// </summary>
  220. /// <param name="duplicate"></param>
  221. protected override void DuplicateDetection(MagicaPhysicsManager duplicate)
  222. {
  223. // 設定をコピーする
  224. UpdateMode = duplicate.UpdateMode;
  225. UpdatePerSeccond = duplicate.UpdatePerSeccond;
  226. FuturePredictionRate = duplicate.FuturePredictionRate;
  227. }
  228. protected void OnEnable()
  229. {
  230. if (isActive == false)
  231. {
  232. isActive = true;
  233. Component.UpdateComponentStatus();
  234. }
  235. }
  236. protected void OnDisable()
  237. {
  238. if (isActive == true)
  239. {
  240. isActive = false;
  241. Component.UpdateComponentStatus();
  242. }
  243. }
  244. private void Update()
  245. {
  246. // Unity2019.3以降の場合はUpdate時に一度カスタムループの登録チェックを行う
  247. // すでに登録されていればスルーし、登録されていなければ再登録する
  248. // これは他のアセットによりPlayerLoopが書き換えられてしまった場合の対策です
  249. if (updatePlayerLoop == false)
  250. {
  251. //Debug.Log("Update check!!");
  252. InitCustomGameLoop();
  253. updatePlayerLoop = true;
  254. }
  255. }
  256. private void FixedUpdate()
  257. {
  258. if (isActive)
  259. {
  260. UpdateTime.AddFixedUpdateCount();
  261. }
  262. }
  263. /// <summary>
  264. /// 破棄
  265. /// </summary>
  266. protected override void OnDestroy()
  267. {
  268. Compute.Dispose();
  269. Wind.Dispose();
  270. Team.Dispose();
  271. Mesh.Dispose();
  272. Bone.Dispose();
  273. Particle.Dispose();
  274. Component.Dispose();
  275. base.OnDestroy();
  276. }
  277. //=========================================================================================
  278. /// <summary>
  279. /// EarlyUpdateの後
  280. /// </summary>
  281. private void AfterEarlyUpdate()
  282. {
  283. //Debug.Log($"After Early Update! F:{Time.frameCount}");
  284. // フレーム開始時に行うチーム更新
  285. Team.EarlyUpdateTeamAlways();
  286. }
  287. //private void BeforeFixedUpdate()
  288. //{
  289. // //Debug.Log("Before Fixed Update!" + Time.frameCount);
  290. // // シミュレーションに必要なボーンの状態をもとに戻す(更新モード = UnityPhysics)
  291. // if (Team.ActiveTeamCount > 0 && Team.PhysicsUpdateCount > 0)
  292. // {
  293. // Compute.InitJob();
  294. // Compute.UpdateRestoreBone(PhysicsTeam.TeamUpdateMode.UnityPhysics);
  295. // Compute.CompleteJob();
  296. // }
  297. //}
  298. private void AfterFixedUpdate()
  299. {
  300. //Debug.Log("After Fixed Update!" + Time.frameCount);
  301. // シミュレーションに必要なボーンの状態をもとに戻す(更新モード = UnityPhysics)
  302. if (Team.ActiveTeamCount > 0 && Team.PhysicsUpdateCount > 0)
  303. {
  304. Compute.InitJob();
  305. Compute.UpdateRestoreBone(PhysicsTeam.TeamUpdateMode.UnityPhysics);
  306. Compute.CompleteJob();
  307. }
  308. }
  309. /// <summary>
  310. /// Update()後の更新
  311. /// </summary>
  312. private void AfterUpdate()
  313. {
  314. //Debug.Log("After Update!" + Time.frameCount);
  315. // シミュレーションに必要なボーンの状態をもとに戻す(更新モード = Normal)
  316. if (Team.ActiveTeamCount > 0 && Team.NormalUpdateCount > 0)
  317. {
  318. Compute.InitJob();
  319. Compute.UpdateRestoreBone(PhysicsTeam.TeamUpdateMode.Normal);
  320. Compute.CompleteJob();
  321. }
  322. }
  323. /// <summary>
  324. /// LateUpdate()前の更新
  325. /// </summary>
  326. //private void BeforeLateUpdate()
  327. //{
  328. // //Debug.Log("Before Late Update!" + Time.frameCount);
  329. //}
  330. /// <summary>
  331. /// LateUpdate()後の更新
  332. /// </summary>
  333. private void AfterLateUpdate()
  334. {
  335. //Debug.Log("After Late Update!" + Time.frameCount);
  336. //Debug.Log("dtime:" + Time.deltaTime + " smooth:" + Time.smoothDeltaTime);
  337. // 遅延実行の切り替え判定
  338. if (useDelay != UpdateTime.IsDelay)
  339. {
  340. if (useDelay == false)
  341. {
  342. // 結果の保持
  343. Compute.UpdateSwapBuffer();
  344. Compute.UpdateSyncBuffer();
  345. }
  346. useDelay = UpdateTime.IsDelay;
  347. }
  348. // パーティクルコンポーネントのデータ更新処理
  349. Component.DataUpdateParticleComponent();
  350. if (useDelay == false)
  351. {
  352. // 即時
  353. OnPreUpdate.Invoke();
  354. Compute.UpdateTeamAlways();
  355. Compute.InitJob();
  356. Compute.UpdateReadBone();
  357. Compute.UpdateStartSimulation(updateTime);
  358. Compute.UpdateWriteBone();
  359. Compute.MeshCalculation();
  360. Compute.UpdateCompleteSimulation();
  361. Compute.NormalWritingMesh();
  362. OnPostUpdate.Invoke();
  363. }
  364. }
  365. /// <summary>
  366. /// PostLateUpdate.ScriptRunDelayedDynamicFrameRateの後
  367. /// LateUpdate()やアセットバンドルロード完了コールバックでクロスコンポーネントをインスタンス化すると、
  368. /// Start()が少し遅れてPostLateUpdateのScriptRunDelayedDynamicFrameRateで呼ばれることになる。
  369. /// 遅延実行時にこの処理が入ると、すでにクロスシミュレーションのジョブが開始されているため、
  370. /// Start()の初期化処理などでNativeリストにアクセスすると例外が発生してしまう。
  371. /// 従って遅延実行時はクロスコンポーネントのStart()が完了するScriptRunDelayedDynamicFrameRate
  372. /// の後にシミュレーションを開始するようにする。(v1.5.1)
  373. /// </summary>
  374. private void PostLateUpdate()
  375. {
  376. //Debug.Log("Post Late Update!" + Time.frameCount);
  377. if (useDelay)
  378. {
  379. // 遅延実行
  380. OnPreUpdate.Invoke();
  381. Compute.UpdateTeamAlways();
  382. Compute.InitJob();
  383. Compute.UpdateReadWriteBone();
  384. Compute.UpdateStartSimulation(updateTime);
  385. Compute.ScheduleJob();
  386. Compute.MeshCalculation();
  387. Compute.NormalWritingMesh(); // 前回の結果をメッシュに反映
  388. //Debug.Log($"Delay Job! F:{Time.frameCount}");
  389. }
  390. }
  391. /// <summary>
  392. /// レンダリング完了後の更新
  393. /// </summary>
  394. private void AfterRendering()
  395. {
  396. //Debug.Log($"After Rendering Update! F:{Time.frameCount}");
  397. if (useDelay)
  398. {
  399. // 遅延実行
  400. // シミュレーション終了待機
  401. Compute.UpdateCompleteSimulation();
  402. // 結果の保持
  403. Compute.UpdateSwapBuffer();
  404. Compute.UpdateSyncBuffer();
  405. OnPostUpdate.Invoke();
  406. }
  407. // シミュレーションに必要なボーンの状態をもとに戻す
  408. //Compute.InitJob();
  409. //Compute.UpdateRestoreBone();
  410. //Compute.CompleteJob();
  411. // FixedUpdateCountクリア
  412. UpdateTime.ResetFixedUpdateCount();
  413. }
  414. //=========================================================================================
  415. /// <summary>
  416. /// Reload Domain 対策
  417. /// </summary>
  418. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
  419. private static void Init()
  420. {
  421. InitMember();
  422. }
  423. /// <summary>
  424. /// カスタム更新ループ登録
  425. /// </summary>
  426. [RuntimeInitializeOnLoadMethod()]
  427. public static void InitCustomGameLoop()
  428. {
  429. //Debug.Log("PhysicsManager.InitCustomGameLoop()");
  430. PlayerLoopSystem playerLoop = PlayerLoop.GetCurrentPlayerLoop();
  431. // すでに設定されているならばスルー
  432. if (CheckRegist(ref playerLoop))
  433. {
  434. //Debug.Log("Skip!!");
  435. return;
  436. }
  437. // MagicaCloth用PlayerLoopを追加
  438. SetCustomGameLoop(ref playerLoop);
  439. PlayerLoop.SetPlayerLoop(playerLoop);
  440. }
  441. /// <summary>
  442. /// playerLoopにMagicaClothで必要なCustomPlayerLoopを追加します
  443. /// </summary>
  444. /// <param name="playerLoop"></param>
  445. public static void SetCustomGameLoop(ref PlayerLoopSystem playerLoop)
  446. {
  447. #if false
  448. // debug
  449. foreach (var header in playerLoop.subSystemList)
  450. {
  451. Debug.LogFormat("------{0}------", header.type.Name);
  452. foreach (var subSystem in header.subSystemList)
  453. {
  454. Debug.LogFormat("{0}.{1}", header.type.Name, subSystem.type.Name);
  455. }
  456. }
  457. #endif
  458. PlayerLoopSystem afterEarlyUpdate = new PlayerLoopSystem()
  459. {
  460. type = typeof(MagicaPhysicsManager),
  461. updateDelegate = () =>
  462. {
  463. if (IsInstance())
  464. {
  465. Instance.AfterEarlyUpdate();
  466. }
  467. }
  468. };
  469. //PlayerLoopSystem beforeFixedUpdate = new PlayerLoopSystem()
  470. //{
  471. // type = typeof(MagicaPhysicsManager),
  472. // updateDelegate = () =>
  473. // {
  474. // if (IsInstance())
  475. // {
  476. // Instance.BeforeFixedUpdate();
  477. // }
  478. // }
  479. //};
  480. PlayerLoopSystem afterFixedUpdate = new PlayerLoopSystem()
  481. {
  482. type = typeof(MagicaPhysicsManager),
  483. updateDelegate = () =>
  484. {
  485. if (IsInstance())
  486. {
  487. Instance.AfterFixedUpdate();
  488. }
  489. }
  490. };
  491. PlayerLoopSystem afterUpdate = new PlayerLoopSystem()
  492. {
  493. type = typeof(MagicaPhysicsManager),
  494. updateDelegate = () =>
  495. {
  496. if (IsInstance())
  497. {
  498. Instance.AfterUpdate();
  499. }
  500. }
  501. };
  502. //PlayerLoopSystem beforeLateUpdate = new PlayerLoopSystem()
  503. //{
  504. // type = typeof(MagicaPhysicsManager),
  505. // updateDelegate = () =>
  506. // {
  507. // if (IsInstance())
  508. // {
  509. // Instance.BeforeLateUpdate();
  510. // }
  511. // }
  512. //};
  513. PlayerLoopSystem afterLateUpdate = new PlayerLoopSystem()
  514. {
  515. type = typeof(MagicaPhysicsManager),
  516. updateDelegate = () =>
  517. {
  518. if (IsInstance())
  519. {
  520. Instance.AfterLateUpdate();
  521. }
  522. }
  523. };
  524. PlayerLoopSystem postLateUpdate = new PlayerLoopSystem()
  525. {
  526. type = typeof(MagicaPhysicsManager),
  527. updateDelegate = () =>
  528. {
  529. if (IsInstance())
  530. {
  531. Instance.PostLateUpdate();
  532. }
  533. }
  534. };
  535. PlayerLoopSystem afterRendering = new PlayerLoopSystem()
  536. {
  537. type = typeof(MagicaPhysicsManager),
  538. updateDelegate = () =>
  539. {
  540. if (IsInstance())
  541. {
  542. Instance.AfterRendering();
  543. }
  544. }
  545. };
  546. int sysIndex = 0;
  547. int index = 0;
  548. // early update
  549. sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "EarlyUpdate");
  550. PlayerLoopSystem earlyUpdateSystem = playerLoop.subSystemList[sysIndex];
  551. var earlyUpdateSubsystemList = new List<PlayerLoopSystem>(earlyUpdateSystem.subSystemList);
  552. earlyUpdateSubsystemList.Add(afterEarlyUpdate);
  553. earlyUpdateSystem.subSystemList = earlyUpdateSubsystemList.ToArray();
  554. playerLoop.subSystemList[sysIndex] = earlyUpdateSystem;
  555. // fixed udpate
  556. //sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "FixedUpdate");
  557. //PlayerLoopSystem fixedUpdateSystem = playerLoop.subSystemList[sysIndex];
  558. //var fixedUpdateSubsystemList = new List<PlayerLoopSystem>(fixedUpdateSystem.subSystemList);
  559. //fixedUpdateSubsystemList.Insert(0, beforeFixedUpdate);
  560. //fixedUpdateSystem.subSystemList = fixedUpdateSubsystemList.ToArray();
  561. //playerLoop.subSystemList[sysIndex] = fixedUpdateSystem;
  562. // after fixed update
  563. sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "FixedUpdate");
  564. PlayerLoopSystem fixedUpdateSystem = playerLoop.subSystemList[sysIndex];
  565. var fixedUpdateSubsystemList = new List<PlayerLoopSystem>(fixedUpdateSystem.subSystemList);
  566. index = fixedUpdateSubsystemList.FindIndex(h => h.type.Name.Contains("ScriptRunBehaviourFixedUpdate"));
  567. fixedUpdateSubsystemList.Insert(index + 1, afterFixedUpdate); // FixedUpdate() after
  568. fixedUpdateSystem.subSystemList = fixedUpdateSubsystemList.ToArray();
  569. playerLoop.subSystemList[sysIndex] = fixedUpdateSystem;
  570. // update
  571. sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "Update");
  572. PlayerLoopSystem updateSystem = playerLoop.subSystemList[sysIndex];
  573. var updateSubsystemList = new List<PlayerLoopSystem>(updateSystem.subSystemList);
  574. index = updateSubsystemList.FindIndex(h => h.type.Name.Contains("ScriptRunDelayedDynamicFrameRate"));
  575. updateSubsystemList.Insert(index + 1, afterUpdate); // Update() after
  576. updateSystem.subSystemList = updateSubsystemList.ToArray();
  577. playerLoop.subSystemList[sysIndex] = updateSystem;
  578. // late update
  579. sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "PreLateUpdate");
  580. PlayerLoopSystem lateUpdateSystem = playerLoop.subSystemList[sysIndex];
  581. var lateUpdateSubsystemList = new List<PlayerLoopSystem>(lateUpdateSystem.subSystemList);
  582. index = lateUpdateSubsystemList.FindIndex(h => h.type.Name.Contains("ScriptRunBehaviourLateUpdate"));
  583. //lateUpdateSubsystemList.Insert(index, beforeLateUpdate); // LateUpdate() before
  584. //lateUpdateSubsystemList.Insert(index + 2, afterLateUpdate); // LateUpdate() after
  585. lateUpdateSubsystemList.Insert(index + 1, afterLateUpdate); // LateUpdate() after
  586. lateUpdateSystem.subSystemList = lateUpdateSubsystemList.ToArray();
  587. playerLoop.subSystemList[sysIndex] = lateUpdateSystem;
  588. // post late update
  589. sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "PostLateUpdate");
  590. PlayerLoopSystem postLateUpdateSystem = playerLoop.subSystemList[sysIndex];
  591. var postLateUpdateSubsystemList = new List<PlayerLoopSystem>(postLateUpdateSystem.subSystemList);
  592. index = postLateUpdateSubsystemList.FindIndex(h => h.type.Name.Contains("ScriptRunDelayedDynamicFrameRate"));
  593. postLateUpdateSubsystemList.Insert(index + 1, postLateUpdate); // postLateUpdate()
  594. postLateUpdateSystem.subSystemList = postLateUpdateSubsystemList.ToArray();
  595. playerLoop.subSystemList[sysIndex] = postLateUpdateSystem;
  596. // rendering
  597. sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "PostLateUpdate");
  598. PlayerLoopSystem postLateSystem = playerLoop.subSystemList[sysIndex];
  599. var postLateSubsystemList = new List<PlayerLoopSystem>(postLateSystem.subSystemList);
  600. index = postLateSubsystemList.FindIndex(h => h.type.Name.Contains("FinishFrameRendering"));
  601. postLateSubsystemList.Insert(index + 1, afterRendering); // rendering after
  602. postLateSystem.subSystemList = postLateSubsystemList.ToArray();
  603. playerLoop.subSystemList[sysIndex] = postLateSystem;
  604. }
  605. /// <summary>
  606. /// MagicaClothのカスタムループが登録されているかチェックする
  607. /// </summary>
  608. /// <param name="playerLoop"></param>
  609. /// <returns></returns>
  610. private static bool CheckRegist(ref PlayerLoopSystem playerLoop)
  611. {
  612. var t = typeof(MagicaPhysicsManager);
  613. foreach (var subloop in playerLoop.subSystemList)
  614. {
  615. if (subloop.subSystemList != null && subloop.subSystemList.Any(x => x.type == t))
  616. {
  617. return true;
  618. }
  619. }
  620. return false;
  621. }
  622. }
  623. }