public virtual async Task SpawnAsync(IGame game)
 {
     if (Spawned != null)
     {
         await Spawned.Invoke(SpawnedEntity, Map);
     }
 }
Beispiel #2
0
 private void Spawn()
 {
     CurrentInstance = Instantiate(Prefab, this.transform.position, Quaternion.identity);
     if (OnSpawned != null)
     {
         OnSpawned.Invoke(CurrentInstance.GetInstanceID());
     }
 }
 public void OnSpawn()
 {
     CurrentHealth = BaseHealth;
     HealthSet?.Invoke(CurrentHealth);
     ActionSet?.Invoke(CurrentActions);
     DefenseSet?.Invoke(DefenseModifier);
     Spawned?.Invoke();
 }
    public void Spawn()
    {
        if (Tile.Blocked)
        {
            Tile.ApplyHealthChange(-1);
        }

        Spawned?.Invoke(this);

        Destroy(gameObject);
    }
Beispiel #5
0
        public T Spawn()
        {
            lock (syncObject)
            {
                for (int i = 0; i < itemList.Count; ++i)
                {
                    PoolItem item = itemList[i];
                    if (!item.used)
                    {
                        --residueCount;
                        item.used = true;

                        item.poolItem?.OnSpawned();
                        Spawned?.Invoke(item.instance);

                        return(item.instance);
                    }
                }

                if (Mode == (int)PoolMode.Add)
                {
                    Rebuild(Capacity + Math.Max(1, originCount));
                }
                else if (Mode == (int)PoolMode.Multiple)
                {
                    Rebuild(Math.Max(1, Capacity) * 2);
                }
                else if (Mode == (int)PoolMode.Recovery)
                {
                    while (!Recycle(itemList[stopIndex].instance))
                    {
                        ++stopIndex;
                        if (stopIndex >= itemList.Count - 1)
                        {
                            stopIndex = 0;
                        }
                    }

                    ++stopIndex;
                    if (stopIndex >= itemList.Count - 1)
                    {
                        stopIndex = 0;
                    }
                }
                else
                {
                    Rebuild(Capacity + Mode);
                }

                return(Spawn());
            }
        }
Beispiel #6
0
    private void FixedUpdate()
    {
        if (timer.Execute(Time.fixedDeltaTime))
        {
            return;
        }
        AIActionListComponent ai = AIPooler.Get();

        ai.Position = Origin.position;
        ai.gameObject.SetActive(true);
        gameObject.SetActive(false);
        Spawned?.Invoke(this, ai);
    }
Beispiel #7
0
 private void Update()
 {
     _currentTime += Time.deltaTime;
     {
         if (_currentTime >= _spawnDelay)
         {
             _numberOfSpawns++;
             Spawned?.Invoke(_numberOfSpawns);
             int numberPoint = UnityEngine.Random.Range(0, _spawnPoints.Length);
             StartCoroutine(EmergenceEnemy(numberPoint));
             _currentTime = 0;
         }
     }
 }
Beispiel #8
0
        public void Start()
        {
            if (DidStart)
            {
                return;
            }

            foreach (var component in Components)
            {
                component.Start();
            }
            DidStart = true;

            Spawned?.Invoke(this);
        }
Beispiel #9
0
    protected void Spawn()
    {
        Spawned?.Invoke();
        foreach (var package in ListBasePackage)
        {
            if (package.IsActive == false)
            {
                package.Activate();
                return;
            }
        }

        var basePackage = SpawnObject <BasePackage>(_basePackage);

        ListBasePackage.Add(basePackage);
    }
    private void Start()
    {
        transform.localScale = Helpers.Range(new Vector3(0.9f, 0.9f, 0.9f), new Vector3(1.1f, 1.1f, 1.1f));

        m_interpolationTime = URandom.Range(m_config.MinTime, m_config.MaxTime);

        // Cache the spawn position, drop the pirate in
        m_startPosition    = transform.position;
        m_dropPosition     = m_startPosition + new Vector3(0, m_config.DropHeight, 0);
        transform.position = m_dropPosition;
        StartCoroutine(DoDrop());

        transform.rotation = Quaternion.LookRotation(PirateSpawner.TreasurePosition - m_startPosition);

        // Offset time/distance for each pirate, this helps with the floating effect
        m_accumulatedTime = m_startPosition.sqrMagnitude + (URandom.value / 2.0f);

        Spawned?.Invoke(this);
    }
Beispiel #11
0
        /// <summary>
        /// Spawn a new tree and returns the object and it's random seed
        /// </summary>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        /// <returns></returns>
        public (ProceduralTree go, int seed) Spawn(Vector3 position, Quaternion rotation)
        {
            Spawned?.Invoke();
            m_TreeCount++;
            GameObject go;

            if (m_TreePool.Count == 0)
            {
                go = Instantiate(prefab);
            }
            else
            {
                go = m_TreePool.Pop();
                go.SetActive(true);
            }
            go.transform.position = position;
            go.transform.rotation = rotation;
            var tree = go.GetComponent <ProceduralTree>();

            tree.Data.randomSeed = Random.Range(int.MinValue, int.MaxValue);
            return(tree, tree.Data.randomSeed);
        }
Beispiel #12
0
        internal void OnSpawn(SpawnMessage msg)
        {
            if (msg.assetId == Guid.Empty && msg.sceneId == 0)
            {
                throw new InvalidOperationException("OnObjSpawn netId: " + msg.netId + " has invalid asset Id");
            }
            if (logger.LogEnabled())
            {
                logger.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}");
            }

            bool spawned = false;

            // was the object already spawned?
            NetworkIdentity identity = GetExistingObject(msg.netId);

            if (identity == null)
            {
                //is the object on the prefab or scene object lists?
                identity = msg.sceneId == 0 ? SpawnPrefab(msg) : SpawnSceneObject(msg);
                spawned  = true;
            }

            if (identity == null)
            {
                //object could not be found.
                throw new InvalidOperationException($"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}");
            }

            ApplySpawnPayload(identity, msg);

            if (spawned)
            {
                Spawned.Invoke(identity);
            }
        }
Beispiel #13
0
        public void Spawn()
        {
            // To prevent errors it's better check if pooling system is being used and if the pool exists
            // Check if pool exists
            if (usePoolSystem && objectsPool == null)
            {
                                #if UNITY_EDITOR
                UltimateLog("You are trying to use the pooling system, but there is no pool created. " +
                            "UltimateSpawner will create a new pool");
                                #endif
                StartPool();
            }

            // Activate Pool Object
            if (usePoolSystem)
            {
                // Get Object in Pool
                currentPoolGameObject = GetNextObject();

                if (currentPoolGameObject != null)
                {
                    // Activate it
                    currentPoolGameObject.SetActive(true);

                    // Position it
                    currentPoolGameObject.transform.position = GetSpawnPosition();

                    // Rotate it
                    if (spawnRotation != SpawnRotation.ObjectOwnRotation)
                    {
                        currentPoolGameObject.transform.rotation = GetSpawnRotation();
                    }

                    // Move it
                    ApplyMovement(currentPoolGameObject);

                    // Setting Latest Spawned Object
                    latestSpawnedObject = currentPoolGameObject;

                                        #if UNITY_EDITOR
                    UltimateLog(string.Format("Spawning object {0} at position {1} with a rotation of {2}",
                                              currentPoolGameObject.name, currentPoolGameObject.transform.position.ToString(),
                                              currentPoolGameObject.transform.rotation.eulerAngles.ToString()));
                                        #endif
                }
            }
            // Instantiate New Object
            else
            {
                GameObject instantiatedObject = Instantiate(objectToSpawn);

                // Position it
                instantiatedObject.transform.position = GetSpawnPosition();

                // Rotate it
                if (spawnRotation != SpawnRotation.ObjectOwnRotation)
                {
                    instantiatedObject.transform.rotation = GetSpawnRotation();
                }

                // Move it
                ApplyMovement(instantiatedObject);

                // Setting Latest Spawned Object
                latestSpawnedObject = currentPoolGameObject;

                                #if UNITY_EDITOR
                UltimateLog(string.Format("Spawning object {0} at position {1} with a rotation of {2}",
                                          instantiatedObject.name, instantiatedObject.transform.position.ToString(),
                                          instantiatedObject.transform.rotation.eulerAngles.ToString()));
                                #endif
            }

            totalSpawns++;

            if (Spawned != null)
            {
                Spawned.Invoke();
            }
        }
Beispiel #14
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            //WriteLine($"Zone app packet: {(ZoneOp) packet.Opcode}");
            switch ((ZoneOp)packet.Opcode)
            {
            case ZoneOp.PlayerProfile:
                var player = packet.Get <PlayerProfile>();
                //WriteLine(player);
                break;

            case ZoneOp.TimeOfDay:
                var timeofday = packet.Get <TimeOfDay>();
                //WriteLine(timeofday);
                break;

            case ZoneOp.TaskActivity:
                // XXX: Handle short activities!
                //var activity = packet.Get<TaskActivity>();
                //WriteLine(activity);
                break;

            case ZoneOp.TaskDescription:
                var desc = packet.Get <TaskDescription>();
                //WriteLine(desc);
                break;

            case ZoneOp.CompletedTasks:
                var comp = packet.Get <CompletedTasks>();
                //WriteLine(comp);
                break;

            case ZoneOp.XTargetResponse:
                var xt = packet.Get <XTarget>();
                //WriteLine(xt);
                break;

            case ZoneOp.Weather:
                var weather = packet.Get <Weather>();
                //WriteLine(weather);

                if (Entering)
                {
                    Send(AppPacket.Create(ZoneOp.ReqNewZone));
                }
                break;

            case ZoneOp.TributeTimer:
                var timer = packet.Get <TributeTimer>();
                //WriteLine(timer);
                break;

            case ZoneOp.TributeUpdate:
                var update = packet.Get <TributeInfo>();
                //WriteLine(update);
                break;

            case ZoneOp.ZoneEntry:
                var mob = packet.Get <Spawn>();
                if (mob.Name == CharName)
                {
                    PlayerSpawnId = (ushort)mob.SpawnID;
                }
                Spawned?.Invoke(this, mob);
                break;

            case ZoneOp.NewZone:
                Send(AppPacket.Create(ZoneOp.ReqClientSpawn));
                break;

            case ZoneOp.SendExpZonein:
                if (Entering)
                {
                    Send(AppPacket.Create(ZoneOp.ClientReady));
                    Entering = false;
                }

                break;

            case ZoneOp.CharInventory:
                break;

            case ZoneOp.SendFindableNPCs:
                var npc = packet.Get <FindableNPC>();
                //WriteLine(npc);
                break;

            case ZoneOp.ClientUpdate:
                var pu = packet.Get <PlayerPositionUpdate>();
                PositionUpdated?.Invoke(this, pu);
                break;

            case ZoneOp.HPUpdate:
                break;

            case ZoneOp.SpawnDoor:
                for (var i = 0; i < packet.Data.Length; i += 92)
                {
                    var door = new Door(packet.Data, i);
                    WriteLine(door);
                }
                break;

            default:
                WriteLine($"Unhandled packet in ZoneStream: {(ZoneOp) packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Beispiel #15
0
 public void Spawn()
 {
     gameObject.SetActive(true);
     Spawned?.Invoke();
 }
 protected virtual void OnSpawned(T spawnedObject)
 {
     _onSpawned.Invoke();
     Spawned?.Invoke(this, spawnedObject);
 }
 internal void WasSpawned()
 {
     IsSpawned = true;
     Spawned?.Invoke(this);
     BroadcastMessage("OnSpawned", SendMessageOptions.DontRequireReceiver);
 }
Beispiel #18
0
 public void SendSpawned(Monster m, Vector2Int coords)
 {
     Spawned?.Invoke(m, coords);
 }
Beispiel #19
0
        public void Spawn()
        {
            // To prevent errors it's better check if pooling system is being used and if the pool exists
            // Check if pool exists
            if (usePoolSystem && objectsPool == null)
            {
#if UNITY_EDITOR
                UltimateLog("You are trying to use the pooling system, but there is no pool created. " +
                            "UltimateSpawner will create a new pool");
#endif
                StartPool();
            }

            // Activate Pool Object
            if (usePoolSystem)
            {
                // Get Object in Pool
                currentPoolGameObject = GetNextObject();

                if (currentPoolGameObject != null)
                {
                    // Activate it
                    currentPoolGameObject.SetActive(spawnActive);

                    // Position it
                    Vector3 pos = GetSpawnPosition();
                    if (raycastPositionAssist)
                    {
                        RaycastHit hit;
                        var        hitSomething = Physics.Raycast(pos, Vector3.down, out hit, Mathf.Infinity, raycastAssistLayerMask);
                        if (!hitSomething)
                        {
                            pos.y       += 1000;
                            hitSomething = Physics.Raycast(pos, Vector3.down, out hit, Mathf.Infinity, raycastAssistLayerMask);
                        }
                        if (hitSomething)
                        {
                            pos    = hit.point;
                            pos.y += currentPoolGameObject.transform.localScale.y / 2;
                        }
                    }

                    currentPoolGameObject.transform.position = pos;

                    // Rotate it
                    if (spawnRotation != SpawnRotation.ObjectOwnRotation)
                    {
                        currentPoolGameObject.transform.rotation = GetSpawnRotation();
                    }

                    // Move it
                    ApplyMovement(currentPoolGameObject);

                    // Setting Latest Spawned Object
                    latestSpawnedObject = currentPoolGameObject;

#if UNITY_EDITOR
                    UltimateLog(string.Format("Spawning object {0} at position {1} with a rotation of {2}",
                                              currentPoolGameObject.name, currentPoolGameObject.transform.position.ToString(),
                                              currentPoolGameObject.transform.rotation.eulerAngles.ToString()));
#endif
                }
            }
            // Instantiate New Object
            else
            {
                GameObject instantiatedObject = Instantiate(objectToSpawn);

                // Position it
                instantiatedObject.transform.position = GetSpawnPosition();

                // Rotate it
                if (spawnRotation != SpawnRotation.ObjectOwnRotation)
                {
                    instantiatedObject.transform.rotation = GetSpawnRotation();
                }

                // Move it
                ApplyMovement(instantiatedObject);

                // Setting Latest Spawned Object
                latestSpawnedObject = currentPoolGameObject;

#if UNITY_EDITOR
                UltimateLog(string.Format("Spawning object {0} at position {1} with a rotation of {2}",
                                          instantiatedObject.name, instantiatedObject.transform.position.ToString(),
                                          instantiatedObject.transform.rotation.eulerAngles.ToString()));
#endif
            }

            totalSpawns++;

            if (Spawned != null)
            {
                Spawned.Invoke();
            }
        }
Beispiel #20
0
    public void Spawn()
    {
        Waypoint = waypointProvider.GetWaypoint();

        Spawned?.Invoke();
    }