Esempio n. 1
0
        private void HandleTagNode(XmlNode node, GameObject parent, BSMLParserParams parserParams)
        {
            if (!tags.TryGetValue(node.Name, out BSMLTag currentTag))
            {
                throw new Exception("Tag type '" + node.Name + "' not found");
            }

            //TEMPORARY
            if (node.Name == "image")
            {
                for (int i = 0; i < 100; i++)
                {
                    Logger.log.Critical("do not use image tag for raw images please switch to raw-image");
                }
            }
            //

            GameObject currentNode = currentTag.CreateObject(parent.transform);

            List <ComponentTypeWithData> componentTypes = new List <ComponentTypeWithData>();

            foreach (TypeHandler typeHandler in typeHandlers)
            {
                Type      type      = (typeHandler.GetType().GetCustomAttributes(typeof(ComponentHandler), true).FirstOrDefault() as ComponentHandler).type;
                Component component = GetExternalComponent(currentNode, type);
                if (component != null)
                {
                    ComponentTypeWithData componentType = new ComponentTypeWithData();
                    componentType.data        = GetParameters(node, typeHandler.CachedProps, parserParams, out Dictionary <string, BSMLPropertyValue> propertyMap);
                    componentType.propertyMap = propertyMap;
                    componentType.typeHandler = typeHandler;
                    componentType.component   = component;
                    componentTypes.Add(componentType);
                }
            }
            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleType(componentType, parserParams);
            }

            object host = parserParams.host;

            if (host != null && node.Attributes["id"] != null)
            {
                foreach (FieldInfo fieldInfo in host.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    UIComponent uicomponent = fieldInfo.GetCustomAttributes(typeof(UIComponent), true).FirstOrDefault() as UIComponent;
                    if (uicomponent != null && uicomponent.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, GetExternalComponent(currentNode, fieldInfo.FieldType));
                    }

                    UIObject uiobject = fieldInfo.GetCustomAttributes(typeof(UIObject), true).FirstOrDefault() as UIObject;
                    if (uiobject != null && uiobject.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, currentNode);
                    }
                }
            }
            if (node.Attributes["tags"] != null)
            {
                parserParams.AddObjectTags(currentNode, node.Attributes["tags"].Value.Split(','));
            }

            if (currentTag.AddChildren)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    HandleNode(childNode, currentNode, parserParams);
                }
            }

            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleTypeAfterChildren(componentType, parserParams);
            }
        }
Esempio n. 2
0
        private void HandleTagNode(XmlNode node, GameObject parent, BSMLParserParams parserParams, out IEnumerable <ComponentTypeWithData> componentInfo)
        {
            if (!tags.TryGetValue(node.Name, out BSMLTag currentTag))
            {
                throw new Exception("Tag type '" + node.Name + "' not found");
            }

            GameObject currentNode = currentTag.CreateObject(parent.transform);

            List <ComponentTypeWithData> componentTypes = new List <ComponentTypeWithData>();

            foreach (TypeHandler typeHandler in typeHandlers)
            {
                Type type = (typeHandler.GetType().GetCustomAttributes(typeof(ComponentHandler), true).FirstOrDefault() as ComponentHandler)?.type;
                if (type == null)
                {
                    continue;
                }
                Component component = GetExternalComponent(currentNode, type);
                if (component != null)
                {
                    ComponentTypeWithData componentType = new ComponentTypeWithData();
                    componentType.data        = GetParameters(node, typeHandler.CachedProps, parserParams, out Dictionary <string, BSMLValue> valueMap);
                    componentType.valueMap    = valueMap;
                    componentType.typeHandler = typeHandler;
                    componentType.component   = component;
                    componentTypes.Add(componentType);
                }
            }
            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleType(componentType, parserParams);
            }

            object host = parserParams.host;

            if (host != null && node.Attributes["id"] != null)
            {
                foreach (FieldInfo fieldInfo in host.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    UIComponent uicomponent = fieldInfo.GetCustomAttributes(typeof(UIComponent), true).FirstOrDefault() as UIComponent;
                    if (uicomponent != null && uicomponent.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, GetExternalComponent(currentNode, fieldInfo.FieldType));
                    }

                    UIObject uiobject = fieldInfo.GetCustomAttributes(typeof(UIObject), true).FirstOrDefault() as UIObject;
                    if (uiobject != null && uiobject.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, currentNode);
                    }
                }
            }
            if (node.Attributes["tags"] != null)
            {
                parserParams.AddObjectTags(currentNode, node.Attributes["tags"].Value.Split(','));
            }

            IEnumerable <ComponentTypeWithData> childrenComponents = Enumerable.Empty <ComponentTypeWithData>();

            if (currentTag.AddChildren)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    HandleNode(childNode, currentNode, parserParams, out IEnumerable <ComponentTypeWithData> children);
                    childrenComponents = childrenComponents.Concat(children);
                }
            }

            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleTypeAfterChildren(componentType, parserParams);
            }

            componentInfo = componentTypes.Concat(childrenComponents);
        }