Esempio n. 1
0
        public static Type GetTypeFromName(string typeName)
        {
            if (typeName == "void*")
            {
                return(typeof(Agent));
            }

            //Type type = Agent.GetTypeFromName(typeName);
            Type type = AgentMeta.GetTypeFromName(typeName);

            if (type == null)
            {
                type = Utils.GetPrimitiveTypeFromName(typeName);

                if (type == null)
                {
                    Type elementType = Utils.GetElementTypeFromName(typeName);

                    if (elementType != null)
                    {
                        Type vectorType = typeof(List <>).MakeGenericType(elementType);
                        return(vectorType);
                    }
                    else
                    {
                        typeName = typeName.Replace("::", ".");
                        type     = Utils.GetType(typeName);
                    }
                }
            }

            return(type);
        }
Esempio n. 2
0
        private static void registerCustomizedProperty(AgentMeta meta, string propName, string typeName, string valueStr, bool isStatic)
        {
            typeName = typeName.Replace("::", ".");

            uint                nameId  = Utils.MakeVariableId(propName);
            IProperty           prop    = meta.GetProperty(nameId);
            ICustomizedProperty newProp = AgentMeta.CreateCustomizedProperty(typeName, nameId, propName, valueStr);

            if (prop != null && newProp != null)
            {
                object newValue = newProp.GetValueObject(null);
                object value    = prop.GetValueObject(null);

                if (newValue != null && value != null && newValue.GetType() == value.GetType())
                {
                    return;
                }

                string errorInfo = string.Format("The type of '{0}' has been modified to {1}, which would bring the unpredictable consequences.", propName, typeName);
                Debug.LogWarning(errorInfo);
                Debug.Check(false, errorInfo);
            }

            if (isStatic)
            {
                meta.RegisterStaticCustomizedProperty(nameId, newProp);
            }
            else
            {
                meta.RegisterCustomizedProperty(nameId, newProp);
            }

            Type type = AgentMeta.GetTypeFromName(typeName);

            if (Utils.IsArrayType(type))
            {
                // Get item type, i.e. vector<int>
                int kStartIndex = "vector<".Length;
                typeName = typeName.Substring(kStartIndex, typeName.Length - kStartIndex - 1); // item type
                ICustomizedProperty arrayItemProp = AgentMeta.CreateCustomizedArrayItemProperty(typeName, nameId, propName);
                nameId = Utils.MakeVariableId(propName + "[]");

                if (isStatic)
                {
                    meta.RegisterStaticCustomizedProperty(nameId, arrayItemProp);
                }
                else
                {
                    meta.RegisterCustomizedProperty(nameId, arrayItemProp);
                }
            }
        }
Esempio n. 3
0
        private static void registerCustomizedProperty(AgentMeta meta, string propName, string typeName, string valueStr, bool isStatic)
        {
            typeName = typeName.Replace("::", ".");

            uint nameId = Utils.MakeVariableId(propName);
            ICustomizedProperty prop = AgentMeta.CreateCustomizedProperty(typeName, nameId, propName, valueStr);

            if (isStatic)
            {
                meta.RegisterStaticCustomizedProperty(nameId, prop);
            }
            else
            {
                meta.RegisterCustomizedProperty(nameId, prop);
            }

            Type type = AgentMeta.GetTypeFromName(typeName);

            if (Utils.IsArrayType(type))
            {
                // Get item type, i.e. vector<int>
                int kStartIndex = "vector<".Length;
                typeName = typeName.Substring(kStartIndex, typeName.Length - kStartIndex - 1); // item type
                ICustomizedProperty arrayItemProp = AgentMeta.CreateCustomizedArrayItemProperty(typeName, nameId, propName);
                nameId = Utils.MakeVariableId(propName + "[]");

                if (isStatic)
                {
                    meta.RegisterStaticCustomizedProperty(nameId, arrayItemProp);
                }
                else
                {
                    meta.RegisterCustomizedProperty(nameId, arrayItemProp);
                }
            }
        }