Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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
C# Unity为我已经制作的编辑器/属性抽屉创建数组,其中包含数组_C#_Arrays_Unity3d - Fatal编程技术网

C# Unity为我已经制作的编辑器/属性抽屉创建数组,其中包含数组

C# Unity为我已经制作的编辑器/属性抽屉创建数组,其中包含数组,c#,arrays,unity3d,C#,Arrays,Unity3d,我觉得我很接近,但就我的一生而言,我无法理解这一点,因为我一直在得到令人不安的结果。在下图中,我想制作多个,但我就是想不出来: 正如你可以看到的,我可以在上面的图片中看到,我希望有另一个“大小”,我可以设置一个数字,你在红色框中看到的倍数会显示出来 目前我有一个带编辑器的Camera_定位脚本,[System.Serializable]脚本保存变量和一个抽屉 我曾经尝试过制作一个脚本来制作一个摄像机阵列,我也尝试了一些2D阵列,但是我没有工作或者我做错了什么。有人对如何制作我的一系列红盒子有什

我觉得我很接近,但就我的一生而言,我无法理解这一点,因为我一直在得到令人不安的结果。在下图中,我想制作多个,但我就是想不出来:

正如你可以看到的,我可以在上面的图片中看到,我希望有另一个“大小”,我可以设置一个数字,你在红色框中看到的倍数会显示出来

目前我有一个带编辑器的Camera_定位脚本,[System.Serializable]脚本保存变量和一个抽屉

我曾经尝试过制作一个脚本来制作一个摄像机阵列,我也尝试了一些2D阵列,但是我没有工作或者我做错了什么。有人对如何制作我的一系列红盒子有什么想法吗

编辑:以下是我目前拥有的代码:

我的相机定位和相机定位编辑器脚本。相机的位置是我附加到游戏对象上的

public class Camera_Positioning : MonoBehaviour {

    public CamPosLookArray[] PosLook;

}


[CanEditMultipleObjects]
[CustomEditor(typeof(Camera_Positioning))]
public class Camera_Positioning_Editor : Editor {

SerializedProperty posLook;


void OnEnable()
{
    // Setup the SerializedProperties.
    posLook = serializedObject.FindProperty("PosLook");
}

public override void OnInspectorGUI()
{
    // Set the indentLevel to 0 as default (no indent).
    EditorGUI.indentLevel = 0;
    // Update
    serializedObject.Update();

    EditorGUILayout.PropertyField(posLook.FindPropertyRelative("Array.size"));

    EditorGUILayout.BeginHorizontal();
    EditorGUILayout.LabelField("Camera Position", EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
    EditorGUILayout.LabelField("Camera Look", EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
    EditorGUILayout.LabelField("Story", EditorStyles.boldLabel, GUILayout.Width(75f));
    EditorGUILayout.EndHorizontal();

    for (int i = 0; i < posLook.arraySize; i++)
    {
        EditorGUILayout.PropertyField(posLook.GetArrayElementAtIndex(i), GUIContent.none);
    }

    // Apply.
    serializedObject.ApplyModifiedProperties();
}
}
我的CameraPos_CameraLook和CameraPos_CameraLook编辑器脚本:

[System.Serializable]
public class CameraPos_CameraLook {

    public Transform CameraPosition;
    public Transform CameraLook;
    public int CameraStory;
}


[CustomPropertyDrawer(typeof(CameraPos_CameraLook))]
public class CameraPos_CameraLook_Drawer : PropertyDrawer {

// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    // Using BeginProperty / EndProperty on the parent property means that
    // prefab override logic works on the entire property.
    EditorGUI.BeginProperty(position, label, property);

    // Draw label
    position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

    // Don't make child fields be indented
    var indent = EditorGUI.indentLevel;
    EditorGUI.indentLevel = 0;

    // Calculate rects
    Rect camPos = new Rect(position.x, position.y, Screen.width / 3f, position.height);
    Rect camLook = new Rect(position.x + Screen.width / 2.75f, position.y, Screen.width / 3f, position.height);
    Rect camStory = new Rect(position.x + (2.2f *Screen.width) / 3f, position.y, 75f, position.height);

    // Draw fields - passs GUIContent.none to each so they are drawn without labels
    EditorGUI.PropertyField(camPos, property.FindPropertyRelative("CameraPosition"), GUIContent.none);
    EditorGUI.PropertyField(camLook, property.FindPropertyRelative("CameraLook"), GUIContent.none);
    EditorGUI.PropertyField(camStory, property.FindPropertyRelative("CameraStory"), GUIContent.none);

    // Set indent back to what it was
    EditorGUI.indentLevel = indent;

    EditorGUI.EndProperty();
}
}

当我拥有我所拥有的一切时:


我试图在上图中实现的是,在你看到的任何地方,一个三角形(其中两个)应该是红色框顶部第一张图片中的三角形。

你可以尝试使用一个脚本,该脚本包含一系列相机定位

编辑:


您可以尝试创建一个脚本,该脚本具有一组摄影机位置

编辑:


在对
Camera\u Positioning\u编辑器
脚本进行了一些调整后,我成功地使检查器看起来像这样:

这是
OnInspectorGUI
方法的
Camera\u Positioning\u编辑器
脚本:

public override void OnInspectorGUI()
{
    EditorGUI.indentLevel = 0;
    serializedObject.Update();

    EditorGUILayout.PropertyField(posLook
                   .FindPropertyRelative("Array.size"));

    for(int i = 0; i < posLook.arraySize; i++)
    {
        SerializedProperty item = posLook.GetArrayElementAtIndex(i);
        SerializedProperty posLookArrayProperty = 
            item.FindPropertyRelative("PosLookArray");

        EditorGUILayout.PropertyField(
            posLookArrayProperty.FindPropertyRelative("Array.size"));

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Camera Position", 
            EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
        EditorGUILayout.LabelField("Camera Look", 
            EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
        EditorGUILayout.LabelField("Story", 
            EditorStyles.boldLabel, GUILayout.Width(75f));
        EditorGUILayout.EndHorizontal();

        for(int j = 0; j < posLookArrayProperty.arraySize; j++)
        {
            EditorGUILayout.PropertyField(
                posLookArrayProperty.GetArrayElementAtIndex(j), GUIContent.none);
        }
    }

    serializedObject.ApplyModifiedProperties();
}
public override void OnInspectorGUI()
{
EditorGUI.indentLevel=0;
serializedObject.Update();
EditorGUILayout.PropertyField(posLook
.FindPropertyRelative(“Array.size”);
for(int i=0;i

在本例中,top
Size
属性是
Camera\u Positioning
组件中阵列的大小。每个后续的
Size
都是针对
CamPosLookArray.PosLookArray.PosLookArray
中的每个
Camera\u Positioning.PosLook
数组。

在对
Camera\u Positioning\u编辑器
脚本进行一些调整后,我设法使检查器看起来像这样:

这是
OnInspectorGUI
方法的
Camera\u Positioning\u编辑器
脚本:

public override void OnInspectorGUI()
{
    EditorGUI.indentLevel = 0;
    serializedObject.Update();

    EditorGUILayout.PropertyField(posLook
                   .FindPropertyRelative("Array.size"));

    for(int i = 0; i < posLook.arraySize; i++)
    {
        SerializedProperty item = posLook.GetArrayElementAtIndex(i);
        SerializedProperty posLookArrayProperty = 
            item.FindPropertyRelative("PosLookArray");

        EditorGUILayout.PropertyField(
            posLookArrayProperty.FindPropertyRelative("Array.size"));

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Camera Position", 
            EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
        EditorGUILayout.LabelField("Camera Look", 
            EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
        EditorGUILayout.LabelField("Story", 
            EditorStyles.boldLabel, GUILayout.Width(75f));
        EditorGUILayout.EndHorizontal();

        for(int j = 0; j < posLookArrayProperty.arraySize; j++)
        {
            EditorGUILayout.PropertyField(
                posLookArrayProperty.GetArrayElementAtIndex(j), GUIContent.none);
        }
    }

    serializedObject.ApplyModifiedProperties();
}
public override void OnInspectorGUI()
{
EditorGUI.indentLevel=0;
serializedObject.Update();
EditorGUILayout.PropertyField(posLook
.FindPropertyRelative(“Array.size”);
for(int i=0;i

在本例中,top
Size
属性是
Camera\u Positioning
组件中阵列的大小。每个后续的
Size
都是针对
CamPosLookArray.PosLookArray
中的每个
CamPosLookArray.PosLookArray
数组。

我试过了,但它拖放了脚本。我是否需要为这个新脚本创建一个编辑器脚本,该脚本也包含一个Camera_定位数组?请参阅dit,我有一个包含Camera_定位数组的类。然后该类成为组件中的一个数组。布局与您的不同,因为我认为您使用了一些编辑器脚本。我试过了,但它做了一个拖放来放入该脚本。我是否需要为这个新脚本创建一个编辑器脚本,该脚本也包含一个Camera_定位数组?请参阅dit,我有一个包含Camera_定位数组的类。然后该类成为组件中的一个数组。布局与您的不同,因为我认为您使用了一些编辑器脚本。使用我当前的代码编辑。使用我当前的代码编辑。MotoSV,我可以给您邮寄一些啤酒吗?因为这是现在
public override void OnInspectorGUI()
{
    EditorGUI.indentLevel = 0;
    serializedObject.Update();

    EditorGUILayout.PropertyField(posLook
                   .FindPropertyRelative("Array.size"));

    for(int i = 0; i < posLook.arraySize; i++)
    {
        SerializedProperty item = posLook.GetArrayElementAtIndex(i);
        SerializedProperty posLookArrayProperty = 
            item.FindPropertyRelative("PosLookArray");

        EditorGUILayout.PropertyField(
            posLookArrayProperty.FindPropertyRelative("Array.size"));

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Camera Position", 
            EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
        EditorGUILayout.LabelField("Camera Look", 
            EditorStyles.boldLabel, GUILayout.Width(Screen.width / 2.8f));
        EditorGUILayout.LabelField("Story", 
            EditorStyles.boldLabel, GUILayout.Width(75f));
        EditorGUILayout.EndHorizontal();

        for(int j = 0; j < posLookArrayProperty.arraySize; j++)
        {
            EditorGUILayout.PropertyField(
                posLookArrayProperty.GetArrayElementAtIndex(j), GUIContent.none);
        }
    }

    serializedObject.ApplyModifiedProperties();
}