Search code examples
c#unity-game-enginehololensunity-editor

how to change the output from Unity Display dialog to specific Gameobject?


I am a beginner in programming so I need to know the following: I am calling REST APIs from my project to the server, and I am stuck here.

I am trying to show the output of my button on specific Gameobject in my Scene. I want to know how many UnityEditor properties are there or how to point my game object for an output instead of DialogDisplay popup?

EditorUtility.DisplayDialog("Posts", JsonHelper.ArrayToJsonString(res, true), "Ok");
return RestClient.GetArray(basePath + "/todos");
}).Then(res => {
EditorUtility.DisplayDialog("Todos", JsonHelper.ArrayToJsonString(res, true), "Ok");
return RestClient.GetArray(basePath + "/users");
}).Then(res => {
EditorUtility.DisplayDialog("Users", JsonHelper.ArrayToJsonString(res, true), "Ok");

the name of my GameObject is Output


Solution

  • Here is a very basic example on how to use EditorUtility.DisplayDialog from Unity documentation

    // Places the selected Objects on the surface of a terrain.
    
    using UnityEngine;
    using UnityEditor;
    
    public class PlaceSelectionOnSurface : ScriptableObject
    {
        [MenuItem("Example/Place Selection On Surface")]
        static void CreateWizard()
        {
            Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep |
                    SelectionMode.ExcludePrefab | SelectionMode.Editable);
    
            if (transforms.Length > 0 &&
                EditorUtility.DisplayDialog("Place Selection On Surface?",
                    "Are you sure you want to place " + transforms.Length
                    + " on the surface?", "Place", "Do Not Place"))
            {
                foreach (Transform transform in transforms)
                {
                    RaycastHit hit;
                    if (Physics.Raycast(transform.position, -Vector3.up, out hit))
                    {
                        transform.position = hit.point;
                        Vector3 randomized = Random.onUnitSphere;
                        randomized = new Vector3(randomized.x, 0F, randomized.z);
                        transform.rotation = Quaternion.LookRotation(randomized, hit.normal);
                    }
                }
            }
        }
    }
    

    So I think you can make something like that and access the object using Selection.gameobjects which get you a list of the selected game objects then you can can do any thing with them.

    GameObject[] objects = Selection.gameObjects;
    if (EditorUtility.DisplayDialog("Title", "Msg", "Ok"))
    {
        Debug.Log(objects[0]);
    
        // ... //
    }