This question was
closed Jan 09 at 03:03 AM by
dark9spring for the following reason:
不可重现或已经过期的问题
Question by
dark9spring · Jan 01 at 12:46 PM ·
script errorcustom-inspectorcustomeditor
Using CustomEditor caused error which was CS0246.
I have two classes of my project. First one is some data to show up.
using System;
using UnityEngine;
public class InspectorTest : MonoBehaviour
{
public int a;
public float b;
public string c;
public DataBase d;
}
[Serializable]
public class DataBase
{
public int a;
public float b;
}
Second one is used to exhibit those data onto inspector.
using UnityEditor;
[CustomEditor(typeof(InspectorTest))]
public class InspectorEditor : Editor
{
public SerializedObject inspectorTest;
public SerializedProperty aInteger;
public SerializedProperty bFloat;
public SerializedProperty cString;
public SerializedProperty dDataBase;
private void OnEnable()
{
inspectorTest = new SerializedObject(target);
aInteger = inspectorTest.FindProperty("a");
bFloat = inspectorTest.FindProperty("b");
cString = inspectorTest.FindProperty("c");
dDataBase = inspectorTest.FindProperty("d");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.PropertyField(aInteger);
EditorGUILayout.PropertyField(cString);
EditorGUILayout.PropertyField(bFloat);
EditorGUILayout.PropertyField(dDataBase);
inspectorTest.Update();
}
}
When I typed InspectorTest into "typeof", the compiler done nothing and without any tips. Then caused the error was CS0246. I tried to save my code in VS. The error was remaining here. So I turned to unity and figured out there was no error in console panel but same properties in inspector. First one is located in "Assets/Scripts/Attribute", second one is located in "Assets/Scripts/Attribute/Editor". My Unity version is 2020.3.24.f1c1. How could I fix it?
Comment
I have uploaded inspector panel's image. Wishing this could be helpful.
snipaste-2022-01-01-10-19-09.png
(64.1 kB)