Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 统一中的GUI.BeginScrollView_Android_User Interface_Unity3d_Scrollview - Fatal编程技术网

Android 统一中的GUI.BeginScrollView

Android 统一中的GUI.BeginScrollView,android,user-interface,unity3d,scrollview,Android,User Interface,Unity3d,Scrollview,我不明白如何在Unity中使用滚动视图。下面是我用来创建scrollview的脚本: #pragma strict //not implemented yet var selectObjectIcon : Texture2D; var addEntityIcon : Texture2D; var selectNextEntityIcon : Texture2D; var createPathIcon : Texture2D; var assignPathIcon : Texture2D; va

我不明白如何在Unity中使用滚动视图。下面是我用来创建scrollview的脚本:

#pragma strict

//not implemented yet
var selectObjectIcon : Texture2D;
var addEntityIcon : Texture2D;
var selectNextEntityIcon : Texture2D;
var createPathIcon : Texture2D;
var assignPathIcon : Texture2D;
var changeSpeedIcon : Texture2D;
var deleteObjectIcon : Texture2D;
var zoomIcon : Texture2D;

//not supposed to be implemented
var dragEntityIcon : Texture2D;
var assignPointIcon : Texture2D;
var haltIcon : Texture2D;
var warpIcon : Texture2D;
var glowStickIcon : Texture2D;
var selectWeaponIcon : Texture2D;
var reviveIcon : Texture2D;
var lineOfSightIcon : Texture2D;

var buttonDimensions : float;
var buttonStyle : GUIStyle;

private var scrollPosition : Vector2 = Vector2.zero;

function OnGUI () {
    //scrollPosition = GUI.BeginScrollView(Rect(Screen.width-buttonDimensions, 0, buttonDimensions, Screen.height), scrollPosition, Rect(0, 0, buttonDimensions, buttonDimensions));
    scrollPosition = GUI.BeginScrollView(Rect(Screen.width-buttonDimensions, 0, buttonDimensions, Screen.height), scrollPosition, Rect(0, 0, buttonDimensions, Screen.height));
    GUILayout.BeginVertical();

    if(GUILayout.Button(selectObjectIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(addEntityIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(selectNextEntityIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(createPathIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(assignPathIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(changeSpeedIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(deleteObjectIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(zoomIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }

    if(GUILayout.Button(dragEntityIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(assignPointIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(haltIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(warpIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(glowStickIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(selectWeaponIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(reviveIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(lineOfSightIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }

    GUILayout.EndVertical();
    GUI.EndScrollView();
}

但这并没有达到预期效果。按钮离右边太远,正在被切断,我无法向上滚动。我也不明白BeginScrollView的第三个论点应该是什么。文档只是说“滚动视图中使用的矩形”。我应该计算滚动视图窗口和内容窗口的值吗?我来自Android GUI开发,这似乎比需要做的工作多得多。

好吧,通过反复试验,我能够将脚本组合在一起,按照预期显示所有内容。困扰我的是我需要估计滚动条的大小并计算按钮的像素值来创建滚动视图。我想,对于更复杂的UI,显式计算这些值将非常令人头痛。有没有更好的方法来实现这一点,类似于在Android中相对轻松地创建ListView

#pragma strict

//not implemented yet
var selectObjectIcon : Texture2D;
var addEntityIcon : Texture2D;
var selectNextEntityIcon : Texture2D;
var createPathIcon : Texture2D;
var assignPathIcon : Texture2D;
var changeSpeedIcon : Texture2D;
var deleteObjectIcon : Texture2D;
var zoomIcon : Texture2D;

//not supposed to be implemented
var dragEntityIcon : Texture2D;
var assignPointIcon : Texture2D;
var haltIcon : Texture2D;
var warpIcon : Texture2D;
var glowStickIcon : Texture2D;
var selectWeaponIcon : Texture2D;
var reviveIcon : Texture2D;
var lineOfSightIcon : Texture2D;

var buttonDimensions : float;
var buttonStyle : GUIStyle;

private var scrollPosition : Vector2 = Vector2.zero;
private var scrollBarWidth : float = 17.5;

function OnGUI () {
    scrollPosition = GUI.BeginScrollView(Rect(Screen.width-buttonDimensions-scrollBarWidth-buttonStyle.padding.right, 0, buttonDimensions+scrollBarWidth+buttonStyle.padding.right, Screen.height), scrollPosition, Rect(0, 0, buttonDimensions, (buttonDimensions+buttonStyle.padding.bottom+buttonStyle.padding.top)*16));
    GUILayout.BeginVertical();

    if(GUILayout.Button(selectObjectIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(addEntityIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(selectNextEntityIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(createPathIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(assignPathIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(changeSpeedIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(deleteObjectIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(zoomIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }

    if(GUILayout.Button(dragEntityIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(assignPointIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(haltIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(warpIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(glowStickIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(selectWeaponIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(reviveIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }
    if(GUILayout.Button(lineOfSightIcon, buttonStyle)){
        Debug.Log("select object pressed");
    }

    GUILayout.EndVertical();
    GUI.EndScrollView();
}