Beispiel #1
0
    // Update is called once per frame. It is the main workhorse function for frame updates.
    void Update()
    {
        if (Input.GetButtonDown("Fire3"))
        {
            //Rigidbody bulletInstance = Instantiate(m_BulletPrefab, m_BulletSpawnPoint.position, m_BulletSpawnPoint.rotation) as Rigidbody;
            //bulletInstance.velocity = m_BulletVelocity * m_BulletSpawnPoint.up; //(up = y-axis)

            // Get a bullet and initialize it before activating it.
            //m_Bullet = GameManager.instance.m_BulletPool.Pop();
            m_Bullet = m_BulletPool.Pop();
            Rigidbody rigidbody = m_Bullet.GetComponent <Rigidbody>();
            m_Bullet.transform.position = m_BulletSpawnPoint.position;
            m_Bullet.transform.rotation = m_BulletSpawnPoint.rotation;
            rigidbody.velocity          = m_BulletVelocity * m_BulletSpawnPoint.up; //(up: y-axis)
            m_Bullet.gameObject.SetActive(true);

            //Invoke("Repool", m_BulletLife);
            //StartCoroutine(Repool(m_Bullet, m_BulletLife));

            // Change the clip to the firing clip and play it.
            //m_ShootingAudio.clip = m_ShootClip;
            m_ShootingAudio.Play();
            //SoundManager.instance.PlaySingle(m_ShootClip);
        }
    }
Beispiel #2
0
        void InsertCellData(int index)
        {
            List <int> keys = SortedKeys();

            for (int i = keys.Count - 1; i >= 0; --i)
            {
                int key = keys[i];
                if (key < index)
                {
                    break;
                }

                Poolable item = cellPooler.Collection[key];
                cellPooler.Collection.Remove(key);
                cellPooler.Collection.Add(key + 1, item);
                Vector2 offset = container.Flow.GetCellOffset(key);
                item.GetComponent <TableViewCell>().Pin(offset);
            }

            spacer.Insert(index);

            visibleRange = container.Flow.GetVisibleCellRange();
            if (index >= visibleRange.x && index <= visibleRange.y)
            {
                InsertCellView(index);
            }
        }
    // Update is called once per frame. It is the main workhorse function for frame updates.
    void Update()
    {
        if(Input.GetButtonDown("Fire3"))
        {
            //Rigidbody bulletInstance = Instantiate(m_BulletPrefab, m_BulletSpawnPoint.position, m_BulletSpawnPoint.rotation) as Rigidbody;
            //bulletInstance.velocity = m_BulletVelocity * m_BulletSpawnPoint.up; //(up = y-axis)

            // Get a bullet and initialize it before activating it.
            //m_Bullet = GameManager.instance.m_BulletPool.Pop();
            m_Bullet = m_BulletPool.Pop();
            Rigidbody rigidbody = m_Bullet.GetComponent<Rigidbody>();
            m_Bullet.transform.position = m_BulletSpawnPoint.position;
            m_Bullet.transform.rotation = m_BulletSpawnPoint.rotation;
            rigidbody.velocity = m_BulletVelocity * m_BulletSpawnPoint.up; //(up: y-axis)
            m_Bullet.gameObject.SetActive(true);

            //Invoke("Repool", m_BulletLife);
            //StartCoroutine(Repool(m_Bullet, m_BulletLife));

            // Change the clip to the firing clip and play it.
            //m_ShootingAudio.clip = m_ShootClip;
            m_ShootingAudio.Play();
            //SoundManager.instance.PlaySingle(m_ShootClip);
        }
    }
Beispiel #4
0
    public void Insert(Poolable _object)
    {
        _object.transform.SetParent(transform);
        _object.gameObject.SetActive(false);
        PhotonView view = _object.GetComponent <PhotonView>();

        view.ViewID = 0;
    }
    private void Fire()
    {
        SoundManager.Instance.PlayAudio("skelefire");
        fireTimer = fireDelay + Time.time;
        Poolable arrow = Poolable.Get(() => Poolable.CreateObj <Arrow>(arrowPrefab.gameObject));

        arrow.transform.position = firePos.position;
        arrow.GetComponent <Rigidbody2D>().velocity = -Vector2.right * arrowSpeed * Time.deltaTime;
    }
    StatusIndicatorEntry Dequeue(StatPanel panel)
    {
        Poolable             p     = GameObjectPoolController.Dequeue(EntryPoolKey);
        StatusIndicatorEntry entry = p.GetComponent <StatusIndicatorEntry>();

        entry.transform.SetParent(panel.statusParent.transform, false);
        entry.transform.localScale = Vector3.one;
        entry.gameObject.SetActive(true);
        return(entry);
    }
Beispiel #7
0
    PartyEntry Dequeue()
    {
        Poolable   p     = GameObjectPoolController.Dequeue(DemoUnitKey);
        PartyEntry entry = p.GetComponent <PartyEntry>();

        entry.transform.SetParent(panel.transform, false);
        entry.transform.localScale = Vector3.one;
        entry.gameObject.SetActive(true);
        return(entry);
    }
Beispiel #8
0
        public Poolable Spawn(string id, bool isAlly = true)
        {
            Poolable poolable = poolManager.Spawn(id, isAlly ? allySpawnPoint.position : enemySpawnPoint.position, spawnParent);

            UnitGravityBody body = poolable.GetComponent <UnitGravityBody>();

            body.Initialize();
            body.SetAttractor(attractor);
            return(poolable);
        }
    public U GetScript <U> (T key) where U : MonoBehaviour
    {
        Poolable item = GetItem(key);

        if (item != null)
        {
            return(item.GetComponent <U>());
        }
        return(null);
    }
Beispiel #10
0
    IEnumerator InstantiateBox()
    {
        while (boxToInstantiate.Count > 0 && PosFree.Count > 0)
        {
            yield return(new WaitForSeconds(1.2f));

            if (PosFree.Contains(PosInstantiation.Count() - 2))
            {
                int posIndex = PosInstantiation.Count() - 1;
                int finalPosIndex;

                Poolable           foodToInstantiate = PoolManager.Instance.Get(boxToInstantiate[0], true);
                BoxDatasController box  = foodToInstantiate.GetComponent <BoxDatasController>();
                PhotonView         view = foodToInstantiate.GetComponent <PhotonView>();

                foodToInstantiate.transform.position = PosInstantiation[posIndex].position;
                foodToInstantiate.transform.rotation = PosInstantiation[posIndex].rotation;

                box.Init();
                box.SetActive(false);
                box.Grabable.onGrab += OnGrabBox;

                boxInPos.Add(box, posIndex);

                PosFree.Remove(posIndex);

                finalPosIndex = GetFinalBoxPosition(posIndex);

                boxInPos[box] = finalPosIndex;
                PosFree.Remove(finalPosIndex);

                StartCoroutine(TranslateBoxToPosition(box, posIndex));

                photonView.RPC("InstantiateBox", RpcTarget.Others, boxToInstantiate[0].Key, boxToInstantiate[0].Value, posIndex, finalPosIndex, view.ViewID);

                boxToInstantiate.RemoveAt(0);
            }

            yield return(0);
        }

        yield return(0);
    }
Beispiel #11
0
    // FixedUpdate is called every physics tick
    void FixedUpdate()
    {
        float percent = playerInput.CurrentInput.MoveDir.magnitude;

        if (playerInput.CurrentInput.MoveDir.magnitude > 0)
        {
            percent = energyManager.SpendThrustEnergy(percent);
        }

        /* movement handling */
        if (playerInput.CurrentInput.MoveDir == Vector2.zero)
        {
            // decelerate if no input
            rb.velocity *= 1 - decelerationPerTick;
        }
        else
        {
            rb.AddForce(playerInput.CurrentInput.MoveDir * thrust * percent);

            // clamp velocity to max speed
            rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxControlledVelocity);
        }

        /* weapon handling */
        if (fire1 && Time.time >= (time + fireWait))
        {
            if (energyManager.SpendBulletEnergy())
            {
                gunSoundSource.Play();
                Poolable        obj    = bulletPool.Pop();
                BulletBehaviour bullet = obj.GetComponent <BulletBehaviour>();

                // sin and cosine for current aim direction
                float sin = Mathf.Sin(rb.rotation * Mathf.Deg2Rad);
                float cos = Mathf.Cos(rb.rotation * Mathf.Deg2Rad);

                // find offset for gun barrel
                Vector2 b      = barrels[barrelNum];
                Vector2 offset = new Vector2(b.x * cos - b.y * sin,
                                             b.x * sin + b.y * cos);
                if (++barrelNum >= barrels.Length)
                {
                    barrelNum = 0;
                }

                // fire bullet from offset position
                bullet.transform.position = rb.position + offset;
                bullet.Fire(aimDir);
                time = Time.time;
            }

            // reset input bool
            fire1 = false;
        }
    }
Beispiel #12
0
    AbilityBarSlot Dequeue()
    {
        Poolable       p     = GameObjectPoolController.Dequeue(EntryPoolKey);
        AbilityBarSlot entry = p.GetComponent <AbilityBarSlot>();

        entry.transform.SetParent(spellContainer.transform, false);
        entry.transform.localScale = Vector3.one;
        entry.gameObject.SetActive(true);
        entry.Reset();
        return(entry);
    }
Beispiel #13
0
        void OnWillEnqueue(Poolable item)
        {
            TableViewCell cell = item.GetComponent <TableViewCell>();

            cell.Hide();

            if (willHideCell != null)
            {
                willHideCell(this, cell);
            }
        }
        /// <summary>
        /// <para>Poner en cola</para>
        /// </summary>
        /// <returns></returns>
        private BtnHabilidad PonerEnCola()        // Poner en cola
        {
            Poolable     pool    = GameObjectPoolController.EnColaPoolable(EntradaPoolKey);
            BtnHabilidad entrada = pool.GetComponent <BtnHabilidad>();

            entrada.transform.SetParent(panel.transform, false);
            entrada.transform.localScale = Vector3.one;
            entrada.gameObject.SetActive(true);
            entrada.Reset();
            return(entrada);
        }
Beispiel #15
0
    // methods for getting and returning menu entries from the pool
    AbilityMenuEntry Dequeue()
    {
        Poolable         p     = GameObjectPoolController.Dequeue(EntryPoolKey);
        AbilityMenuEntry entry = p.GetComponent <AbilityMenuEntry>();

        entry.transform.SetParent(panel.transform, false);
        entry.transform.localScale = Vector3.one;
        entry.gameObject.SetActive(true);
        entry.Reset();
        return(entry);
    }
    CommandMenuButton Dequeue()
    {
        Poolable          p     = GameObjectPoolController.Dequeue(EntryPoolKey);
        CommandMenuButton entry = p.GetComponent <CommandMenuButton>();

        entry.transform.SetParent(buttonCenter, false);
        entry.transform.localScale = Vector3.one;
        entry.GetComponent <RectTransform>().localPosition = Vector3.zero;
        entry.gameObject.SetActive(true);
        entry.Reset();
        return(entry);
    }
Beispiel #17
0
    private void ThrowRock()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0) && rockCount != 0)
        {
            //Instantiate(rock, throwPoint.position, throwPoint.rotation);

            Poolable obj = GameObjectPoolController.Dequeue(PoolKey);
            obj.transform.position = transform.position;
            obj.gameObject.SetActive(true);
            instances.Add(obj);
            obj.GetComponent <ThrowRock>().ShootRock();

            rockCount--;
            UpdateRockCountUI();
        }
    }
Beispiel #18
0
        void OnDidDequeueForKey(Poolable item, int key)
        {
            TableViewCell cell = item.GetComponent <TableViewCell>();

            cell.transform.SetParent(scrollRect.content);
            cell.transform.localScale = Vector3.one;
            cell.gameObject.SetActive(true);

            container.Flow.ConfigureCell(cell, key);
            Vector2 offset = container.Flow.GetCellOffset(key);

            cell.Show(offset);

            if (willShowCellAtIndex != null)
            {
                willShowCellAtIndex(this, cell, key);
            }
        }
Beispiel #19
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("RockShot") || other.gameObject.CompareTag("Rock"))
        {
            int coinAmmount = Random.Range(1, 3);
            for (int i = 0; i < coinAmmount; i++)
            {
                Poolable obj = GameObjectPoolController.Dequeue(PoolKey);
                obj.transform.position = transform.position;
                obj.gameObject.SetActive(true);
                instances.Add(obj);
                Vector3 otherSpeed = other.GetComponent <Rigidbody2D>().velocity;
                obj.GetComponent <Rigidbody2D>().velocity = otherSpeed / 2;
            }

            gameObject.active = false;
        }
    }
Beispiel #20
0
    public void GetObjectInColdRoom(string _alimentName, AlimentState _alimentState, int alimentViewID, int actorNumber, bool _Remove = false)
    {
        PlayerController ownerPlayer = InGamePhotonManager.Instance.PlayersConnected[actorNumber];

        KeyValuePair <string, AlimentState> keyFood;

        keyFood = new KeyValuePair <string, AlimentState>(_alimentName, _alimentState);
        Poolable foodToGet = null;

        if (_Remove == false)
        {
            if (keyFood.Value != AlimentState.Box && keyFood.Value != AlimentState.Stack)
            {
                foodToGet = PoolManager.Instance.Get(keyFood, alimentViewID);
                limitedFoodsStocked[keyFood] -= 1;
                if (limitedFoodsStocked[keyFood] == 0)
                {
                    limitedFoodsStocked.Remove(keyFood);
                    ui.RemoveButton(keyFood);
                }
            }
            else
            {
                keyFood   = new KeyValuePair <string, AlimentState>(_alimentName, AlimentState.InContent);
                foodToGet = PoolManager.Instance.Get(keyFood, alimentViewID);
            }
        }
        else
        {
            foodToGet = PoolManager.Instance.Get(keyFood, alimentViewID);
            foodsStocked.Remove(keyFood);
            ui.RemoveButton(keyFood);
        }

        if (foodToGet != null)
        {
            GrabableObject toGrab = foodToGet.GetComponent <GrabableObject>();
            toGrab.Init();
            toGrab.AllowGrab(true);
            ownerPlayer.pInteract.GrabObject(toGrab, false);
        }
    }
Beispiel #21
0
        void RemoveCellData(int index)
        {
            List <int> keys = SortedKeys();

            for (int i = 0; i < keys.Count; ++i)
            {
                int key = keys[i];
                if (key < index)
                {
                    continue;
                }
                else if (key == index)
                {
                    RemoveCellView(key);
                }
                else
                {
                    Poolable item = cellPooler.Collection[key];
                    cellPooler.Collection.Remove(key);
                    cellPooler.Collection.Add(key - 1, item);
                    Vector2 offset = container.Flow.GetCellOffset(key);
                    item.GetComponent <TableViewCell>().Pin(offset);
                }
            }

            int height = spacer.GetSize(index);

            spacer.Remove(index);

            visibleRange = container.Flow.GetVisibleCellRange();
            for (int i = visibleRange.x; i <= visibleRange.y; ++i)
            {
                if (cellPooler.HasKey(i))
                {
                    continue;
                }
                TableViewCell cell   = cellPooler.DequeueScriptByKey <TableViewCell>(i);
                Vector2       offset = container.Flow.GetCellOffset(i, height);
                cell.Pin(offset);
            }
        }
    // Called when hit by a bullet trigger collider.
    void OnTriggerEnter(Collider other)
    {
        // other = Bullet. Inactivate it until it repools itself.
        other.gameObject.SetActive(false);

        if (gameObject.CompareTag("AsteroidBig"))
        {
            // Split the big asteroid into 2 smaller ones.
            for (int i = 0; i < 2; i++)
            {
                //GameObject a1 = Instantiate(m_SmallAsteroidPrefab);
                Poolable          small     = GameManager.instance.m_AsteroidSmallPool.Pop();
                AsteroidBehaviour behaviour = small.GetComponent <AsteroidBehaviour>();
                small.transform.position = gameObject.transform.position;
                small.gameObject.SetActive(true);
                behaviour.SetRandomForces();
            }

            // Recycle this (big) asteroid.
            GameManager.instance.m_AsteroidBigPool.Push(m_Poolable);
        }
        else // "AsteroidSmall"
        {
            // Recycle this (small) asteroid.
            GameManager.instance.m_AsteroidSmallPool.Push(m_Poolable);
        }

        // Play the explosion sound clip via SM (because object will be destroyed).
        // Could also use  AudioSource.PlayClipAtPoint()
        //SoundManager.instance.PlaySingle(m_ExplosionClip);

        // Activate an explosion.
        SpawnExplosion();
        //Poolable explosion = GameManager.instance.m_ExplosionPool.Pop();
        //explosion.transform.position = transform.position;
        //explosion.transform.Rotate(new Vector3(0f, 0f, 360f * Random.value));
        //explosion.gameObject.SetActive(true);
    }
Beispiel #23
0
    void InstantiateBox(string _alimentName, AlimentState _alimentState, int posFree, int finalPos, int viewID)
    {
        //Debug.Log("Receive RPC InstantiateBox :" + _alimentName + " AlimentState:" + _alimentState + " viewID:" + viewID);
        KeyValuePair <string, AlimentState> key = new KeyValuePair <string, AlimentState>(_alimentName, _alimentState);

        Poolable           foodToInstantiate = PoolManager.Instance.Get(key, viewID);
        BoxDatasController box = foodToInstantiate.GetComponent <BoxDatasController>();

        foodToInstantiate.transform.position = PosInstantiation[posFree].position;
        foodToInstantiate.transform.rotation = PosInstantiation[posFree].rotation;

        box.Init();
        box.SetActive(false);
        box.Grabable.onGrab += OnGrabBox;

        boxInPos.Add(box, posFree);

        PosFree.Remove(posFree);

        boxInPos[box] = finalPos;
        PosFree.Remove(finalPos);

        StartCoroutine(TranslateBoxToPosition(box, posFree));
    }
    public virtual U DequeueScriptByKey <U> (T key) where U : MonoBehaviour
    {
        Poolable item = DequeueByKey(key);

        return(item.GetComponent <U>());
    }
Beispiel #25
0
    // instantiate food object in hand of player
    public void GetFood(bool _Remove = false)
    {
        KeyValuePair <string, AlimentState> keyFood;
        Poolable foodToGet = null;

        if (_Remove == false)         // "se servir" button
        {
            // Take the key of prefab stock in slected button
            keyFood = ui.GetPoolableFromSelectedButton();
            // change state of the prefab stock in selected button if it's a box
            if (keyFood.Value == AlimentState.Box || keyFood.Value == AlimentState.Stack)
            {
                KeyValuePair <string, AlimentState> newKeyFood = new KeyValuePair <string, AlimentState>(keyFood.Key, AlimentState.InContent);
                foodToGet = PoolManager.Instance.Get(newKeyFood, true);
            }
            else             // remove object if state different of box or stack (limited food)
            {
                limitedFoodsStocked[keyFood] -= 1;
                if (limitedFoodsStocked[keyFood] == 0)
                {
                    if (ui.RemoveButton(out keyFood))
                    {
                        limitedFoodsStocked.Remove(keyFood);

                        foodToGet = PoolManager.Instance.Get(keyFood, true);
                    }
                }
                else
                {
                    foodToGet = PoolManager.Instance.Get(keyFood, true);
                }
            }
        }
        else        // remove object "Tout prendre" button
        {
            if (ui.RemoveButton(out keyFood))
            {
                foodsStocked.Remove(keyFood);
                foodToGet = PoolManager.Instance.Get(keyFood, true);


                if (keyFood.Value == AlimentState.Box)
                {
                    foodToGet.GetComponent <BoxDatasController>().Init();
                }
            }
        }

        GrabableObject toGrab = foodToGet.GetComponent <GrabableObject>();

        toGrab.Init();
        toGrab.AllowGrab(true);

        if (!player.pInteract.GrabObject(toGrab, false))
        {
            // player can't grab object.
            Debug.Log("grab");
        }
        else
        {
            photonView.RPC("GetObjectInColdRoom", RpcTarget.Others, keyFood.Key, keyFood.Value, foodToGet.photonView.ViewID, player.photonView.OwnerActorNr, _Remove);
            StopInteraction();

            GameManager.Instance.Audio.PlaySound("GrabCardboard", AudioManager.Canal.SoundEffect);
        }
    }
Beispiel #26
0
    public virtual U DequeueScript <U> () where U : MonoBehaviour
    {
        Poolable item = Dequeue();

        return(item.GetComponent <U>());
    }