// Magica Cloth.
// Copyright (c) MagicaSoft, 2020-2022.
// https://magicasoft.jp
using UnityEngine;
namespace MagicaCloth
{
[System.Serializable]
public class SpringData : ShareDataObject
{
///
/// データバージョン
///
private const int DATA_VERSION = 2;
///
/// 各デフォーマーの状態
///
[System.Serializable]
public class DeformerData : IDataHash
{
///
/// デフォーマーハッシュ
///
public int deformerDataHash;
///
/// デフォーマーの頂点数
///
public int vertexCount;
///
/// 使用頂点番号リスト
///
public int[] useVertexIndexList;
///
/// 使用頂点のウエイト値
///
public float[] weightList;
public int UseVertexCount
{
get
{
if (useVertexIndexList != null)
return useVertexIndexList.Length;
return 0;
}
}
public int GetDataHash()
{
int hash = 0;
hash += deformerDataHash;
hash += vertexCount.GetDataHash();
hash += UseVertexCount.GetDataHash();
return hash;
}
}
public DeformerData deformerData;
///
/// 設計時のスケール(WorldInfluenceのInfluenceTargetが基準)
///
public Vector3 initScale;
//=========================================================================================
///
/// データハッシュ計算
///
///
public override int GetDataHash()
{
int hash = 0;
if (deformerData != null)
hash += deformerData.GetDataHash();
return hash;
}
//=========================================================================================
public int UseVertexCount
{
get
{
int cnt = 0;
if (deformerData != null)
cnt += deformerData.UseVertexCount;
return cnt;
}
}
//=========================================================================================
public override int GetVersion()
{
return DATA_VERSION;
}
///
/// 現在のデータが正常(実行できる状態)か返す
///
///
public override Define.Error VerifyData()
{
if (dataHash == 0)
return Define.Error.InvalidDataHash;
//if (dataVersion != GetVersion())
// return Define.Error.DataVersionMismatch;
if (deformerData == null)
return Define.Error.DeformerNull;
return Define.Error.None;
}
}
}