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.

56 lines
2.1 KiB

// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Fungus.EditorUtils
{
/// <summary>
/// Custom drawer for the BlockReference, allows for more easily selecting a target block in external c#
/// scripts.
/// </summary>
[CustomPropertyDrawer(typeof(Fungus.BlockReference))]
public class BlockReferenceDrawer : PropertyDrawer
{
public Fungus.Flowchart lastFlowchart;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var l = EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, l);
position.height = EditorGUIUtility.singleLineHeight;
var block = property.FindPropertyRelative("block");
Fungus.Block b = block.objectReferenceValue as Fungus.Block;
if (block.objectReferenceValue != null && lastFlowchart == null)
{
if (b != null)
{
lastFlowchart = b.GetFlowchart();
}
}
lastFlowchart = EditorGUI.ObjectField(position, lastFlowchart, typeof(Fungus.Flowchart), true) as Fungus.Flowchart;
position.y += EditorGUIUtility.singleLineHeight;
if (lastFlowchart != null)
b = Fungus.EditorUtils.BlockEditor.BlockField(position, new GUIContent("None"), lastFlowchart, b);
else
EditorGUI.PrefixLabel(position, new GUIContent("Flowchart Required"));
block.objectReferenceValue = b;
block.serializedObject.ApplyModifiedProperties();
property.serializedObject.ApplyModifiedProperties();
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight * 2;
}
}
}