public override void OnEnter() { if (message.Length == 0) { Continue(); } FungusScript fungusScript = GetFungusScript(); MessageReceived[] receivers = null; if (messageTarget == MessageTarget.SameScript) { receivers = fungusScript.GetComponentsInChildren <MessageReceived>(); } else { receivers = GameObject.FindObjectsOfType <MessageReceived>(); } if (receivers != null) { foreach (MessageReceived receiver in receivers) { receiver.OnSendFungusMessage(message); } } Continue(); }
static public void SequenceField(SerializedProperty property, GUIContent label, GUIContent nullLabel, FungusScript fungusScript) { if (fungusScript == null) { return; } Sequence sequence = property.objectReferenceValue as Sequence; // Build dictionary of child sequences List <GUIContent> sequenceNames = new List <GUIContent>(); int selectedIndex = 0; sequenceNames.Add(nullLabel); Sequence[] sequences = fungusScript.GetComponentsInChildren <Sequence>(); for (int i = 0; i < sequences.Length; ++i) { sequenceNames.Add(new GUIContent(sequences[i].name)); if (sequence == sequences[i]) { selectedIndex = i + 1; } } selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray()); if (selectedIndex == 0) { sequence = null; // Option 'None' } else { sequence = sequences[selectedIndex - 1]; } property.objectReferenceValue = sequence; }
static public Sequence SequenceField(Rect position, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence) { if (fungusScript == null) { return(null); } Sequence result = sequence; // Build dictionary of child sequences List <GUIContent> sequenceNames = new List <GUIContent>(); int selectedIndex = 0; sequenceNames.Add(nullLabel); Sequence[] sequences = fungusScript.GetComponentsInChildren <Sequence>(); for (int i = 0; i < sequences.Length; ++i) { sequenceNames.Add(new GUIContent(sequences[i].name)); if (sequence == sequences[i]) { selectedIndex = i + 1; } } selectedIndex = EditorGUI.Popup(position, selectedIndex, sequenceNames.ToArray()); if (selectedIndex == 0) { result = null; // Option 'None' } else { result = sequences[selectedIndex - 1]; } return(result); }
protected virtual void DrawScriptView(FungusScript fungusScript) { Sequence[] sequences = fungusScript.GetComponentsInChildren <Sequence>(true); foreach (Sequence s in sequences) { fungusScript.scrollViewRect.xMin = Mathf.Min(fungusScript.scrollViewRect.xMin, s.nodeRect.xMin - 400); fungusScript.scrollViewRect.xMax = Mathf.Max(fungusScript.scrollViewRect.xMax, s.nodeRect.xMax + 400); fungusScript.scrollViewRect.yMin = Mathf.Min(fungusScript.scrollViewRect.yMin, s.nodeRect.yMin - 400); fungusScript.scrollViewRect.yMax = Mathf.Max(fungusScript.scrollViewRect.yMax, s.nodeRect.yMax + 400); } // Calc rect for script view Rect scriptViewRect = new Rect(0, 0, this.position.width / fungusScript.zoom, this.position.height / fungusScript.zoom); EditorZoomArea.Begin(fungusScript.zoom, scriptViewRect); DrawGrid(fungusScript); GLDraw.BeginGroup(scriptViewRect); if (Event.current.button == 0 && Event.current.type == EventType.MouseDown && !mouseOverVariables) { fungusScript.selectedSequence = null; if (!EditorGUI.actionKey) { fungusScript.ClearSelectedCommands(); } Selection.activeGameObject = fungusScript.gameObject; } // Draw connections foreach (Sequence s in sequences) { DrawConnections(fungusScript, s, false); } foreach (Sequence s in sequences) { DrawConnections(fungusScript, s, true); } GUIStyle windowStyle = new GUIStyle(); windowStyle.stretchHeight = true; BeginWindows(); windowSequenceMap.Clear(); for (int i = 0; i < sequences.Length; ++i) { Sequence sequence = sequences[i]; float nodeWidthA = nodeStyle.CalcSize(new GUIContent(sequence.sequenceName)).x + 10; float nodeWidthB = 0f; if (sequence.eventHandler != null) { nodeWidthB = nodeStyle.CalcSize(new GUIContent(sequence.eventHandler.GetSummary())).x + 10; } sequence.nodeRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120); sequence.nodeRect.height = 40; if (Event.current.button == 0) { if (Event.current.type == EventType.MouseDrag && dragWindowId == i) { sequence.nodeRect.x += Event.current.delta.x; sequence.nodeRect.y += Event.current.delta.y; forceRepaintCount = 6; } else if (Event.current.type == EventType.MouseUp && dragWindowId == i) { Vector2 newPos = new Vector2(sequence.nodeRect.x, sequence.nodeRect.y); sequence.nodeRect.x = startDragPosition.x; sequence.nodeRect.y = startDragPosition.y; Undo.RecordObject(sequence, "Node Position"); sequence.nodeRect.x = newPos.x; sequence.nodeRect.y = newPos.y; dragWindowId = -1; forceRepaintCount = 6; } } Rect windowRect = new Rect(sequence.nodeRect); windowRect.x += fungusScript.scrollPos.x; windowRect.y += fungusScript.scrollPos.y; GUILayout.Window(i, windowRect, DrawWindow, "", windowStyle); GUI.backgroundColor = Color.white; windowSequenceMap.Add(sequence); } EndWindows(); // Draw play icons beside all executing sequences if (Application.isPlaying) { foreach (Sequence s in sequences) { if (s.IsExecuting()) { s.executingIconTimer = playIconFadeTime; forceRepaintCount = 6; } if (s.executingIconTimer > 0f) { s.executingIconTimer = Mathf.Max(s.executingIconTimer - Time.deltaTime, 0f); Rect rect = new Rect(s.nodeRect); rect.x += fungusScript.scrollPos.x - 37; rect.y += fungusScript.scrollPos.y + 3; rect.width = 34; rect.height = 34; if (!s.IsExecuting() && s.executingIconTimer < playIconFadeTime) { float alpha = s.executingIconTimer / playIconFadeTime; GUI.color = new Color(1f, 1f, 1f, alpha); } if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle())) { SelectSequence(fungusScript, s); } GUI.color = Color.white; } } } // Right click to drag view if (Event.current.button == 1 && Event.current.type == EventType.MouseDrag) { fungusScript.scrollPos += Event.current.delta; forceRepaintCount = 6; } else if (Event.current.type == EventType.ScrollWheel) { fungusScript.zoom -= Event.current.delta.y * 0.01f; fungusScript.zoom = Mathf.Clamp(fungusScript.zoom, minZoomValue, maxZoomValue); forceRepaintCount = 6; } GLDraw.EndGroup(); EditorZoomArea.End(); }
void DrawScriptView(FungusScript fungusScript) { EditorUtility.SetDirty(fungusScript); Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>(); Rect scrollViewRect = new Rect(); foreach (Sequence s in sequences) { scrollViewRect.xMin = Mathf.Min(scrollViewRect.xMin, s.nodeRect.xMin); scrollViewRect.xMax = Mathf.Max(scrollViewRect.xMax, s.nodeRect.xMax); scrollViewRect.yMin = Mathf.Min(scrollViewRect.yMin, s.nodeRect.yMin); scrollViewRect.yMax = Mathf.Max(scrollViewRect.yMax, s.nodeRect.yMax); } // Empty buffer area around edges of scroll rect float bufferScale = 0.25f; scrollViewRect.xMin -= position.width * bufferScale; scrollViewRect.yMin -= position.height * bufferScale; scrollViewRect.xMax += position.width * bufferScale; scrollViewRect.yMax += position.height * bufferScale; // Calc rect for left hand script view Rect scriptViewRect = new Rect(0, 0, this.position.width - fungusScript.commandViewWidth, this.position.height); // Clip GL drawing so not to overlap scrollbars Rect clipRect = new Rect(fungusScript.scriptScrollPos.x + scrollViewRect.x, fungusScript.scriptScrollPos.y + scrollViewRect.y, scriptViewRect.width - 15, scriptViewRect.height - 15); GUILayoutUtility.GetRect(scriptViewRect.width, scriptViewRect.height); fungusScript.scriptScrollPos = GLDraw.BeginScrollView(scriptViewRect, fungusScript.scriptScrollPos, scrollViewRect, clipRect); if (Event.current.type == EventType.ContextClick && clipRect.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); Vector2 mousePos = Event.current.mousePosition; mousePos += fungusScript.scriptScrollPos; menu.AddItem (new GUIContent ("Create Sequence"), false, CreateSequenceCallback, mousePos); menu.ShowAsContext (); Event.current.Use(); } BeginWindows(); GUIStyle windowStyle = new GUIStyle(EditorStyles.toolbarButton); windowStyle.stretchHeight = true; windowStyle.fixedHeight = 40; windowSequenceMap.Clear(); for (int i = 0; i < sequences.Length; ++i) { Sequence sequence = sequences[i]; float titleWidth = windowStyle.CalcSize(new GUIContent(sequence.name)).x; float windowWidth = Mathf.Max (titleWidth + 10, 100); if (fungusScript.selectedSequence == sequence || fungusScript.executingSequence == sequence) { GUI.backgroundColor = Color.green; } sequence.nodeRect = GUILayout.Window(i, sequence.nodeRect, DrawWindow, "", windowStyle, GUILayout.Width(windowWidth), GUILayout.Height(20), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUI.backgroundColor = Color.white; windowSequenceMap.Add(sequence); } // Draw connections foreach (Sequence s in windowSequenceMap) { DrawConnections(fungusScript, s, false); } foreach (Sequence s in windowSequenceMap) { DrawConnections(fungusScript, s, true); } EndWindows(); GLDraw.EndScrollView(); }
void DrawScriptView(FungusScript fungusScript) { EditorUtility.SetDirty(fungusScript); Sequence[] sequences = fungusScript.GetComponentsInChildren <Sequence>(); Rect scrollViewRect = new Rect(); foreach (Sequence s in sequences) { scrollViewRect.xMin = Mathf.Min(scrollViewRect.xMin, s.nodeRect.xMin); scrollViewRect.xMax = Mathf.Max(scrollViewRect.xMax, s.nodeRect.xMax); scrollViewRect.yMin = Mathf.Min(scrollViewRect.yMin, s.nodeRect.yMin); scrollViewRect.yMax = Mathf.Max(scrollViewRect.yMax, s.nodeRect.yMax); } // Empty buffer area around edges of scroll rect float bufferScale = 0.25f; scrollViewRect.xMin -= position.width * bufferScale; scrollViewRect.yMin -= position.height * bufferScale; scrollViewRect.xMax += position.width * bufferScale; scrollViewRect.yMax += position.height * bufferScale; // Calc rect for left hand script view Rect scriptViewRect = new Rect(0, 0, this.position.width - fungusScript.commandViewWidth, this.position.height); // Clip GL drawing so not to overlap scrollbars Rect clipRect = new Rect(fungusScript.scriptScrollPos.x + scrollViewRect.x, fungusScript.scriptScrollPos.y + scrollViewRect.y, scriptViewRect.width - 15, scriptViewRect.height - 15); GUILayoutUtility.GetRect(scriptViewRect.width, scriptViewRect.height); fungusScript.scriptScrollPos = GLDraw.BeginScrollView(scriptViewRect, fungusScript.scriptScrollPos, scrollViewRect, clipRect); if (Event.current.type == EventType.ContextClick && clipRect.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); Vector2 mousePos = Event.current.mousePosition; mousePos += fungusScript.scriptScrollPos; menu.AddItem(new GUIContent("Create Sequence"), false, CreateSequenceCallback, mousePos); menu.ShowAsContext(); Event.current.Use(); } BeginWindows(); GUIStyle windowStyle = new GUIStyle(EditorStyles.toolbarButton); windowStyle.stretchHeight = true; windowStyle.fixedHeight = 40; windowSequenceMap.Clear(); for (int i = 0; i < sequences.Length; ++i) { Sequence sequence = sequences[i]; float titleWidth = windowStyle.CalcSize(new GUIContent(sequence.name)).x; float windowWidth = Mathf.Max(titleWidth + 10, 100); if (fungusScript.selectedSequence == sequence || fungusScript.executingSequence == sequence) { GUI.backgroundColor = Color.green; } sequence.nodeRect = GUILayout.Window(i, sequence.nodeRect, DrawWindow, "", windowStyle, GUILayout.Width(windowWidth), GUILayout.Height(20), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUI.backgroundColor = Color.white; windowSequenceMap.Add(sequence); } // Draw connections foreach (Sequence s in windowSequenceMap) { DrawConnections(fungusScript, s, false); } foreach (Sequence s in windowSequenceMap) { DrawConnections(fungusScript, s, true); } EndWindows(); GLDraw.EndScrollView(); }
static public void SequenceField(SerializedProperty property, GUIContent label, GUIContent nullLabel, FungusScript fungusScript) { if (fungusScript == null) { return; } Sequence sequence = property.objectReferenceValue as Sequence; // Build dictionary of child sequences List<GUIContent> sequenceNames = new List<GUIContent>(); int selectedIndex = 0; sequenceNames.Add(nullLabel); Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>(); for (int i = 0; i < sequences.Length; ++i) { sequenceNames.Add(new GUIContent(sequences[i].name)); if (sequence == sequences[i]) { selectedIndex = i + 1; } } selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray()); if (selectedIndex == 0) { sequence = null; // Option 'None' } else { sequence = sequences[selectedIndex - 1]; } property.objectReferenceValue = sequence; }
static public Sequence SequenceField(Rect position, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence) { if (fungusScript == null) { return null; } Sequence result = sequence; // Build dictionary of child sequences List<GUIContent> sequenceNames = new List<GUIContent>(); int selectedIndex = 0; sequenceNames.Add(nullLabel); Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>(); for (int i = 0; i < sequences.Length; ++i) { sequenceNames.Add(new GUIContent(sequences[i].name)); if (sequence == sequences[i]) { selectedIndex = i + 1; } } selectedIndex = EditorGUI.Popup(position, selectedIndex, sequenceNames.ToArray()); if (selectedIndex == 0) { result = null; // Option 'None' } else { result = sequences[selectedIndex - 1]; } return result; }