예제 #1
0
            void ExecuteProperty(FastQueue <string> arguments, string argumentString)
            {
                var prop = (PropertyInfo)member;

                if (arguments.Count == 0)
                {
                    if (prop.GetGetMethod(true) == null)
                    {
                        LogResultError(prop.Name + " doesn't have a getter");
                        return;
                    }
                    if (isStatic)
                    {
                        LogValue(prop, obj);
                    }
                    else
                    {
                        HashSet <object> instances = registeredInstancesLookup[(Type)obj];
                        CheckDestroyedMonoBehaviours(instances);
                        foreach (object instance in instances)
                        {
                            LogValue(prop, instance);
                        }
                    }
                }
                else
                {
                    if (prop.GetSetMethod(true) == null)
                    {
                        LogResultError(prop.Name + " doesn't have a setter");
                        return;
                    }

                    object arg;
                    if (!Parser.TryParse(prop.PropertyType, arguments, out arg))
                    {
                        return;
                    }
                    if (arguments.Count > 0)
                    {
                        LogResultError("Too many arguments");
                        return;
                    }

                    if (isStatic)
                    {
                        SetProperty(prop, obj, arg);
                    }
                    else
                    {
                        HashSet <object> instances = registeredInstancesLookup[(Type)obj];
                        CheckDestroyedMonoBehaviours(instances);
                        foreach (object instance in instances)
                        {
                            SetProperty(prop, instance, arg);
                        }
                    }
                }
            }
예제 #2
0
파일: Parser.cs 프로젝트: jonbla/Chess
        static bool ChangeType(Type t, FastQueue <string> paramQueue, out object result)
        {
            if (paramQueue.Count == 0)
            {
                RuntimeConsole.LogResultError("Not enough parameters");
                result = null;
                return(false);
            }

            string value = paramQueue.Dequeue();

            return(ChangeType(t, value, out result));
        }
예제 #3
0
        static public void GetArguments(string argumentString, FastQueue <string> inputCommands)
        {
            argumentString = argumentString.Trim(' ');
            inputCommands.FastClear();

            int startIndex = 0;

            for (int i = 0; i < argumentString.Length; i++)
            {
                char c = argumentString[i];

                if (i == argumentString.Length - 1)
                {
                    inputCommands.Enqueue(argumentString.Substring(startIndex, (i - startIndex) + 1).Trim());
                    break;
                }

                if (c == ' ')
                {
                    if (i < argumentString.Length - 1)
                    {
                        if (argumentString[i + 1] == ' ')
                        {
                            continue;
                        }
                    }
                    int spaceIndex = argumentString.IndexOf(' ', i + 1);
                    int length     = i - startIndex;
                    inputCommands.Enqueue(argumentString.Substring(startIndex, length).Trim());
                    if (spaceIndex == -1)
                    {
                        inputCommands.Enqueue(argumentString.Substring(i + 1).Trim());
                        break;
                    }
                    startIndex += length + 1;
                }
                if (c == '\"')
                {
                    int stringIndex = argumentString.IndexOf('\"', i + 1);
                    if (stringIndex == -1)
                    {
                        LogCommandFailed(argumentString, "String closing \" is missing");
                        return;
                    }
                    int length = stringIndex - startIndex;
                    inputCommands.Enqueue(argumentString.Substring(startIndex + 1, length - 1).Trim());
                    startIndex += length + 1;
                    i           = stringIndex + 1;
                }
            }
        }
예제 #4
0
            void ExecuteField(FastQueue <string> arguments, string argumentString)
            {
                var field = (FieldInfo)member;

                if (arguments.Count == 0)
                {
                    if (isStatic)
                    {
                        LogValue(field, obj);
                    }
                    else
                    {
                        HashSet <object> instances = registeredInstancesLookup[(Type)obj];
                        CheckDestroyedMonoBehaviours(instances);
                        foreach (object instance in instances)
                        {
                            LogValue(field, instance);
                        }
                    }
                }
                else
                {
                    object arg;
                    if (!Parser.TryParse(field.FieldType, arguments, out arg))
                    {
                        return;
                    }
                    if (arguments.Count > 0)
                    {
                        LogResultError("Too many arguments");
                        return;
                    }

                    if (isStatic)
                    {
                        SetField(field, obj, arg);
                    }
                    else
                    {
                        HashSet <object> instances = registeredInstancesLookup[(Type)obj];
                        CheckDestroyedMonoBehaviours(instances);
                        foreach (object instance in instances)
                        {
                            SetField(field, instance, arg);
                        }
                    }
                }
            }
예제 #5
0
 public void Execute(FastQueue <string> arguments, string argumentString)
 {
     // Debug.Log(method.Name + " : " + paramInfos.Length);
     if (memberType == MemberType.Method || memberType == MemberType.Delegate)
     {
         ExecuteMethodOrDelegate(arguments, argumentString);
     }
     else if (memberType == MemberType.Field)
     {
         ExecuteField(arguments, argumentString);
     }
     else if (memberType == MemberType.Property)
     {
         ExecuteProperty(arguments, argumentString);
     }
 }
예제 #6
0
        static object ChangeType(Type t, FastQueue <string> paramQueue, ref bool valid)
        {
            if (paramQueue.Count == 0)
            {
                LogResultError("Not enough parameters");
                valid = false;
                return(null);
            }

            string value = paramQueue.Dequeue();

            value = value.Trim();

            // Debug.Log("TryParse: " + value);

            if (t == typeof(string))
            {
                return(value);
            }
            else if (t == typeof(bool))
            {
                bool result; bool.TryParse(value, out result); return(result);
            }
            else if (t == typeof(byte))
            {
                byte result; byte.TryParse(value, out result); return(result);
            }
            else if (t == typeof(sbyte))
            {
                sbyte result; sbyte.TryParse(value, out result); return(result);
            }
            else if (t == typeof(char))
            {
                char result; char.TryParse(value, out result); return(result);
            }
            else if (t == typeof(decimal))
            {
                decimal result; decimal.TryParse(value, out result); return(result);
            }
            else if (t == typeof(double))
            {
                double result; double.TryParse(value, out result); return(result);
            }
            else if (t == typeof(float))
            {
                float result; float.TryParse(value, out result); return(result);
            }
            else if (t == typeof(int))
            {
                int result; int.TryParse(value, out result); return(result);
            }
            else if (t == typeof(uint))
            {
                uint result; uint.TryParse(value, out result); return(result);
            }
            else if (t == typeof(long))
            {
                long result; long.TryParse(value, out result); return(result);
            }
            else if (t == typeof(ulong))
            {
                ulong result; ulong.TryParse(value, out result); return(result);
            }
            else if (t == typeof(short))
            {
                short result; short.TryParse(value, out result); return(result);
            }
            else if (t == typeof(ushort))
            {
                ushort result; ushort.TryParse(value, out result); return(result);
            }
            else if (t.IsEnum)
            {
                try
                {
                    return(Enum.Parse(t, value, true));
                }
                catch (Exception)
                {
                    LogResultError("Cannot find '" + value + "'");
                }
            }

            valid = false;
            return(null);
        }
예제 #7
0
        static bool TryParse(Type t, FastQueue <string> paramQueue, out object result)
        {
            bool valid = true;

            if (t == typeof(Vector2))
            {
                var v = new Vector2();
                for (int i = 0; i < 2; i++)
                {
                    object r = ChangeType(typeof(float), paramQueue, ref valid);
                    if (r != null)
                    {
                        v[i] = (float)r;
                    }
                    else
                    {
                        result = null; return(false);
                    }
                }
                result = v;
            }
            else if (t == typeof(Vector3))
            {
                var v = new Vector3();
                for (int i = 0; i < 3; i++)
                {
                    object r = ChangeType(typeof(float), paramQueue, ref valid);
                    if (r != null)
                    {
                        v[i] = (float)r;
                    }
                    else
                    {
                        result = null; return(false);
                    }
                }
                result = v;
            }
            else if (t == typeof(Vector4))
            {
                var v = new Vector4();
                for (int i = 0; i < 4; i++)
                {
                    object r = ChangeType(typeof(float), paramQueue, ref valid);
                    if (r != null)
                    {
                        v[i] = (float)r;
                    }
                    else
                    {
                        result = null; return(false);
                    }
                }
                result = v;
            }
            else if (t == typeof(Quaternion))
            {
                var v = new Quaternion();
                for (int i = 0; i < 4; i++)
                {
                    object r = ChangeType(typeof(float), paramQueue, ref valid);
                    if (r != null)
                    {
                        v[i] = (float)r;
                    }
                    else
                    {
                        result = null; return(false);
                    }
                }
                result = v;
            }
            else
            {
                result = ChangeType(t, paramQueue, ref valid);
            }

            return(valid);
        }
예제 #8
0
            void ExecuteMethodOrDelegate(FastQueue <string> arguments, string argumentString)
            {
                if (paramInfos != null)
                {
                    int argumentsCount = arguments.Count;

                    for (int i = 0; i < paramInfos.Length; i++)
                    {
                        // Debug.Log(paramInfos[i].ParameterType.Name);
                        ParameterInfo paramInfo = paramInfos[i];

                        Type type = paramInfo.ParameterType;

                        if (i >= argumentsCount)
                        {
                            if (!paramInfo.IsOptional)
                            {
                                LogResultError("Can't execute because of wrong number of arguments");
                                return;
                            }
                            args[i] = paramInfo.DefaultValue;
                            continue;
                        }

                        // Debug.Log(type.Name + " " + type.IsPrimitive);

                        if (!Parser.TryParse(type, arguments, out args[i]))
                        {
                            return;
                        }
                    }
                }

                if (arguments.Count > 0)
                {
                    LogResultError("Too many arguments");
                    return;
                }

                if (memberType == MemberType.Method)
                {
                    if (isStatic)
                    {
                        ExecuteMethod(member, (MethodInfo)member, obj, args, argumentString);
                    }
                    else
                    {
                        HashSet <object> instances = registeredInstancesLookup[(Type)obj];
                        CheckDestroyedMonoBehaviours(instances);
                        foreach (object instance in instances)
                        {
                            MonoBehaviour mono = instance as MonoBehaviour;
                            if (mono == null && instance.GetType().IsSubclassOf(typeof(MonoBehaviour)))
                            {
                                Debug.Log("Mono = isDestroyed");
                            }
                            else
                            {
                                ExecuteMethod(member, (MethodInfo)member, instance, args, argumentString);
                            }
                        }
                    }
                }
                else
                {
                    if (isStatic)
                    {
                        ExecuteDelegateMethod(member, obj, args, argumentString);
                    }
                    else
                    {
                        HashSet <object> instances = registeredInstancesLookup[(Type)obj];
                        CheckDestroyedMonoBehaviours(instances);
                        foreach (object instance in instances)
                        {
                            ExecuteDelegateMethod(member, instance, args, argumentString);
                        }
                    }
                }
            }