Ejemplo n.º 1
0
    private Spawned SpawnObjectInMesh(int index, int trashArrayPos)
    {
        Mesh        m       = spawnArea[index].mesh;
        Transform   t       = center[index];
        SpawnedList curRow  = spawnable_SmallTrash[trashArrayPos];
        Spawned     current = curRow[curRow.Count - 1];

        Vector3 vec = m.GetRandomPointInsideConvex();

        vec = t.TransformPoint(vec);

        RaycastHit info;
        LayerMask  mask = LayerMask.GetMask("Ground");

        if (Physics.Raycast(vec, Vector3.down, out info, Mathf.Infinity, mask))
        {
            current.gameObject.transform.position = info.point + Vector3.up * 0.2f;
            current.gameObject.transform.rotation = Random.rotation;
            current.gameObject.SetActive(true);
            curRow.Remove(current);
            spawned_SmallTrash[trashArrayPos].Add(current);

            LevelBalancing.SetTrashValue(current.personalTrashValue);
            return(current);
        }

        return(null);
    }
Ejemplo n.º 2
0
    public Spawned SpawnTrashArea()
    {
        Spawned ret           = null;
        int     indexMeshForm = Random.Range(0, maxSpawnIndexTrashAreas);

        int indexSpawnArea = Random.Range(0, spawnArea.Length);

        if (center[indexSpawnArea] == SpArTracker.getCurrentVisited())
        {
            indexSpawnArea = (indexSpawnArea + 1) % spawnArea.Length;
        }
        SpawnSpecificTrashArea(indexMeshForm, indexSpawnArea);

        if (maxSpawnIndexTrashAreas >= 3 && maxSpawnIndexTrashAreas < 5)
        {
            Transform extraArea = SpArTracker.getVisitedArea();
            indexSpawnArea = System.Array.IndexOf <Transform>(center, extraArea);
            SpawnSpecificTrashArea(indexMeshForm, indexSpawnArea);
        }

        if (maxSpawnIndexTrashAreas == 5)
        {
            Transform extraArea = SpArTracker.getCurrentVisited();
            indexSpawnArea = System.Array.IndexOf <Transform>(center, extraArea);
            SpawnSpecificTrashArea(indexMeshForm, indexSpawnArea);
        }
        return(ret);
    }
    public void PlaceCylinder(Vector3 pointOnPlane, Vector3 normalOfPlane, Spawned cylinderToPlace, int percentage)
    {
        visiblePercentage           = percentage;
        this.cylinder               = cylinderToPlace.gameObject;
        this.cylinderMesh           = cylinderToPlace.meshFltr;
        cylinder.transform.position = pointOnPlane;
        cylinder.transform.rotation = Quaternion.FromToRotation(cylinder.transform.up, normalOfPlane);

        curNormal      = normalOfPlane;
        rotationNumber = Random.Range(1, 4);

        RotateCylinderToSide();
        PushCylinderDown();
        RotateCylinderAtFinalPlace();

        if (inDebug)
        {
            lR.SetPosition(0, pointOnPlane + cylinder.transform.up * 10f);
            lR.SetPosition(1, pointOnPlane);
            lR.SetPosition(2, pointOnPlane + cylinder.transform.forward * 10f);
        }

        cylinder     = null;
        cylinderMesh = null;
    }
Ejemplo n.º 4
0
 void Update()
 {
     if (Input.anyKeyDown)
     {
         if (Input.GetKeyDown(KeyCode.P))
         {
             last = SpawnOnTimer();
         }
         else if (Input.GetKeyDown(KeyCode.O) && last != null)
         {
             despawnObjectWithID(last.poolNumber);
         }
         else
         {
             for (int i = 0; i < codes.Length; i++)
             {
                 if (Input.GetKeyDown(codes[i]))
                 {
                     int indexSpawnArea = Random.Range(0, spawnArea.Length);
                     SpawnSpecificTrashArea(i, indexSpawnArea);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        public void Despawn()
        {
            //stitch over with Previous in data structure
            if (Previous)
            {
                Previous.Next = Next;
            }
            else if (ContainingProjectile != null)
            {
                ContainingProjectile.Head = Next;
            }

            //stitch over with Next in data structure
            if (Next)
            {
                Next.Previous = Previous;
            }
            else if (ContainingProjectile != null)
            {
                ContainingProjectile.Tail = Previous;
            }

            //destroy ourselves
            Spawned spawnedComponent = this.GetComponent <Spawned>();

            if (spawnedComponent)
            {
                spawnedComponent.Despawn();
            }
            else
            {
                gameObject.Recycle();
            }
        }
Ejemplo n.º 6
0
    public Spawned SpawnSmallTrash()
    {
        Spawned ret   = null;
        int     index = Random.Range(0, maxSpawnIndexSmallTrash);

        if (spawnable_SmallTrash[index].Count >= spawnArea.Length)
        {
            //spawnObject();
            for (int i = 0; i < spawnArea.Length; i++)
            {
                ret = SpawnObjectInMesh(i, index);
            }
        }
        else
        {
            for (int i = 0; i < spawnArea.Length; i++)
            {
                Spawned current = spawned_SmallTrash[index][0];
                spawned_SmallTrash[index].RemoveAt(0);
                spawnable_SmallTrash[index].Add(current);
            }
            //spawnObject();
            for (int i = 0; i < spawnArea.Length; i++)
            {
                ret = SpawnObjectInMesh(i, index);
            }
        }
        return(ret);
    }
Ejemplo n.º 7
0
    public bool Spawn(TA_SHAPES shape, MeshFilter spawnArea, Spawned geometry, int visiblePercentage)
    {
        Vector3 RandomPos = spawnArea.mesh.GetRandomPointInsideConvex();

        RandomPos = spawnArea.transform.TransformPoint(RandomPos);

        if (Physics.Raycast(RandomPos, Vector3.down, out info, Mathf.Infinity, mask))
        {
            switch (shape)
            {
            case TA_SHAPES.Cube:
                geometryHandler.PlaceCube(info.point, info.normal, geometry, visiblePercentage);
                break;

            case TA_SHAPES.Cylinder:
                geometryHandler.PlaceCylinder(info.point, info.normal, geometry, visiblePercentage);
                break;

            case TA_SHAPES.Plane_Small:
            case TA_SHAPES.Plane_Big:
                geometryHandler.PlacePlane(info.point, info.normal, geometry, visiblePercentage);
                break;

            case TA_SHAPES.Sphere:
                geometryHandler.PlaceSphere(info.point, info.normal, geometry, visiblePercentage);
                break;
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 8
0
    public (GameObject, Spawned) SpawnNewInstance(Transform matchPositionAndRotation, Spawner context)
    {
        if (this.target == null)
        {
            return(null, null);
        }

        GameObject result = Object.Instantiate(this.target, matchPositionAndRotation.position, matchPositionAndRotation.rotation, matchPositionAndRotation);

        if (result == null)
        {
            Debug.LogError("Instantiate returned null", context.gameObject);
            return(null, null);
        }

        Spawned spawned = result.AddComponent(typeof(Spawned)) as Spawned;

        if (spawned != null)
        {
            spawned.SetTargetRenderersEnabled(true);

            result.SetActive(true);
        }

        return(result, spawned);
    }
Ejemplo n.º 9
0
 public virtual async Task SpawnAsync(IGame game)
 {
     if (Spawned != null)
     {
         await Spawned.Invoke(SpawnedEntity, Map);
     }
 }
Ejemplo n.º 10
0
    private bool CheckForOtherTrash(ref List <Spawned> found)
    {
        Vector3   mid  = transform.position;
        float     dist = 4f;
        LayerMask interactableCheck = LayerMask.GetMask("Trash");

        Collider[] temp = Physics.OverlapSphere(mid, dist, interactableCheck);
        if (temp.Length >= replaceTreshold)
        {
            print($"there are at least 3 or more collider in range of [{ownSpawnScript.poolNumber}]");
            foreach (Collider c in temp)
            {
                if (c.gameObject.CompareTag("Small Trash"))
                {
                    Spawned s = c.gameObject.GetComponent <Spawned>();
                    if (s.poolNumber != ownSpawnScript.poolNumber && !found.Contains(s))
                    {
                        print($"Call from [{ownSpawnScript.poolNumber}]-> despawn: [{s.poolNumber}]");
                        found.Add(s);
                    }
                }
            }
            print("-----------------");
            if (found.Count >= replaceTreshold)
            {
                print("there are 3 or more Small Trash Objects in range");
                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 11
0
    public IEnumerator setStage_LetObjectFall()
    {
        while (wayTraveled < 1f)//!hand.transform.localRotation == idleRot )
        {
            wayTraveled += interpolationSpeed * Time.deltaTime;
            hand.transform.localPosition = Vector3.Lerp(curStart, curEnd, wayTraveled);
            hand.localRotation           = Quaternion.Lerp(curStartRot, curEndRot, wayTraveled);
            yield return(new WaitForSeconds(0.01f));
        }

        hand.transform.localRotation.Set(idleRot.x, idleRot.y, idleRot.z, idleRot.w);
        hand.transform.localPosition.Set(idleVec.x, idleVec.y, idleVec.z);
        curStartRot = Quaternion.identity;
        curEndRot   = Quaternion.identity;
        curStart    = resetVector;
        curEnd      = resetVector;

        wayTraveled = 0f;

        lastPickup.transform.parent = null;
        lastPickup.getBody().isKinematic = false;
        lastPickup.transform.localScale = originalScale;
        lastPickup = null;
        yield return(null);
    }
Ejemplo n.º 12
0
 public void OnSpawn()
 {
     CurrentHealth = BaseHealth;
     HealthSet?.Invoke(CurrentHealth);
     ActionSet?.Invoke(CurrentActions);
     DefenseSet?.Invoke(DefenseModifier);
     Spawned?.Invoke();
 }
Ejemplo n.º 13
0
        internal void OnHostClientObjectDestroy(ObjectDestroyMessage msg)
        {
            if (logger.LogEnabled())
            {
                logger.Log("ClientScene.OnLocalObjectObjDestroy netId:" + msg.netId);
            }

            Spawned.Remove(msg.netId);
        }
Ejemplo n.º 14
0
        internal void OnHostClientObjectDestroy(ObjectDestroyMessage msg)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("ClientScene.OnLocalObjectObjDestroy netId:" + msg.netId);
            }

            Spawned.Remove(msg.netId);
        }
Ejemplo n.º 15
0
        public void Update(GameTime gameTime, Map MAP, PlayerStats player, int id, TcpClient client) //this is the update method and takes in gameTime to determine time elapsed, the MAP for its width and height and the player for all their information
        {
            switch (currentSpawned)                                                                  // this switch checks current spawned to see how it should update the sprite
            {
            case Spawned.Not:                                                                        //if its not spawned
            {
                exist++;                                                                             // it will just add 1 to exist untill it reaches spawn timer,
                if (exist > spawntimer)
                {
                    currentSpawned = Spawned.Is;                            // it will then set currentspawned state to is
                }
                break;
            }

            case Spawned.Is:                                                                                     // if it is spawned
            {
                if (Health <= 0)                                                                                 // if its health is less than or equal to zero
                {
                    Position          = new Vector2(rng.Next(75, MAP.Width - 75), rng.Next(0, MAP.Height - 75)); // it will give it a new random location within the borders of the map
                    player.experience = MaxHealth;                                                               //add experience to the player of the sae value of the Enemies health
                    player.mana       = MaxHealth / 2 + player.intelligence;                                     //add mana to the player bsaed on the monsters health and the players intelligence
                    MaxHealth        += 10;                                                                      //increase the monsters max health
                    Health            = MaxHealth;                                                               // set the monsters health to its new max health

                    MemoryStream writeStream = new MemoryStream();
                    BinaryWriter writer      = new BinaryWriter(writeStream);
                    writeStream.Position = 0;
                    writer.Write((byte)Protocol.enemyDied);
                    writer.Write(Convert.ToInt32(id));
                    writer.Write(Position.X);
                    writer.Write(Position.Y);
                    writer.Write(Convert.ToInt32(action));
                    writer.Write(Convert.ToInt32(health));
                    SendData(GetDataFromMemoryStream(writeStream), client);
                }
                if (player.experience >= player.Level * 100)        // if the players experience is greater than the players level*100 it will level up the player
                {
                    player.LevelUp();
                }
                Move(gameTime);                                                                                      //This moves the sprite in the move method
                rectangle = new Rectangle(currentFrame * Width, 0, Width, Height);                                   // this updates the rectangle of the sprite to display the current frame that wouldve been updated in move()
                origin    = new Vector2(rectangle.Width / 2, rectangle.Height / 2);                                  // sets the origin to always be the width and height /2 of the rectangle
                Position += velocity;                                                                                // adds velocity to the position which wouldve been updated in the move method
                POSRect   = new Rectangle((int)Position.X - Width / 2, (int)Position.Y - Height / 2, Width, Height); // makes a new rectangle at the Position of the enemy for use in collision detection
                if (hitTimer < 0)                                                                                    //if the hit timer is less than 0 it will set hit back to false and the hitimer to 0
                {
                    hit      = false;
                    hitTimer = 0;
                }
                else        //otherwise it will subtract 1 from hittimer
                {
                    hitTimer--;
                }
                break;
            }
            }
        }
Ejemplo n.º 16
0
    public void Spawn()
    {
        if (Tile.Blocked)
        {
            Tile.ApplyHealthChange(-1);
        }

        Spawned?.Invoke(this);

        Destroy(gameObject);
    }
Ejemplo n.º 17
0
 private void _registerType(Type type)
 {
     if (!Spawned.ContainsKey(type))
     {
         Spawned.Add(type, new List <IPoolable>());
     }
     if (!Despawned.ContainsKey(type))
     {
         Despawned.Add(type, new List <IPoolable>());
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Destroys all networked objects on the client.
 /// <para>This can be used to clean up when a network connection is closed.</para>
 /// </summary>
 public void DestroyAllClientObjects()
 {
     foreach (NetworkIdentity identity in Spawned.Values)
     {
         if (identity != null && identity.gameObject != null)
         {
             UnSpawn(identity);
         }
     }
     Spawned.Clear();
 }
Ejemplo n.º 19
0
        /// <summary>
        /// <paramref name="prefab"/>を生成する
        /// </summary>
        public static Actor Spawn(this Actor prefab, Vector3 position)
        {
            var instance = Object.Instantiate(prefab);

            instance.CachedTransform.position = position;

            instance.Broker.Publish(Spawned.Get());
            Broker.Global.Publish(SpawnedActor.Get(instance));

            return(instance);
        }
Ejemplo n.º 20
0
        internal void OnHostClientObjectHide(ObjectHideMessage msg)
        {
            if (logger.LogEnabled())
            {
                logger.Log("ClientScene::OnLocalObjectObjHide netId:" + msg.netId);
            }

            if (Spawned.TryGetValue(msg.netId, out NetworkIdentity localObject) && localObject != null)
            {
                localObject.OnSetHostVisibility(false);
            }
        }
Ejemplo n.º 21
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());
            }
        }
Ejemplo n.º 22
0
        internal void OnRpcMessage(RpcMessage msg)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("ClientScene.OnRPCMessage hash:" + msg.functionHash + " netId:" + msg.netId);
            }

            if (Spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
            {
                using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(msg.payload))
                    identity.HandleRpc(msg.componentIndex, msg.functionHash, networkReader);
            }
        }
Ejemplo n.º 23
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);
    }
Ejemplo n.º 24
0
        internal void OnRpcMessage(RpcMessage msg)
        {
            if (logger.LogEnabled())
            {
                logger.Log("ClientScene.OnRPCMessage hash:" + msg.functionHash + " netId:" + msg.netId);
            }

            if (Spawned.TryGetValue(msg.netId, out NetworkIdentity identity) && identity != null)
            {
                using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(msg.payload))
                    identity.HandleRemoteCall(msg.componentIndex, msg.functionHash, MirrorInvokeType.ClientRpc, networkReader);
            }
        }
Ejemplo n.º 25
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;
         }
     }
 }
Ejemplo n.º 26
0
        public void Dispose()
        {
            if (Spawned != null)
            {
                foreach (var spawn in Spawned)
                {
                    spawn.Disposed  -= OnEntityDisposed;
                    spawn.Destroyed -= OnEntityDisposed;

                    spawn.Dispose();
                }
                Spawned.Clear();
            }
            Spawned = null;
        }
Ejemplo n.º 27
0
        public void Start()
        {
            if (DidStart)
            {
                return;
            }

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

            Spawned?.Invoke(this);
        }
Ejemplo n.º 28
0
    IEnumerator GrowToSize(Spawned currentPlaced)
    {
        // Mögliche Erweiterung:
        //   -> Object wächst aus Mitte heraus zu voller Größe...

        /*
         * currentPlaced.transform.localScale = Vector3.zero;
         * Vector3 growing = Vector3.zero;
         * for (float i = 0.02f; i <= 1f; i += 0.05f)
         * {
         *  growing = Vector3.one * i;
         *  //Debug.Log("growing: " + growing+"/ i: "+i);
         *  currentPlaced.transform.localScale = growing;
         *  yield return new WaitForFixedUpdate();
         * }
         * currentPlaced.transform.localScale = Vector3.one;
         * <-... bis hier. */

        Vector3 posTarget = currentPlaced.transform.position;
        Vector3 posStart  = posTarget - Vector3.up * 2f;
        Vector3 posCur    = posStart;
        Vector3 help      = Vector3.zero;

        ParticleSystem dTInstance = GameObject.Instantiate(DirtThrow);

        dTInstance.transform.position = currentPlaced.transform.position;
        dTInstance.transform.Translate(Vector3.up * 0.03f);

        currentPlaced.transform.position = posCur;

        dTInstance.Play();
        for (float value = 0f; value <= 1f; value += Time.deltaTime * 1f)
        {
            help.y = (1 - value) * posStart.y + value * posTarget.y;
            help.x = posCur.x;
            help.z = posCur.z;

            posCur = help;
            currentPlaced.transform.position = posCur;
            yield return(new WaitForFixedUpdate());
        }
        currentPlaced.transform.position = posTarget;
        Destroy(dTInstance.transform.GetChild(0).gameObject);
        yield return(new WaitForSeconds(4f));

        Destroy(dTInstance.gameObject);
        yield return(null);
    }
Ejemplo n.º 29
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);
    }
Ejemplo n.º 30
0
        internal void OnHostClientSpawn(SpawnMessage msg)
        {
            if (Spawned.TryGetValue(msg.netId, out NetworkIdentity localObject) && localObject != null)
            {
                if (msg.isLocalPlayer)
                {
                    InternalAddPlayer(localObject);
                }

                localObject.HasAuthority = msg.isOwner;
                localObject.NotifyAuthority();
                localObject.StartClient();
                localObject.OnSetHostVisibility(true);
                CheckForLocalPlayer(localObject);
            }
        }