Browse Source

Added custom character editor

master
chrisgregan 11 years ago
parent
commit
3d74c06400
  1. 71
      Assets/Fungus/Dialog/Editor/CharacterEditor.cs
  2. 8
      Assets/Fungus/Dialog/Editor/CharacterEditor.cs.meta
  3. 2
      Assets/Fungus/Dialog/Scripts/Dialog.cs
  4. BIN
      Assets/Shuttle/NewDialog.unity

71
Assets/Fungus/Dialog/Editor/CharacterEditor.cs

@ -0,0 +1,71 @@
using UnityEditor;
using UnityEngine;
using System.Collections;
namespace Fungus.Script
{
[CustomEditor (typeof(Character))]
public class CharacterEditor : Editor
{
Material spriteMaterial;
void OnEnable()
{
Shader shader = Shader.Find("Sprites/Default");
if (shader != null)
{
spriteMaterial = new Material(shader);
}
}
public override void OnInspectorGUI()
{
Character t = target as Character;
EditorGUI.BeginChangeCheck();
string characterName = EditorGUILayout.TextField(new GUIContent("Name Text", "Name of the character display in the dialog"),
t.characterName);
Color characterColor = EditorGUILayout.ColorField(new GUIContent("Text Color", "Color of name text display in the dialog"),
t.characterColor);
Sprite characterImage = EditorGUILayout.ObjectField(new GUIContent("Image", "Character image sprite to display in the dialog"),
t.characterImage,
typeof(Sprite),
true) as Sprite;
Dialog.DialogSide dialogSide = (Dialog.DialogSide)EditorGUILayout.EnumPopup(new GUIContent("Image Side", "Which side to display the image in the dialog"),
t.dialogSide);
EditorGUILayout.Separator();
if (characterImage != null &&
spriteMaterial != null)
{
float aspect = (float)characterImage.texture.width / (float)characterImage.texture.height;
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
Rect imagePreviewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(150), GUILayout.ExpandWidth(false));
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
EditorGUI.DrawPreviewTexture(imagePreviewRect,
characterImage.texture,
spriteMaterial);
}
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Set Character");
t.characterName = characterName;
t.characterColor = characterColor;
t.characterImage = characterImage;
t.dialogSide = dialogSide;
}
}
}
}

8
Assets/Fungus/Dialog/Editor/CharacterEditor.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ae00f6490546486da033e6785d09f54
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

2
Assets/Fungus/Dialog/Scripts/Dialog.cs

@ -76,7 +76,6 @@ namespace Fungus.Script
if (rightImage != null)
{
rightImage.sprite = null;
if (image != null &&
side == DialogSide.Right)
{
@ -85,7 +84,6 @@ namespace Fungus.Script
}
else
{
rightImage.sprite = null;
rightImage.enabled = false;
}
}

BIN
Assets/Shuttle/NewDialog.unity

Binary file not shown.
Loading…
Cancel
Save