コード例 #1
0
 private static void CreateChildElements(FrameworkElement parent, Data.Element parentTemplate, Scene scene, Schema schema)
 {
     foreach (var childTemplate in parentTemplate.children)
     {
         var go      = new GameObject(childTemplate.name);
         var element = CreateElement(go, childTemplate, scene, schema);
         parent.AddChild(element);
     }
 }
コード例 #2
0
        private IEnumerable <Data.Element> GetElementChain(Data.Element element)
        {
            while (element != null)
            {
                yield return(element);

                element = element.parent;
            }
        }
コード例 #3
0
        private Data.Element ParseElement(Core.Element template, Data.Element parent)
        {
            var attributes = ReadAttributes(reader);

            if (!TryGetElementType(template, attributes, elementBaseType, out var ownerType, out var className))
            {
                throw new Exception($"Failed to get type {className}");
            }

            var typeInfo = ElementRegistry.GetElementType(ownerType);

            var namespaces = attributes
                             .Where(p => NamespaceAttribute.IsNamespaceKey(p.Value) && NamespaceAttribute.IsCLRNamespace(p.Value))
                             .Select(p => NamespaceAttribute.Parse(p.Value).Value)
                             .ToList();

            if (parent == null && schema.namespaces != null)
            {
                namespaces.Add(schema.namespaces);
            }

            var nsHierarchy = GetElementChain(parent)
                              .SelectMany(e => e.namespaces)
                              .Concat(namespaces);

            var properties = attributes
                             .Where(p => typeInfo.hierarchyProps.ContainsKey(p.Key, nsHierarchy))
                             .ToDictionary(p => p.Key, p => p.Value);

            var events = attributes
                         .Where(p => EventManager.HasRoutedEvent(p.Key, ownerType, nsHierarchy))
                         .ToDictionary(p => p.Key, p => p.Value);

            return(new Data.Element
            {
                parent = parent,
                name = reader.Name,
                className = className,
                type = ownerType,
                rawAttributes = attributes,
                properties = properties,
                events = events,
                namespaces = namespaces
            });
        }
コード例 #4
0
        private static FrameworkElement CreateElement(GameObject go, Data.Element template, Scene scene, Schema schema)
        {
            var prefab   = schema.GetElementPrefab(template.name);
            var instance = Instantiate(prefab, scene);

            var element = (FrameworkElement)go.AddComponent(template.type);

            element.gameObject.name = template.name;
            element.Name            = template.name;
            element.schema          = schema;
            element.SetInstance(instance);
            element.SetNamespaces(template.namespaces);
            element.SetProperties(template.properties.Values);
            element.SetEvents(template.events.Values);

            CreateChildElements(element, template, scene, schema);

            return(element);
        }