MagicaCloth

概要

すべてのクロスコンポーネントの取りまとめを行う重要なMonoBehaviourクラスです。
通常はエディタ環境でGameObjectに取り付けますが、すべてをスクリプトから構築することも可能です。
また、実行中にパラメータを操作して振る舞いを変えることも可能です。

スクリプトからの構築や操作は実行時スクリプトのページを参照してください。

Properties


serializeData

/// <summary>
/// Serialize data (1).
/// Basic parameters.
/// Import/export target.
/// Can be rewritten at runtime.
/// </summary>
[SerializeField]
private ClothSerializeData serializeData = new ClothSerializeData();
public ClothSerializeData SerializeData => serializeData;

実行時に操作可能なパラメータを保持します。
スクリプトからは主にこのクラスを操作します。
詳細はClothSerializeDataを参照してください。

OnBuildComplete

/// <summary>
/// クロスデータ構築完了後イベント
/// Event after completion of cloth data construction.
/// (true = Success, false = Failure)
/// </summary>
public Action<bool> OnBuildComplete;

Methods


IsValid

/// <summary>
/// Check if the cloth component is in a valid state.
/// クロスコンポーネントが有効な状態か確認します。
/// </summary>
/// <returns></returns>
public bool IsValid()

Initialize

/// <summary>
/// 初期化を実行します
/// すでに初期化済みの場合は何もしません。
/// perform initialization.
/// If already initialized, do nothing.
/// </summary>
public void Initialize()

DisableAutoBuild

/// <summary>
/// コンポーネントのStart()で実行される自動ビルドを無効にします
/// Disable automatic builds that run on the component's Start().
/// </summary>
public void DisableAutoBuild()

BuildAndRun

/// <summary>
/// コンポーネントを構築し実行します
/// すべてのデータをセットアップしたあとに呼び出す必要があります
/// build and run the component.
/// Must be called after setting up all data.
/// </summary>
/// <returns>true=start build. false=build failed.</returns>
public bool BuildAndRun()

ReplaceTransform

/// <summary>
/// コンポーネントが保持するトランスフォームを置換します。
/// 置換先のトランスフォーム名をキーとした辞書を渡します。
/// Replaces a component's transform.
/// Passes a dictionary keyed by the name of the transform to be replaced.
/// </summary>
/// <param name="targetTransformDict">Dictionary keyed by the name of the transform to be replaced.</param>
public void ReplaceTransform(Dictionary<string, Transform> targetTransformDict)

SetParameterChange

/// <summary>
/// パラメータの変更を通知
/// 実行中にパラメータを変更した場合はこの関数を呼ぶ必要があります
/// You should call this function if you changed parameters during execution.
/// </summary>
public void SetParameterChange()

SetTimeScale

/// <summary>
/// タイムスケールを変更します
/// Change the time scale.
/// </summary>
/// <param name="timeScale">0.0-1.0</param>
public void SetTimeScale(float timeScale)

GetTimeScale

/// <summary>
/// タイムスケールを取得します
/// Get the time scale.
/// </summary>
/// <returns></returns>
public float GetTimeScale()

ResetCloth

/// <summary>
/// シミュレーションを初期状態にリセットします
/// Reset the simulation to its initial state.
/// </summary>
/// <param name="keepPose">If true, resume while maintaining posture.</param>
public void ResetCloth(bool keepPose = false)

GetCenterPosition

/// <summary>
/// 慣性の中心座標を取得します
/// Get the center of inertia position.
/// </summary>
/// <returns></returns>
public Vector3 GetCenterPosition()

GetSerializeData2

/// <summary>
/// シリアライズデータ2の取得
/// SerializeData2クラスはシステムが利用するパラメータクラスです。
/// そのためユーザーによる変更は推奨されていません。
///
/// Acquisition of SerializedData2.
/// The SerializeData2 class is a parameter class used by the system.
/// Therefore, user modification is not recommended.
/// </summary>
/// <returns></returns>
public ClothSerializeData2 GetSerializeData2()

AddForce

/// <summary>
/// 外力を加えます
/// Add external force.
/// </summary>
/// <param name="forceDirection"></param>
/// <param name="forceVelocity">(m/s)</param>
/// <param name="fmode"></param>
public void AddForce(Vector3 forceDirection, float forceVelocity, ClothForceMode fmode = ClothForceMode.VelocityAdd)
public enum ClothForceMode
{
  None,

  /// <summary>
  /// 速度に加算(深さの影響を受ける)
  /// Add to velocity (affected by depth).
  /// </summary>
  VelocityAdd,

  /// <summary>
  /// 速度を変更(深さの影響を受ける)
  /// Change velocity (affected by depth).
  /// </summary>
  VelocityChange,

  /// <summary>
  /// 速度に加算(深さ無視)
  /// Add to velocity (ignoring depth).
  /// </summary>
  VelocityAddWithoutDepth = 10,

  /// <summary>
  /// 速度を変更(深さ無視)
  /// Change velocity (ignoring depth).
  /// </summary>
  VelocityChangeWithoutDepth,
}

SetSkipWriting

/// <summary>
/// TransformおよびMeshへの書き込みを禁止または許可します
/// この機能を使うことでストップモーションを実装することが可能です
/// Prevent or allow writing to Transform and Mesh.
/// By using this function, it is possible to implement stop motion.
/// </summary>
/// <param name="sw">true=write disabled, false=write enabled</param>
public void SetSkipWriting(bool sw)
{
  if (IsValid())
  {
    Process.SetSkipWriting(sw);
  }
}