/// Create a new instance
 /// @param template The template GameObject to spawn instances of
 /// @param spawnObjectEvery Spawn a new instance this often
 /// @param maxPoolSize Allow at most this many objects to exist
 /// @param callback Callback to provide animation curve, etc.
 public ObjectStream(GameObject template, float spawnObjectEvery, int maxPoolSize, SpawnCallback <TStream> factory)
 {
     this.SpawnObjectEvery = spawnObjectEvery;
     this._factory         = factory;
     _pool   = new SpawnedObjectPool(Option.Some(template), maxPoolSize);
     Elapsed = spawnObjectEvery;
 }
示例#2
0
        private static IEnumerator delayedSpawn(SpawnCallback callback, Action <SpawnCallback, Vector3> spawnAction, float duration, Vector3 pos)
        {
            // wait
            yield return(new WaitForSecondsRealtime(duration));

            // spawn
            spawnAction(callback, pos);
        }
 public void SpawnPreviewModel(string meshName, Vector3 position, bool valid, SpawnCallback callback)
 {
     SpawnModel(meshName, position, (obj) =>
     {
         BackupMaterials(obj);
         obj.GetComponent <MeshRenderer>().SetAllMaterial(valid ? PreviewMaterial : InvalidPreviewMaterial);
         callback.Invoke(obj);
     });
 }
示例#4
0
        public override void spawnAction(SpawnCallback callback, Vector3 pos)
        {
            base.spawnAction(callback, pos);

            Light2D newLight = newGameObject.GetComponent <Light2D>();

            if (newLight)
            {
                newLight.color = new Color(Mathf.Clamp(newLight.color.r + Random.Range(-variance, variance), 0, 1), Mathf.Clamp(newLight.color.g + Random.Range(-variance, variance), 0, 1), Mathf.Clamp(newLight.color.b + Random.Range(-variance, variance), 0, 1));
            }
        }
示例#5
0
 public void spawn(SpawnCallback callback, Vector3 pos)
 {
     // wait X seconds before spawning
     if (delay != 0)
     {
         StartCoroutine(delayedSpawn(callback, spawnAction, delay, pos));
     }
     // spawm immediately
     else
     {
         spawnAction(callback, pos);
     }
 }
示例#6
0
        public virtual void spawnAction(SpawnCallback callback, Vector3 pos)
        {
            // spawn and positionned newly object
            TryGetNextObject(transform.position, transform.rotation, out newGameObject);
            newGameObject.transform.localPosition = pos;

            // do callback
            callback?.Invoke(newGameObject);

            // play spawn sound
            if (spawnSound != "")
            {
                AudioCtrl.Instance.playSoundEvent.Invoke(spawnSound);
            }
        }
示例#7
0
        public static DisposeCallback RegisterSpawning(DemoOpenInfo info, Key key, SpawnCallback callback)
        {
            EventHandler <KeyboardEventArgs> downHandler = delegate(object sender, KeyboardEventArgs e)
            {
                if (e.Key == key)
                {
                    callback(info.Viewport.MousePosition);
                }
            };

            Events.KeyboardDown += downHandler;
            return(delegate()
            {
                Events.KeyboardDown -= downHandler;
            });
        }
示例#8
0
 public static extern int startHaggle(SpawnCallback callback);
示例#9
0
 public Spawner(SpawnCallback spawnCallback)
 {
     _onSpawnMonster += spawnCallback;
 }
示例#10
0
 public Spawner(SpawnCallback spawnCallback)
 {
     _onSpawnMonster += spawnCallback;
 }
        public void SpawnModel(string address, Vector3 position, SpawnCallback callback)
        {
            var obj = ActivatePoolObject(address, position, transform);

            callback.Invoke(obj);
        }
        private void InitModel(string address, Vector3 position, SpawnCallback callback)
        {
            var op = Addressables.InstantiateAsync(address, position, Quaternion.identity, transform);

            op.Completed += (AsyncOperationHandle <GameObject> obj) => callback.Invoke(obj.Result);
        }
示例#13
0
        public override void spawnAction(SpawnCallback callback, Vector3 pos)
        {
            base.spawnAction(callback, pos);

            //GameCtrl.Instance.player.control.animator = GameObject.FindGameObjectWithTag("Player").GetComponent<Animator>();
        }
示例#14
0
        public static DisposeCallback RegisterMaintainSpawning(DemoOpenInfo info, Key key, SpawnCallback callback)
        {
            IPhysicsEntity current = null;
            EventHandler <KeyboardEventArgs> downHandler = delegate(object sender, KeyboardEventArgs e)
            {
                if (e.Key == key)
                {
                    current = callback(info.Viewport.MousePosition);
                }
            };
            EventHandler <KeyboardEventArgs> upHandler = delegate(object sender, KeyboardEventArgs e)
            {
                if (e.Key == key)
                {
                    if (current != null)
                    {
                        current.Lifetime.IsExpired = true;
                        current = null;
                    }
                }
            };

            Events.KeyboardDown += downHandler;
            Events.KeyboardUp   += upHandler;
            return(delegate()
            {
                Events.KeyboardDown -= downHandler;
                Events.KeyboardUp -= upHandler;
            });
        }
示例#15
0
 public static DisposeCallback RegisterMaintainSpawning(DemoOpenInfo info, Key key, SpawnCallback callback)
 {
     IPhysicsEntity current = null;
     EventHandler<KeyboardEventArgs> downHandler = delegate(object sender, KeyboardEventArgs e)
     {
         if (e.Key == key)
         {
             current = callback(info.Viewport.MousePosition);
         }
     };
     EventHandler<KeyboardEventArgs> upHandler = delegate(object sender, KeyboardEventArgs e)
     {
         if (e.Key == key)
         {
             if (current != null)
             {
                 current.Lifetime.IsExpired = true;
                 current = null;
             }
         }
     };
     Events.KeyboardDown += downHandler;
     Events.KeyboardUp += upHandler;
     return delegate()
     {
         Events.KeyboardDown -= downHandler;
         Events.KeyboardUp -= upHandler;
     };
 }
示例#16
0
 public static DisposeCallback RegisterSpawning(DemoOpenInfo info, Key key, SpawnCallback callback)
 {
     EventHandler<KeyboardEventArgs> downHandler = delegate(object sender, KeyboardEventArgs e)
     {
         if (e.Key == key)
         {
              callback(info.Viewport.MousePosition);
         }
     };
     Events.KeyboardDown += downHandler;
     return delegate()
     {
         Events.KeyboardDown -= downHandler;
     };
 }
 public void SpawnPreviewModel(StructureDefinition.StructureType type, Vector3 position, bool valid, SpawnCallback callback)
 {
     SpawnPreviewModel(_structureDefinitionManager.GetAssetNameForStructureType(type), position, valid, callback);
 }
示例#18
0
 static public extern int startHaggle(SpawnCallback callback);
        public void SpawnUIElement(string name, Transform parent, SpawnCallback callback)
        {
            var op = Addressables.InstantiateAsync(name, parent.transform.position, Quaternion.identity, parent);

            op.Completed += (AsyncOperationHandle <GameObject> obj) => callback.Invoke(obj.Result);
        }