I’m doing a test to see if I can create an asset instance of a script that I can drag into an object inspector, but afterward it just turns into a blank “default asset”
ScriptableObject script:
public class CF_Constant : ScriptableObject
{
public Color value = new Color (1f, 1f, 1f, 1f);
public Color getValue (float t){ return value; }
}
I turn it into an asset using this script:
static void createConstantCF()
{
CF_Constant c = ScriptableObject.CreateInstance("CF_Constant") as CF_Constant;
string path = AssetDatabase.GenerateUniqueAssetPath("Assets/New Constant CF");
AssetDatabase.CreateAsset(c, path);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = c;
}
and have a custom inspector for it:
public override void OnInspectorGUI()
{
CF_Constant _target = target as CF_Constant;
_target.value = EditorGUILayout.ColorField("Color", _target.value);
}
This works and shows a “CF_Constant (Script)” in the inspector with the custom inspector showing the color property.
The problem is, as soon as I click on anything else, even if I click the newly created asset, it turns into a blank “default asset” and it could not be dragged into a
_target.customColor = EditorGUILayout.ObjectField("Color", _target.customColor, typeof(CF_Constant)) as CF_Constant;
inspector code.
Am I missing something? Or is this just not possible to do?
I’m using Unity 3.3 for a test bed.