2015-09-15 32 views

回答

1

答案在序列化和属性字段中。

用我的代码的例子,这里的第一部分只是显示在我的主脚本中,我已经声明了这个。现在请记住,公共变量已经被序列化了,所以不需要这么做。

public class Original : MonoBehaviour { 

// Used for the user to input their board section width and height. 
[Tooltip("The desired Camera Width.")] 
public float cameraWidth; 
} 

现在,在我的自定义检查我有这样的:

pubilc class Original_Editor : Editor{ 
     public override void OnInspectorGUI(){ 
       serializedObject.Update(); 
       // Get the camera width. 
       SerializedProperty width = serializedObject.FindProperty("cameraWidth"); 
       // Set the layout. 
       EditorGUILayout.PropertyField(width); 
       // Clamp the desired values 
       width.floatValue = Mathf.Clamp((int)width.floatValue, 0, 9999); 
       // apply 
       serializedObject.ApplyModifiedProperties(); 
     } 
    } 
相关问题