简体   繁体   English

Unity-自定义检查器不可编辑数组

[英]Unity - Custom Inspector non-editable array

i'm creating a voxel game for fun while on vacation and i came across Custom Inspector and Editors, to make my life easier when creating new voxels. 我在度假时创建了一个有趣的体素游戏,并且遇到了Custom Inspector和Editors,这使创建新体素时的生活变得更加轻松。

The problem is: a simple voxel has a mesh composed of an array of 6 faces, each index corresponding to one direction, for example, the north face is the face of index 0, the upper face is index 4, and so on. 问题是:一个简单的体素具有一个网格,该网格由6个面的阵列组成,每个索引对应一个方向,例如,北面是索引0的面,上表面是索引4的依此类推。 But if i leave the inspector to show the array as it is, it's not guaranteed that each face will be placed on the right index. 但是,如果我离开检查器以按原样显示数组,则不能保证每个面都将放置在正确的索引上。

My idea is to create the custom inspector and make it reorganize the array, the script of the editor would contain a new array "faces" (see the code below), that receive a face and a direction, and show in the inspector, making it possible . 我的想法是创建自定义检查器并使它重组数组,编辑器的脚本将包含一个新的数组“ faces”(请参见下面的代码),该数组接收一个人脸和一个方向,并在检查器中显示,有可能。 The current code is: 当前代码是:

 using System; using UnityEditor; using UnityEngine; [CustomEditor(typeof(VoxelMesh))] public class VoxelMeshEditor: Editor { public enum DirectionEnum { North, East, South, West, Up, Down, Other, Special, All } [Serializable] public struct DirectionalFace { public DirectionEnum direction; public Face face; } [SerializeField] private DirectionalFace[] faces; private SerializedObject soEditor; private SerializedProperty spFaces; private void OnEnable() { soEditor = new SerializedObject(this); spFaces = soEditor.FindProperty("faces"); } public override void OnInspectorGUI() { base.OnInspectorGUI(); if (EditorGUILayout.PropertyField(spFaces, true)) { soEditor.ApplyModifiedProperties(); } } } 

The result is: 结果是:

在此处输入图片说明

It creates an unchangeable array, i cannot edit it. 它创建了一个不可更改的数组,我无法对其进行编辑。 How can i make it editable? 我如何使其可编辑?

Thanks in advance. 提前致谢。

尝试将DirectionalFace [] faces变量从private更改为public。

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

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