Ejemplo n.º 1
0
		void UpdateIndentLevels(Sequence sequence)
		{
			int indentLevel = 0;
			foreach(Command command in sequence.commandList)
			{
				indentLevel += command.GetPreIndent();
				command.indentLevel = Math.Max(indentLevel, 0);
				indentLevel += command.GetPostIndent();
			}
		}
Ejemplo n.º 2
0
        public static void LabelField(SerializedProperty property, 
		                              GUIContent labelText, 
		                              Sequence sequence)
        {
            List<string> labelKeys = new List<string>();
            List<Label> labelObjects = new List<Label>();

            labelKeys.Add("<None>");
            labelObjects.Add(null);

            Label selectedLabel = property.objectReferenceValue as Label;

            int index = 0;
            int selectedIndex = 0;
            foreach (Command command in sequence.commandList)
            {
                Label label = command as Label;
                if (label == null)
                {
                    continue;
                }

                labelKeys.Add(label.key);
                labelObjects.Add(label);

                index++;

                if (label == selectedLabel)
                {
                    selectedIndex = index;
                }
            }

            selectedIndex = EditorGUILayout.Popup(labelText.text, selectedIndex, labelKeys.ToArray());

            property.objectReferenceValue = labelObjects[selectedIndex];
        }
Ejemplo n.º 3
0
        public virtual void ExecuteSequence(Sequence s)
        {
            OnExit();
            if (parentSequence != null)
            {
                FungusScript fungusScript = parentSequence.GetFungusScript();

                // Record the currently selected sequence because Stop() will clear it.
                Sequence selectedSequence = fungusScript.selectedSequence;

                parentSequence.Stop();
                if (fungusScript != null)
                {
                    // If the executing sequence is currently selected then follow the execution
                    // onto the next sequence in the inspector.
                    if (selectedSequence == parentSequence)
                    {
                        fungusScript.selectedSequence = s;
                    }

                    fungusScript.ExecuteSequence(s);
                }
            }
        }
Ejemplo n.º 4
0
		/**
		 * Start running the Fungus Script by executing a specific child sequence.
		 */
		public void ExecuteSequence(Sequence sequence)
		{
			// Sequence must be a child of the parent Fungus Script
			if (sequence == null ||
			    sequence.transform.parent != transform) 
			{
				return;
			}

			executingSequence = sequence;
			selectedSequence = sequence;
			sequence.ExecuteNextCommand();
		}
Ejemplo n.º 5
0
		void ShowCommandMenu(int index, Sequence sequence)
		{
			GenericMenu commandMenu = new GenericMenu();

			// Build menu list
			List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
			foreach(System.Type type in menuTypes)
			{
				object[] attributes = type.GetCustomAttributes(false);
				foreach (object obj in attributes)
				{
					CommandInfoAttribute infoAttr = obj as CommandInfoAttribute;
					if (infoAttr != null)
					{
						SetCommandOperation commandOperation = new SetCommandOperation();

						commandOperation.sequence = sequence;
						commandOperation.commandType = type;
						commandOperation.index = index;

						commandMenu.AddItem (new GUIContent (infoAttr.Category + "/" + infoAttr.CommandName), 
						                     false, Callback, commandOperation);
					}
				}
			}

			commandMenu.ShowAsContext();
		}
Ejemplo n.º 6
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);
				}
			}
		}
Ejemplo n.º 7
0
 /**
  * Called when the command is deleted from a sequence in the editor.
  */
 public virtual void OnCommandRemoved(Sequence parentSequence)
 {
 }
Ejemplo n.º 8
0
 /**
  * Called when the new command is added to a sequence in the editor.
  */
 public virtual void OnCommandAdded(Sequence parentSequence)
 {
 }
Ejemplo n.º 9
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);
				}
			}
		}
Ejemplo n.º 10
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;
		}