An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.1 KiB

using UnityEditor;
using UnityEngine;
using System.Collections;
namespace Fungus
{
[CustomEditor (typeof(Character))]
public class CharacterEditor : Editor
{
protected Material spriteMaterial;
protected SerializedProperty nameTextProp;
protected SerializedProperty nameColorProp;
protected SerializedProperty sayDialogBoxProp;
protected SerializedProperty chooseDialogBoxProp;
protected SerializedProperty profileSpriteProp;
protected SerializedProperty soundEffectProp;
protected SerializedProperty notesProp;
protected virtual void OnEnable()
{
nameTextProp = serializedObject.FindProperty ("nameText");
nameColorProp = serializedObject.FindProperty ("nameColor");
sayDialogBoxProp = serializedObject.FindProperty ("sayDialogBox");
chooseDialogBoxProp = serializedObject.FindProperty ("chooseDialogBox");
profileSpriteProp = serializedObject.FindProperty ("profileSprite");
soundEffectProp = serializedObject.FindProperty ("soundEffect");
notesProp = serializedObject.FindProperty ("notes");
Shader shader = Shader.Find("Sprites/Default");
if (shader != null)
{
spriteMaterial = new Material(shader);
spriteMaterial.hideFlags = HideFlags.DontSave;
}
}
protected virtual void OnDisable()
{
DestroyImmediate(spriteMaterial);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(nameTextProp, new GUIContent("Name Text", "Name of the character display in the dialog"));
EditorGUILayout.PropertyField(nameColorProp, new GUIContent("Name Color", "Color of name text display in the dialog"));
EditorGUILayout.PropertyField(sayDialogBoxProp, new GUIContent("Say Dialog", "Say dialog box this character should use"));
EditorGUILayout.PropertyField(chooseDialogBoxProp, new GUIContent("Choose Dialog", "Choose dialog box this character should use"));
EditorGUILayout.PropertyField(profileSpriteProp, new GUIContent("Image", "Character image sprite to display in the dialog"));
EditorGUILayout.PropertyField(soundEffectProp, new GUIContent("Sound Effect", "Sound to play when the character is talking. Overrides the setting in the Dialog."));
EditorGUILayout.PropertyField(notesProp, new GUIContent("Notes", "Notes about this story character (personality, attibutes, etc.)"));
EditorGUILayout.Separator();
Character t = target as Character;
if (t.profileSprite != null &&
spriteMaterial != null)
{
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
float aspect = (float)t.profileSprite.texture.width / (float)t.profileSprite.texture.height;
Rect imagePreviewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(250), GUILayout.ExpandWidth(true));
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
DrawPreview(imagePreviewRect, t.profileSprite.texture);
}
serializedObject.ApplyModifiedProperties();
}
public virtual void DrawPreview(Rect previewRect, Texture2D texture)
{
if (texture == null)
{
return;
}
EditorGUI.DrawPreviewTexture(previewRect,
texture,
spriteMaterial);
}
}
}