Example #1
0
        /// <summary>
        /// Create a new actor of the specified type, reusing recycled instance whenever possible.
        /// </summary>
        /// <param name="gameActorType"></param>
        /// <returns></returns>
        public static GameActor Create(StaticActor staticActor)
        {
            Stack <GameActor> freeActors;

            recycleBin.TryGetValue(staticActor, out freeActors);

            GameActor actor;

            if (freeActors != null && freeActors.Count > 0)
            {
                actor = freeActors.Pop();
            }
            else
            {
                actor = staticActor.CreateNewInstance();
            }

            if (actor != null)
            {
                // Default to actor name.
                actor.DisplayName = actor.StaticActor.LocalizedName;

                actor.InRecycleBin   = false;
                actor.FactoryCreated = true;

                // For this call we ignore the current state so we know that the
                // subsystems will get reset.  Without this the smoke emitters
                // don't turn on until the level has been run and reset.
                actor.ResetState(ignoreCurrentState: true);
            }

            return(actor);
        }
        public static StaticActor GetActor(string nonLocalizedName)
        {
            StaticActor result = null;

            Actors.TryGetValue(nonLocalizedName, out result);

            return(result);
        }