示例#1
0
        void node_AttributeChanged(object sender, AttributeEventArgs e)
        {
            // process events only for the DomNode attached to this adapter.
            if (this.DomNode != e.DomNode)
            {
                return;
            }

            // the "attribInfo" given to us may not belong this this exact
            // object type. It might belong to a base class (or even, possibly, to a super class).
            // We need to check for these cases, and remap to the exact attribute that
            // belongs our concrete class.
            var type       = DomNode.Type;
            var attribInfo = e.AttributeInfo;

            if (attribInfo.DefiningType != type)
            {
                attribInfo = DomNode.Type.GetAttributeInfo(attribInfo.Name);
                if (attribInfo == null)
                {
                    return;
                }
            }

            bool hierarchicalProperty = (e.AttributeInfo.Name == "transform") || (e.AttributeInfo.Name == "visible");

            using (var transfer = new NativePropertyTransfer())
            {
                using (var stream = transfer.CreateStream())
                {
                    UpdateNativeProperty(DomNode, attribInfo, transfer.Properties, stream);
                    if (hierarchicalProperty)
                    {
                        UpdateSecondaryNativeProperties(transfer.Properties, stream);
                    }
                    if (transfer.Properties.Count > 0)
                    {
                        GameEngine.SetObjectProperty(
                            TypeId, DocumentId, InstanceId,
                            transfer.Properties);
                    }
                }
            }
            if (hierarchicalProperty)
            {
                UpdateLocalToWorld_Children();
            }
        }
示例#2
0
 internal void UpdateLocalToWorld()
 {
     using (var transfer = new NativePropertyTransfer())
     {
         using (var stream = transfer.CreateStream())
         {
             UpdateSecondaryNativeProperties(transfer.Properties, stream);
             if (transfer.Properties.Count > 0)
             {
                 GameEngine.SetObjectProperty(
                     TypeId, DocumentId, InstanceId,
                     transfer.Properties);
             }
         }
     }
 }
示例#3
0
        /// <summary>
        /// Updates all the shared properties
        /// between this and native object
        /// only call onece.
        /// </summary>
        public unsafe void UpdateNativeObject()
        {
            using (var transfer = new NativePropertyTransfer())
            {
                using (var stream = transfer.CreateStream())
                    foreach (AttributeInfo attribInfo in this.DomNode.Type.Attributes)
                    {
                        UpdateNativeProperty(DomNode, attribInfo, transfer.Properties, stream);
                    }

                if (transfer.Properties.Count > 0)
                {
                    GameEngine.SetObjectProperty(
                        TypeId, DocumentId, InstanceId,
                        transfer.Properties);
                }
            }
        }
示例#4
0
        private void CreateNativeObject()
        {
            var node = DomNode;

            if (DomNode == null || m_instanceId != 0)
            {
                return;
            }

            var doc = node.GetRoot().As <NativeDocumentAdapter>();

            if (doc != null && doc.ManageNativeObjectLifeTime)
            {
                // The object might have a pre-assigned instance id.
                // If so, we should attempt to use that same id.
                // This is important if we want the id to persist between sessions
                //      --  For example, we must reference placement objects through
                //          a GUID value that remains constant. We don't want to create
                //          new temporary ids for placements every time we create them,
                //          when the GUID value is more reliable

                ulong existingId = 0;
                var   idField    = DomNode.Type.GetAttributeInfo("ID");
                if (idField != null)
                {
                    var id = DomNode.GetAttribute(idField);
                    if (id is UInt64)
                    {
                        existingId = (UInt64)id;
                    }
                    else
                    {
                        string stringId = id as string;
                        if (stringId != null && stringId.Length > 0)
                        {
                            if (!UInt64.TryParse(stringId, out existingId))
                            {
                                existingId = GUILayer.Utils.HashID(stringId);
                            }
                        }
                    }
                }

                using (var transfer = new NativePropertyTransfer())
                {
                    using (var stream = transfer.CreateStream())
                    {
                        foreach (AttributeInfo attribInfo in this.DomNode.Type.Attributes)
                        {
                            UpdateNativeProperty(DomNode, attribInfo, transfer.Properties, stream);
                        }
                        UpdateSecondaryNativeProperties(transfer.Properties, stream);
                        m_instanceId = GameEngine.CreateObject(doc.NativeDocumentId, existingId, TypeId, transfer.Properties);
                    }
                }

                if (m_instanceId != 0)
                {
                    m_documentId = doc.NativeDocumentId;
                    GameEngine.RegisterGob(m_documentId, m_instanceId, this);
                }
            }
        }