0

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

我试图在我的场景中的特定游戏对象上显示我的按钮的输出。我想知道有多少 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");

我的游戏对象的名称是输出

4

1 回答 1

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

    // ... //
}
于 2018-06-11T21:18:14.093 回答