Ejemplo n.º 1
0
 private void InitializePool()
 {
     _pool         = new GameObject("Pool").AddComponent <LeanGameObjectPool>();
     _pool.Prefab  = GetPlayerControlledObjectPrefab();
     _pool.Preload = 500;
     _pool.PreloadAll();
 }
Ejemplo n.º 2
0
    /// <summary>
    ///     回收目标实例至对应池
    /// </summary>
    /// <param name="clone">目标实例</param>
    /// <param name="delay">延迟时间</param>
    public void Despawn(GameObject clone, float delay = 0.0f)
    {
        if (clone != null)
        {
            var pool = default(LeanGameObjectPool);

            // Try and find the pool associated with this clone
            if (Links.TryGetValue(clone, out pool))
            {
                // Remove the association
                Links.Remove(clone);

                pool.Despawn(clone, delay);
            }
            else
            {
                if (LeanGameObjectPool.TryFindPoolByClone(clone, ref pool))
                {
                    pool.Despawn(clone, delay);
                }
                else
                {
                    Debug.LogWarning("You're attempting to despawn a gameObject that wasn't spawned from this pool",
                                     clone);

                    // Fall back to normal destroying
                    Object.Destroy(clone);
                }
            }
        }
        else
        {
            Debug.LogWarning("You're attempting to despawn a null gameObject", clone);
        }
    }
Ejemplo n.º 3
0
 private void Awake()
 {
     _anim         = GetComponent <Animator>();
     _knifePool    = GameObject.FindGameObjectWithTag(_Data._tagKnifePool).GetComponent <LeanGameObjectPool>();
     _AIPawn       = GetComponents <BehaviorTree>();
     _target       = GameObject.FindGameObjectWithTag(_Data._tagPlayer).transform;
     _playerAtkDmg = _target.GetComponent <PlayerAtkDmg>();
 }
Ejemplo n.º 4
0
 private void Start()
 {
     _anim         = GetComponent <Animator>();
     _knifePool    = GameObject.FindGameObjectWithTag(_Data._tagKnifePool).GetComponent <LeanGameObjectPool>();
     _myTimer      = 0f;
     _isFlashing   = _isInvincible = false;
     _flashingBody = transform.GetChild(0).GetComponent <SkinnedMeshRenderer>();
     _childCount   = transform.GetChildCount();
 }
Ejemplo n.º 5
0
    LeanGameObjectPool CreatePool(GameObject prefab, int maxCopies)
    {
        LeanGameObjectPool _pool = PlayerManager.Instance.Player.gameObject.AddComponent <LeanGameObjectPool>();

        _pool.Prefab   = prefab;
        _pool.Recycle  = true;
        _pool.Capacity = maxCopies;

        return(_pool);
    }
Ejemplo n.º 6
0
    public void Init(CardController controller, LeanGameObjectPool pool)
    {
        Controller = controller;
        _pool      = pool;

        Controller.ValueChanged += OnValueChanged;
        Controller.StateChanged += OnCardStateChanged;

        // A material instance is required so we can apply different textures to different cards.
        ArtImage.material = new Material(CardArtMaterial);

        _canvas = GetComponentInChildren <Canvas>();
    }
Ejemplo n.º 7
0
 void Awake()
 {
     _initialPos   = new Vector3(0, 0, 5f);
     _startPoint   = new Vector3(0, 0, 2.5f);
     _target       = GameObject.FindGameObjectWithTag(_Data._tagPlayer).transform;
     _playerAtkDmg = _target.GetComponent <PlayerAtkDmg>();
     _knifePool    = GameObject.FindGameObjectWithTag(_Data._tagKnifePool).GetComponent <LeanGameObjectPool>();
     _anim         = GetComponent <Animator>();
     _bossTree     = GetComponent <BehaviorTree>();
     _FWPoints     = new Vector3[] { new Vector3(-0.7f, 1, 1.6f), new Vector3(0.5f, 1, 1.6f) };
     _FWRotation   = new Vector3[] { new Vector3(0, -120, 0), new Vector3(0, 120, 0) };
     _knifePoints  = new Vector3[] { new Vector3(1.3f, 1, 4), new Vector3(0, 1, 4), new Vector3(-1.3f, 1, 4) };
 }
        /// <summary>
        /// Initializes ThrowablePool with the set numberOfThrowables
        /// </summary>
        public virtual void Initialize()
        {
            ThrowablePool = GetComponent <LeanGameObjectPool>();

            //the number of Objects to load into the pool
            ThrowablePool.Preload = numberOfThrowables;
            //the max number of Objects that the pool uses without recycling the last
            ThrowablePool.Capacity = numberOfThrowables;
            //Initializes the pool
            ThrowablePool.PreloadAll();

            //Loads throwables into DisplaySpots from the Pool
            LoadInitialThrowables();
        }
Ejemplo n.º 9
0
        private bool Exists()
        {
            if (LeanPool.Links.TryGetValue(gameObject, out cachedPool) == true)
            {
                return(true);
            }

            if (LeanGameObjectPool.TryFindPoolByClone(gameObject, ref cachedPool) == true)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
    public GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent)
    {
        if (prefab != null)
        {
            var gameObjectPool = default(LeanGameObjectPool);

            if (LeanGameObjectPool.TryFindPoolByPrefab(prefab, ref gameObjectPool) == false)
            {
                gameObjectPool = new GameObject(prefab.name + " Pool").AddComponent <LeanGameObjectPool>();
                gameObjectPool.transform.SetParent(_pool.transform);

                gameObjectPool.Prefab = prefab;
            }

            var clone = gameObjectPool.Spawn(position, rotation, parent);

            if (clone != null)
            {
                if (gameObjectPool.Recycle && gameObjectPool.Spawned >= gameObjectPool.Capacity)
                {
                    var existingPool = default(LeanGameObjectPool);

                    if (Links.TryGetValue(clone, out existingPool))
                    {
                        if (existingPool != gameObjectPool)
                        {
                            Links.Remove(clone);
                        }
                        else
                        {
                            return(clone.gameObject);
                        }
                    }
                }

                Links.Add(clone, gameObjectPool);

                return(clone.gameObject);
            }
        }
        else
        {
            Debug.LogError("Attempting to spawn a null prefab");
        }

        return(null);
    }
Ejemplo n.º 11
0
    private static void SpawnFOWTeamViewObjects(int[] teams, LeanGameObjectPool pool, ActiveMap map)
    {
        //aca debo entregar una lista con todas las entidades que generan vision de un team y cual es su rango.
        var visionPointOfTeam = SightSystem.GetVisionPointsForEachTeam(teams);

        foreach (var point in visionPointOfTeam)
        {
            //debo agragarle la altura
            var elevation = MapUtilities.GetElevationOfPosition(point.center);
            var fixPositionNoElevation = map.layout.HexToWorld(point.center);
            var fixScale = map.layout.size * point.radius;

            var position      = new Vector3((float)fixPositionNoElevation.x, (float)fixPositionNoElevation.y + elevation);
            var scale         = new Vector3((float)fixScale.x, (float)fixScale.y) * 2;
            var spawnedObject = pool.Spawn(position, Quaternion.identity);
            spawnedObject.transform.localScale = scale;
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    ///     池中预加载一定数量目标预制体的实例
    /// </summary>
    /// <param name="prefab">目标预制体</param>
    /// <param name="size">预加载数量</param>
    public void Preload(GameObject prefab, int size = 5)
    {
        if (prefab != null)
        {
            var gameObjectPool = default(LeanGameObjectPool);

            if (LeanGameObjectPool.TryFindPoolByPrefab(prefab, ref gameObjectPool) == false)
            {
                gameObjectPool = new GameObject(prefab.name + " Pool").AddComponent <LeanGameObjectPool>();
                gameObjectPool.transform.SetParent(_pool.transform);

                gameObjectPool.Prefab = prefab;
            }

            gameObjectPool.Preload = size;
            gameObjectPool.PreloadAll();
        }
        else
        {
            Debug.LogError("无法为 null 预制体做预加载");
        }
    }
Ejemplo n.º 13
0
 private void OnEnable()
 {
     _pool = GetComponent <LeanGameObjectPool>();
 }
Ejemplo n.º 14
0
 //========================================================== Start Up
 public void SetAttackPools(GameObject basic, GameObject special)
 {
     _poolBasic   = CreatePool(basic, 10);
     _poolSpecial = CreatePool(special, 3);
 }
Ejemplo n.º 15
0
    private void Start()
    {
        soundPool = GetComponent <LeanGameObjectPool>();

        //StartCoroutine( Test() );
    }