BaseCloth.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using System.Collections.Generic;
  5. using Unity.Mathematics;
  6. using UnityEngine;
  7. using System.Linq;
  8. #if UNITY_EDITOR
  9. using UnityEditor;
  10. #endif
  11. namespace MagicaCloth
  12. {
  13. /// <summary>
  14. /// クロス基本クラス
  15. /// </summary>
  16. public abstract partial class BaseCloth : PhysicsTeam
  17. {
  18. /// <summary>
  19. /// パラメータ設定
  20. /// </summary>
  21. [SerializeField]
  22. protected ClothParams clothParams = new ClothParams();
  23. [SerializeField]
  24. protected List<int> clothParamDataHashList = new List<int>();
  25. /// <summary>
  26. /// クロスデータ
  27. /// </summary>
  28. [SerializeField]
  29. private ClothData clothData = null;
  30. [SerializeField]
  31. protected int clothDataHash;
  32. [SerializeField]
  33. protected int clothDataVersion;
  34. /// <summary>
  35. /// 頂点選択データ
  36. /// </summary>
  37. [SerializeField]
  38. private SelectionData clothSelection = null;
  39. [SerializeField]
  40. private int clothSelectionHash;
  41. [SerializeField]
  42. private int clothSelectionVersion;
  43. /// <summary>
  44. /// カリング用レンダラーリスト
  45. /// BoneCloth / BoneSpring で使用
  46. /// </summary>
  47. [SerializeField]
  48. private List<Renderer> cullRendererList = new List<Renderer>();
  49. /// <summary>
  50. /// ランタイムクロス設定
  51. /// </summary>
  52. protected ClothSetup setup = new ClothSetup();
  53. //=========================================================================================
  54. private float oldBlendRatio = -1.0f;
  55. private TeamUpdateMode oldUpdateMode = 0;
  56. private TeamCullingMode oldCullingMode = 0;
  57. private bool oldUseAnimatedDistance = false;
  58. //=========================================================================================
  59. /// <summary>
  60. /// データハッシュを求める
  61. /// </summary>
  62. /// <returns></returns>
  63. public override int GetDataHash()
  64. {
  65. int hash = base.GetDataHash();
  66. if (ClothData != null)
  67. hash += ClothData.GetDataHash();
  68. if (ClothSelection != null)
  69. hash += ClothSelection.GetDataHash();
  70. return hash;
  71. }
  72. //=========================================================================================
  73. public ClothParams Params
  74. {
  75. get
  76. {
  77. return clothParams;
  78. }
  79. }
  80. public ClothData ClothData
  81. {
  82. get
  83. {
  84. #if UNITY_EDITOR
  85. if (Application.isPlaying)
  86. return clothData;
  87. else
  88. {
  89. // unity2019.3で参照がnullとなる不具合の対処(臨時)
  90. var so = new SerializedObject(this);
  91. return so.FindProperty("clothData").objectReferenceValue as ClothData;
  92. }
  93. #else
  94. return clothData;
  95. #endif
  96. }
  97. set
  98. {
  99. clothData = value;
  100. }
  101. }
  102. public SelectionData ClothSelection
  103. {
  104. get
  105. {
  106. #if UNITY_EDITOR
  107. if (Application.isPlaying)
  108. return clothSelection;
  109. else
  110. {
  111. // unity2019.3で参照がnullとなる不具合の対処(臨時)
  112. var so = new SerializedObject(this);
  113. return so.FindProperty("clothSelection").objectReferenceValue as SelectionData;
  114. }
  115. #else
  116. return clothSelection;
  117. #endif
  118. }
  119. }
  120. public ClothSetup Setup
  121. {
  122. get
  123. {
  124. return setup;
  125. }
  126. }
  127. //=========================================================================================
  128. protected virtual void Reset()
  129. {
  130. }
  131. protected virtual void OnValidate()
  132. {
  133. if (Application.isPlaying == false)
  134. return;
  135. // クロスパラメータのラインタイム変更
  136. setup.ChangeData(this, clothParams, clothData);
  137. }
  138. //=========================================================================================
  139. protected override void OnInit()
  140. {
  141. base.OnInit();
  142. BaseClothInit();
  143. }
  144. protected override void OnActive()
  145. {
  146. base.OnActive();
  147. // パーティクル有効化
  148. EnableParticle(UserTransform, UserTransformLocalPosition, UserTransformLocalRotation);
  149. // コライダー状態更新
  150. TeamData.UpdateStatus();
  151. SetUseMesh(true);
  152. ClothActive();
  153. }
  154. protected override void OnInactive()
  155. {
  156. base.OnInactive();
  157. // パーティクル無効化
  158. DisableParticle(UserTransform, UserTransformLocalPosition, UserTransformLocalRotation);
  159. SetUseMesh(false);
  160. ClothInactive();
  161. }
  162. protected override void OnDispose()
  163. {
  164. BaseClothDispose();
  165. base.OnDispose();
  166. }
  167. //=========================================================================================
  168. internal override void UpdateCullingMode(CoreComponent caller)
  169. {
  170. //Debug.Log($"UpdateCullingMode [{this.name}]");
  171. // カリングモード
  172. bool isBoneCloth = GetComponentType() == ComponentType.BoneCloth || GetComponentType() == ComponentType.BoneSpring;
  173. if (CullingMode != TeamCullingMode.Off && isBoneCloth && cullRendererList.Count == 0)
  174. {
  175. // BoneCloth/BoneSpringだが参照レンダラーが設定されていないので強制的にカリングをOFFに設定する
  176. CullingMode = TeamCullingMode.Off;
  177. }
  178. // deformer
  179. CoreComponent vd = GetDeformer()?.Parent;
  180. // 表示状態
  181. bool visible = false;
  182. if (CullingMode == TeamCullingMode.Off)
  183. {
  184. visible = true;
  185. }
  186. else if (IsActive()) // 起動中のみ
  187. {
  188. if (isBoneCloth)
  189. {
  190. // カリング用レンダラーリストから判定する
  191. if (cullRendererList.Count > 0)
  192. {
  193. foreach (var ren in cullRendererList)
  194. {
  195. if (ren && ren.isVisible)
  196. {
  197. visible = true;
  198. break;
  199. }
  200. }
  201. }
  202. else
  203. {
  204. // 未設定は念の為動作させておく
  205. visible = true;
  206. }
  207. }
  208. else
  209. {
  210. // デフォーマーの表示状態から判定する
  211. visible = vd ? vd.IsVisible : false;
  212. }
  213. }
  214. IsVisible = visible;
  215. // 計算状態
  216. bool stopInvisible = (CullingMode != TeamCullingMode.Off);
  217. bool calc = true;
  218. if (stopInvisible)
  219. {
  220. calc = visible;
  221. }
  222. int val = calc ? 1 : 0;
  223. // コンポーネントアクティブ状態
  224. val = Status.IsActive ? val : 0;
  225. // 最終判定
  226. if (calculateValue != val)
  227. {
  228. calculateValue = val;
  229. OnChangeCalculation();
  230. }
  231. // デフォーマーへ伝達
  232. if (vd && vd != caller)
  233. GetDeformer()?.Parent?.UpdateCullingMode(this);
  234. }
  235. protected override void OnChangeCalculation()
  236. {
  237. //Debug.Log($"Cloth [{this.name}] Visible:{IsVisible} Calc:{IsCalculate} F:{Time.frameCount}");
  238. MagicaPhysicsManager.Instance.Team.SetFlag(teamId, PhysicsManagerTeamData.Flag_Pause, !IsCalculate);
  239. if (IsCalculate)
  240. {
  241. // 一時停止再開によるリセット
  242. if (CullingMode == TeamCullingMode.Reset)
  243. {
  244. //Debug.Log($"Reset cloth! [{this.name}] F:{Time.frameCount}");
  245. ResetCloth(ClothParams.TeleportMode.Reset);
  246. }
  247. // デフォーマの未来予測をリセットする
  248. // 遅延実行+再アクティブ時のみ
  249. //if (MagicaPhysicsManager.Instance.IsDelay && ActiveCount > 1)
  250. if (MagicaPhysicsManager.Instance.IsDelay)
  251. {
  252. GetDeformer()?.ResetFuturePrediction();
  253. }
  254. // コライダーボーンの未来予測をリセットする
  255. // 遅延実行+再アクティブ時のみ
  256. //if (MagicaPhysicsManager.Instance.IsDelay && ActiveCount > 1)
  257. if (MagicaPhysicsManager.Instance.IsDelay)
  258. {
  259. MagicaPhysicsManager.Instance.Team.ResetFuturePredictionCollidere(TeamId);
  260. }
  261. }
  262. }
  263. public int GetCullRenderListCount()
  264. {
  265. if (cullRendererList == null)
  266. return 0;
  267. return cullRendererList.Count(x => x != null);
  268. }
  269. //=========================================================================================
  270. void BaseClothInit()
  271. {
  272. // デフォーマー初期化
  273. if (IsRequiresDeformer())
  274. {
  275. var deformer = GetDeformer();
  276. if (deformer == null)
  277. {
  278. Status.SetInitError();
  279. return;
  280. }
  281. // デフォーマーと状態を連動
  282. var component = deformer.Parent;
  283. Status.LinkParentStatus(component.Status); // デフォーマーが親、クロスコンポーネントが子
  284. component.Init();
  285. if (component.Status.IsInitError)
  286. {
  287. Status.SetInitError();
  288. return;
  289. }
  290. }
  291. if (VerifyData() != Define.Error.None)
  292. {
  293. Status.SetInitError();
  294. return;
  295. }
  296. // クロス初期化
  297. ClothInit();
  298. // クロス初期化後の主にワーカーへの登録
  299. WorkerInit();
  300. // 頂点有効化
  301. SetUseVertex(true);
  302. // 更新モード記録
  303. oldUpdateMode = UpdateMode;
  304. oldCullingMode = CullingMode;
  305. oldUseAnimatedDistance = UseAnimatedPose;
  306. // UnityPhysics更新モードによる各種設定
  307. if (UpdateMode == TeamUpdateMode.UnityPhysics)
  308. SetUseUnityPhysics(true);
  309. }
  310. void BaseClothDispose()
  311. {
  312. if (MagicaPhysicsManager.IsInstance() == false)
  313. return;
  314. // デフォーマとの状態の連動を解除
  315. var deformer = GetDeformer();
  316. if (deformer != null)
  317. {
  318. var component = deformer.Parent;
  319. Status.UnlinkParentStatus(component.Status);
  320. }
  321. if (Status.IsInitSuccess)
  322. {
  323. // 頂点無効化
  324. SetUseVertex(false);
  325. // クロス破棄
  326. // この中ですべてのコンストレイントとワーカーからチームのデータが自動削除される
  327. setup.ClothDispose(this);
  328. ClothDispose();
  329. }
  330. }
  331. /// <summary>
  332. /// クロス初期化
  333. /// </summary>
  334. protected virtual void ClothInit()
  335. {
  336. setup.ClothInit(this, GetMeshData(), ClothData, clothParams, UserFlag);
  337. }
  338. protected virtual void ClothActive()
  339. {
  340. setup.ClothActive(this, clothParams, ClothData);
  341. // アニメーションされた距離の使用設定
  342. MagicaPhysicsManager.Instance.Team.SetFlag(TeamId, PhysicsManagerTeamData.Flag_AnimatedPose, UseAnimatedPose);
  343. }
  344. protected virtual void ClothInactive()
  345. {
  346. setup.ClothInactive(this);
  347. }
  348. protected virtual void ClothDispose()
  349. {
  350. }
  351. /// <summary>
  352. /// 頂点ごとのパーティクルフラグ設定(不要な場合は0)
  353. /// </summary>
  354. /// <param name="vindex"></param>
  355. /// <returns></returns>
  356. protected abstract uint UserFlag(int vindex);
  357. /// <summary>
  358. /// 頂点ごとの連動トランスフォーム設定(不要な場合はnull)
  359. /// </summary>
  360. /// <param name="vindex"></param>
  361. /// <returns></returns>
  362. protected abstract Transform UserTransform(int vindex);
  363. /// <summary>
  364. /// 頂点ごとの連動トランスフォームのLocalPositionを返す(不要な場合は0)
  365. /// </summary>
  366. /// <param name="vindex"></param>
  367. /// <returns></returns>
  368. protected abstract float3 UserTransformLocalPosition(int vindex);
  369. /// <summary>
  370. /// 頂点ごとの連動トランスフォームのLocalRotationを返す(不要な場合はquaternion.identity)
  371. /// </summary>
  372. /// <param name="vindex"></param>
  373. /// <returns></returns>
  374. protected abstract quaternion UserTransformLocalRotation(int vindex);
  375. /// <summary>
  376. /// デフォーマーが必須か返す
  377. /// </summary>
  378. /// <returns></returns>
  379. public abstract bool IsRequiresDeformer();
  380. /// <summary>
  381. /// デフォーマーを返す
  382. /// </summary>
  383. /// <param name="index"></param>
  384. /// <returns></returns>
  385. public abstract BaseMeshDeformer GetDeformer();
  386. /// <summary>
  387. /// クロス初期化時に必要なMeshDataを返す(不要ならnull)
  388. /// </summary>
  389. /// <returns></returns>
  390. protected abstract MeshData GetMeshData();
  391. /// <summary>
  392. /// クロス初期化後の主にワーカーへの登録
  393. /// </summary>
  394. protected abstract void WorkerInit();
  395. //=========================================================================================
  396. /// <summary>
  397. /// 使用デフォーマー設定
  398. /// </summary>
  399. /// <param name="sw"></param>
  400. void SetUseMesh(bool sw)
  401. {
  402. if (MagicaPhysicsManager.IsInstance() == false)
  403. return;
  404. if (Status.IsInitSuccess == false)
  405. return;
  406. var deformer = GetDeformer();
  407. if (deformer != null)
  408. {
  409. if (sw)
  410. deformer.AddUseMesh(this);
  411. else
  412. deformer.RemoveUseMesh(this);
  413. }
  414. }
  415. /// <summary>
  416. /// 使用頂点設定
  417. /// </summary>
  418. /// <param name="sw"></param>
  419. void SetUseVertex(bool sw)
  420. {
  421. if (MagicaPhysicsManager.IsInstance() == false)
  422. return;
  423. var deformer = GetDeformer();
  424. if (deformer != null)
  425. {
  426. SetDeformerUseVertex(sw, deformer);
  427. }
  428. }
  429. /// <summary>
  430. /// デフォーマーの使用頂点設定
  431. /// 使用頂点に対して AddUseVertex() / RemoveUseVertex() を実行する
  432. /// </summary>
  433. /// <param name="sw"></param>
  434. /// <param name="deformer"></param>
  435. protected abstract void SetDeformerUseVertex(bool sw, BaseMeshDeformer deformer);
  436. /// <summary>
  437. /// デフォーマーに対してアクションを実行する
  438. /// </summary>
  439. /// <param name="act"></param>
  440. internal void DeformerForEach(System.Action<BaseMeshDeformer> act)
  441. {
  442. var deformer = GetDeformer();
  443. if (deformer != null)
  444. {
  445. act(deformer);
  446. }
  447. }
  448. //=========================================================================================
  449. /// <summary>
  450. /// ブレンド率更新
  451. /// </summary>
  452. public void UpdateBlend()
  453. {
  454. if (teamId <= 0)
  455. return;
  456. // ユーザーブレンド率
  457. float blend = UserBlendWeight;
  458. // 距離ブレンド率
  459. blend *= setup.DistanceBlendRatio;
  460. // 変更チェック
  461. blend = Mathf.Clamp01(blend);
  462. if (blend != oldBlendRatio)
  463. {
  464. // チームデータへ反映
  465. MagicaPhysicsManager.Instance.Team.SetBlendRatio(teamId, blend);
  466. // コンポーネント有効化判定
  467. SetUserEnable(blend >= 1e-03f);
  468. oldBlendRatio = blend;
  469. }
  470. // カリングモード変更
  471. if (CullingMode != oldCullingMode)
  472. {
  473. // 反映
  474. UpdateCullingMode(this);
  475. oldCullingMode = CullingMode;
  476. }
  477. // 更新モード変更
  478. if (UpdateMode != oldUpdateMode)
  479. {
  480. // チームデータへ反映
  481. //Debug.Log($"Change Update Mode:{UpdateMode}");
  482. MagicaPhysicsManager.Instance.Team.SetUpdateMode(TeamId, UpdateMode);
  483. // チームのパーティクルおよびボーンに反映
  484. SetUseUnityPhysics(UpdateMode == TeamUpdateMode.UnityPhysics);
  485. oldUpdateMode = UpdateMode;
  486. }
  487. // アニメーションされた距離の使用
  488. if (UseAnimatedPose != oldUseAnimatedDistance)
  489. {
  490. // チームデータへ反映
  491. MagicaPhysicsManager.Instance.Team.SetFlag(TeamId, PhysicsManagerTeamData.Flag_AnimatedPose, UseAnimatedPose);
  492. oldUseAnimatedDistance = UseAnimatedPose;
  493. }
  494. }
  495. //=========================================================================================
  496. /// <summary>
  497. /// ボーンを置換する
  498. /// </summary>
  499. /// <param name="boneReplaceDict"></param>
  500. public override void ReplaceBone<T>(Dictionary<T, Transform> boneReplaceDict)
  501. {
  502. base.ReplaceBone(boneReplaceDict);
  503. // セットアップデータのボーン置換
  504. setup.ReplaceBone(this, clothParams, boneReplaceDict);
  505. }
  506. /// <summary>
  507. /// 現在使用しているボーンを格納して返す
  508. /// </summary>
  509. /// <returns></returns>
  510. public override HashSet<Transform> GetUsedBones()
  511. {
  512. var bones = base.GetUsedBones();
  513. // セットアップデータのボーン取得
  514. bones.UnionWith(setup.GetUsedBones(this, clothParams));
  515. return bones;
  516. }
  517. //=========================================================================================
  518. /// <summary>
  519. /// UnityPhyiscsでの更新の変更
  520. /// 継承クラスは自身の使用するボーンの状態更新などを記述する
  521. /// </summary>
  522. /// <param name="sw"></param>
  523. protected override void ChangeUseUnityPhysics(bool sw)
  524. {
  525. if (teamId <= 0)
  526. return;
  527. setup.ChangeUseUnityPhysics(sw);
  528. MagicaPhysicsManager.Instance.Team.ChangeUseUnityPhysics(TeamId, sw);
  529. }
  530. //=========================================================================================
  531. /// <summary>
  532. /// データを検証して結果を格納する
  533. /// </summary>
  534. /// <returns></returns>
  535. public override void CreateVerifyData()
  536. {
  537. base.CreateVerifyData();
  538. clothDataHash = ClothData != null ? ClothData.SaveDataHash : 0;
  539. clothDataVersion = ClothData != null ? ClothData.SaveDataVersion : 0;
  540. clothSelectionHash = ClothSelection != null ? ClothSelection.SaveDataHash : 0;
  541. clothSelectionVersion = ClothSelection != null ? ClothSelection.SaveDataVersion : 0;
  542. // パラメータハッシュ
  543. clothParamDataHashList.Clear();
  544. for (int i = 0; i < (int)ClothParams.ParamType.Max; i++)
  545. {
  546. int paramHash = clothParams.GetParamHash(this, (ClothParams.ParamType)i);
  547. clothParamDataHashList.Add(paramHash);
  548. }
  549. }
  550. /// <summary>
  551. /// 現在のデータが正常(実行できる状態)か返す
  552. /// </summary>
  553. /// <returns></returns>
  554. public override Define.Error VerifyData()
  555. {
  556. var baseError = base.VerifyData();
  557. if (baseError != Define.Error.None)
  558. return baseError;
  559. // clothDataはオプション
  560. if (ClothData != null)
  561. {
  562. var clothDataError = ClothData.VerifyData();
  563. if (clothDataError != Define.Error.None)
  564. return clothDataError;
  565. if (clothDataHash != ClothData.SaveDataHash)
  566. return Define.Error.ClothDataHashMismatch;
  567. if (clothDataVersion != ClothData.SaveDataVersion)
  568. return Define.Error.ClothDataVersionMismatch;
  569. }
  570. // clothSelectionはオプション
  571. if (ClothSelection != null)
  572. {
  573. var clothSelectionError = ClothSelection.VerifyData();
  574. if (clothSelectionError != Define.Error.None)
  575. return clothSelectionError;
  576. if (clothSelectionHash != ClothSelection.SaveDataHash)
  577. return Define.Error.ClothSelectionHashMismatch;
  578. if (clothSelectionVersion != ClothSelection.SaveDataVersion)
  579. return Define.Error.ClothSelectionVersionMismatch;
  580. }
  581. return Define.Error.None;
  582. }
  583. /// <summary>
  584. /// パラメータに重要な変更が発生したか調べる
  585. /// 重要な変更はデータを作り直す必要を指している
  586. /// </summary>
  587. /// <param name="ptype"></param>
  588. /// <returns></returns>
  589. public bool HasChangedParam(ClothParams.ParamType ptype)
  590. {
  591. int index = (int)ptype;
  592. if (clothParamDataHashList.Count == 0)
  593. return false;
  594. if (index >= clothParamDataHashList.Count)
  595. {
  596. return true;
  597. }
  598. int hash = clothParams.GetParamHash(this, ptype);
  599. if (hash == 0)
  600. return false;
  601. return clothParamDataHashList[index] != hash;
  602. }
  603. /// <summary>
  604. /// アルゴリズムバージョンチェック
  605. /// </summary>
  606. /// <returns></returns>
  607. public Define.Error VerifyAlgorithmVersion()
  608. {
  609. if (clothData == null)
  610. return Define.Error.None;
  611. if (clothData.clampRotationAlgorithm != ClothParams.Algorithm.Algorithm_2)
  612. return Define.Error.OldAlgorithm;
  613. if (clothData.restoreRotationAlgorithm != ClothParams.Algorithm.Algorithm_2)
  614. return Define.Error.OldAlgorithm;
  615. if (clothData.triangleBendAlgorithm != ClothParams.Algorithm.Algorithm_2)
  616. return Define.Error.OldAlgorithm;
  617. return Define.Error.None;
  618. }
  619. /// <summary>
  620. /// データフォーマットを最新に更新する
  621. /// 主に古いパラメータを最新のパラメータに変換する
  622. /// </summary>
  623. /// <returns>true=更新あり, false=更新なし</returns>
  624. public override bool UpgradeFormat()
  625. {
  626. bool change = false;
  627. // アルゴリズム
  628. if (clothParams.AlgorithmType == ClothParams.Algorithm.Algorithm_1)
  629. {
  630. // アルゴリズム[2]へアップグレード
  631. clothParams.AlgorithmType = ClothParams.Algorithm.Algorithm_2;
  632. clothParams.ConvertToLatestAlgorithmParameter();
  633. change = true;
  634. }
  635. return change;
  636. }
  637. //=========================================================================================
  638. /// <summary>
  639. /// 共有データオブジェクト収集
  640. /// </summary>
  641. /// <returns></returns>
  642. public override List<ShareDataObject> GetAllShareDataObject()
  643. {
  644. var sdata = base.GetAllShareDataObject();
  645. sdata.Add(ClothData);
  646. sdata.Add(ClothSelection);
  647. return sdata;
  648. }
  649. /// <summary>
  650. /// sourceの共有データを複製して再セットする
  651. /// 再セットした共有データを返す
  652. /// </summary>
  653. /// <param name="source"></param>
  654. /// <returns></returns>
  655. public override ShareDataObject DuplicateShareDataObject(ShareDataObject source)
  656. {
  657. if (ClothData == source)
  658. {
  659. //clothData = Instantiate(ClothData);
  660. clothData = ShareDataObject.Clone(ClothData);
  661. return clothData;
  662. }
  663. if (ClothSelection == source)
  664. {
  665. //clothSelection = Instantiate(ClothSelection);
  666. clothSelection = ShareDataObject.Clone(ClothSelection);
  667. return clothSelection;
  668. }
  669. return null;
  670. }
  671. //=========================================================================================
  672. /// <summary>
  673. /// シミュレーションリセットAPIの内部実装
  674. /// </summary>
  675. /// <param name="teleportMode"></param>
  676. /// <param name="resetStabilizationTime"></param>
  677. private void ResetClothInternal(ClothParams.TeleportMode teleportMode, float resetStabilizationTime)
  678. {
  679. if (IsValid())
  680. {
  681. switch (teleportMode)
  682. {
  683. case ClothParams.TeleportMode.Reset:
  684. MagicaPhysicsManager.Instance.Team.SetFlag(teamId, PhysicsManagerTeamData.Flag_Reset_WorldInfluence, true);
  685. MagicaPhysicsManager.Instance.Team.SetFlag(teamId, PhysicsManagerTeamData.Flag_Reset_Position, true);
  686. MagicaPhysicsManager.Instance.Team.SetFlag(teamId, PhysicsManagerTeamData.Flag_Reset_Keep, false);
  687. MagicaPhysicsManager.Instance.Team.ResetStabilizationTime(teamId, resetStabilizationTime);
  688. break;
  689. case ClothParams.TeleportMode.Keep:
  690. MagicaPhysicsManager.Instance.Team.SetFlag(teamId, PhysicsManagerTeamData.Flag_Reset_WorldInfluence, false);
  691. MagicaPhysicsManager.Instance.Team.SetFlag(teamId, PhysicsManagerTeamData.Flag_Reset_Position, false);
  692. MagicaPhysicsManager.Instance.Team.SetFlag(teamId, PhysicsManagerTeamData.Flag_Reset_Keep, true);
  693. break;
  694. }
  695. }
  696. }
  697. }
  698. }