Search Unity

Resolved VRChat Avatar Import Script

Discussion in 'VR' started by yelby, Nov 28, 2020.

Thread Status:
Not open for further replies.
  1. yelby

    yelby

    Joined:
    Jan 11, 2018
    Posts:
    10
    Hello, I'm trying to make an avatar import script for VRChat avatars. I'm using unity 2018.4.20 as that's what the game uses. I want this script to do a bunch of setup stuff every avatar would do, but make it really simple to do and much faster. I'm new to coding in unity and I've tried to research the pieces I need, and I'm getting stuck.

    Current Location
    Apply a pre-made preset to target.

    Any and all help appreciated!


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEngine.SceneManagement;
    4. using UnityEditor.SceneManagement;
    5. using UnityEditor.Presets;
    6. using System.IO;
    7.  
    8. public class Avatar_Importer_Main : EditorWindow
    9. {
    10.     //Attributes
    11.     string myString = "<Avatar Name>";
    12.     public Object source;
    13.  
    14.     [MenuItem("Yelby/Importer")]
    15.     public static void ShowWindow()
    16.     {
    17.         GetWindow<Avatar_Importer_Main>("Importer");
    18.     }
    19.  
    20.     void OnGUI()
    21.     {
    22.         //Header
    23.         GUILayout.Label("Step 1: Generate Files", EditorStyles.boldLabel);
    24.  
    25.         //Text Field
    26.         myString = EditorGUILayout.TextField("Name of Avatar", myString);
    27.  
    28.         //Object Field
    29.         EditorGUILayout.BeginHorizontal();
    30.         source = EditorGUILayout.ObjectField(source, typeof(GameObject), false);
    31.         EditorGUILayout.EndHorizontal();
    32.  
    33.         //Button
    34.         if (GUILayout.Button("Generate"))
    35.         {
    36.             CreateFolders();
    37.             moveAvatar();
    38.             inspectorOptions();
    39.             createScene();
    40.             addDescriptor();
    41.         }
    42.     }
    43.     //~~~~Methods~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    44.     void CreateFolders()
    45.     {
    46.         string guid = "";
    47.         string newFolderPath = "";
    48.         //string[] subfolders = { };
    49.  
    50.         //Make avatar folder is folder doesn't exist
    51.         if (!AssetDatabase.IsValidFolder("Assets/Avatars"))
    52.         {
    53.             guid = AssetDatabase.CreateFolder("Assets", "Avatars");
    54.             newFolderPath = AssetDatabase.GUIDToAssetPath(guid);
    55.         }
    56.         else
    57.         {
    58.             //Make the <Character File> if it doesn't exist
    59.             if (!AssetDatabase.IsValidFolder("Assets/Avatars/" + myString))
    60.             {
    61.                 guid = AssetDatabase.CreateFolder("Assets/Avatars", myString);
    62.                 newFolderPath = AssetDatabase.GUIDToAssetPath(guid);
    63.             }
    64.         }
    65.         //Creates the sub folders
    66.         string[] subfoldernames = { "Animations", "FBX", "Prefabs", "Textures", "UMats" };
    67.         string[] subfolders = new string[subfoldernames.Length];
    68.         //Genterating subfolders
    69.         for (int i = 0; i < subfoldernames.Length; i++)
    70.         {
    71.             if (!AssetDatabase.IsValidFolder("Assets/Avatars/" + myString + "/" + subfoldernames[i]))
    72.             {
    73.                 subfolders[i] = AssetDatabase.CreateFolder("Assets/Avatars/" + myString, subfoldernames[i]);
    74.                 newFolderPath = AssetDatabase.GUIDToAssetPath(subfolders[i]);
    75.            
    76.             }
    77.         }
    78.     }
    79.  
    80.     void moveAvatar()
    81.     {
    82.         //string oldpath = "Assets/" + source.name + ".fbx";
    83.         string oldpath = AssetDatabase.GetAssetPath(source);
    84.         string newpath = ("Assets/Avatars/"+myString+"/"+"FBX/"+ myString + ".fbx");
    85.         AssetDatabase.MoveAsset(oldpath,newpath);
    86.         AssetDatabase.Refresh();
    87.     }
    88.  
    89.     void inspectorOptions()
    90.     {
    91.         //Load premade preset to avatar in "Assets/Yelby/Programs/Avatar Importer/ImportPreset.preset"
    92.         //Scan through Avatar options to [Remove Toe Bones; Check if Chest is chest, spine is spine, hip is hip; Remove jaw bone]
    93.         //Export Materials to "Assets/Avatars/ <avatar name> / UMats"
    94.     }
    95.  
    96.     void createScene()
    97.     {
    98.         //Create scene with name of avatar and saved to "Assets/Avatars/ <Avatar Name>
    99.         //Load Scene
    100.         //Place avatar into scene at 0,0,0
    101.         //Save scene
    102.     }
    103.  
    104.     void addDescriptor()
    105.     {
    106.         //Add avatar Descriptor to scene
    107.         //Change eye position to be between assigned eyebones in humanoid/avatar
    108.         //Auto select "auto visemes" from descriptor
    109.     }
    110. }
    111.  
     
  2. mfuad

    mfuad

    Unity Technologies

    Joined:
    Jun 12, 2018
    Posts:
    335
    Hi @yelby, please send this question to the VRChat team. Thanks.
     
Thread Status:
Not open for further replies.