DeveloperConsole.ApplyCommandsToGameObject C# (CSharp) Method

ApplyCommandsToGameObject() public method

public ApplyCommandsToGameObject ( GameObject go, string workWithText, bool printResult ) : void
go GameObject
workWithText string
printResult bool
return void
	void ApplyCommandsToGameObject(GameObject go, string workWithText, bool printResult)
	{
		string[] splitDots = workWithText.Split('.');
		int endIndexOfObjectName = splitDots[0].Length + 1;
		//if (callingFunction) endIndexOfObjectName += 5;
		string[] splitSpacesAgain = workWithText.Substring(endIndexOfObjectName, workWithText.Length - endIndexOfObjectName).Split(' ');
		
		splitDots = splitSpacesAgain[0].Split('.');
		
		if (splitDots.Length >= 2)
		{
			string argsString = "";
			if (splitSpacesAgain[0].Length > 0)
			{
				if (workWithText.Length - (endIndexOfObjectName + splitSpacesAgain[0].Length + 1) >= 0)
				{
					argsString = workWithText.Substring(endIndexOfObjectName + splitSpacesAgain[0].Length + 1,
					                                    workWithText.Length - (endIndexOfObjectName + splitSpacesAgain[0].Length + 1));
				}
			}
			
			List<string> foundArgs = new List<string>();
			bool inQuote = false;
			string currentString = "";
			for (int sI = 0; sI < argsString.Length; sI++)
			{
				if (argsString[sI] == ' ')
				{
					if (!inQuote)
					{
						if (currentString != "")
						{
							foundArgs.Add(currentString);
							currentString = "";
						}
						continue;
					}
				}
				else if (argsString[sI] == '"')
				{
					if (inQuote)
					{
						inQuote = false;
						if (currentString != "")
						{
							foundArgs.Add(currentString);
							currentString = "";
						}
					}
					else
					{
						inQuote = true;
						
					}
					continue;
				}
				
				currentString += argsString[sI];
				
				if (sI == argsString.Length - 1)
				{
					foundArgs.Add(currentString);
				}
			}
			
			string[] arguments = foundArgs.ToArray();
			
			Component component = go.GetComponent(splitDots[0]) as Component;
			
			if (component != null)
			{
				bool foundMatch = false;
				MethodInfo[] mInfos = ( component.GetType() ).GetMethods();
				foreach (MethodInfo mInfo in mInfos)
				{
					if (mInfo.Name.ToLower() == splitDots[1].ToLower())
					{
						RunMethod(go, component, splitDots[1], arguments, printResult);
						foundMatch = true;
						break;
					}
				}
				if (!foundMatch)
				{
					FieldInfo[] fInfos = (component.GetType()).GetFields();
					foreach (FieldInfo fInfo in fInfos)
					{
						if (fInfo.Name.ToLower() == splitDots[1].ToLower())
						{
							if (arguments.Length == 0)
							{
								GetField(go, component, splitDots[1]);
							}
							else
							{
								SetField(go, component, splitDots[1], arguments[0]);
							}
							foundMatch = true;
							break;
						}
					}
				}
				if (!foundMatch)
				{
					PropertyInfo[] pInfos = (component.GetType()).GetProperties();
					foreach (PropertyInfo pInfo in pInfos)
					{
						if (pInfo.Name.ToLower() == splitDots[1].ToLower())
						{
							if (arguments.Length == 0)
							{
								GetProperty(go, component, splitDots[1]);
							}
							else
							{
								SetProperty(go, component, splitDots[1], arguments[0]);
							}
							foundMatch = true;
							break;
						}
					}
				}
			}
		}
	}