コード例 #1
0
ファイル: Root.cs プロジェクト: ryan-bunker/axiom3d
		/// <summary>
		///     Register a new MovableObjectFactory which will create new MovableObject
		///	    instances of a particular type, as identified by the Type property.
		/// </summary>
		/// <remarks>
		///     Plugin creators can create subclasses of MovableObjectFactory which
		///	    construct custom subclasses of MovableObject for insertion in the
		///	    scene. This is the primary way that plugins can make custom objects
		///	    available.
		/// </remarks>
		/// <param name="fact">
		///     The factory instance.
		/// </param>
		/// <param name="overrideExisting">
		///     Set this to true to override any existing
		///	    factories which are registered for the same type. You should only
		///	    change this if you are very sure you know what you're doing.
		/// </param>
		public void AddMovableObjectFactory( MovableObjectFactory fact, bool overrideExisting )
		{
			if ( this.movableObjectFactoryMap.ContainsKey( fact.Type ) && !overrideExisting )
			{
				throw new AxiomException( "A factory of type '" + fact.Type + "' already exists." );
			}

			if ( fact.RequestTypeFlags )
			{
				if ( this.movableObjectFactoryMap.ContainsValue( fact ) )
				{
					// Copy type flags from the factory we're replacing
					fact.TypeFlag = ( this.movableObjectFactoryMap[ fact.Type ] ).TypeFlag;
				}
				else
				{
					// Allocate new
					fact.TypeFlag = NextMovableObjectTypeFlag();
				}
			}

			// Save
			if ( this.movableObjectFactoryMap.ContainsKey( fact.Type ) )
			{
				LogManager.Instance.Write( "Factory {0} has been replaced by {1}.",
				                           this.movableObjectFactoryMap[ fact.Type ].GetType().Name, fact.GetType().Name );

				this.movableObjectFactoryMap[ fact.Type ] = fact;
			}
			else
			{
				this.movableObjectFactoryMap.Add( fact.Type, fact );
			}

			LogManager.Instance.Write( "Factory " + fact.GetType().Name + " registered for MovableObjectType '" + fact.Type +
			                           "'." );
		}