#Hi everyone !

1 messages · Page 1 of 1 (latest)

bleak ibex
#

Solution from chatgpt :

public string GetSelectedSizeLabel()
    {
        
        // Get the GameView type
        Type gameViewType = typeof(Editor).Assembly.GetType("UnityEditor.GameView");

        
        // Get the GameView instance
        //EditorWindow gameViewWindow = EditorWindow.GetWindow(gameViewType);
        // Find the existing GameView instance
        EditorWindow gameViewWindow = null;
        var gameViewWindows = Resources.FindObjectsOfTypeAll(gameViewType);
        if (gameViewWindows != null && gameViewWindows.Length > 0)
        {
            gameViewWindow = gameViewWindows[0] as EditorWindow;
        }

        if (gameViewWindow == null)
        {
            Debug.LogError("GameView window not found.");
            return null;
        }
#

        // Get the selectedSizeIndex property
        PropertyInfo selectedSizeIndexProperty = gameViewType.GetProperty("selectedSizeIndex", BindingFlags.Instance | BindingFlags.Public);

        // Get the value of selectedSizeIndex
        int selectedSizeIndex = (int)selectedSizeIndexProperty.GetValue(gameViewWindow);

        // Get the GameViewSizes instance
        Type gameViewSizesType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes");
        Type scriptableSingletonType = typeof(ScriptableSingleton<>).MakeGenericType(gameViewSizesType);
        PropertyInfo instanceProperty = scriptableSingletonType.GetProperty("instance");
        object gameViewSizesInstance = instanceProperty.GetValue(null, null);

        // Get the current group type
        PropertyInfo currentGroupTypeProp = gameViewSizesInstance.GetType().GetProperty("currentGroupType");
        object currentGroupType = currentGroupTypeProp.GetValue(gameViewSizesInstance, null);

        // Get the group
        MethodInfo getGroupMethod = gameViewSizesType.GetMethod("GetGroup");
        object group = getGroupMethod.Invoke(gameViewSizesInstance, new object[] { currentGroupType });

        // Get the display text for the selected size index
        MethodInfo getDisplayTextsMethod = group.GetType().GetMethod("GetDisplayTexts");
        string[] displayTexts = getDisplayTextsMethod.Invoke(group, null) as string[];

        // Return the display text for the selected size index
        if (selectedSizeIndex >= 0 && selectedSizeIndex < displayTexts.Length)
        {
            return displayTexts[selectedSizeIndex];
        }
        else
        {
            return "Invalid Size Index";
        }
    }