private RagdollModel BindToSkin(WorkshopItemMetadata wsMeta)
        {
            if (wsMeta == null)
            {
                return(null);
            }
            RagdollModelMetadata ragdollModelMetadata = wsMeta as RagdollModelMetadata;

            if (ragdollModelMetadata != null)
            {
                RagdollModel component;
                if (ragdollModelMetadata.modelPrefab == null)
                {
                    AssetBundle assetBundle   = WorkshopRepository.LoadBundle(ragdollModelMetadata);
                    string[]    allAssetNames = assetBundle.GetAllAssetNames();
                    GameObject  original      = assetBundle.LoadAsset(ragdollModelMetadata.model) as GameObject;
                    component = UnityEngine.Object.Instantiate(original).GetComponent <RagdollModel>();
                    assetBundle.Unload(unloadAllLoadedObjects: false);
                }
                else
                {
                    component = UnityEngine.Object.Instantiate(ragdollModelMetadata.modelPrefab.gameObject).GetComponent <RagdollModel>();
                }
                component.meta = ragdollModelMetadata;
                component.BindToRagdoll(ragdoll);
                component.texture.LoadFromPreset(preset);
                return(component);
            }
            return(null);
        }
 private bool RebindHead(RagdollPresetMetadata preset, bool forceRebuild)
 {
     if (head != null && (forceRebuild || !allowHead || preset == null || preset.head == null || preset.head.modelPath != head.meta.folder))
     {
         head.Unbind(ragdoll);
         UnityEngine.Object.DestroyImmediate(head.gameObject);
         head = null;
     }
     if (head == null && allowHead && preset != null && preset.head != null)
     {
         RagdollModelMetadata item = WorkshopRepository.instance.GetPartRepository(WorkshopItemType.ModelHead).GetItem(preset.head.modelPath);
         if (item != null)
         {
             head = BindToSkin(item);
             return(true);
         }
     }
     return(false);
 }
 private bool RebindLower(RagdollPresetMetadata preset, bool forceRebuild)
 {
     if (lower != null && (forceRebuild || !allowLower || preset == null || preset.lowerBody == null || preset.lowerBody.modelPath != lower.meta.folder))
     {
         lower.Unbind(ragdoll);
         UnityEngine.Object.DestroyImmediate(lower.gameObject);
         lower = null;
     }
     if (lower == null && allowLower && preset != null && preset.lowerBody != null)
     {
         RagdollModelMetadata item = WorkshopRepository.instance.GetPartRepository(WorkshopItemType.ModelLowerBody).GetItem(preset.lowerBody.modelPath);
         if (item != null)
         {
             lower = BindToSkin(item);
             return(true);
         }
     }
     return(false);
 }
 private bool RebindMain(RagdollPresetMetadata preset, bool forceRebuild)
 {
     if (main != null && (forceRebuild || preset == null || preset.main == null || main.meta.folder != preset.main.modelPath))
     {
         main.Unbind(ragdoll);
         UnityEngine.Object.DestroyImmediate(main.gameObject);
         main = null;
     }
     if (main == null && preset != null && preset.main != null)
     {
         RagdollModelMetadata item = WorkshopRepository.instance.GetPartRepository(WorkshopItemType.ModelFull).GetItem(preset.main.modelPath);
         if (item != null)
         {
             main = BindToSkin(item);
             return(true);
         }
     }
     return(false);
 }