Search Unity

how do i get what the player has selected in the EditorUtility Window?

Discussion in 'Getting Started' started by thaFoxy, Mar 23, 2023.

  1. thaFoxy

    thaFoxy

    Joined:
    Jan 25, 2022
    Posts:
    1
    hello, so today i've been trying to make a script that basically makes the player be able to import a 3d model (only one) as a mod, but i can't seem to get the file that the player has selected, it only instantiates the object that has the script on, if you want to help me, the script is this:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using System.IO;
    7. using UnityEditor;
    8.  
    9. public class openFileSelector : MonoBehaviour
    10. {
    11.     public GameObject LockedCube;
    12.     void Apply()
    13.     {
    14.         Object obj = Selection.activeObject as Object; //this is where i try to get the selected 3d model that the player selected.
    15.         if (obj == null)
    16.         {
    17.             EditorUtility.DisplayDialog("Select Map", "You must select an FBX first!", "OK");
    18.             return;
    19.         }
    20.  
    21.         string path = EditorUtility.OpenFilePanel("Overwrite with FBX", "", "fbx");
    22.         if (path.Length != 0)
    23.         {
    24.             var fileContent = File.ReadAllBytes(path);
    25.             Instantiate(obj); //this is where i try to instantiate the selected 3d model but instead it instantiates the gameobject that the script is put on.
    26.             Destroy(LockedCube);
    27.         }
    28.         gameObject.GetComponent<openFileSelector>().enabled = false; //to prevent people from abusing the importing 3d model stuff.
    29.     }
    30.     void Start() {
    31.         Apply();
    32.     }
    33.     void Update()
    34.     {
    35.  
    36.     }
    37. }
    EDIT: i think i posted this in the wrong thing lol
     
    Last edited: Mar 24, 2023