Esempio n. 1
0
        public TContract Create(PrefabFactorySpawnParams spawnParams = null)
        {
            TContract instance = null;
            Pool      pool     = null;

            var prefab = _resolver.ResolvePrefab();

            Assert.That(prefab != null,
                        "Null prefab given to factory create method when instantiating object with type '{0}'.", typeof(TContract));

            if (!_prefabPool.ContainsKey(prefab.name))
            {
                _prefabPool[prefab.name] = _factory.Create(prefab);
            }

            pool = _prefabPool[prefab.name];

            instance = pool.Spawn();

            if (spawnParams != null)
            {
                PrefabFactoryNameBasedHelper.SetupGameObject(instance.gameObject, spawnParams);
            }

            instance.OnSpawned(pool);

            return(instance);
        }
Esempio n. 2
0
        public static void SetupGameObject(GameObject go, PrefabFactorySpawnParams spawnParams)
        {
            if (spawnParams.position != null)
            {
                go.transform.position = spawnParams.position.Value;
            }

            if (spawnParams.rotation != null)
            {
                go.transform.rotation = spawnParams.rotation.Value;
            }

            if (spawnParams.scale != null)
            {
                go.transform.localScale = spawnParams.scale.Value;
            }

            if (spawnParams.parent != null)
            {
                go.transform.SetParent(spawnParams.parent);
            }
        }