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);
        }
Exemple #2
0
        public static WorkshopItemMetadata Load(string folder)
        {
            string path = FileTools.Combine(folder, "metadata.json");
            string text = FileTools.ReadAllText(path);

            if (text == null)
            {
                return(null);
            }
            try
            {
                WorkshopItemMetadata workshopItemMetadata = JsonUtility.FromJson <WorkshopItemMetadata>(text);
                if (workshopItemMetadata != null)
                {
                    switch (workshopItemMetadata.itemType)
                    {
                    case WorkshopItemType.Levels:
                    case WorkshopItemType.Lobbies:
                        workshopItemMetadata = JsonUtility.FromJson <WorkshopLevelMetadata>(text);
                        if (workshopItemMetadata.typeTags == 2)
                        {
                            workshopItemMetadata.itemType = WorkshopItemType.Lobbies;
                        }
                        break;

                    case WorkshopItemType.ModelFull:
                    case WorkshopItemType.ModelHead:
                    case WorkshopItemType.ModelUpperBody:
                    case WorkshopItemType.ModelLowerBody:
                        workshopItemMetadata = JsonUtility.FromJson <RagdollModelMetadata>(text);
                        break;

                    case WorkshopItemType.RagdollPreset:
                        workshopItemMetadata = JsonUtility.FromJson <RagdollPresetMetadata>(text);
                        break;
                    }
                    if (workshopItemMetadata != null)
                    {
                        workshopItemMetadata.folder = folder;
                        return(workshopItemMetadata);
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.LogException(exception);
            }
            return(null);
        }