我有這個自定義編輯器:
[CustomEditor(typeof(Fluid3D), true)]
public class Fluid3DEditor : Editor
{
public override void OnInspectorGUI()
{
//this method for create default monoBehavior fields
//that i make it in base class (Fluid3D)
DrawDefaultInspector();
EditorUtility.SetDirty(target);
SerializedProperty zz = serializedObject.FindProperty("Particle Radius");
// Debug.Log(zz.intValue);
Fluid3D fluid3D = (Fluid3D)target;
switch (fluid3D.initParticleWay)
{
case InitParticleWay.SPHERE:
Sphere(ref fluid3D);
break;
case InitParticleWay.CUBE:
Cube(ref fluid3D);
break;
}
}
void Sphere(ref Fluid3D fluid3D)
{
fluid3D.BallRadius = EditorGUILayout.FloatField("Sphere Radius", fluid3D.BallRadius);
}
void Cube(ref Fluid3D fluid3D)
{
fluid3D.ParticleRadius = EditorGUILayout.FloatField("Particle Radius", fluid3D.ParticleRadius);
fluid3D.separationFactor = EditorGUILayout.FloatField("Sepreation Factor", fluid3D.separationFactor);
EditorGUILayout.LabelField("Volume", fluid3D.Volume.ToString());
}
Field3D 類的初始值為
private float ballRadius = 0.1f;
public float separationFactor = 1.4f;
private float particleRadius = 0.15f;
當我在運行場景之前從檢查器編輯值時,值沒有改變,只是在游戲中改變,但我需要在游戲開始之前改變。
uj5u.com熱心網友回復:
球半徑和粒子半徑這兩個變數是私有的。序列化它們:
[SerializeField] private float ballRadius = 0.1f;
[SerializeField] public float separationFactor = 1.4f;
[SerializeField] private float particleRadius = 0.15f;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/483844.html
下一篇:Unity腳本未附加到其他腳本