Exemplo n.º 1
0
        } // GameObject
        
        #endregion

        #region Dispose

        /// <summary>
        /// Dispose managed resources.
        /// </summary>
        protected override void DisposeManagedResources()
        {
            ContentManager = null;
            GameObjects.Remove(this);
            // A disposed object could be still generating events, because it is alive for a time, in a disposed state, but alive nevertheless.
            LayerChanged = null;
            ActiveChanged = null;
            RemoveAllComponents();
        } // DisposeManagedResources
Exemplo n.º 2
0
        } // Unload

        #endregion

        #region Sort

        /// <summary>
        /// This comparation allows to sort the content managers by their names.
        /// </summary>
        protected static int CompareContentManagers(GameObjectContentManager contentManager1, GameObjectContentManager contentManager2)
        {
            // If they are the same asset then return equals.
            if (contentManager1 == contentManager2)
            {
                return(0);
            }

            string x = contentManager1.Name;
            string y = contentManager2.Name;

            if (x == null)
            {
                if (y == null)
                {
                    // If x is null and y is null, they're equal.
                    return(0);
                }
                else
                {
                    // If x is null and y is not null, y is greater.
                    return(-1);
                }
            }
            else
            {
                // If x is not null...
                if (y == null)
                {
                    // ...and y is null, x is greater.
                    return(1);
                }
                else
                {
                    // ...and y is not null, compare the two strings.
                    int retval = x.CompareTo(y);

                    if (retval != 0)
                    {
                        // If the strings are not of equal length,
                        // the longer string is greater.
                        return(retval);
                    }
                    else
                    {
                        // Create a new unique name for the second asset and do a comparation again.
                        contentManager2.SetUniqueName(y);
                        y = contentManager2.Name;
                        // If the strings are of equal length,
                        // sort them with ordinary string comparison.
                        return(x.CompareTo(y));
                    }
                }
            }
        } // CompareContentManagers
Exemplo n.º 3
0
 /// <summary>
 /// This constructor is called by all objects and set the ID.
 /// </summary>
 protected GameObject()
 {
     // Create a unique ID
     Id = uniqueIdCounter;
     uniqueIdCounter++;
     GameObjects.Add(this);
     Components = new List<Component>(5);
     Layer = Layer.CurrentCreationLayer;
     // TODO: I have to analyse if a content manager for game objects is needed in all cases.
     // if (GameObjectContentManager.CurrentContentManager == null)
         // throw new InvalidOperationException("Game Object: The Content Manager is null.");
     ContentManager = GameObjectContentManager.CurrentContentManager;
 } // GameObject