默认情况下Public是暴露给Unity,protect/private是不暴露给Unity的,但有时候想让外部引用,又不想暴露给Unity,怎么办? 对Unity隐藏,使用[HideInInspector] using UnityEngine; using System.Collections; publicclassNewBehaviourScript:MonoBehaviour{ [HideInINspector]//起作用publicintbb =2; } 对Unity暴露,使用[Seria...
//Make the private field of our PlayerStats struct visible in the Inspector //by applying [SerializeField] attribute to it [SerializeField] private PlayerStats stats; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. [InspectorName(“xxx”)] 通过此属...
Unity's inspectorwill notattempt to display properties. A common workaround is to have a private backing field for your property with[SerializeField]attached. Setters won't be called on the value set in the inspector, but since that's only set pre-compilation, that's acceptable. Unity has ...
using System.Collections.Generic; #if UNITY_EDITOR using UnityEditor; #endif using UnityEngine; namespace DialogueSystem { public abstract class DialogNodeDataBase : ScriptableObject { /// /// 节点坐标 /// [HideInInspector] public Vector2 Position = Vector2.zero; [HideInInspector] public st...
通过Init真正生成字典,通过Destroy销毁字典。 通过TryGetValue获取目标值,通过TryAdd添加数据,通过Remove删除数据。 通过ShowDict打印字典内容。 代码 FanDict.cs usingSystem.Collections.Generic;usingUnityEngine;[System.Serializable]publicclassFanDict<K,T>{[SerializeField]privateFanKeyValue<K,T>[]_keyValueElements...
[HideInInspector]//使属性在inspector中隐藏,但是还是可序列化,想赋值可以通过写程序赋值序列化publicfloatCloudHideInInspector =1f; [NonSerialized]//使public属性不能序列化publicfloatCloudNonSerialized =1f; [SerializeField]//使private属性可以被序列化,在面板上显示并且可以读取保存privateboolCloudSerializeField =...
例如,下面的类向Inspector 窗口公开了3个私有字段: usingUnityEngine;publicclassEnemyCreatorComponent:MonoBehaviour{[SerializeField]privateint_numEnemies;[SerializeField]privateGameObject_enemyPrefab;[SerializeField]privateEnemyManagerComponent_enemyManager;voidstart(){for(inti=0;i<_numEnemies;++i){CreateEnemy();...
ShowInInspector Shows non-serialized property in the inspector. private float _field; [ShowInInspector] private bool _myToggle; [ShowInInspector] public float ReadOnlyProperty => _field; [ShowInInspector] public float EditableProperty { get => _field; set => _field = value; } HideReference...
利用反射,将Inspector默认隐藏的字段全都显示出来 包括私有字段, 字典, 字段类的子字段 例: Test_View public class Test_View : MonoBehaviour { private Vector3 _vector3; public MonoBehaviour showMono; public Test_View_Data data; public Dictionary<int, Test_View_Data> dic; ...
利用反射,将Inspector默认隐藏的字段全都显示出来 包括私有字段, 字典, 字段类的子字段 例: Test_View publicclassTest_View:MonoBehaviour{privateVector3 _vector3;publicMonoBehaviour showMono;publicTest_View_Data data;publicDictionary<int,Test_View_Data>dic;privateList<int>ints;} ...