如何将Unity Display对话框的输出更改为特定的Gameobject?

时间:2018-06-11 17:03:38

标签: c# unity3d hololens unity-editor

我是编程的初学者所以我需要知道以下内容:我从我的项目调用REST API到服务器,我被困在这里。

我正在尝试在我的场景中的特定Gameobject上显示我的按钮的输出。我想知道有多少UnityEditor属性或如何将我的游戏对象指向输出而不是DialogDisplay弹出窗口?

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");

我的GameObject的名称是输出

1 个答案:

答案 0 :(得分:0)

以下是有关如何使用Unity文档中的 EditorUtility.DisplayDialog 的基本示例

// 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);
                }
            }
        }
    }
}

所以我认为你可以制作类似的东西并使用Selection.gameobjects访问该对象,它可以获得所选游戏对象的列表,然后你可以用它们做任何事情。

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

    // ... //
}