This question was
closed Apr 10, 2017 at 09:23 AM by
jamescauwelier for the following reason:
Solved before passing moderation
Question by
jamescauwelier · Apr 10, 2017 at 09:25 AM ·
extensions
[SOLVED] How to use multiple object fields in custom editor?
I am creating a custom window with multiple object fields. Whatever I do I can only get 1 field to work and accept TextAssets. The XmlFile attribute works, the other two don't.
They look exactly the same to me and I really can't tell what I'm doing wrong. It could be something very simple as I am very new to Unity.
Any help is much appreciated!
UPDATE
I was assigning to Font instead of FontMetadata in the third call to .ObjectField(). Assigning to the proper field fixed the issue completely.
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class CustomWindow : EditorWindow
{
public TextAsset Font;
public TextAsset XmlFile;
public TextAsset FontMetadata;
[MenuItem("Window/XML")]
public static void ShowWindow()
{
var window = EditorWindow.GetWindow(typeof(CustomWindow), false, "Custom import");
//window.Show();
}
public void OnGUI()
{
GUILayout.Label("Import settings", EditorStyles.boldLabel);
EditorGUIUtility.labelWidth = 100;
this.Font = (TextAsset)EditorGUILayout.ObjectField("Font", this.Font, typeof(TextAsset), true);
this.XmlFile = (TextAsset)EditorGUILayout.ObjectField("XML file", this.XmlFile, typeof(TextAsset), true);
this.Font = (TextAsset)EditorGUILayout.ObjectField("Font metadata", this.FontMetadata, typeof(TextAsset), true);
EditorGUILayout.BeginHorizontal();
GUILayout.Space(100);
bool clicked = GUILayout.Button("Process");
EditorGUILayout.EndHorizontal();
if (clicked)
{
Debug.Log("Should be processing now");
}
}
}
Comment