desktop-maesty/steve
7 years ago
4 changed files with 103 additions and 0 deletions
@ -0,0 +1,53 @@ |
|||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 9755f9b06e534264e94b45e16e12338e |
||||||
|
timeCreated: 1523271928 |
||||||
|
licenseType: Free |
||||||
|
MonoImporter: |
||||||
|
externalObjects: {} |
||||||
|
serializedVersion: 2 |
||||||
|
defaultReferences: [] |
||||||
|
executionOrder: 0 |
||||||
|
icon: {instanceID: 0} |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
@ -0,0 +1,24 @@ |
|||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using UnityEngine; |
||||||
|
|
||||||
|
namespace Fungus |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// A simple struct wrapping a reference to a Fungus Block. Allows for BlockReferenceDrawer. |
||||||
|
/// This is the recommended way to directly reference a fungus block in external c# scripts, |
||||||
|
/// as it will give you an inspector field that gives a drop down of all the blocks on a |
||||||
|
/// flowchart, in a similar way to what you would expect from selecting a block on a command. |
||||||
|
/// </summary> |
||||||
|
[System.Serializable] |
||||||
|
public struct BlockReference |
||||||
|
{ |
||||||
|
public Block block; |
||||||
|
|
||||||
|
public void Execute() |
||||||
|
{ |
||||||
|
if (block != null) |
||||||
|
block.StartExecution(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: ab8298053f5d7eb49b16e15fb3570c3c |
||||||
|
timeCreated: 1523271928 |
||||||
|
licenseType: Free |
||||||
|
MonoImporter: |
||||||
|
externalObjects: {} |
||||||
|
serializedVersion: 2 |
||||||
|
defaultReferences: [] |
||||||
|
executionOrder: 0 |
||||||
|
icon: {instanceID: 0} |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
Loading…
Reference in new issue