// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Eden.AutoMorpher.profile.EdenAutoMorpher_ProfileSaver
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

public class EdenAutoMorpher_ProfileSaver : MonoBehaviour
{
    public Transform sourceAvatar;

    public List<SkinnedMeshRenderer> sourceBodyMeshes = new List<SkinnedMeshRenderer>();

    public string profileName;

    private const float adjustHigh = 1.5f;

    [ContextMenu("SaveProfile")]
    public void SaveProfile()
    {
        Vector3 position = this.sourceAvatar.position;
        Quaternion rotation = this.sourceAvatar.rotation;
        Vector3 localScale = this.sourceAvatar.localScale;
        Transform parent = this.sourceAvatar.parent;
        this.sourceAvatar.SetParent(null);
        this.sourceAvatar.position = Vector3.zero;
        this.sourceAvatar.rotation = Quaternion.identity;
        this.sourceAvatar.localScale = Vector3.one;
        ProfileData newProfileData = new ProfileData();
        ProfileUtils profileUtils = new ProfileUtils();
        newProfileData.version = profileUtils.GetProfileVersion();
        Animator component = this.sourceAvatar.GetComponent<Animator>();
        if (component == null)
        {
            Debug.LogError("[EdenAutoMorpher_ProfileSaver] Source Avatar Has No Animator\nSet Animator to Source Avatar " + this.sourceAvatar.name);
        }
        Dictionary<HumanBodyBones, HashSet<Transform>> humanoidMeshBoneMap = profileUtils.GetHumanoidMeshBoneMap(component, this.sourceBodyMeshes);
        List<ProfileBakedBodyMesh> list = new List<ProfileBakedBodyMesh>();
        foreach (SkinnedMeshRenderer sourceBodyMesh in this.sourceBodyMeshes)
        {
            list.Add(new ProfileBakedBodyMesh(sourceBodyMesh));
        }
        this.SaveBoneData(ref newProfileData, this.sourceAvatar, humanoidMeshBoneMap, list);
        ProfileUtils_BVHUtil profileUtils_BVHUtil = new ProfileUtils_BVHUtil();
        ProfileBVH bVHData = profileUtils_BVHUtil.GetBVHData(this.sourceAvatar, list);
        profileUtils_BVHUtil.SaveProfileBVH(bVHData, Path.Combine(profileUtils.GetProfileBasePath(), this.profileName), this.profileName);
        newProfileData.neckTargetHeight = 1.5f;
        this.AdjustAvatarHigh(this.sourceAvatar, humanoidMeshBoneMap, 1.5f);
        foreach (ProfileBakedBodyMesh item in list)
        {
            item.ReBakeMesh();
        }
        this.SaveSpatialData(ref newProfileData, humanoidMeshBoneMap, list);
        this.SaveProfileToJson(newProfileData, Path.Combine(profileUtils.GetProfileBasePath(), this.profileName), this.profileName);
        this.sourceAvatar.SetParent(parent);
        this.sourceAvatar.position = position;
        this.sourceAvatar.rotation = rotation;
        this.sourceAvatar.localScale = localScale;
    }

    public void SaveSpatialData(ref ProfileData newProfileData, Dictionary<HumanBodyBones, HashSet<Transform>> sourceBoneMap, List<ProfileBakedBodyMesh> sourceBodyBakedMeshes)
    {
        ProfileUtils profileUtils = new ProfileUtils();
        HumanBodyBones[] influencedBones = new HumanBodyBones[1] { HumanBodyBones.Neck };
        newProfileData.NeckSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Neck, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.LeftUpperArm,
            HumanBodyBones.LeftLowerArm,
            HumanBodyBones.LeftHand
        };
        newProfileData.LeftUpperArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftUpperArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.RightUpperArm,
            HumanBodyBones.RightLowerArm,
            HumanBodyBones.RightHand
        };
        newProfileData.RightUpperArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightUpperArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLowerArm };
        newProfileData.LeftLowerArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLowerArm };
        newProfileData.RightLowerArmSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftHand };
        newProfileData.LeftLowerArm_HandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightHand };
        newProfileData.RightLowerArm_HandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLowerArm, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[2]
        {
            HumanBodyBones.LeftUpperLeg,
            HumanBodyBones.LeftLowerLeg
        };
        newProfileData.LeftUpperLegSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftUpperLeg, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[2]
        {
            HumanBodyBones.RightUpperLeg,
            HumanBodyBones.RightLowerLeg
        };
        newProfileData.RightUpperLegSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightUpperLeg, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftFoot };
        newProfileData.LeftFootSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftFoot, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightFoot };
        newProfileData.RightFootSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightFoot, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.Chest };
        newProfileData.ChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Chest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.UpperChest };
        newProfileData.UpperChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.UpperChest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[2]
        {
            HumanBodyBones.Chest,
            HumanBodyBones.UpperChest
        };
        newProfileData.IntegratedChestSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Chest, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.Spine };
        newProfileData.SpineSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.Spine, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftHand };
        newProfileData.LeftHandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftHand, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.LeftThumbProximal,
            HumanBodyBones.LeftThumbIntermediate,
            HumanBodyBones.LeftThumbDistal
        };
        newProfileData.LeftHandThumbSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbProximal };
        newProfileData.LeftHandThumbProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbIntermediate };
        newProfileData.LeftHandThumbIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftThumbDistal };
        newProfileData.LeftHandThumbDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftThumbDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.LeftIndexProximal,
            HumanBodyBones.LeftIndexIntermediate,
            HumanBodyBones.LeftIndexDistal
        };
        newProfileData.LeftHandIndexSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexProximal };
        newProfileData.LeftHandIndexProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexIntermediate };
        newProfileData.LeftHandIndexIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftIndexDistal };
        newProfileData.LeftHandIndexDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftIndexDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.LeftMiddleProximal,
            HumanBodyBones.LeftMiddleIntermediate,
            HumanBodyBones.LeftMiddleDistal
        };
        newProfileData.LeftHandMiddleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleProximal };
        newProfileData.LeftHandMiddleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleIntermediate };
        newProfileData.LeftHandMiddleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftMiddleDistal };
        newProfileData.LeftHandMiddleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftMiddleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.LeftRingProximal,
            HumanBodyBones.LeftRingIntermediate,
            HumanBodyBones.LeftRingDistal
        };
        newProfileData.LeftHandRingSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingProximal };
        newProfileData.LeftHandRingProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingIntermediate };
        newProfileData.LeftHandRingIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftRingDistal };
        newProfileData.LeftHandRingDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftRingDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.LeftLittleProximal,
            HumanBodyBones.LeftLittleIntermediate,
            HumanBodyBones.LeftLittleDistal
        };
        newProfileData.LeftHandLittleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleProximal };
        newProfileData.LeftHandLittleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleIntermediate };
        newProfileData.LeftHandLittleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.LeftLittleDistal };
        newProfileData.LeftHandLittleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.LeftLittleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightHand };
        newProfileData.RightHandSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightHand, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.RightThumbProximal,
            HumanBodyBones.RightThumbIntermediate,
            HumanBodyBones.RightThumbDistal
        };
        newProfileData.RightHandThumbSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbProximal };
        newProfileData.RightHandThumbProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbIntermediate };
        newProfileData.RightHandThumbIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightThumbDistal };
        newProfileData.RightHandThumbDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightThumbDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.RightIndexProximal,
            HumanBodyBones.RightIndexIntermediate,
            HumanBodyBones.RightIndexDistal
        };
        newProfileData.RightHandIndexSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexProximal };
        newProfileData.RightHandIndexProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexIntermediate };
        newProfileData.RightHandIndexIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightIndexDistal };
        newProfileData.RightHandIndexDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightIndexDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.RightMiddleProximal,
            HumanBodyBones.RightMiddleIntermediate,
            HumanBodyBones.RightMiddleDistal
        };
        newProfileData.RightHandMiddleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleProximal };
        newProfileData.RightHandMiddleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleIntermediate };
        newProfileData.RightHandMiddleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightMiddleDistal };
        newProfileData.RightHandMiddleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightMiddleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.RightRingProximal,
            HumanBodyBones.RightRingIntermediate,
            HumanBodyBones.RightRingDistal
        };
        newProfileData.RightHandRingSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingProximal };
        newProfileData.RightHandRingProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingIntermediate };
        newProfileData.RightHandRingIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightRingDistal };
        newProfileData.RightHandRingDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightRingDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[3]
        {
            HumanBodyBones.RightLittleProximal,
            HumanBodyBones.RightLittleIntermediate,
            HumanBodyBones.RightLittleDistal
        };
        newProfileData.RightHandLittleSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes, addChildBones: true);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleProximal };
        newProfileData.RightHandLittleProximalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleProximal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleIntermediate };
        newProfileData.RightHandLittleIntermediateSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleIntermediate, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
        influencedBones = new HumanBodyBones[1] { HumanBodyBones.RightLittleDistal };
        newProfileData.RightHandLittleDistalSpatialData = profileUtils.GetBoneSpatialData(HumanBodyBones.RightLittleDistal, influencedBones, sourceBoneMap, sourceBodyBakedMeshes);
    }

    public void SaveBoneData(ref ProfileData newProfileData, Transform sourceAvatar, Dictionary<HumanBodyBones, HashSet<Transform>> sourceBoneMap, List<ProfileBakedBodyMesh> sourceBodyBakedMeshes)
    {
        ProfileUtils profileUtils = new ProfileUtils();
        HashSet<Transform> hashSet = new HashSet<Transform>();
        foreach (ProfileBakedBodyMesh sourceBodyBakedMesh in sourceBodyBakedMeshes)
        {
            foreach (Transform bodyMeshBone in profileUtils.GetBodyMeshBones(sourceBodyBakedMesh.smr))
            {
                hashSet.Add(bodyMeshBone);
            }
        }
        if (hashSet.Count == 0)
        {
            Debug.LogWarning("[EdenAutoMorpher_ProfileSaver] SaveBoneData - avatarBones is empty.");
            newProfileData.boneRootId = -1;
            newProfileData.bones = new List<BoneData>();
        }
        else
        {
            newProfileData.boneRootId = 0;
            newProfileData.bones = profileUtils.GetBoneDatas(sourceAvatar, hashSet, sourceBoneMap);
        }
    }

    private void AdjustAvatarHigh(Transform sourceRoot, Dictionary<HumanBodyBones, HashSet<Transform>> sourceBoneMap, float targetHeight)
    {
        if (!sourceBoneMap.TryGetValue(HumanBodyBones.Neck, out var value) || value.Count == 0)
        {
            Debug.LogError("[EdenAutoMorpher_ProfileSaver] Can't Find Neck Bones");
            return;
        }
        float num = value.FirstOrDefault().position.y - sourceRoot.position.y;
        if (Mathf.Approximately(num, 0f))
        {
            Debug.LogWarning($"[EdenAutoMorpher_ProfileSaver] {sourceRoot.name} Neck Y가 0에 가까워 스케일 계산을 건너뜁니다. (neckY = {num})");
            return;
        }
        float num2 = targetHeight / num;
        Vector3 localScale = sourceRoot.localScale;
        localScale *= num2;
        sourceRoot.localScale = localScale;
    }

    private void SaveProfileToJson(ProfileData profileData, string savePath, string profileName)
    {
        if (profileData == null)
        {
            Debug.LogError("[EdenAutoMorpher_ProfileSaver] ProfileData is null. Abort save.");
            return;
        }
        if (string.IsNullOrEmpty(profileName))
        {
            Debug.LogError("[EdenAutoMorpher_ProfileSaver] profileName is empty.");
            return;
        }
        string path = (profileName.EndsWith(".json") ? profileName : (profileName + ".json"));
        string text = Path.Combine(Application.dataPath, savePath ?? string.Empty);
        if (!Directory.Exists(text))
        {
            Directory.CreateDirectory(text);
        }
        string text2 = Path.Combine(text, path);
        string contents = JsonUtility.ToJson(profileData, prettyPrint: true);
        File.WriteAllText(text2, contents);
        Debug.Log("[EdenAutoMorpher_ProfileSaver] Profile saved successfully.\nPath: " + text2);
        AssetDatabase.Refresh();
    }

    public bool IsExistBaseData()
    {
        ProfileUtils profileUtils = new ProfileUtils();
        return File.Exists(Path.Combine(Application.dataPath, profileUtils.GetBaseDataPath()));
    }
}
