Esempio n. 1
0
    private void GetHitObject(ObjectPrefab objectPrefab, ObjectAnimation objectAnimation)
    {
        objectPrefab.IsActive = false;
        objectAnimation.StartAnimation();
        int id = objectPrefab.ID;

        OnClick?.Invoke(id);
    }
Esempio n. 2
0
    private void CreateObject()
    {
        ObjectPrefab objectPrefab = Instantiate(_objectData.ObjectPrefab, gameObject.transform);

        objectPrefab.gameObject.SetActive(false);
        _objects.Add(objectPrefab);
        objectPrefab.Speed = _speed;
    }
Esempio n. 3
0
    /// <summary>
    /// This fuction sets the params for the object pool that will be created.
    /// </summary>
    /// <param name="GenericObj">Choose from the pooledSubject enum what the secondary "generic" object is</param>
    /// <param name="PoolStartSize">the amount of objects the pool starts with</param>
    /// <param name="IncreaseIncrement">the amount of objects that will be added when the pool hits its current limit</param>
    /// <param name="ManagerTicksBeforeClean">the amount of ticks needed before the pool wil check for a clean</param>
    /// <param name="CleanThreshold">the amount of unused objects needed for a clean to happen example</param>
    public void Init(PooledSubObject GenericObj, int PoolStartSize = 20, int IncreaseIncrement = 5, int ManagerTicksBeforeClean = 5, int CleanThreshold = 20)
    {
        m_ObjectsAliveInPool = 0;


        m_objEnum = GenericObj;
        PoolObj TempData = ObjectPrefab.GetComponent <PoolObj>();

        TempData.Pool                 = this;
        this.m_CleanThreshold         = CleanThreshold;
        this.m_IncreaseIncrement      = IncreaseIncrement;
        this.m_anagerTicksBeforeClean = ManagerTicksBeforeClean;

        //m_DeadList = new Queue<GameObject>();
        m_DeadList = new Queue <PoolObj>();

        for (int i = 0; i < PoolStartSize; i++)
        {
            GameObject NewPoolGameObj = Instantiate(ObjectPrefab, transform);
            PoolObj    poolObj        = NewPoolGameObj.GetComponent <PoolObj>();
            switch (GenericObj)
            {
            case PooledSubObject.Default:
                poolObj.GenericObj = null;
                break;

            case PooledSubObject.GameObject:
                poolObj.GenericObj = poolObj.gameObject;
                break;

            case PooledSubObject.VisualEffect:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <VisualEffect>();
                break;

            case PooledSubObject.Enemy:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <Enemy>();
                break;

            case PooledSubObject.Rigidbody:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <Rigidbody>();
                break;

            case PooledSubObject.TowerProjectile:
                poolObj.GenericObj = poolObj.gameObject.GetComponent <TowerProjectile>();
                break;

            default:
                //m_GenericObj = null;
                break;
            }
            m_DeadList.Enqueue(poolObj);

            m_ObjectsInPool++;
            NewPoolGameObj.SetActive(false);
        }
    }
Esempio n. 4
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
         if (hit.collider != null && hit.collider.GetComponent <ObjectPrefab>() && hit.collider.GetComponent <ObjectAnimation>())
         {
             ObjectPrefab    objectPrefab    = hit.collider.GetComponent <ObjectPrefab>();
             ObjectAnimation objectAnimation = hit.collider.GetComponent <ObjectAnimation>();
             GetHitObject(objectPrefab, objectAnimation);
         }
     }
 }
Esempio n. 5
0
        public void ReturnObject(GameObject target)
        {
            ObjectPrefab prefab = target.GetComponent <ObjectPrefab>();

            if (prefab == null || !gameObjectPoolList.ContainsKey(prefab.prefab))
            {
                Debug.LogError("The target object is not from the object pool.");
                return;
            }

            if (!target.activeSelf)
            {
                Debug.LogWarning("You tried to return object that already returned. The return is ignored.");
                return;
            }

            target.SetActive(false);
            gameObjectPoolList[prefab.prefab].Push(target);
        }