示例#1
0
        public void GetBuilder2()
        {
            var provider   = new FactoryProvider();
            var collection = new FactoryCollection <Type>();
            var factory    = new Factory <string>();

            factory.Add("empty", new GameObjectBuilderEmpty());
            factory.Add("prefab", new GameObjectBuilder(new GameObject("prefab")));
            collection.Add(typeof(IGameObjectBuilder), factory);
            provider.Add(collection);

            IGameObjectBuilder builder1 = provider.GetBuilder <IGameObjectBuilder, Type, string>(typeof(IGameObjectBuilder), "empty");
            IGameObjectBuilder builder2 = provider.GetBuilder <IGameObjectBuilder, Type, string>(typeof(IGameObjectBuilder), "prefab");

            Assert.NotNull(builder1);
            Assert.NotNull(builder2);
        }
        public void BuildGameObject()
        {
            var provider   = new FactoryProvider();
            var collection = new FactoryCollection <Type>();
            var factory    = new Factory <string>();

            provider.Add(collection);
            collection.Add(typeof(IGameObjectBuilder), factory);
            factory.Add("prefab", new GameObjectBuilder(new GameObject("prefab")));
            factory.Add("empty", new GameObjectBuilderEmpty());

            GameObject gameObject1 = provider.GetBuilder <IGameObjectBuilder, string>("prefab").Build();
            GameObject gameObject2 = provider.GetBuilder <IGameObjectBuilder, string>("empty").Build();

            Assert.NotNull(gameObject1);
            Assert.NotNull(gameObject2);
            Assert.AreEqual("prefab(Clone)", gameObject1.name);
            Assert.AreEqual("New Game Object", gameObject2.name);
        }