Exemplo n.º 1
0
        //=========================================================================================
        /// <summary> 
        /// Unregisters a widgets's type name with the scene. After this has finished the object will 
        /// no longer be found when searching for objects with this type name.
        /// </summary>
        /// 
        /// <param name="obj"> Object to unregister name for </param>
        //=========================================================================================
        private void UnregisterType( GuiWidget obj )
        {
            // Abort if null object:

            if ( obj == null ) return;

            // Do nothing if the object has no ID or is not in the gui:

            if ( obj.Id == 0 || obj.ParentContainer != this || obj.ParentGui != this.m_gui ) return;

            // Get the object's type name:

            string typeName = obj.GetType().Name;

            // Make sure the hash contains the type name

            if ( m_types.ContainsKey( typeName ) )
            {
                // Get the hash for this type name:

                Dictionary<int,GuiWidget> hash = m_types[typeName];

                // See if this object exists in the hash

                if ( hash.ContainsKey( obj.Id ) )
                {
                    // Bingo: remove the object from the hash

                    hash.Remove( obj.Id );

                    // If the hash is now empty then remove it from the parent hash

                    if ( hash.Count == 0 ){ m_types.Remove( typeName ); }
                }
            }
        }
Exemplo n.º 2
0
        //=========================================================================================
        /// <summary> 
        /// Registers a widgets type name with the gui data so the object can later be found by 
        /// using this type name. Multiple objects can be registered with the same type.
        /// </summary>
        /// 
        /// <param name="obj">Object to register type name for</param>
        //=========================================================================================
        private void RegisterType( GuiWidget obj )
        {
            // Abort if null object:

            if ( obj == null ) return;

            // Do nothing if the object has no ID or is not in the gui:

            if ( obj.Id == 0 || obj.ParentContainer != this || obj.ParentGui != this.m_gui ) return;

            // Get the object's type name:

            string typeName = obj.GetType().Name;

            // Create a hash for widgets with this type if not already in existance

            if ( m_types.ContainsKey( typeName ) == false )
            {
                m_types.Add( typeName , new Dictionary<int,GuiWidget>() );
            }

            // Add the object into the hash:

            m_types[typeName][obj.Id] = obj;
        }