@ -71,13 +71,13 @@ namespace Fungus
}
if ( Selection . activeGameObject = = null & &
flowchart . s electedBlock ! = null )
flowchart . S electedBlock ! = null )
{
if ( blockInspector = = null )
{
ShowBlockInspector ( flowchart ) ;
}
blockInspector . block = flowchart . s electedBlock;
blockInspector . block = flowchart . S electedBlock;
}
forceRepaintCount - - ;
@ -103,11 +103,11 @@ namespace Fungus
Flowchart fs = Selection . activeGameObject . GetComponent < Flowchart > ( ) ;
if ( fs ! = null )
{
fungusState . s electedFlowchart = fs ;
fungusState . S electedFlowchart = fs ;
}
}
return fungusState . s electedFlowchart;
return fungusState . S electedFlowchart;
}
protected virtual void OnGUI ( )
@ -122,9 +122,9 @@ namespace Fungus
// Delete any scheduled objects
foreach ( Block deleteBlock in deleteList )
{
bool isSelected = ( flowchart . s electedBlock = = deleteBlock ) ;
bool isSelected = ( flowchart . S electedBlock = = deleteBlock ) ;
foreach ( Command command in deleteBlock . c ommandList)
foreach ( Command command in deleteBlock . C ommandList)
{
Undo . DestroyObjectImmediate ( command ) ;
}
@ -160,22 +160,22 @@ namespace Fungus
if ( GUILayout . Button ( new GUIContent ( addTexture , "Add a new block" ) ) )
{
Vector2 newNodePosition = new Vector2 ( 5 0 - flowchart . s crollPos. x ,
5 0 - flowchart . s crollPos. y ) ;
Vector2 newNodePosition = new Vector2 ( 5 0 - flowchart . S crollPos. x ,
5 0 - flowchart . S crollPos. y ) ;
CreateBlock ( flowchart , newNodePosition ) ;
}
GUILayout . Space ( 8 ) ;
flowchart . z oom = GUILayout . HorizontalSlider ( flowchart . z oom, minZoomValue , maxZoomValue , GUILayout . Width ( 1 0 0 ) ) ;
flowchart . Z oom = GUILayout . HorizontalSlider ( flowchart . Z oom, minZoomValue , maxZoomValue , GUILayout . Width ( 1 0 0 ) ) ;
GUILayout . FlexibleSpace ( ) ;
GUILayout . BeginVertical ( ) ;
GUILayout . Label ( flowchart . name , EditorStyles . whiteBoldLabel ) ;
if ( flowchart . d escription. Length > 0 )
if ( flowchart . D escription. Length > 0 )
{
GUILayout . Label ( flowchart . d escription, EditorStyles . helpBox ) ;
GUILayout . Label ( flowchart . D escription, EditorStyles . helpBox ) ;
}
GUILayout . EndVertical ( ) ;
@ -189,7 +189,7 @@ namespace Fungus
GUILayout . FlexibleSpace ( ) ;
flowchart . v ariablesScrollPos = GUILayout . BeginScrollView ( flowchart . v ariablesScrollPos, GUILayout . MaxHeight ( position . height * 0.75f ) ) ;
flowchart . V ariablesScrollPos = GUILayout . BeginScrollView ( flowchart . V ariablesScrollPos, GUILayout . MaxHeight ( position . height * 0.75f ) ) ;
GUILayout . FlexibleSpace ( ) ;
@ -200,8 +200,8 @@ namespace Fungus
DestroyImmediate ( flowchartEditor ) ;
Rect variableWindowRect = GUILayoutUtility . GetLastRect ( ) ;
if ( flowchart . v ariablesExpanded & &
flowchart . v ariables. Count > 0 )
if ( flowchart . V ariablesExpanded & &
flowchart . V ariables. Count > 0 )
{
variableWindowRect . y - = 2 0 ;
variableWindowRect . height + = 2 0 ;
@ -226,16 +226,18 @@ namespace Fungus
foreach ( Block block in blocks )
{
flowchart . scrollViewRect . xMin = Mathf . Min ( flowchart . scrollViewRect . xMin , block . nodeRect . xMin - 4 0 0 ) ;
flowchart . scrollViewRect . xMax = Mathf . Max ( flowchart . scrollViewRect . xMax , block . nodeRect . xMax + 4 0 0 ) ;
flowchart . scrollViewRect . yMin = Mathf . Min ( flowchart . scrollViewRect . yMin , block . nodeRect . yMin - 4 0 0 ) ;
flowchart . scrollViewRect . yMax = Mathf . Max ( flowchart . scrollViewRect . yMax , block . nodeRect . yMax + 4 0 0 ) ;
var newRect = new Rect ( ) ;
newRect . xMin = Mathf . Min ( flowchart . ScrollViewRect . xMin , block . _ NodeRect . xMin - 4 0 0 ) ;
newRect . xMax = Mathf . Max ( flowchart . ScrollViewRect . xMax , block . _ NodeRect . xMax + 4 0 0 ) ;
newRect . yMin = Mathf . Min ( flowchart . ScrollViewRect . yMin , block . _ NodeRect . yMin - 4 0 0 ) ;
newRect . yMax = Mathf . Max ( flowchart . ScrollViewRect . yMax , block . _ NodeRect . yMax + 4 0 0 ) ;
flowchart . ScrollViewRect = newRect ;
}
// Calc rect for script view
Rect scriptViewRect = new Rect ( 0 , 0 , this . position . width / flowchart . z oom, this . position . height / flowchart . z oom) ;
Rect scriptViewRect = new Rect ( 0 , 0 , this . position . width / flowchart . Z oom, this . position . height / flowchart . Z oom) ;
EditorZoomArea . Begin ( flowchart . z oom, scriptViewRect ) ;
EditorZoomArea . Begin ( flowchart . Z oom, scriptViewRect ) ;
DrawGrid ( flowchart ) ;
@ -245,7 +247,7 @@ namespace Fungus
Event . current . type = = EventType . MouseDown & &
! mouseOverVariables )
{
flowchart . s electedBlock = null ;
flowchart . S electedBlock = null ;
if ( ! EditorGUI . actionKey )
{
flowchart . ClearSelectedCommands ( ) ;
@ -277,46 +279,49 @@ namespace Fungus
{
Block block = blocks [ i ] ;
float nodeWidthA = nodeStyle . CalcSize ( new GUIContent ( block . b lockName) ) . x + 1 0 ;
float nodeWidthA = nodeStyle . CalcSize ( new GUIContent ( block . B lockName) ) . x + 1 0 ;
float nodeWidthB = 0f ;
if ( block . e ventHandler ! = null )
if ( block . _ E ventHandler ! = null )
{
nodeWidthB = nodeStyle . CalcSize ( new GUIContent ( block . e ventHandler. GetSummary ( ) ) ) . x + 1 0 ;
nodeWidthB = nodeStyle . CalcSize ( new GUIContent ( block . _ E ventHandler. GetSummary ( ) ) ) . x + 1 0 ;
}
block . nodeRect . width = Mathf . Max ( Mathf . Max ( nodeWidthA , nodeWidthB ) , 1 2 0 ) ;
block . nodeRect . height = 4 0 ;
if ( Event . current . button = = 0 )
{
Rect tempRect = block . _ NodeRect ;
tempRect . width = Mathf . Max ( Mathf . Max ( nodeWidthA , nodeWidthB ) , 1 2 0 ) ;
tempRect . height = 4 0 ;
if ( Event . current . type = = EventType . MouseDrag & & dragWindowId = = i )
{
block . nodeRect . x + = Event . current . delta . x ;
block . nodeRect . y + = Event . current . delta . y ;
temp Rect. x + = Event . current . delta . x ;
temp Rect. y + = Event . current . delta . y ;
forceRepaintCount = 6 ;
}
else if ( Event . current . type = = EventType . MouseUp & &
dragWindowId = = i )
{
Vector2 newPos = new Vector2 ( block . node Rect. x , block . node Rect. y ) ;
Vector2 newPos = new Vector2 ( temp Rect. x , temp Rect. y ) ;
block . node Rect. x = startDragPosition . x ;
block . node Rect. y = startDragPosition . y ;
temp Rect. x = startDragPosition . x ;
temp Rect. y = startDragPosition . y ;
Undo . RecordObject ( block , "Node Position" ) ;
block . node Rect. x = newPos . x ;
block . node Rect. y = newPos . y ;
temp Rect. x = newPos . x ;
temp Rect. y = newPos . y ;
dragWindowId = - 1 ;
forceRepaintCount = 6 ;
}
block . _ NodeRect = tempRect ;
}
Rect windowRect = new Rect ( block . n odeRect) ;
windowRect . x + = flowchart . s crollPos. x ;
windowRect . y + = flowchart . s crollPos. y ;
Rect windowRect = new Rect ( block . _ N odeRect) ;
windowRect . x + = flowchart . S crollPos. x ;
windowRect . y + = flowchart . S crollPos. y ;
GUILayout . Window ( i , windowRect , DrawWindow , "" , windowStyle ) ;
@ -330,10 +335,10 @@ namespace Fungus
// Draw Event Handler labels
foreach ( Block block in blocks )
{
if ( block . e ventHandler ! = null )
if ( block . _ E ventHandler ! = null )
{
string handlerLabel = "" ;
EventHandlerInfoAttribute info = EventHandlerEditor . GetEventHandlerInfo ( block . e ventHandler. GetType ( ) ) ;
EventHandlerInfoAttribute info = EventHandlerEditor . GetEventHandlerInfo ( block . _ E ventHandler. GetType ( ) ) ;
if ( info ! = null )
{
handlerLabel = "<" + info . EventHandlerName + "> " ;
@ -345,10 +350,10 @@ namespace Fungus
handlerStyle . margin . bottom = 0 ;
handlerStyle . alignment = TextAnchor . MiddleCenter ;
Rect rect = new Rect ( block . n odeRect) ;
rect . height = handlerStyle . CalcHeight ( new GUIContent ( handlerLabel ) , block . n odeRect. width ) ;
rect . x + = flowchart . s crollPos. x ;
rect . y + = flowchart . s crollPos. y - rect . height ;
Rect rect = new Rect ( block . _ N odeRect) ;
rect . height = handlerStyle . CalcHeight ( new GUIContent ( handlerLabel ) , block . _ N odeRect. width ) ;
rect . x + = flowchart . S crollPos. x ;
rect . y + = flowchart . S crollPos. y - rect . height ;
GUI . Label ( rect , handlerLabel , handlerStyle ) ;
}
@ -362,23 +367,23 @@ namespace Fungus
{
if ( b . IsExecuting ( ) )
{
b . e xecutingIconTimer = Time . realtimeSinceStartup + Block . executingIconFadeTime ;
b . activeCommand . e xecutingIconTimer = Time . realtimeSinceStartup + Block . executingIconFadeTime ;
b . E xecutingIconTimer = Time . realtimeSinceStartup + Block . executingIconFadeTime ;
b . ActiveCommand . E xecutingIconTimer = Time . realtimeSinceStartup + Block . executingIconFadeTime ;
forceRepaintCount = 6 ;
}
if ( b . e xecutingIconTimer > Time . realtimeSinceStartup )
if ( b . E xecutingIconTimer > Time . realtimeSinceStartup )
{
Rect rect = new Rect ( b . n odeRect) ;
Rect rect = new Rect ( b . _ N odeRect) ;
rect . x + = flowchart . s crollPos. x - 3 7 ;
rect . y + = flowchart . s crollPos. y + 3 ;
rect . x + = flowchart . S crollPos. x - 3 7 ;
rect . y + = flowchart . S crollPos. y + 3 ;
rect . width = 3 4 ;
rect . height = 3 4 ;
if ( ! b . IsExecuting ( ) )
{
float alpha = ( b . e xecutingIconTimer - Time . realtimeSinceStartup ) / Block . executingIconFadeTime ;
float alpha = ( b . E xecutingIconTimer - Time . realtimeSinceStartup ) / Block . executingIconFadeTime ;
alpha = Mathf . Clamp01 ( alpha ) ;
GUI . color = new Color ( 1f , 1f , 1f , alpha ) ;
}
@ -408,15 +413,15 @@ namespace Fungus
return ;
}
Vector2 min = blocks [ 0 ] . n odeRect. min ;
Vector2 max = blocks [ 0 ] . n odeRect. max ;
Vector2 min = blocks [ 0 ] . _ N odeRect. min ;
Vector2 max = blocks [ 0 ] . _ N odeRect. max ;
foreach ( Block block in blocks )
{
min . x = Mathf . Min ( min . x , block . n odeRect. center . x ) ;
min . y = Mathf . Min ( min . y , block . n odeRect. center . y ) ;
max . x = Mathf . Max ( max . x , block . n odeRect. center . x ) ;
max . y = Mathf . Max ( max . y , block . n odeRect. center . y ) ;
min . x = Mathf . Min ( min . x , block . _ N odeRect. center . x ) ;
min . y = Mathf . Min ( min . y , block . _ N odeRect. center . y ) ;
max . x = Mathf . Max ( max . x , block . _ N odeRect. center . x ) ;
max . y = Mathf . Max ( max . y , block . _ N odeRect. center . y ) ;
}
Vector2 center = ( min + max ) * - 0.5f ;
@ -424,7 +429,7 @@ namespace Fungus
center . x + = position . width * 0.5f ;
center . y + = position . height * 0.5f ;
flowchart . c enterPosition = center ;
flowchart . C enterPosition = center ;
}
protected virtual void PanAndZoom ( Flowchart flowchart )
@ -454,7 +459,7 @@ namespace Fungus
if ( drag )
{
flowchart . s crollPos + = Event . current . delta ;
flowchart . S crollPos + = Event . current . delta ;
forceRepaintCount = 6 ;
}
@ -475,16 +480,16 @@ namespace Fungus
if ( zoom )
{
flowchart . z oom - = Event . current . delta . y * 0.01f ;
flowchart . z oom = Mathf . Clamp ( flowchart . z oom, minZoomValue , maxZoomValue ) ;
flowchart . Z oom - = Event . current . delta . y * 0.01f ;
flowchart . Z oom = Mathf . Clamp ( flowchart . Z oom, minZoomValue , maxZoomValue ) ;
forceRepaintCount = 6 ;
}
}
protected virtual void DrawGrid ( Flowchart flowchart )
{
float width = this . position . width / flowchart . z oom;
float height = this . position . height / flowchart . z oom;
float width = this . position . width / flowchart . Z oom;
float height = this . position . height / flowchart . Z oom;
// Match background color of scene view
if ( EditorGUIUtility . isProSkin )
@ -502,14 +507,14 @@ namespace Fungus
float gridSize = 1 2 8f ;
float x = flowchart . s crollPos. x % gridSize ;
float x = flowchart . S crollPos. x % gridSize ;
while ( x < width )
{
GLDraw . DrawLine ( new Vector2 ( x , 0 ) , new Vector2 ( x , height ) , color , 1f ) ;
x + = gridSize ;
}
float y = ( flowchart . s crollPos. y % gridSize ) ;
float y = ( flowchart . S crollPos. y % gridSize ) ;
while ( y < height )
{
if ( y > = 0 )
@ -524,11 +529,11 @@ namespace Fungus
{
// Select the block and also select currently executing command
ShowBlockInspector ( flowchart ) ;
flowchart . s electedBlock = block ;
flowchart . S electedBlock = block ;
flowchart . ClearSelectedCommands ( ) ;
if ( block . a ctiveCommand ! = null )
if ( block . A ctiveCommand ! = null )
{
flowchart . AddSelectedCommand ( block . a ctiveCommand) ;
flowchart . AddSelectedCommand ( block . A ctiveCommand) ;
}
}
@ -537,7 +542,7 @@ namespace Fungus
Block newBlock = flowchart . CreateBlock ( position ) ;
Undo . RegisterCreatedObjectUndo ( newBlock , "New Block" ) ;
ShowBlockInspector ( flowchart ) ;
flowchart . s electedBlock = newBlock ;
flowchart . S electedBlock = newBlock ;
flowchart . ClearSelectedCommands ( ) ;
return newBlock ;
@ -545,7 +550,7 @@ namespace Fungus
protected virtual void DeleteBlock ( Flowchart flowchart , Block block )
{
foreach ( Command command in block . c ommandList)
foreach ( Command command in block . C ommandList)
{
Undo . DestroyObjectImmediate ( command ) ;
}
@ -574,8 +579,8 @@ namespace Fungus
Event . current . alt = = false )
{
dragWindowId = windowId ;
startDragPosition . x = block . n odeRect. x ;
startDragPosition . y = block . n odeRect. y ;
startDragPosition . x = block . _ N odeRect. x ;
startDragPosition . y = block . _ N odeRect. y ;
}
if ( windowId < windowBlockMap . Count )
@ -588,11 +593,11 @@ namespace Fungus
}
}
bool selected = ( flowchart . s electedBlock = = block ) ;
bool selected = ( flowchart . S electedBlock = = block ) ;
GUIStyle nodeStyleCopy = new GUIStyle ( nodeStyle ) ;
if ( block . e ventHandler ! = null )
if ( block . _ E ventHandler ! = null )
{
nodeStyleCopy . normal . background = selected ? FungusEditorResources . texEventNodeOn : FungusEditorResources . texEventNodeOff ;
}
@ -624,17 +629,19 @@ namespace Fungus
nodeStyleCopy . normal . textColor = Color . black ;
// Make sure node is wide enough to fit the node name text
float width = nodeStyleCopy . CalcSize ( new GUIContent ( block . blockName ) ) . x ;
block . nodeRect . width = Mathf . Max ( block . nodeRect . width , width ) ;
float width = nodeStyleCopy . CalcSize ( new GUIContent ( block . BlockName ) ) . x ;
Rect tempRect = block . _ NodeRect ;
tempRect . width = Mathf . Max ( block . _ NodeRect . width , width ) ;
block . _ NodeRect = tempRect ;
GUI . backgroundColor = Color . white ;
GUILayout . Box ( block . b lockName, nodeStyleCopy , GUILayout . Width ( block . n odeRect. width ) , GUILayout . Height ( block . n odeRect. height ) ) ;
GUILayout . Box ( block . B lockName, nodeStyleCopy , GUILayout . Width ( block . _ N odeRect. width ) , GUILayout . Height ( block . _ N odeRect. height ) ) ;
if ( block . d escription. Length > 0 )
if ( block . D escription. Length > 0 )
{
GUIStyle descriptionStyle = new GUIStyle ( EditorStyles . helpBox ) ;
descriptionStyle . wordWrap = true ;
GUILayout . Label ( block . d escription, descriptionStyle ) ;
GUILayout . Label ( block . D escription, descriptionStyle ) ;
}
if ( Event . current . type = = EventType . ContextClick )
@ -657,9 +664,9 @@ namespace Fungus
List < Block > connectedBlocks = new List < Block > ( ) ;
bool blockIsSelected = ( flowchart . s electedBlock = = block ) ;
bool blockIsSelected = ( flowchart . S electedBlock = = block ) ;
foreach ( Command command in block . c ommandList)
foreach ( Command command in block . C ommandList)
{
if ( command = = null )
{
@ -667,7 +674,7 @@ namespace Fungus
}
bool commandIsSelected = false ;
foreach ( Command selectedCommand in flowchart . s electedCommands)
foreach ( Command selectedCommand in flowchart . S electedCommands)
{
if ( selectedCommand = = command )
{
@ -676,7 +683,7 @@ namespace Fungus
}
}
bool highlight = command . i sExecuting | | ( blockIsSelected & & commandIsSelected ) ;
bool highlight = command . I sExecuting | | ( blockIsSelected & & commandIsSelected ) ;
if ( highlightedOnly & & ! highlight | |
! highlightedOnly & & highlight )
@ -696,13 +703,13 @@ namespace Fungus
continue ;
}
Rect startRect = new Rect ( block . n odeRect) ;
startRect . x + = flowchart . s crollPos. x ;
startRect . y + = flowchart . s crollPos. y ;
Rect startRect = new Rect ( block . _ N odeRect) ;
startRect . x + = flowchart . S crollPos. x ;
startRect . y + = flowchart . S crollPos. y ;
Rect endRect = new Rect ( blockB . n odeRect) ;
endRect . x + = flowchart . s crollPos. x ;
endRect . y + = flowchart . s crollPos. y ;
Rect endRect = new Rect ( blockB . _ N odeRect) ;
endRect . x + = flowchart . S crollPos. x ;
endRect . y + = flowchart . S crollPos. y ;
DrawRectConnection ( startRect , endRect , highlight ) ;
}
@ -769,18 +776,18 @@ namespace Fungus
Flowchart flowchart = GetFlowchart ( ) ;
Block block = obj as Block ;
Vector2 newPosition = new Vector2 ( block . n odeRect. position . x +
block . n odeRect. width + 2 0 ,
block . n odeRect. y ) ;
Vector2 newPosition = new Vector2 ( block . _ N odeRect. position . x +
block . _ N odeRect. width + 2 0 ,
block . _ N odeRect. y ) ;
Block oldBlock = block ;
Block newBlock = FlowchartWindow . CreateBlock ( flowchart , newPosition ) ;
newBlock . b lockName = flowchart . GetUniqueBlockKey ( oldBlock . b lockName + " (Copy)" ) ;
newBlock . B lockName = flowchart . GetUniqueBlockKey ( oldBlock . B lockName + " (Copy)" ) ;
Undo . RecordObject ( newBlock , "Duplicate Block" ) ;
foreach ( Command command in oldBlock . c ommandList)
foreach ( Command command in oldBlock . C ommandList)
{
if ( ComponentUtility . CopyComponent ( command ) )
{
@ -790,8 +797,8 @@ namespace Fungus
Command pastedCommand = commands . Last < Command > ( ) ;
if ( pastedCommand ! = null )
{
pastedCommand . i temId = flowchart . NextItemId ( ) ;
newBlock . c ommandList. Add ( pastedCommand ) ;
pastedCommand . I temId = flowchart . NextItemId ( ) ;
newBlock . C ommandList. Add ( pastedCommand ) ;
}
}
@ -800,9 +807,9 @@ namespace Fungus
}
}
if ( oldBlock . e ventHandler ! = null )
if ( oldBlock . _ E ventHandler ! = null )
{
if ( ComponentUtility . CopyComponent ( oldBlock . e ventHandler) )
if ( ComponentUtility . CopyComponent ( oldBlock . _ E ventHandler) )
{
if ( ComponentUtility . PasteComponentAsNew ( flowchart . gameObject ) )
{
@ -810,8 +817,8 @@ namespace Fungus
EventHandler pastedEventHandler = eventHandlers . Last < EventHandler > ( ) ;
if ( pastedEventHandler ! = null )
{
pastedEventHandler . p arentBlock = newBlock ;
newBlock . e ventHandler = pastedEventHandler ;
pastedEventHandler . P arentBlock = newBlock ;
newBlock . _ E ventHandler = pastedEventHandler ;
}
}
}