/// <summary>
    /// Set character clothes
    /// </summary>
    /// <param name="type">Type of clothes</param>
    /// <param name="index">Index of element</param>
    public void SetElementByIndex(ClothesPartType type, int index)
    {
        ClothesAnchor ca = GetClothesAnchor(type);

        ClothPreset clothPreset = getPreset(type, clothesActiveIndexes[type]);


        if (clothPreset != null)
        {
            UnHideParts(clothPreset.hideParts, type);
        }

        if (index != -1)
        {
            var newPreset = getPreset(type, index);

            for (var i = 0; i < ca.skinnedMesh.Length; i++)
            {
                ca.skinnedMesh[i].sharedMesh = newPreset.mesh[i];
            }

            HideParts(newPreset.hideParts);
        }
        else
        {
            foreach (var sm in ca.skinnedMesh)
            {
                sm.sharedMesh = null;
            }
        }

        clothesActiveIndexes[type] = index;
    }
    /// <summary>
    /// Get preset element
    /// </summary>
    /// <param name="type">Type of clothes</param>
    /// <param name="index">Index</param>
    /// <returns></returns>
    ClothPreset getPreset(ClothesPartType type, int index)
    {
        if (index == -1)
        {
            return(null);
        }
        switch (type)
        {
        case ClothesPartType.Hat:
            return(hatsPresets[index]);

        case ClothesPartType.TShirt:
            return(shirtsPresets[index]);

        case ClothesPartType.Pants:
            return(pantsPresets[index]);

        case ClothesPartType.Shoes:
            return(shoesPresets[index]);

        case ClothesPartType.Accessory:
            return(accessoryPresets[index]);

        default:
            return(null);
        }
    }
    /// <summary>
    /// UnHide character parts
    /// </summary>
    /// <param name="parts">Array of parts to unhide</param>
    public void UnHideParts(string[] parts, ClothesPartType hidePartsForElement)
    {
        foreach (string p in parts)
        {
            bool ph_in_shirt = false, ph_in_pants = false, ph_in_shoes = false;

            #region Code to exclude the UnHide parts of the character that are hidden in active presets
            int shirt_i = clothesActiveIndexes[ClothesPartType.TShirt];
            int pants_i = clothesActiveIndexes[ClothesPartType.Pants];
            int shoes_i = clothesActiveIndexes[ClothesPartType.Shoes];

            if (shirt_i != -1 && hidePartsForElement != ClothesPartType.TShirt)
            {
                foreach (var shirtPart in getPreset(ClothesPartType.TShirt, shirt_i).hideParts)
                {
                    if (shirtPart == p)
                    {
                        ph_in_shirt = true;
                        break;
                    }
                }
            }
            if (pants_i != -1 && hidePartsForElement != ClothesPartType.Pants)
            {
                foreach (var pantPart in getPreset(ClothesPartType.Pants, pants_i).hideParts)
                {
                    if (pantPart == p)
                    {
                        ph_in_pants = true;
                        break;
                    }
                }
            }
            if (shoes_i != -1 && hidePartsForElement != ClothesPartType.Shoes)
            {
                foreach (var shoesPart in getPreset(ClothesPartType.Shoes, shoes_i).hideParts)
                {
                    if (shoesPart == p)
                    {
                        ph_in_shoes = true;
                        break;
                    }
                }
            }

            if (ph_in_shirt || ph_in_pants || ph_in_shoes)
            {
                continue;
            }
            #endregion

            foreach (CharacterPart cp in characterParts)
            {
                if (cp.name == p)
                {
                    cp.skinnedMesh.enabled = true;
                }
            }
        }
    }
    /// <summary>
    /// Set character clothes
    /// </summary>
    /// <param name="type">Type of clothes</param>
    /// <param name="index">Index of element</param>
    public void SetElementByIndex(ClothesPartType type, int index)
    {
        ClothesAnchor ca = GetClothesAnchor(type);

        ClothPreset clothPreset = getPreset(type, clothesActiveIndexes[type]);


        if (clothPreset != null)
        {
            UnHideParts(clothPreset.hideParts, type);
        }

        if (index != -1)
        {
            var newPreset = getPreset(type, index);
            ca.skinnedMesh.sharedMesh = newPreset.mesh;

            HideParts(newPreset.hideParts);
        }
        else
        {
            ca.skinnedMesh.sharedMesh = null;
        }

        clothesActiveIndexes[type] = index;
    }
    /// <summary>
    /// Set character clothes
    /// </summary>
    /// <param name="type">Type of clothes</param>
    /// <param name="index">Index of element</param>
    public void SetElementByIndex(ClothesPartType type, int index)
    {
        ClothesAnchor ca          = GetClothesAnchor(type);
        ClothPreset   clothPreset = getPreset(type, clothesActiveIndexes[type]);
        float         yOffset     = 0f;

        if (clothPreset != null)
        {
            UnHideParts(clothPreset.hideParts, type);
        }

        if (type == ClothesPartType.Pants || type == ClothesPartType.TShirt)
        {
            UnHideParts(new string[] { "Spine" }, type);
        }

        clothesActiveIndexes[type] = index;

        if (index != -1)
        {
            var newPreset = getPreset(type, index);

            yOffset = newPreset.yOffset;

            for (var i = 0; i < ca.skinnedMesh.Length; i++)
            {
                ca.skinnedMesh[i].sharedMesh = newPreset.mesh[i];

                for (var blendCount = 0; blendCount < ca.skinnedMesh[i].sharedMesh.blendShapeCount; blendCount++)
                {
                    ca.skinnedMesh[i].SetBlendShapeWeight(blendCount, bodyShapeWeight[blendCount]);
                }
            }
            ClothPreset shirt = getPreset(ClothesPartType.TShirt, clothesActiveIndexes[ClothesPartType.TShirt]);
            ClothPreset pants = getPreset(ClothesPartType.Pants, clothesActiveIndexes[ClothesPartType.Pants]);
            if ((shirt != null && pants != null) && (shirt.notVisibleSpine && pants.notVisibleSpine))
            {
                HideParts(new string[] { "Spine" });
            }
            HideParts(newPreset.hideParts);
        }
        else
        {
            foreach (var sm in ca.skinnedMesh)
            {
                sm.sharedMesh = null;
            }
        }
        if (transforms[0].localPosition.y != yOffset && type == ClothesPartType.Shoes)
        {
            foreach (var tr in transforms)
            {
                tr.localPosition = new Vector3(tr.localPosition.x, yOffset, tr.localPosition.z);
            }
        }
    }
    public void PrevElement(ClothesPartType type)
    {
        int next = clothesActiveIndexes[type] - 1;

        if (next < -1)
        {
            next = getPresetArray(type).Count - 1;
        }
        SetElementByIndex(type, next);
    }
 /// <summary>
 /// Get clothes anchor by type
 /// </summary>
 /// <param name="type">Type of clothes</param>
 /// <returns></returns>
 public ClothesAnchor GetClothesAnchor(ClothesPartType type)
 {
     foreach (ClothesAnchor p in clothesAnchors)
     {
         if (p.partType == type)
         {
             return(p);
         }
     }
     return(null);
 }
    /// <summary>
    /// Get preset array by type
    /// </summary>
    List <ClothPreset> getPresetArray(ClothesPartType type)
    {
        switch (type)
        {
        case ClothesPartType.Hat:
            return(hatsPresets);

        case ClothesPartType.TShirt:
            return(shirtsPresets);

        case ClothesPartType.Pants:
            return(pantsPresets);

        case ClothesPartType.Shoes:
            return(shoesPresets);

        case ClothesPartType.Accessory:
            return(accessoryPresets);

        default:
            return(null);
        }
    }