chrisgregan
10 years ago
46 changed files with 1293 additions and 1 deletions
@ -0,0 +1,36 @@
|
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Fungus; |
||||
|
||||
[CustomEditor (typeof(FungusCommand), true)] |
||||
public class FungusCommandEditor : Editor |
||||
{ |
||||
|
||||
public override void OnInspectorGUI() |
||||
{ |
||||
Rect rect = EditorGUILayout.BeginVertical(); |
||||
|
||||
DrawDefaultInspector(); |
||||
|
||||
FungusCommand t = target as FungusCommand; |
||||
if (t != null) |
||||
{ |
||||
if (t.errorMessage.Length > 0) |
||||
{ |
||||
GUIStyle style = new GUIStyle(GUI.skin.label); |
||||
style.normal.textColor = new Color(1,0,0); |
||||
EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style); |
||||
} |
||||
|
||||
if (t.IsExecuting()) |
||||
{ |
||||
EditorGUI.DrawRect(rect, new Color(1f, 1f, 0f, 0.25f)); |
||||
} |
||||
} |
||||
|
||||
EditorGUILayout.EndVertical(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 80223e3961e4449e8a0f1262d71c0cac |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,189 @@
|
||||
using UnityEngine; |
||||
using UnityEditor; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Fungus; |
||||
|
||||
public class FungusEditorWindow : EditorWindow |
||||
{ |
||||
private List<Sequence> windowSequenceMap = new List<Sequence>(); |
||||
private Vector2 scrollPos; // ScrollViews use a Vector2 to track the state of each scroll bar |
||||
|
||||
private GameObject cachedSelection; |
||||
|
||||
[MenuItem("Window/Fungus Editor")] |
||||
static void Init() |
||||
{ |
||||
GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor"); |
||||
} |
||||
|
||||
public void OnInspectorUpdate() |
||||
{ |
||||
Repaint(); |
||||
} |
||||
|
||||
SequenceController GetSequenceController() |
||||
{ |
||||
GameObject activeObject = Selection.activeGameObject; |
||||
|
||||
while (activeObject != null) |
||||
{ |
||||
SequenceController sequenceController = activeObject.GetComponent<SequenceController>(); |
||||
Sequence sequence = activeObject.GetComponent<Sequence>(); |
||||
|
||||
if (sequenceController != null) |
||||
{ |
||||
// Found sequence controller |
||||
return sequenceController; |
||||
} |
||||
else if (sequence != null && |
||||
sequence.transform.parent != null) |
||||
{ |
||||
// Check parent for sequence controller |
||||
activeObject = sequence.transform.parent.gameObject; |
||||
} |
||||
else |
||||
{ |
||||
activeObject = null; |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
void OnGUI() |
||||
{ |
||||
SequenceController sequenceController = GetSequenceController(); |
||||
if (sequenceController == null) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
// BeginScrollView lets you specify a region that 'looks into' a much larger area. In this case, we create a canvas |
||||
// 1000px X 1000px in size that's constrained to the same region as the EditorWindow. If the scrollbars are modified, |
||||
// the new values are stored in the Vector2 that's returned. |
||||
// http://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginScrollView.html |
||||
scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPos, new Rect(0, 0, 1000, 1000)); |
||||
|
||||
// In games, GUI.Window pops up a window on your screen. In the Editor, GUI.Window shows a sub-window inside an EditorWindow. |
||||
// All calls to GUI.Window need to be wrapped in a BeginWindows / EndWindows pair. |
||||
// http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.BeginWindows.html |
||||
BeginWindows(); |
||||
|
||||
Sequence[] sequences = sequenceController.GetComponentsInChildren<Sequence>(); |
||||
|
||||
windowSequenceMap.Clear(); |
||||
for (int i = 0; i < sequences.Length; ++i) |
||||
{ |
||||
Sequence sequence = sequences[i]; |
||||
sequence.nodeRect = GUI.Window(i, sequence.nodeRect, DrawWindow, sequence.name); |
||||
windowSequenceMap.Add(sequence); |
||||
} |
||||
|
||||
// Draw connections |
||||
foreach (Sequence s in windowSequenceMap) |
||||
{ |
||||
DrawConnections(s, false); |
||||
} |
||||
foreach (Sequence s in windowSequenceMap) |
||||
{ |
||||
DrawConnections(s, true); |
||||
} |
||||
|
||||
EndWindows(); |
||||
|
||||
GUI.EndScrollView(); |
||||
} |
||||
|
||||
void DrawWindow(int windowId) |
||||
{ |
||||
// Select game object when node is clicked |
||||
if (Event.current.button == 0 && |
||||
Event.current.type == EventType.MouseUp) |
||||
{ |
||||
if (windowId < windowSequenceMap.Count) |
||||
{ |
||||
Sequence s = windowSequenceMap[windowId]; |
||||
if (s != null) |
||||
{ |
||||
Selection.activeGameObject = s.gameObject; |
||||
} |
||||
} |
||||
} |
||||
|
||||
Sequence sequence = windowSequenceMap[windowId]; |
||||
|
||||
GUIStyle style = new GUIStyle(GUI.skin.box); |
||||
|
||||
FungusCommand[] commands = sequence.gameObject.GetComponents<FungusCommand>(); |
||||
foreach (FungusCommand command in commands) |
||||
{ |
||||
string commandName = command.GetType().Name; |
||||
commandName = commandName.Replace("Command", ""); |
||||
|
||||
if (command.errorMessage.Length > 0) |
||||
{ |
||||
GUI.backgroundColor = Color.red; |
||||
} |
||||
else if (command.IsExecuting()) |
||||
{ |
||||
GUI.backgroundColor = Color.yellow; |
||||
} |
||||
else |
||||
{ |
||||
GUI.backgroundColor = Color.white; |
||||
} |
||||
|
||||
GUILayout.Label(commandName, style, GUILayout.ExpandWidth(true)); |
||||
} |
||||
|
||||
GUI.DragWindow(); |
||||
} |
||||
|
||||
void DrawConnections(Sequence sequence, bool highlightedOnly) |
||||
{ |
||||
List<Sequence> connectedSequences = new List<Sequence>(); |
||||
|
||||
FungusCommand[] commands = sequence.GetComponentsInChildren<FungusCommand>(); |
||||
foreach (FungusCommand command in commands) |
||||
{ |
||||
bool isExecuting = command.IsExecuting(); |
||||
|
||||
if (highlightedOnly && !isExecuting || |
||||
!highlightedOnly && isExecuting) |
||||
{ |
||||
continue; |
||||
} |
||||
|
||||
connectedSequences.Clear(); |
||||
command.GetConnectedSequences(ref connectedSequences); |
||||
|
||||
foreach (Sequence sequenceB in connectedSequences) |
||||
{ |
||||
Rect rectA = sequence.nodeRect; |
||||
Rect rectB = sequenceB.nodeRect; |
||||
|
||||
Vector2 pointA; |
||||
Vector2 pointB; |
||||
|
||||
Vector2 p1 = rectA.center; |
||||
Vector2 p2 = rectB.center; |
||||
GLDraw.segment_rect_intersection(rectA, ref p1, ref p2); |
||||
pointA = p2; |
||||
|
||||
p1 = rectB.center; |
||||
p2 = rectA.center; |
||||
GLDraw.segment_rect_intersection(rectB, ref p1, ref p2); |
||||
pointB = p2; |
||||
|
||||
Color color = Color.grey; |
||||
if (command.IsExecuting()) |
||||
{ |
||||
color = Color.yellow; |
||||
} |
||||
|
||||
GLDraw.DrawConnectingCurve(pointA, pointB, color, 2); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 4fbdd10bc8bb942a588a63ffdcb57895 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 6ae11e36c1f504a5db97beed10849329 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
userData: |
After Width: | Height: | Size: 2.9 KiB |
@ -0,0 +1,47 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 8139f896cbf0a44b69c097c5f2e491e6 |
||||
TextureImporter: |
||||
fileIDToRecycleName: {} |
||||
serializedVersion: 2 |
||||
mipmaps: |
||||
mipMapMode: 0 |
||||
enableMipMap: 0 |
||||
linearTexture: 0 |
||||
correctGamma: 0 |
||||
fadeOut: 0 |
||||
borderMipMap: 0 |
||||
mipMapFadeDistanceStart: 1 |
||||
mipMapFadeDistanceEnd: 3 |
||||
bumpmap: |
||||
convertToNormalMap: 0 |
||||
externalNormalMap: 0 |
||||
heightScale: .25 |
||||
normalMapFilter: 0 |
||||
isReadable: 0 |
||||
grayScaleToAlpha: 0 |
||||
generateCubemap: 0 |
||||
seamlessCubemap: 0 |
||||
textureFormat: -1 |
||||
maxTextureSize: 1024 |
||||
textureSettings: |
||||
filterMode: -1 |
||||
aniso: -1 |
||||
mipBias: -1 |
||||
wrapMode: 1 |
||||
nPOTScale: 0 |
||||
lightmap: 0 |
||||
compressionQuality: 50 |
||||
spriteMode: 0 |
||||
spriteExtrude: 1 |
||||
spriteMeshType: 1 |
||||
alignment: 0 |
||||
spritePivot: {x: .5, y: .5} |
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
||||
spritePixelsToUnits: 100 |
||||
alphaIsTransparency: 1 |
||||
textureType: 5 |
||||
buildTargetSettings: [] |
||||
spriteSheet: |
||||
sprites: [] |
||||
spritePackingTag: |
||||
userData: |
@ -0,0 +1,16 @@
|
||||
using UnityEditor; |
||||
using UnityEditorInternal; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Fungus; |
||||
|
||||
/* |
||||
[CustomEditor (typeof(SayCommand))] |
||||
public class SayCommandEditor : Editor |
||||
{ |
||||
public override void OnInspectorGUI() |
||||
{ |
||||
} |
||||
} |
||||
*/ |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 9cf4a398fbf29437cb1c786f4d196279 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,10 @@
|
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Fungus; |
||||
|
||||
[CustomEditor (typeof(Sequence))] |
||||
public class SequenceEditor : Editor |
||||
{ |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 2c421ad4b1b9d4c48a3a04de2cb8146a |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: e5b842381bd124899be70e0726dd4505 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
userData: |
@ -0,0 +1,62 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
public static class EditorExtensions |
||||
{ |
||||
/// <summary> |
||||
/// FindDerivedTypesFromAssembly allows a user to query all of types derived from a |
||||
/// particular Type at runtime. |
||||
/// Example usage: |
||||
/// foreach (System.Type st in EditorUtility.FindDerivedTypesFromAssembly(System.Reflection.Assembly.GetAssembly(typeof(BaseTimelineEvent)), typeof(BaseTimelineEvent), true)) |
||||
/// </summary> |
||||
/// <param name="assembly">The assembly to search in</param> |
||||
/// <param name="baseType">The base Type from which all returned Types derive</param> |
||||
/// <param name="classOnly">If true, only class Types will be returned</param> |
||||
/// <returns></returns> |
||||
public static System.Type[] FindDerivedTypesFromAssembly(this System.Reflection.Assembly assembly, System.Type baseType, bool classOnly = true) |
||||
{ |
||||
if (assembly == null) |
||||
Debug.LogError("Assembly must be defined"); |
||||
if (baseType == null) |
||||
Debug.LogError("Base type must be defined"); |
||||
|
||||
// Iterate through all available types in the assembly |
||||
var types = assembly.GetTypes().Where(type => |
||||
{ |
||||
if (classOnly && !type.IsClass) |
||||
return false; |
||||
|
||||
if (baseType.IsInterface) |
||||
{ |
||||
var it = type.GetInterface(baseType.FullName); |
||||
|
||||
if (it != null) |
||||
return true; |
||||
} |
||||
else if (type.IsSubclassOf(baseType)) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
); |
||||
|
||||
return types.ToArray(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// A convenient method for calling the above. |
||||
/// Example usage: |
||||
/// List<System.Type> subTypes = EditorUtility.FindDerivedTypes(typeof(BaseTimelineEvent)).ToList(); |
||||
/// </summary> |
||||
/// <param name="baseType"></param> |
||||
/// <param name="classOnly"></param> |
||||
/// <returns></returns> |
||||
public static System.Type[] FindDerivedTypes(System.Type baseType, bool classOnly = true) |
||||
{ |
||||
return FindDerivedTypesFromAssembly(System.Reflection.Assembly.GetAssembly(baseType), baseType, classOnly); |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 4d2feaeae344d44e681ac408cb745f03 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,264 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System; |
||||
|
||||
public class GLDraw |
||||
{ |
||||
/* |
||||
* Clipping code: http://forum.unity3d.com/threads/17066-How-to-draw-a-GUI-2D-quot-line-quot?p=230386#post230386 |
||||
* Thick line drawing code: http://unifycommunity.com/wiki/index.php?title=VectorLine |
||||
*/ |
||||
protected static bool clippingEnabled; |
||||
protected static Rect clippingBounds; |
||||
public static Material lineMaterial = null; |
||||
|
||||
/* @ Credit: "http://cs-people.bu.edu/jalon/cs480/Oct11Lab/clip.c" */ |
||||
protected static bool clip_test(float p, float q, ref float u1, ref float u2) |
||||
{ |
||||
float r; |
||||
bool retval = true; |
||||
|
||||
if (p < 0.0) |
||||
{ |
||||
r = q / p; |
||||
if (r > u2) |
||||
retval = false; |
||||
else if (r > u1) |
||||
u1 = r; |
||||
} |
||||
else if (p > 0.0) |
||||
{ |
||||
r = q / p; |
||||
if (r < u1) |
||||
retval = false; |
||||
else if (r < u2) |
||||
u2 = r; |
||||
} |
||||
else if (q < 0.0) |
||||
retval = false; |
||||
|
||||
return retval; |
||||
} |
||||
|
||||
public static bool segment_rect_intersection(Rect bounds, ref Vector2 p1, ref Vector2 p2) |
||||
{ |
||||
float u1 = 0.0f, u2 = 1.0f, dx = p2.x - p1.x, dy; |
||||
|
||||
if (clip_test(-dx, p1.x - bounds.xMin, ref u1, ref u2)) |
||||
{ |
||||
if (clip_test(dx, bounds.xMax - p1.x, ref u1, ref u2)) |
||||
{ |
||||
dy = p2.y - p1.y; |
||||
if (clip_test(-dy, p1.y - bounds.yMin, ref u1, ref u2)) |
||||
{ |
||||
if (clip_test(dy, bounds.yMax - p1.y, ref u1, ref u2)) |
||||
{ |
||||
if (u2 < 1.0) |
||||
{ |
||||
p2.x = p1.x + u2 * dx; |
||||
p2.y = p1.y + u2 * dy; |
||||
} |
||||
|
||||
if (u1 > 0.0) |
||||
{ |
||||
p1.x += u1 * dx; |
||||
p1.y += u1 * dy; |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public static void BeginGroup(Rect position) |
||||
{ |
||||
clippingEnabled = true; |
||||
clippingBounds = new Rect(0, 0, position.width, position.height); |
||||
GUI.BeginGroup(position); |
||||
} |
||||
|
||||
public static void EndGroup() |
||||
{ |
||||
GUI.EndGroup(); |
||||
clippingBounds = new Rect(0, 0, Screen.width, Screen.height); |
||||
clippingEnabled = false; |
||||
} |
||||
|
||||
public static void CreateMaterial() |
||||
{ |
||||
if (lineMaterial != null) |
||||
return; |
||||
|
||||
lineMaterial = new Material("Shader \"Lines/Colored Blended\" {" + |
||||
"SubShader { Pass { " + |
||||
" Blend SrcAlpha OneMinusSrcAlpha " + |
||||
" ZWrite Off Cull Off Fog { Mode Off } " + |
||||
" BindChannels {" + |
||||
" Bind \"vertex\", vertex Bind \"color\", color }" + |
||||
"} } }"); |
||||
lineMaterial.hideFlags = HideFlags.HideAndDontSave; |
||||
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave; |
||||
} |
||||
|
||||
public static void DrawLine(Vector2 start, Vector2 end, Color color, float width) |
||||
{ |
||||
if (Event.current == null) |
||||
return; |
||||
if (Event.current.type != EventType.repaint) |
||||
return; |
||||
|
||||
if (clippingEnabled) |
||||
if (!segment_rect_intersection(clippingBounds, ref start, ref end)) |
||||
return; |
||||
|
||||
CreateMaterial(); |
||||
|
||||
lineMaterial.SetPass(0); |
||||
|
||||
Vector3 startPt; |
||||
Vector3 endPt; |
||||
|
||||
if (width == 1) |
||||
{ |
||||
GL.Begin(GL.LINES); |
||||
GL.Color(color); |
||||
startPt = new Vector3(start.x, start.y, 0); |
||||
endPt = new Vector3(end.x, end.y, 0); |
||||
GL.Vertex(startPt); |
||||
GL.Vertex(endPt); |
||||
} |
||||
else |
||||
{ |
||||
GL.Begin(GL.QUADS); |
||||
GL.Color(color); |
||||
startPt = new Vector3(end.y, start.x, 0); |
||||
endPt = new Vector3(start.y, end.x, 0); |
||||
Vector3 perpendicular = (startPt - endPt).normalized * width; |
||||
Vector3 v1 = new Vector3(start.x, start.y, 0); |
||||
Vector3 v2 = new Vector3(end.x, end.y, 0); |
||||
GL.Vertex(v1 - perpendicular); |
||||
GL.Vertex(v1 + perpendicular); |
||||
GL.Vertex(v2 + perpendicular); |
||||
GL.Vertex(v2 - perpendicular); |
||||
} |
||||
GL.End(); |
||||
} |
||||
|
||||
public static void DrawBox(Rect box, Color color, float width) |
||||
{ |
||||
Vector2 p1 = new Vector2(box.xMin, box.yMin); |
||||
Vector2 p2 = new Vector2(box.xMax, box.yMin); |
||||
Vector2 p3 = new Vector2(box.xMax, box.yMax); |
||||
Vector2 p4 = new Vector2(box.xMin, box.yMax); |
||||
DrawLine(p1, p2, color, width); |
||||
DrawLine(p2, p3, color, width); |
||||
DrawLine(p3, p4, color, width); |
||||
DrawLine(p4, p1, color, width); |
||||
} |
||||
|
||||
public static void DrawBox(Vector2 topLeftCorner, Vector2 bottomRightCorner, Color color, float width) |
||||
{ |
||||
Rect box = new Rect(topLeftCorner.x, topLeftCorner.y, bottomRightCorner.x - topLeftCorner.x, bottomRightCorner.y - topLeftCorner.y); |
||||
DrawBox(box, color, width); |
||||
} |
||||
|
||||
public static void DrawRoundedBox(Rect box, float radius, Color color, float width) |
||||
{ |
||||
Vector2 p1, p2, p3, p4, p5, p6, p7, p8; |
||||
p1 = new Vector2(box.xMin + radius, box.yMin); |
||||
p2 = new Vector2(box.xMax - radius, box.yMin); |
||||
p3 = new Vector2(box.xMax, box.yMin + radius); |
||||
p4 = new Vector2(box.xMax, box.yMax - radius); |
||||
p5 = new Vector2(box.xMax - radius, box.yMax); |
||||
p6 = new Vector2(box.xMin + radius, box.yMax); |
||||
p7 = new Vector2(box.xMin, box.yMax - radius); |
||||
p8 = new Vector2(box.xMin, box.yMin + radius); |
||||
|
||||
DrawLine(p1, p2, color, width); |
||||
DrawLine(p3, p4, color, width); |
||||
DrawLine(p5, p6, color, width); |
||||
DrawLine(p7, p8, color, width); |
||||
|
||||
Vector2 t1, t2; |
||||
float halfRadius = radius / 2; |
||||
|
||||
t1 = new Vector2(p8.x, p8.y + halfRadius); |
||||
t2 = new Vector2(p1.x - halfRadius, p1.y); |
||||
DrawBezier(p8, t1, p1, t2, color, width); |
||||
|
||||
t1 = new Vector2(p2.x + halfRadius, p2.y); |
||||
t2 = new Vector2(p3.x, p3.y - halfRadius); |
||||
DrawBezier(p2, t1, p3, t2, color, width); |
||||
|
||||
t1 = new Vector2(p4.x, p4.y + halfRadius); |
||||
t2 = new Vector2(p5.x + halfRadius, p5.y); |
||||
DrawBezier(p4, t1, p5, t2, color, width); |
||||
|
||||
t1 = new Vector2(p6.x - halfRadius, p6.y); |
||||
t2 = new Vector2(p7.x, p7.y + halfRadius); |
||||
DrawBezier(p6, t1, p7, t2, color, width); |
||||
} |
||||
|
||||
public static void DrawConnectingCurve(Vector2 start, Vector2 end, Color color, float width) |
||||
{ |
||||
Vector2 distance = start - end; |
||||
|
||||
Vector2 tangentA = start; |
||||
tangentA.x -= distance.x * 0.5f; |
||||
Vector2 tangentB = end; |
||||
tangentB.x += distance.x * 0.5f; |
||||
|
||||
int segments = Mathf.FloorToInt((distance.magnitude / 20) * 3); |
||||
|
||||
DrawBezier(start, tangentA, end, tangentB, color, width, segments); |
||||
|
||||
Vector2 pA = CubeBezier(start, tangentA, end, tangentB, 0.7f); |
||||
Vector2 pB = CubeBezier(start, tangentA, end, tangentB, 0.8f); |
||||
|
||||
float arrowHeadSize = 10; |
||||
|
||||
Vector2 arrowPosA = pB; |
||||
Vector2 arrowPosB = arrowPosA; |
||||
Vector2 arrowPosC = arrowPosA; |
||||
|
||||
Vector2 dir = (pB - pA).normalized; |
||||
|
||||
arrowPosB.x += dir.y * arrowHeadSize; |
||||
arrowPosB.y -= dir.x * arrowHeadSize; |
||||
arrowPosB -= dir * arrowHeadSize; |
||||
|
||||
arrowPosC.x -= dir.y * arrowHeadSize; |
||||
arrowPosC.y += dir.x * arrowHeadSize; |
||||
arrowPosC -= dir * arrowHeadSize; |
||||
|
||||
DrawLine(arrowPosA, arrowPosB, color, 1); |
||||
DrawLine(arrowPosA, arrowPosC, color, 1); |
||||
DrawLine(arrowPosB, arrowPosC, color, 1); |
||||
} |
||||
|
||||
public static void DrawBezier(Vector2 start, Vector2 startTangent, Vector2 end, Vector2 endTangent, Color color, float width) |
||||
{ |
||||
int segments = Mathf.FloorToInt((start - end).magnitude / 20) * 3; // Three segments per distance of 20 |
||||
DrawBezier(start, startTangent, end, endTangent, color, width, segments); |
||||
} |
||||
|
||||
public static void DrawBezier(Vector2 start, Vector2 startTangent, Vector2 end, Vector2 endTangent, Color color, float width, int segments) |
||||
{ |
||||
Vector2 startVector = CubeBezier(start, startTangent, end, endTangent, 0); |
||||
for (int i = 1; i <= segments; i++) |
||||
{ |
||||
Vector2 endVector = CubeBezier(start, startTangent, end, endTangent, i / (float)segments); |
||||
DrawLine(startVector, endVector, color, width); |
||||
startVector = endVector; |
||||
} |
||||
} |
||||
|
||||
private static Vector2 CubeBezier(Vector2 s, Vector2 st, Vector2 e, Vector2 et, float t) |
||||
{ |
||||
float rt = 1 - t; |
||||
float rtt = rt * t; |
||||
return rt * rt * rt * s + 3 * rt * rtt * st + 3 * rtt * t * et + t * t * t * e; |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 5184535fd41514a0ebd42c1d70a53545 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
@ -0,0 +1,50 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 0e15bd6b84cec4a2499ad47398736102 |
||||
TextureImporter: |
||||
fileIDToRecycleName: |
||||
21300000: Mushroom |
||||
21300002: Mushroom 1 |
||||
21300004: ScriptIcon |
||||
serializedVersion: 2 |
||||
mipmaps: |
||||
mipMapMode: 0 |
||||
enableMipMap: 0 |
||||
linearTexture: 0 |
||||
correctGamma: 0 |
||||
fadeOut: 0 |
||||
borderMipMap: 0 |
||||
mipMapFadeDistanceStart: 1 |
||||
mipMapFadeDistanceEnd: 3 |
||||
bumpmap: |
||||
convertToNormalMap: 0 |
||||
externalNormalMap: 0 |
||||
heightScale: .25 |
||||
normalMapFilter: 0 |
||||
isReadable: 0 |
||||
grayScaleToAlpha: 0 |
||||
generateCubemap: 0 |
||||
seamlessCubemap: 0 |
||||
textureFormat: -3 |
||||
maxTextureSize: 1024 |
||||
textureSettings: |
||||
filterMode: -1 |
||||
aniso: 1 |
||||
mipBias: -1 |
||||
wrapMode: 1 |
||||
nPOTScale: 0 |
||||
lightmap: 0 |
||||
compressionQuality: 50 |
||||
spriteMode: 1 |
||||
spriteExtrude: 1 |
||||
spriteMeshType: 1 |
||||
alignment: 0 |
||||
spritePivot: {x: .5, y: .5} |
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
||||
spritePixelsToUnits: 100 |
||||
alphaIsTransparency: 1 |
||||
textureType: 8 |
||||
buildTargetSettings: [] |
||||
spriteSheet: |
||||
sprites: [] |
||||
spritePackingTag: |
||||
userData: |
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 3d934f071cde745c4b765174311a8a71 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
userData: |
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 84ac7916d4a1e49b79780733895b5fd2 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
userData: |
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 5eb4cf18a4b5a440ba6e04861135daba |
||||
DefaultImporter: |
||||
userData: |
@ -0,0 +1,37 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using Fungus; |
||||
|
||||
public class SequenceTestRoom : Room |
||||
{ |
||||
public SequenceController sequenceController; |
||||
|
||||
void OnEnter() |
||||
{ |
||||
sequenceController.ExecuteSequence(sequenceController.activeSequence); |
||||
|
||||
/* |
||||
Sequence s = GetComponent<Sequence>(); |
||||
|
||||
s.Add(new Say("New sequencer 1")); |
||||
s.Add(new AddOption("Button 1", Clicked)); |
||||
//s.Add(new AddOption("Button 2", Clicked)); |
||||
//s.Add(new AddOption("Button 3", Clicked)); |
||||
s.Add(new Say("New sequencer 2")); |
||||
s.Add(new Say("New sequencer 3")); |
||||
|
||||
s.Execute(); |
||||
*/ |
||||
} |
||||
|
||||
void Clicked() |
||||
{ |
||||
/* |
||||
Sequence s = GetComponent<Sequence>(); |
||||
|
||||
s.Clear(); |
||||
s.Add(new Say("You have clicked")); |
||||
s.Execute(); |
||||
*/ |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ef19cdad7345445e28e7e646ad7a6c56 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 1a6df1b36ed2546c49bdbfaaff2cc9f5 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
userData: |
@ -0,0 +1,44 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public class ExecuteCommand : FungusCommand |
||||
{ |
||||
public Sequence targetSequence; |
||||
|
||||
public override void OnExecute() |
||||
{ |
||||
if (targetSequence == null) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
ExecuteSequence(targetSequence); |
||||
} |
||||
|
||||
public void OnDrawGizmos() |
||||
{ |
||||
if (targetSequence == null) |
||||
{ |
||||
errorMessage = "Please select a Target Sequence object"; |
||||
} |
||||
else |
||||
{ |
||||
errorMessage = ""; |
||||
} |
||||
} |
||||
|
||||
public override void GetConnectedSequences(ref List<Sequence> connectedSequences) |
||||
{ |
||||
if (targetSequence != null) |
||||
{ |
||||
connectedSequences.Add(targetSequence); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: c6a48e2d0a0f542d69398d3c180375da |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,80 @@
|
||||
#if UNITY_EDITOR |
||||
using UnityEditor; |
||||
#endif |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public class FungusCommand : MonoBehaviour |
||||
{ |
||||
[HideInInspector] |
||||
public string errorMessage = ""; |
||||
|
||||
[HideInInspector] |
||||
public SequenceController parentSequenceController; |
||||
|
||||
[HideInInspector] |
||||
public Sequence parentSequence; |
||||
|
||||
public virtual void Start() |
||||
{ |
||||
parentSequence = GetComponent<Sequence>(); |
||||
|
||||
// Populate sequenceController reference |
||||
Transform parent = transform.parent; |
||||
while (parent != null) |
||||
{ |
||||
parentSequenceController = parent.gameObject.GetComponent<SequenceController>(); |
||||
if (parentSequenceController != null) |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public bool IsExecuting() |
||||
{ |
||||
if (parentSequence == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return (parentSequence.activeCommand == this); |
||||
} |
||||
|
||||
public virtual void Execute() |
||||
{ |
||||
OnEnter(); |
||||
OnExecute(); |
||||
} |
||||
|
||||
public virtual void ExecuteNextCommand() |
||||
{ |
||||
OnExit(); |
||||
parentSequence.ExecuteNextCommand(this); |
||||
} |
||||
|
||||
public virtual void ExecuteSequence(Sequence s) |
||||
{ |
||||
OnExit(); |
||||
parentSequence.Finish(); |
||||
parentSequenceController.ExecuteSequence(s); |
||||
} |
||||
|
||||
public virtual void OnEnter() |
||||
{} |
||||
|
||||
public virtual void OnExit() |
||||
{} |
||||
|
||||
public virtual void OnExecute() |
||||
{} |
||||
|
||||
public virtual void GetConnectedSequences(ref List<Sequence> connectedSequences) |
||||
{} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 8e206154a3e694fb2bfc9e518a474603 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,53 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public class IfBooleanCommand : FungusCommand |
||||
{ |
||||
public string key; |
||||
|
||||
public Sequence trueSequence; |
||||
public Sequence falseSequence; |
||||
|
||||
public override void OnExecute() |
||||
{ |
||||
if (Variables.GetBoolean(key)) |
||||
{ |
||||
ExecuteSequence(trueSequence); |
||||
} |
||||
else |
||||
{ |
||||
ExecuteSequence(falseSequence); |
||||
} |
||||
} |
||||
|
||||
public void OnDrawGizmos() |
||||
{ |
||||
if (trueSequence == null || falseSequence == null) |
||||
{ |
||||
errorMessage = "Please select true and false Sequence objects"; |
||||
} |
||||
else |
||||
{ |
||||
errorMessage = ""; |
||||
} |
||||
} |
||||
|
||||
public override void GetConnectedSequences(ref List<Sequence> connectedSequences) |
||||
{ |
||||
if (trueSequence != null) |
||||
{ |
||||
connectedSequences.Add(trueSequence); |
||||
} |
||||
if (falseSequence != null) |
||||
{ |
||||
connectedSequences.Add(falseSequence); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: f4a1d934106ae48ab9c8cc28424bd27e |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,59 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public class SayCommand : FungusCommand |
||||
{ |
||||
public string text; |
||||
|
||||
public List<Sequence> options = new List<Sequence>(); |
||||
|
||||
public override void OnExecute() |
||||
{ |
||||
Dialog dialog = Game.GetInstance().dialog; |
||||
|
||||
foreach (Sequence sequence in options) |
||||
{ |
||||
Sequence s = sequence; |
||||
|
||||
dialog.AddOption(sequence.titleText, () => { |
||||
ExecuteSequence(s); |
||||
}); |
||||
} |
||||
|
||||
dialog.Say (text, delegate { |
||||
ExecuteNextCommand(); |
||||
}); |
||||
} |
||||
|
||||
public void OnDrawGizmos() |
||||
{ |
||||
errorMessage = ""; |
||||
int i = 0; |
||||
foreach (Sequence sequence in options) |
||||
{ |
||||
if (sequence == null) |
||||
{ |
||||
errorMessage = "Please select a Sequence for option " + i; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override void GetConnectedSequences(ref List<Sequence> connectedSequences) |
||||
{ |
||||
foreach (Sequence sequence in options) |
||||
{ |
||||
if (sequence != null) |
||||
{ |
||||
connectedSequences.Add(sequence); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ec422cd568a9c4a31ad7c36d0572b9da |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,119 @@
|
||||
#if UNITY_EDITOR |
||||
using UnityEditor; |
||||
#endif |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public class Sequence : MonoBehaviour |
||||
{ |
||||
public string titleText; |
||||
|
||||
[HideInInspector] |
||||
public Rect nodeRect = new Rect(10, 10, 100, 100); |
||||
|
||||
[HideInInspector] |
||||
public SequenceController sequenceController; |
||||
|
||||
[HideInInspector] |
||||
public FungusCommand activeCommand; |
||||
|
||||
public virtual void Start() |
||||
{ |
||||
// Populate sequenceController reference |
||||
Transform parent = transform.parent; |
||||
while (parent != null) |
||||
{ |
||||
sequenceController = parent.gameObject.GetComponent<SequenceController>(); |
||||
if (sequenceController != null) |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public bool HasError() |
||||
{ |
||||
FungusCommand[] commands = GetComponents<FungusCommand>(); |
||||
foreach (FungusCommand command in commands) |
||||
{ |
||||
if (command.errorMessage.Length > 0) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public bool IsRunning() |
||||
{ |
||||
if (sequenceController == null || |
||||
sequenceController.activeSequence == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return (sequenceController.activeSequence == this); |
||||
} |
||||
|
||||
public void ExecuteNextCommand(FungusCommand currentCommand = null) |
||||
{ |
||||
activeCommand = null; |
||||
FungusCommand nextCommand = null; |
||||
|
||||
bool executeNext = (currentCommand == null); |
||||
FungusCommand[] commands = GetComponents<FungusCommand>(); |
||||
foreach (FungusCommand command in commands) |
||||
{ |
||||
if (command == currentCommand) |
||||
{ |
||||
executeNext = true; |
||||
} |
||||
else if (executeNext) |
||||
{ |
||||
nextCommand = command; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (nextCommand == null) |
||||
{ |
||||
Finish(); |
||||
} |
||||
else |
||||
{ |
||||
if (sequenceController.stepTime == 0f) |
||||
{ |
||||
activeCommand = nextCommand; |
||||
nextCommand.Execute(); |
||||
} |
||||
else |
||||
{ |
||||
StartCoroutine(ExecuteAfterDelay(nextCommand, sequenceController.stepTime)); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
IEnumerator ExecuteAfterDelay(FungusCommand command, float delay) |
||||
{ |
||||
activeCommand = command; |
||||
yield return new WaitForSeconds(delay); |
||||
command.Execute(); |
||||
} |
||||
|
||||
public void Finish() |
||||
{ |
||||
activeCommand = null; |
||||
|
||||
// No more commands to run in current sequence |
||||
#if UNITY_EDITOR |
||||
Selection.activeGameObject = sequenceController.gameObject; |
||||
#endif |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 3d3d73aef2cfc4f51abf34ac00241f60 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,28 @@
|
||||
#if UNITY_EDITOR |
||||
using UnityEditor; |
||||
#endif |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using Fungus; |
||||
|
||||
public class SequenceController : MonoBehaviour |
||||
{ |
||||
public float stepTime; |
||||
|
||||
public Sequence activeSequence; |
||||
|
||||
public void ExecuteSequence(Sequence sequence) |
||||
{ |
||||
if (activeSequence == null) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
#if UNITY_EDITOR |
||||
Selection.activeGameObject = sequence.gameObject; |
||||
#endif |
||||
|
||||
activeSequence = sequence; |
||||
sequence.ExecuteNextCommand(); |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 7a334fe2ffb574b3583ff3b18b4792d3 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,22 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public class SetBooleanCommand : FungusCommand |
||||
{ |
||||
public string key; |
||||
|
||||
public bool value; |
||||
|
||||
public override void OnExecute() |
||||
{ |
||||
Variables.SetBoolean(key, value); |
||||
ExecuteNextCommand(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 1f96fe7b67189415a9884c596c55e96c |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,24 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public class WaitCommand : FungusCommand |
||||
{ |
||||
public float duration; |
||||
|
||||
public override void OnExecute() |
||||
{ |
||||
Invoke ("OnWaitComplete", duration); |
||||
} |
||||
|
||||
void OnWaitComplete() |
||||
{ |
||||
ExecuteNextCommand(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 3315ad2ebb85443909a1203d56d9344e |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
Binary file not shown.
Loading…
Reference in new issue