예제 #1
0
        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();
        }
예제 #2
0
        public void DrawVariablesGUI()
        {
            FungusScript t = target as FungusScript;

            ReorderableListGUI.Title("Variables");

            VariableListAdaptor adaptor = new VariableListAdaptor(variablesProp, 0);

            ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton);

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (!Application.isPlaying && GUILayout.Button("Add Variable"))
            {
                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("Boolean"), false, AddVariable <BooleanVariable>, t);
                menu.AddItem(new GUIContent("Integer"), false, AddVariable <IntegerVariable>, t);
                menu.AddItem(new GUIContent("Float"), false, AddVariable <FloatVariable>, t);
                menu.AddItem(new GUIContent("String"), false, AddVariable <StringVariable>, t);

                menu.ShowAsContext();
            }
            GUILayout.EndHorizontal();
        }
예제 #3
0
        protected void SelectNext()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            int lastSelectedIndex = -1;

            if (fungusScript.selectedCommands.Count > 0)
            {
                for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; i++)
                {
                    Command commandInSequence = fungusScript.selectedSequence.commandList[i];

                    foreach (Command selectedCommand in fungusScript.selectedCommands)
                    {
                        if (commandInSequence == selectedCommand)
                        {
                            lastSelectedIndex = i;
                        }
                    }
                }
            }
            if (lastSelectedIndex < fungusScript.selectedSequence.commandList.Count - 1)
            {
                fungusScript.ClearSelectedCommands();
                fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[lastSelectedIndex + 1]);
            }

            Repaint();
        }
예제 #4
0
        protected void Copy()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            if (fungusScript == null ||
                fungusScript.selectedSequence == null)
            {
                return;
            }

            CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance();

            commandCopyBuffer.Clear();

            // Scan through all commands in execution order to see if each needs to be copied
            foreach (Command command in fungusScript.selectedSequence.commandList)
            {
                if (fungusScript.selectedCommands.Contains(command))
                {
                    System.Type type       = command.GetType();
                    Command     newCommand = Undo.AddComponent(commandCopyBuffer.gameObject, type) as Command;
                    System.Reflection.FieldInfo[] fields = type.GetFields();
                    foreach (System.Reflection.FieldInfo field in fields)
                    {
                        field.SetValue(newCommand, field.GetValue(command));
                    }
                }
            }
        }
예제 #5
0
        protected void Delete()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            if (fungusScript == null ||
                fungusScript.selectedSequence == null)
            {
                return;
            }

            for (int i = fungusScript.selectedSequence.commandList.Count - 1; i >= 0; --i)
            {
                Command command = fungusScript.selectedSequence.commandList[i];
                foreach (Command selectedCommand in fungusScript.selectedCommands)
                {
                    if (command == selectedCommand)
                    {
                        command.OnCommandRemoved(sequence);

                        Undo.RecordObject(fungusScript.selectedSequence, "Delete");
                        fungusScript.selectedSequence.commandList.RemoveAt(i);
                        Undo.DestroyObjectImmediate(command);

                        break;
                    }
                }
            }

            Undo.RecordObject(fungusScript, "Delete");
            fungusScript.ClearSelectedCommands();

            Repaint();
        }
        protected virtual void DrawConnections(FungusScript fungusScript, Sequence sequence, bool highlightedOnly)
        {
            if (sequence == null)
            {
                return;
            }

            List <Sequence> connectedSequences = new List <Sequence>();

            bool sequenceIsSelected = (fungusScript.selectedSequence == sequence);

            foreach (Command command in sequence.commandList)
            {
                if (command == null)
                {
                    continue;
                }

                bool commandIsSelected = false;
                foreach (Command selectedCommand in fungusScript.selectedCommands)
                {
                    if (selectedCommand == command)
                    {
                        commandIsSelected = true;
                        break;
                    }
                }

                bool highlight = command.IsExecuting() || (sequenceIsSelected && commandIsSelected);

                if (highlightedOnly && !highlight ||
                    !highlightedOnly && highlight)
                {
                    continue;
                }

                connectedSequences.Clear();
                command.GetConnectedSequences(ref connectedSequences);

                foreach (Sequence sequenceB in connectedSequences)
                {
                    if (sequenceB == null ||
                        sequence == sequenceB ||
                        sequenceB.GetFungusScript() != fungusScript)
                    {
                        continue;
                    }

                    Rect startRect = new Rect(sequence.nodeRect);
                    startRect.x += fungusScript.scrollPos.x;
                    startRect.y += fungusScript.scrollPos.y;

                    Rect endRect = new Rect(sequenceB.nodeRect);
                    endRect.x += fungusScript.scrollPos.x;
                    endRect.y += fungusScript.scrollPos.y;

                    DrawRectConnection(startRect, endRect, highlight);
                }
            }
        }
예제 #7
0
        public virtual void SetCharacter(Character character, FungusScript fungusScript = null)
        {
            if (character == null)
            {
                if (characterImage != null)
                {
                    characterImage.enabled = false;
                }
                if (nameText != null)
                {
                    nameText.text = "";
                }
                characterTypingSound = null;
            }
            else
            {
                Character prevSpeakingCharacter = speakingCharacter;
                speakingCharacter = character;

                // Dim portraits of non-speaking characters
                foreach (PortraitStage ps in PortraitStage.activePortraitStages)
                {
                    if (ps.dimPortraits)
                    {
                        foreach (Character c in ps.charactersOnStage)
                        {
                            if (prevSpeakingCharacter != speakingCharacter)
                            {
                                if (c != speakingCharacter)
                                {
                                    Portrait.Dim(c, ps);
                                }
                                else
                                {
                                    Portrait.Undim(c, ps);
                                }
                            }
                        }
                    }
                }

                string characterName = character.nameText;
                if (characterName == "")
                {
                    // Use game object name as default
                    characterName = character.name;
                }

                if (fungusScript != null)
                {
                    characterName = fungusScript.SubstituteVariables(characterName);
                }

                characterTypingSound = character.soundEffect;

                SetCharacterName(characterName, character.nameColor);
            }
        }
        protected virtual void DeleteSequence(FungusScript fungusScript, Sequence sequence)
        {
            foreach (Command command in sequence.commandList)
            {
                Undo.DestroyObjectImmediate(command);
            }

            Undo.DestroyObjectImmediate(sequence);
            fungusScript.ClearSelectedCommands();
        }
예제 #9
0
        protected void Paste()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            if (fungusScript == null ||
                fungusScript.selectedSequence == null)
            {
                return;
            }

            CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance();

            // Find where to paste commands in sequence (either at end or after last selected command)
            int pasteIndex = fungusScript.selectedSequence.commandList.Count;

            if (fungusScript.selectedCommands.Count > 0)
            {
                for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; ++i)
                {
                    Command command = fungusScript.selectedSequence.commandList[i];

                    foreach (Command selectedCommand in fungusScript.selectedCommands)
                    {
                        if (command == selectedCommand)
                        {
                            pasteIndex = i + 1;
                        }
                    }
                }
            }

            foreach (Command command in commandCopyBuffer.GetCommands())
            {
                // Using the Editor copy / paste functionality instead instead of reflection
                // because this does a deep copy of the command properties.
                if (ComponentUtility.CopyComponent(command))
                {
                    if (ComponentUtility.PasteComponentAsNew(fungusScript.gameObject))
                    {
                        Command[] commands      = fungusScript.GetComponents <Command>();
                        Command   pastedCommand = commands.Last <Command>();
                        if (pastedCommand != null)
                        {
                            fungusScript.selectedSequence.commandList.Insert(pasteIndex++, pastedCommand);
                        }
                    }

                    // This stops the user pasting the command manually into another game object.
                    ComponentUtility.CopyComponent(fungusScript.transform);
                }
            }

            Repaint();
        }
예제 #10
0
        /**
         * The Event Handler should call this method when the event is detected.
         */
        public virtual bool ExecuteSequence()
        {
            if (parentSequence == null)
            {
                return(false);
            }

            FungusScript fungusScript = parentSequence.GetFungusScript();

            return(fungusScript.ExecuteSequence(parentSequence));
        }
 protected virtual void SelectSequence(FungusScript fungusScript, Sequence sequence)
 {
     // Select the sequence and also select currently executing command
     ShowSequenceInspector(fungusScript);
     fungusScript.selectedSequence = sequence;
     fungusScript.ClearSelectedCommands();
     if (sequence.activeCommand != null)
     {
         fungusScript.AddSelectedCommand(sequence.activeCommand);
     }
 }
        public static Sequence CreateSequence(FungusScript fungusScript, Vector2 position)
        {
            Sequence newSequence = fungusScript.CreateSequence(position);

            Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence");
            ShowSequenceInspector(fungusScript);
            fungusScript.selectedSequence = newSequence;
            fungusScript.ClearSelectedCommands();

            return(newSequence);
        }
예제 #13
0
        public virtual bool IsExecuting()
        {
            FungusScript fungusScript = GetFungusScript();

            if (fungusScript == null)
            {
                return(false);
            }

            return(activeCommand != null);
        }
예제 #14
0
        public bool IsRunning()
        {
            FungusScript fungusScript = GetFungusScript();

            if (fungusScript == null ||
                fungusScript.executingSequence == null)
            {
                return(false);
            }

            return(fungusScript.executingSequence == this);
        }
예제 #15
0
        public virtual void Stop()
        {
            FungusScript fungusScript = GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            activeCommand = null;
            fungusScript.ClearSelectedCommands();
        }
예제 #16
0
        void CreateSequenceCallback(object item)
        {
            FungusScript fungusScript = GetFungusScript();

            if (fungusScript != null)
            {
                Vector2 position = (Vector2)item;
                position -= fungusScript.scriptScrollPos;
                Sequence newSequence = fungusScript.CreateSequence(position);
                Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence");
                fungusScript.selectedSequence = newSequence;
            }
        }
예제 #17
0
        public void Stop()
        {
            FungusScript fungusScript = GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            activeCommand = null;
            fungusScript.executingSequence = null;
            fungusScript.selectedSequence  = null;
            fungusScript.selectedCommand   = null;
        }
        protected static void ShowSequenceInspector(FungusScript fungusScript)
        {
            if (sequenceInspector == null)
            {
                // Create a Scriptable Object with a custom editor which we can use to inspect the selected sequence.
                // Editors for Scriptable Objects display using the full height of the inspector window.
                sequenceInspector           = ScriptableObject.CreateInstance <SequenceInspector>() as SequenceInspector;
                sequenceInspector.hideFlags = HideFlags.DontSave;
            }

            Selection.activeObject = sequenceInspector;

            EditorUtility.SetDirty(sequenceInspector);
        }
예제 #19
0
        public virtual FungusScript GetFungusScript()
        {
            FungusScript fungusScript = GetComponent <FungusScript>();

            if (fungusScript == null)
            {
                // Legacy support for earlier system where Sequences were children of the FungusScript
                if (transform.parent != null)
                {
                    fungusScript = transform.parent.GetComponent <FungusScript>();
                }
            }

            return(fungusScript);
        }
예제 #20
0
        public virtual void ExecuteSequence(Sequence s)
        {
            OnExit();
            Sequence sequence = GetSequence();

            if (sequence != null)
            {
                sequence.Stop();
                FungusScript fungusScript = sequence.GetFungusScript();
                if (fungusScript != null)
                {
                    fungusScript.ExecuteSequence(s);
                }
            }
        }
예제 #21
0
        protected void SelectNone()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            if (fungusScript == null ||
                fungusScript.selectedSequence == null)
            {
                return;
            }

            Undo.RecordObject(fungusScript, "Select None");
            fungusScript.ClearSelectedCommands();

            Repaint();
        }
예제 #22
0
        static void CreateFungusScript()
        {
            GameObject newFungusScriptGO = new GameObject();

            newFungusScriptGO.name = "FungusScript";
            FungusScript fungusScript  = newFungusScriptGO.AddComponent <FungusScript>();
            GameObject   newSequenceGO = new GameObject();

            newSequenceGO.transform.parent = newFungusScriptGO.transform;
            newSequenceGO.name             = "Start";
            newSequenceGO.hideFlags        = HideFlags.HideInHierarchy;
            Sequence sequence = newSequenceGO.AddComponent <Sequence>();

            fungusScript.startSequence    = sequence;
            fungusScript.selectedSequence = sequence;
        }
예제 #23
0
        public void ExecuteNextCommand(Command currentCommand = null)
        {
            if (currentCommand == null)
            {
                executionCount++;
            }

            activeCommand = null;
            Command nextCommand = null;

            bool executeNext = (currentCommand == null);

            foreach (Command command in commandList)
            {
                if (command == currentCommand)
                {
                    executeNext = true;
                }
                else if (executeNext)
                {
                    if (command.enabled)
                    {
                        nextCommand = command;
                        break;
                    }
                }
            }

            if (nextCommand == null)
            {
                Stop();
            }
            else
            {
                FungusScript fungusScript = GetFungusScript();

                if (fungusScript.stepTime == 0f)
                {
                    activeCommand = nextCommand;
                    nextCommand.Execute();
                }
                else
                {
                    StartCoroutine(ExecuteAfterDelay(nextCommand, fungusScript.stepTime));
                }
            }
        }
예제 #24
0
		static public FungusScript GetFungusScript()
		{
			if (locked && activeFungusScript != null)
			{
				return activeFungusScript;
			}

			locked = false;

			if (Selection.activeGameObject != null)
			{
				activeFungusScript = Selection.activeGameObject.GetComponent<FungusScript>();
				return activeFungusScript;
			}

			return null;
		}
예제 #25
0
		static public void VariableField(SerializedProperty property, GUIContent label, FungusScript fungusScript, Func<Variable, bool> filter = null)
		{
			List<string> variableKeys = new List<string>();
			List<Variable> variableObjects = new List<Variable>();
			
			variableKeys.Add("<None>");
			variableObjects.Add(null);
			
			List<Variable> variables = fungusScript.variables;
			int index = 0;
			int selectedIndex = 0;

			Variable selectedVariable = property.objectReferenceValue as Variable;

			foreach (Variable v in variables)
			{
				if (filter != null)
				{
					if (!filter(v))
					{
						continue;
					}
				}
				
				variableKeys.Add(v.key);
				variableObjects.Add(v);
				
				index++;
				
				if (v == selectedVariable)
				{
					selectedIndex = index;
				}
			}
			
			selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray());
			
			property.objectReferenceValue = variableObjects[selectedIndex];
		}
예제 #26
0
		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;
		}
예제 #27
0
		void DrawSequenceView(FungusScript fungusScript)
		{
			GUILayout.Space(5);

			fungusScript.commandScrollPos = GUILayout.BeginScrollView(fungusScript.commandScrollPos);

			EditorGUILayout.BeginVertical();

			GUILayout.Box("Sequence", GUILayout.ExpandWidth(true));

			GUILayout.BeginHorizontal();
			
			if (fungusScript.selectedSequence == null)
			{
				GUILayout.FlexibleSpace();
			}
			
			if (GUILayout.Button(fungusScript.selectedSequence == null ? "Create Sequence" : "Create", 
			                     fungusScript.selectedSequence == null ?  EditorStyles.miniButton : EditorStyles.miniButtonLeft))
			{
				Sequence newSequence = fungusScript.CreateSequence(fungusScript.scriptScrollPos);
				Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence");
				fungusScript.selectedSequence = newSequence;
				fungusScript.selectedCommand = null;
			}
			
			if (fungusScript.selectedSequence == null)
			{
				GUILayout.FlexibleSpace();
			}
			
			if (fungusScript.selectedSequence != null)
			{
				if (GUILayout.Button("Delete", EditorStyles.miniButtonMid))
				{
					Undo.DestroyObjectImmediate(fungusScript.selectedSequence.gameObject);
					fungusScript.selectedSequence = null;
					fungusScript.selectedCommand = null;
				}
				if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight))
				{
					GameObject copy = GameObject.Instantiate(fungusScript.selectedSequence.gameObject) as GameObject;
					copy.transform.parent = fungusScript.transform;
					copy.transform.hideFlags = HideFlags.HideInHierarchy;
					copy.name = fungusScript.selectedSequence.name;
					
					Sequence sequenceCopy = copy.GetComponent<Sequence>();
					sequenceCopy.nodeRect.x += sequenceCopy.nodeRect.width + 10;
					
					Undo.RegisterCreatedObjectUndo(copy, "Duplicate Sequence");
					fungusScript.selectedSequence = sequenceCopy;
					fungusScript.selectedCommand = null;
				}
			}
			
			GUILayout.EndHorizontal();

			if (fungusScript.selectedSequence != null)
			{
				EditorGUILayout.Separator();

				SequenceEditor sequenceEditor = Editor.CreateEditor(fungusScript.selectedSequence) as SequenceEditor;
				sequenceEditor.DrawSequenceGUI(fungusScript);
				DestroyImmediate(sequenceEditor);

				GUILayout.FlexibleSpace();
			}

			EditorGUILayout.EndVertical();

			GUILayout.EndScrollView();
		}
예제 #28
0
		public void DrawSequenceGUI(FungusScript fungusScript)
		{
			if (fungusScript.selectedSequence == null)
			{
				return;
			}

			serializedObject.Update();
			
			Sequence sequence = fungusScript.selectedSequence;

			EditorGUI.BeginChangeCheck();
			string sequenceName = EditorGUILayout.TextField(new GUIContent("Name", "Name of sequence object"), sequence.gameObject.name);
			if (EditorGUI.EndChangeCheck())
			{
				Undo.RecordObject(sequence.gameObject, "Set Sequence Name");
				sequence.gameObject.name = sequenceName;
			}

			EditorGUILayout.PropertyField(descriptionProp);

			EditorGUILayout.Separator();

			UpdateIndentLevels(sequence);

			ReorderableListGUI.Title("Command Sequence");
			SerializedProperty commandListProperty = serializedObject.FindProperty("commandList");
			CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0);
			ReorderableListControl.DrawControlFromState(adaptor, null, 0);

			if (Application.isPlaying)
			{
				serializedObject.ApplyModifiedProperties();
				return;
			}

			EditorGUILayout.BeginHorizontal();

			GUILayout.FlexibleSpace();
		
			if (fungusScript.copyCommand != null)
			{
				if (GUILayout.Button("Paste"))
				{
					fungusScript.selectedCommand = CommandEditor.PasteCommand(fungusScript.copyCommand, fungusScript.selectedSequence);
				}
			}

			EditorGUILayout.EndHorizontal();

			if (fungusScript.selectedCommand != null)
			{
				CommandInfoAttribute infoAttr = CommandEditor.GetCommandInfo(fungusScript.selectedCommand.GetType());
				if (infoAttr != null)
				{
					EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info);
				}
			}

			serializedObject.ApplyModifiedProperties();
		}
예제 #29
0
		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;
		}
예제 #30
0
		void ResizeViews(FungusScript fungusScript)
		{
			cursorChangeRect = new Rect(this.position.width - fungusScript.commandViewWidth, 0, 4f, this.position.height);

			GUI.color = Color.grey;
			GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture);
			GUI.color = Color.white;
			EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeHorizontal);
			
			if (Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition))
			{
				resize = true;
			}
			if (resize)
			{
				fungusScript.commandViewWidth = this.position.width - Event.current.mousePosition.x;
				fungusScript.commandViewWidth = Mathf.Max(minViewWidth, fungusScript.commandViewWidth);
				fungusScript.commandViewWidth = Mathf.Min(this.position.width - minViewWidth, fungusScript.commandViewWidth);
			}
			if(Event.current.type == EventType.MouseUp)
			{
				resize = false;        
			}
		}
예제 #31
0
		void DrawConnections(FungusScript fungusScript, Sequence sequence, bool highlightedOnly)
		{
			if (sequence == null)
			{
				return;
			}

			List<Sequence> connectedSequences = new List<Sequence>();

			bool sequenceIsSelected = (fungusScript.selectedSequence == sequence);

			foreach (Command command in sequence.commandList)
			{
				bool commandIsSelected = (fungusScript.selectedCommand == command);

				bool highlight = command.IsExecuting() || (sequenceIsSelected && commandIsSelected);

				if (highlightedOnly && !highlight ||
				    !highlightedOnly && highlight)
				{
					continue;
				}

				connectedSequences.Clear();
				command.GetConnectedSequences(ref connectedSequences);

				foreach (Sequence sequenceB in connectedSequences)
				{
					if (sequenceB == null ||
					    sequenceB.GetFungusScript() != fungusScript)
					{
						continue;
					}

					DrawRectConnection(sequence.nodeRect, sequenceB.nodeRect, highlight);
				}
			}
		}
예제 #32
0
		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();
		}