using System;
using UnityEngine;

public class BoneHair3
{
	public BoneHair3(TBodySkin bodyskin)
	{
		this.m_BodySkin = bodyskin;
		this.m_Body = bodyskin.body;
	}

	public void WarpInit()
	{
		if (this.m_SkirtBone != null)
		{
			this.m_SkirtBone.m_bResetPos = true;
		}
	}

	public void Init()
	{
	}

	public void Uninit()
	{
		if (this.m_SkirtBone != null)
		{
			this.m_SkirtBone.Uninit();
			UnityEngine.Object.DestroyImmediate(this.m_SkirtBone);
			this.m_SkirtBone = null;
		}
	}

	public bool InitGameObject(GameObject f_goRoot, MPN f_mpn)
	{
		if (!this.m_Body.m_bNewSkirtPhyscs)
		{
			return false;
		}
		Transform transform = this.SearchSkirtBone(f_goRoot.transform);
		if (transform == null)
		{
			return false;
		}
		Transform parent = transform.parent;
		NDebug.Assert(this.m_SkirtBone == null, () => "DynamicSkirtBoneコンポーネントが二重に付けられました。");
		string f_strFileName = f_goRoot.name.Replace("_SM_", string.Empty);
		DynamicSkirtBone dynamicSkirtBone = ImportCM.TryLoadDynamicSkirtBone(f_goRoot, parent, f_strFileName, this.m_BodySkin.body);
		if (dynamicSkirtBone == null)
		{
			string f_strFileName2 = "default_skirt";
			dynamicSkirtBone = ImportCM.TryLoadDynamicSkirtBone(f_goRoot, parent, f_strFileName2, this.m_BodySkin.body);
			if (dynamicSkirtBone == null)
			{
				return false;
			}
		}
		this.m_SkirtBone = dynamicSkirtBone;
		this.m_SkirtBone.InitGameObject(f_goRoot, this.m_BodySkin, parent);
		this.WarpInit();
		return true;
	}

	private Transform SearchSkirtBone(Transform f_goParent)
	{
		if (f_goParent.name.Contains("_yure_skirt_"))
		{
			return f_goParent;
		}
		for (int i = 0; i < f_goParent.childCount; i++)
		{
			Transform transform = this.SearchSkirtBone(f_goParent.GetChild(i));
			if (transform != null)
			{
				return transform;
			}
		}
		return null;
	}

	public void UpdateSelf()
	{
		if (this.m_SkirtBone != null)
		{
			this.m_SkirtBone.UpdateSelf();
		}
	}

	private TBody m_Body;

	private TBodySkin m_BodySkin;

	private DynamicSkirtBone m_SkirtBone;
}
