Пример #1
0
        private void DomNode_AttributeChanged(object sender, AttributeEventArgs e)
        {
            if (e.DomNode == this.DomNode)
            {
                return;
            }

            if (!e.AttributeInfo.Equivalent(e.DomNode.Type.IdAttribute))
            {
                string originalName;
                if (m_intsToOriginal.TryGetValue(e.DomNode, out originalName))
                {
                    ObjectOverride objectOverride;
                    m_overridesMap.TryGetValue(originalName, out objectOverride);
                    if (objectOverride == null)
                    {
                        objectOverride = ObjectOverride.Create(originalName);
                        m_overrideList.Add(objectOverride);
                        m_overridesMap.Add(originalName, objectOverride);
                    }

                    AttributeOverride attrOverride = objectOverride.GetOrCreateByName(e.AttributeInfo.Name);
                    attrOverride.AttribValue = e.AttributeInfo.Type.Convert(e.NewValue);
                }
            }
        }
Пример #2
0
        public static ObjectOverride Create(string name)
        {
            DomNode        node           = new DomNode(Schema.objectOverrideType.Type);
            ObjectOverride objectOverride = node.As <ObjectOverride>();

            objectOverride.ObjectName = name;
            return(objectOverride);
        }
Пример #3
0
 private void updateNode(DomNode node, ObjectOverride objectOverride)
 {
     if (node == null || objectOverride == null)
     {
         return;
     }
     foreach (AttributeOverride attrOverride in objectOverride.AttributeOverrides)
     {
         AttributeInfo attrInfo = node.Type.GetAttributeInfo(attrOverride.Name);
         node.SetAttribute(attrInfo, attrInfo.Type.Convert(attrOverride.AttribValue));
     }
 }
Пример #4
0
        private void updateNode(DomNode node, ObjectOverride objectOverride)
        {
            if (node == null || objectOverride == null)
            {
                return;
            }
            string nodeId = node.GetId();

            System.Diagnostics.Debug.Assert(nodeId == objectOverride.ObjectName);

            foreach (AttributeOverride attrOverride in objectOverride.AttributeOverrides)
            {
                AttributeInfo attrInfo = node.Type.GetAttributeInfo(attrOverride.Name);
                node.SetAttribute(attrInfo, attrInfo.Type.Convert(attrOverride.AttribValue));
            }
        }
Пример #5
0
        private void updateNode(DomNode node, ObjectOverride objectOverride)
        {
            if (node == null || objectOverride == null)
                return;
            string nodeId = node.GetId();
            System.Diagnostics.Debug.Assert(nodeId == objectOverride.ObjectName);

            foreach (AttributeOverride attrOverride in objectOverride.AttributeOverrides)
            {
                AttributeInfo attrInfo = node.Type.GetAttributeInfo(attrOverride.Name);
                node.SetAttribute(attrInfo, attrInfo.Type.Convert(attrOverride.AttribValue));
            }
        }
Пример #6
0
        public void Resolve(UniqueNamer namer)
        {
            try
            {
                m_updating = true;
                Uri resUri = GetAttribute <Uri>(Schema.prefabInstanceType.prefabRefAttribute);
                if (resUri != null)
                {
                    m_prefab = Globals.ResourceService.Load(resUri) as IPrefab;
                }
                if (m_prefab == null)
                {
                    return;
                }

                // update name and uri
                if (resUri == null)
                {
                    SetAttribute(Schema.prefabInstanceType.prefabRefAttribute, m_prefab.Uri);
                }

                // Remove the children that are stored within this group (these remain in the file
                // so that they are used when the resolve fails)
                var childrenCopy = new List <DomNode>(base.Objects.AsIEnumerable <DomNode>());
                foreach (var c in childrenCopy)
                {
                    c.RemoveFromParent();
                }

                // Create new children from the prefab, applying the overriden attributes as we go
                DomNode[]        gobs   = DomNode.Copy(m_prefab.GameObjects.AsIEnumerable <DomNode>());
                HashSet <string> gobIds = new HashSet <string>();
                for (int c = 0; c < gobs.Length; ++c)
                {
                    var gobNode = gobs[c];
                    gobNode.InitializeExtensions();
                    var name = GetName(gobNode, c);

                    m_intsToOriginal.Add(gobNode, name);
                    gobIds.Add(name);
                    ObjectOverride objectOverride;
                    m_overridesMap.TryGetValue(name, out objectOverride);
                    updateNode(gobNode, objectOverride);

                    if (namer != null)
                    {
                        var nameable = gobNode.As <INameable>();
                        if (nameable != null)
                        {
                            nameable.Name = namer.Name(nameable.Name);
                        }
                    }

                    AddChild(gobNode);
                }

                // cleanup m_overridesmap
                List <string> overrideIds = new List <string>(m_overridesMap.Keys);
                foreach (string id in overrideIds)
                {
                    if (!gobIds.Contains(id))
                    {
                        ObjectOverride objectOverride = m_overridesMap[id];
                        objectOverride.DomNode.RemoveFromParent();
                        m_overridesMap.Remove(id);
                        m_overrideList.Remove(objectOverride);
                    }
                }
            }
            finally
            {
                m_updating = false;
            }
        }
Пример #7
0
        public void Resolve(UniqueNamer namer)
        {
            try
            {
                m_updating = true;
                Uri resUri = GetAttribute <Uri>(Schema.prefabInstanceType.prefabRefAttribute);
                if (resUri != null)
                {
                    m_prefab = Globals.ResourceService.Load(resUri) as IPrefab;
                }
                if (m_prefab == null)
                {
                    return;
                }

                // update name and uri
                if (resUri == null)
                {
                    SetAttribute(Schema.prefabInstanceType.prefabRefAttribute, m_prefab.Uri);
                }

                IGameObjectGroup gobgroup = DomNode.As <IGameObjectGroup>();
                if (string.IsNullOrWhiteSpace(gobgroup.Name))
                {
                    gobgroup.Name = "PrefabInst_" + m_prefab.Name;
                }

                DomNode[]        gobs   = DomNode.Copy(m_prefab.GameObjects.AsIEnumerable <DomNode>());
                HashSet <string> gobIds = new HashSet <string>();

                gobgroup.GameObjects.Clear();
                foreach (var gobNode in gobs)
                {
                    gobNode.InitializeExtensions();
                    IGameObject gob = gobNode.As <IGameObject>();
                    m_intsToOriginal.Add(gobNode, gob.Name);
                    gobIds.Add(gob.Name);
                    ObjectOverride objectOverride;
                    m_overridesMap.TryGetValue(gob.Name, out objectOverride);
                    updateNode(gobNode, objectOverride);
                    string name = gob.Name;
                    if (namer != null)
                    {
                        gob.Name = namer.Name(gob.Name);
                    }

                    gobgroup.GameObjects.Add(gob);
                }

                // cleanup m_overridesmap
                List <string> overrideIds = new List <string>(m_overridesMap.Keys);
                foreach (string id in overrideIds)
                {
                    if (!gobIds.Contains(id))
                    {
                        ObjectOverride objectOverride = m_overridesMap[id];
                        m_overridesMap.Remove(id);
                        m_overrideList.Remove(objectOverride);
                    }
                }
            }
            finally
            {
                m_updating = false;
            }
        }