繁体   English   中英

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

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

我是编程的初学者,所以我需要了解以下内容:我正在从我的项目到服务器调用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的名称是Output

这是有关如何使用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]);

    // ... //
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM