/// <summary>
 /// Checks if the specified accessory is a hair accessory
 /// </summary>
 public bool IsHairAccessory(int slot)
 {
     try
     {
         var accessory = ChaControl.GetAccessory(slot);
         if (accessory == null)
         {
             return(false);
         }
         return(accessory.gameObject.GetComponent <ChaCustomHairComponent>() != null);
     }
     catch
     {
         return(false);
     }
 }
            /// <summary>
            /// Checks if the specified accessory has length transforms (trfLength in the ChaCustomHairComponent MonoBehavior)
            /// </summary>
            public bool HasLengthTransforms()
            {
                var accessory = ChaControl.GetAccessory(AccessoriesApi.SelectedMakerAccSlot);

                if (accessory == null)
                {
                    return(false);
                }
                var chaCustomHairComponent = accessory.gameObject.GetComponent <ChaCustomHairComponent>();

                if (chaCustomHairComponent != null)
                {
                    for (var i = 0; i < chaCustomHairComponent.trfLength.Length; i++)
                    {
                        if (chaCustomHairComponent.trfLength[i] != null)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
 internal static void UpdateAccessoryMoveFromInfo(int slotNo, ChaControl __instance) => RemoveNullParts(__instance.GetAccessory(slotNo)?.gameObject.GetComponent <ChaCustomHairComponent>());
        private void ChangeItemType(int selectedItem, ChaControl chaControl)
        {
            var option = ItemTypeDropDown.OptionText(selectedItem).Split(' ');
            int index  = 0;

            if (chaControl == null)
            {
                PopulateList(null, null);
            }

            switch (option[0])
            {
            case "Body":
                PopulateList(chaControl.gameObject, new ObjectData(0, MaterialEditorCharaController.ObjectType.Character));
                break;

            case "Clothes":
                if (option.Length > 1)
                {
                    index = ClothesStringToIndex(option[1]);
                }

                if (index == -1 || chaControl.objClothes[index] == null || chaControl.objClothes[index].GetComponentInChildren <ChaClothesComponent>() == null)
                {
                    PopulateList(chaControl.gameObject, 0);
                }
                else
                {
                    PopulateList(chaControl.objClothes[index], new ObjectData(index, MaterialEditorCharaController.ObjectType.Clothing));
                }
                break;

            case "Hair":
                if (option.Length > 1)
                {
                    index = HairStringToIndex(option[1]);
                }

                if (index == -1 || chaControl.objHair[index] == null || chaControl.objHair[index].GetComponent <ChaCustomHairComponent>() == null)
                {
                    PopulateList(chaControl.gameObject, 0);
                }
                else
                {
                    PopulateList(chaControl.objHair[index], new ObjectData(index, MaterialEditorCharaController.ObjectType.Hair));
                }
                break;

            case "Accessory":
                if (option.Length > 1)
                {
                    index = AccessoryStringToIndex(option[1]);
                }
                var accessory = chaControl.GetAccessory(index);

                if (accessory == null)
                {
                    PopulateList(chaControl.gameObject, 0);
                }
                else
                {
                    PopulateList(accessory.gameObject, new ObjectData(index, MaterialEditorCharaController.ObjectType.Accessory));
                }
                break;
            }
        }
            /// <summary>
            /// Updates the specified hair accessory
            /// </summary>
            public void UpdateAccessory(int slot, bool updateCharacter = true)
            {
                if (!IsHairAccessory(slot))
                {
                    return;
                }

                ChaAccessoryComponent chaAccessoryComponent = ChaControl.GetAccessory(slot);

                if (chaAccessoryComponent == null)
                {
                    return;
                }
                ChaCustomHairComponent chaCustomHairComponent = chaAccessoryComponent.gameObject.GetComponent <ChaCustomHairComponent>();

                if (chaCustomHairComponent.rendHair == null)
                {
                    return;
                }

                if (!HairAccessories.ContainsKey(CurrentCoordinateIndex))
                {
                    return;
                }
                if (!HairAccessories[CurrentCoordinateIndex].TryGetValue(slot, out var hairAccessoryInfo))
                {
                    return;
                }
                if (chaAccessoryComponent.rendNormal == null)
                {
                    return;
                }
                if (chaCustomHairComponent.rendHair == null)
                {
                    return;
                }

                if (updateCharacter && hairAccessoryInfo.ColorMatch)
                {
                    if (MakerAPI.InsideAndLoaded)
                    {
                        CvsAccessory cvsAccessory = AccessoriesApi.GetCvsAccessory(slot);
                        cvsAccessory.UpdateAcsColor01(ChaControl.chaFile.custom.hair.parts[0].baseColor);
                        cvsAccessory.UpdateAcsColor02(ChaControl.chaFile.custom.hair.parts[0].startColor);
                        cvsAccessory.UpdateAcsColor03(ChaControl.chaFile.custom.hair.parts[0].endColor);
                        OutlineColorPicker.SetValue(slot, ChaControl.chaFile.custom.hair.parts[0].outlineColor, false);
                        hairAccessoryInfo.OutlineColor = ChaControl.chaFile.custom.hair.parts[0].outlineColor;
                    }
                    else
                    {
                        for (var i = 0; i < chaCustomHairComponent.rendHair.Length; i++)
                        {
                            Renderer renderer = chaCustomHairComponent.rendHair[i];
                            if (renderer == null)
                            {
                                continue;
                            }

                            if (renderer.sharedMaterial.HasProperty(ChaShader._Color))
                            {
                                renderer.sharedMaterial.SetColor(ChaShader._Color, ChaControl.chaFile.custom.hair.parts[0].baseColor);
                            }
                            if (renderer.sharedMaterial.HasProperty(ChaShader._Color2))
                            {
                                renderer.sharedMaterial.SetColor(ChaShader._Color2, ChaControl.chaFile.custom.hair.parts[0].startColor);
                            }
                            if (renderer.sharedMaterial.HasProperty(ChaShader._Color3))
                            {
                                renderer.sharedMaterial.SetColor(ChaShader._Color3, ChaControl.chaFile.custom.hair.parts[0].endColor);
                            }
                        }
                    }
                }

                Texture2D texHairGloss = (Texture2D)AccessTools.Property(typeof(ChaControl), "texHairGloss").GetValue(ChaControl, null);

                for (var i = 0; i < chaCustomHairComponent.rendHair.Length; i++)
                {
                    Renderer renderer = chaCustomHairComponent.rendHair[i];
                    if (renderer == null)
                    {
                        continue;
                    }

                    if (renderer.sharedMaterial.HasProperty(ChaShader._HairGloss))
                    {
                        if (hairAccessoryInfo.HairGloss)
                        {
                            renderer.sharedMaterial.SetTexture(ChaShader._HairGloss, texHairGloss);
                        }
                        else
                        {
                            renderer.sharedMaterial.SetTexture(ChaShader._HairGloss, null);
                        }
                    }

                    if (renderer.sharedMaterial.HasProperty(ChaShader._LineColor))
                    {
                        if (hairAccessoryInfo.ColorMatch)
                        {
                            renderer.sharedMaterial.SetColor(ChaShader._LineColor, ChaControl.chaFile.custom.hair.parts[0].outlineColor);
                        }
                        else
                        {
                            renderer.sharedMaterial.SetColor(ChaShader._LineColor, hairAccessoryInfo.OutlineColor);
                        }
                    }
                }

                for (var i = 0; i < chaCustomHairComponent.rendAccessory.Length; i++)
                {
                    Renderer renderer = chaCustomHairComponent.rendAccessory[i];
                    if (renderer == null)
                    {
                        continue;
                    }

                    if (renderer.sharedMaterial.HasProperty(ChaShader._Color))
                    {
                        renderer.sharedMaterial.SetColor(ChaShader._Color, hairAccessoryInfo.AccessoryColor);
                    }
                    if (renderer.sharedMaterial.HasProperty(ChaShader._Color2))
                    {
                        renderer.sharedMaterial.SetColor(ChaShader._Color2, hairAccessoryInfo.AccessoryColor);
                    }
                    if (renderer.sharedMaterial.HasProperty(ChaShader._Color3))
                    {
                        renderer.sharedMaterial.SetColor(ChaShader._Color3, hairAccessoryInfo.AccessoryColor);
                    }
                }

                chaCustomHairComponent.lengthRate = hairAccessoryInfo.HairLength;
            }