Beispiel #1
0
        public static string GetAllFsmVariablesGlobalVariablesNames(FsmVariables fsmVariables)
        {
            string text = "";

            foreach (NamedVariable namedVariable in fsmVariables.GetAllNamedVariables())
            {
                text += "namedVariable name: " + namedVariable.Name + "\n";
            }
            return(text);
        }
Beispiel #2
0
        // Perform an action with a batch of FSM variables
        protected bool DoBatchVariableAction(FsmVariables fsmVariables, VariableAction variableAction, string filter, FsmVariableType fsmVariableType)
        {
            // Check data
            if (fsmVariables == null)
            {
                throw new ArgumentNullException("fsmVariables", "Cannot do action with null FSM variable batch: " + variableAction);
            }

            NamedVariable[] fsmVariableSubset;
            switch (fsmVariableType)
            {
            case FsmVariableType.All:
                fsmVariableSubset = fsmVariables.GetAllNamedVariables();
                break;

            case FsmVariableType.Bool:
                fsmVariableSubset = fsmVariables.BoolVariables;
                break;

            case FsmVariableType.Color:
                fsmVariableSubset = fsmVariables.ColorVariables;
                break;

            case FsmVariableType.Float:
                fsmVariableSubset = fsmVariables.FloatVariables;
                break;

            case FsmVariableType.GameObject:
                fsmVariableSubset = fsmVariables.GameObjectVariables;
                break;

            case FsmVariableType.Int:
                fsmVariableSubset = fsmVariables.IntVariables;
                break;

            case FsmVariableType.Quaternion:
                fsmVariableSubset = fsmVariables.QuaternionVariables;
                break;

            case FsmVariableType.Rect:
                fsmVariableSubset = fsmVariables.RectVariables;
                break;

            case FsmVariableType.String:
                fsmVariableSubset = fsmVariables.StringVariables;
                break;

            case FsmVariableType.Vector2:
                fsmVariableSubset = fsmVariables.Vector2Variables;
                break;

            case FsmVariableType.Vector3:
                fsmVariableSubset = fsmVariables.Vector3Variables;
                break;

            case FsmVariableType.Array:
                fsmVariableSubset = fsmVariables.ArrayVariables;
                break;

            case FsmVariableType.Enum:
                fsmVariableSubset = fsmVariables.EnumVariables;
                break;

            default:
                throw new NotSupportedException("Invalid FSM variable type: " + fsmVariableType);
            }

            // Process each FSM variable
            var allComplete = true;

            foreach (var currentVariable in fsmVariableSubset)
            {
                if (MatchFilter(currentVariable.Name, filter) && IsValidFsmVariableType(currentVariable))
                {
                    if (!DoVariableAction(variableAction, currentVariable, null))
                    {
                        allComplete = false;
                    }
                }
            }
            return(allComplete);
        }
Beispiel #3
0
        /// <summary>
        /// Gets specific types variables list as strings from FsmVariables.
        /// Use this method to populate popup selection in inspectors.
        /// </summary>
        /// <returns>The list of variables of defined variableType as strings.</returns>
        /// <param name="fsmVariables">the List of Variables to filter</param>
        /// <param name="includeNone">If set to <c>true</c> include a "none" option. Useful for popup to select an event or not</param>
        /// <param name="variableType">Optional, default to Unknown, else will filter by specific type</param>
        public static string[] GetVariablesStringList(FsmVariables fsmVariables, bool includeNone = false, VariableType variableType = VariableType.Unknown)
        {
            string[] list = new string[0];

            if (fsmVariables != null)
            {
                //Debug.Log("GetVariablesStringList internal "+variableType+" "+fsmVariables.GetNamedVariables(variableType).Length);

                if (variableType == VariableType.Unknown)
                {
                    NamedVariable[] namedVariables = fsmVariables.GetAllNamedVariables();                    // fsmVariables.GetNamedVariables(variableType);// PlayMakerGlobals.Instance.Variables.GetAllNamedVariables();

                    list = new string[namedVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in namedVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Bool)
                {
                    list = new string[fsmVariables.BoolVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.BoolVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Color)
                {
                    list = new string[fsmVariables.ColorVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.ColorVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Float)
                {
                    list = new string[fsmVariables.FloatVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.FloatVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.GameObject)
                {
                    list = new string[fsmVariables.GameObjectVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.GameObjectVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Int)
                {
                    list = new string[fsmVariables.IntVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.IntVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Material)
                {
                    list = new string[fsmVariables.MaterialVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.MaterialVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Object)
                {
                    list = new string[fsmVariables.ObjectVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.ObjectVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Quaternion)
                {
                    list = new string[fsmVariables.QuaternionVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.QuaternionVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Rect)
                {
                    list = new string[fsmVariables.RectVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.RectVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.String)
                {
                    list = new string[fsmVariables.StringVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.StringVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Texture)
                {
                    list = new string[fsmVariables.TextureVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.TextureVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Vector2)
                {
                    list = new string[fsmVariables.Vector2Variables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.Vector2Variables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Vector3)
                {
                    list = new string[fsmVariables.Vector3Variables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.Vector3Variables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                                #if PLAYMAKER_1_8
                if (variableType == VariableType.Array)
                {
                    list = new string[fsmVariables.ArrayVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.ArrayVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }

                if (variableType == VariableType.Enum)
                {
                    list = new string[fsmVariables.EnumVariables.Length];

                    int i = 0;
                    foreach (NamedVariable _variable in fsmVariables.EnumVariables)
                    {
                        list[i] = _variable.Name;
                        i++;
                    }
                }
                                #endif
            }

            if (includeNone)
            {
                ArrayUtility.Insert <string>(ref list, 0, "none");
            }

            return(list);
        }
		/// <summary>
		/// Gets specific types variables list as strings from FsmVariables. 
		/// Use this method to populate popup selection in inspectors.
		/// </summary>
		/// <returns>The list of variables of defined variableType as strings.</returns>
		/// <param name="fsmVariables">the List of Variables to filter</param>
		/// <param name="includeNone">If set to <c>true</c> include a "none" option. Useful for popup to select an event or not</param>
		/// <param name="variableType">Optional, default to Unknown, else will filter by specific type</param>
		public static string[] GetVariablesStringList(FsmVariables fsmVariables,bool includeNone = false, VariableType variableType = VariableType.Unknown)
		{

			string[] list = new string[0];

			if (fsmVariables!=null)
			{
				//Debug.Log("GetVariablesStringList internal "+variableType+" "+fsmVariables.GetNamedVariables(variableType).Length);

				if (variableType == VariableType.Unknown)
				{
					NamedVariable[] namedVariables = fsmVariables.GetAllNamedVariables();// fsmVariables.GetNamedVariables(variableType);// PlayMakerGlobals.Instance.Variables.GetAllNamedVariables();
					
					list = new string[namedVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in namedVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}
				
				if (variableType == VariableType.Bool)
				{
					list = new string[fsmVariables.BoolVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.BoolVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Color)
				{
					list = new string[fsmVariables.ColorVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.ColorVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Float)
				{
					list = new string[fsmVariables.FloatVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.FloatVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.GameObject)
				{
					list = new string[fsmVariables.GameObjectVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.GameObjectVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Int)
				{
					list = new string[fsmVariables.IntVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.IntVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Material)
				{
					list = new string[fsmVariables.MaterialVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.MaterialVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Object)
				{
					list = new string[fsmVariables.ObjectVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.ObjectVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Quaternion)
				{
					list = new string[fsmVariables.QuaternionVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.QuaternionVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Rect)
				{
					list = new string[fsmVariables.RectVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.RectVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.String)
				{
					list = new string[fsmVariables.StringVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.StringVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Texture)
				{
					list = new string[fsmVariables.TextureVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.TextureVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Vector2)
				{
					list = new string[fsmVariables.Vector2Variables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.Vector2Variables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Vector3)
				{
					list = new string[fsmVariables.Vector3Variables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.Vector3Variables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				#if PLAYMAKER_1_8
				if (variableType == VariableType.Array)
				{
					list = new string[fsmVariables.ArrayVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.ArrayVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}

				if (variableType == VariableType.Enum)
				{
					list = new string[fsmVariables.EnumVariables.Length];
					
					int i=0;
					foreach(NamedVariable _variable in fsmVariables.EnumVariables)
					{
						list[i] = _variable.Name;
						i++;
					}
				}
				#endif
			}

			if (includeNone)
			{
				ArrayUtility.Insert<string>(ref list,0,"none");
			}

			return list;
		}