Unity 控制public/private 是否暴露给Inspector面板
默认情况下Public是暴露给Unity,protect/private是不暴露给Unity的,但有时候想让外部引用,又不想暴露给Unity,怎么办?
- 对Unity隐藏,使用
[HideInInspector]
using UnityEngine;
using System.Collections;
public class NewBehaviourScript:MonoBehaviour{
[HideInINspector]//起作用
public int bb = 2;
}
- 对Unity暴露,使用
[SerializeField]
using UnityEngine;
using System.Collections;
public class NewBehaviourScript:MonoBehaviour{
[SerializeField]//起作用
private int bb = 2;
}
- 结构体要暴露给Unity,使用
[System.Serializable]
using UnityEngine;
using System.Collections;
[System.Serializabel]//起作用
public class CustomStruct
{
}
public class NewBehaviourScript:MonoBehaviour{
public CustomStruct Cus;//引用后即可
}