Example #1
0
    /**
     * Handle the player shoot event.
     */
    void handlePlayerShoot()
    {
        if (Input.GetButtonDown("Shoot") && shotCooldownTimer <= 0f)
        {
            shotCooldownTimer = SHOT_COOLDOWN;
            Vector3[] directions = { transform.up, transform.right, -transform.up, -transform.right };

            for (int i = 0; i < directions.Length; i++)
            {
                Vector2 spawnLocation = transform.position + directions[i] * (0.5f + shotPrefab.transform.localScale.x * 0.5f);
                Debug.DrawRay(spawnLocation, directions[i] * 2f, Color.red);

                GameObject go = ObjectPoolController.InstantiateFromPool(shotPrefab, spawnLocation, transform.rotation);
                go.GetComponent <Rigidbody2D>().velocity = /*new Vector3(rb.velocity.x, rb.velocity.y, 0f) +*/ (directions[i] * 1f);

                if (directions[i] == transform.right || directions[i] == -transform.right)
                {
                    go.transform.Rotate(new Vector3(0f, 0f, 90f));
                }
            }

            shrinkPlayer();
        }
        if (shotCooldownTimer > 0f)
        {
            shotCooldownTimer -= Time.deltaTime;
        }
    }
Example #2
0
 void Awake()
 {
     if (Effect == null)
     {
         GameObject obj = GameObject.Find(PrefabRootPath);
         if (obj != null)
         {
             Effect = ObjectPoolController.Instantiate(obj);
             if (Effect != null)
             {
                 Effect.transform.SetParent(transform);
                 Effect.transform.localPosition    = Position;
                 Effect.transform.localEulerAngles = EulerAngles;
                 Effect.transform.localScale       = LocalScale;
                 if (ActiveOnAwake)
                 {
                     Effect.SetActive(true);
                 }
                 else
                 {
                     Effect.SetActive(false);
                 }
             }
         }
     }
 }
Example #3
0
    static private void _DetachChildrenAndDestroy(Transform transform)
    {
        int childCount = transform.childCount;

        Transform[] children = new Transform[childCount];

        var myTransform = transform; // cache for performance reasons

        int i;

        for (i = 0; i < childCount; i++)
        {
            children[i] = myTransform.GetChild(i);
        }
        myTransform.DetachChildren();

        for (i = 0; i < childCount; i++)
        {
            GameObject obj = children[i].gameObject;
            if (obj)
            {
                ObjectPoolController.Destroy(obj);
            }
        }
    }
    // MonoBehaviour's interface

    protected override void Awake()
    {
        base.Awake();

        // Get Component.

        m_ObjectPoolController = GetComponent <ObjectPoolController>();
    }
Example #5
0
    public static ObjectPoolController InstantiatePool(int poolSize, ObjectPoolItem item, string poolName)
    {
        ObjectPoolController pool = Instantiate(
            Resources.Load <ObjectPoolController>("Prefabs/ObjectPool")
            );

        pool.name = poolName;
        pool.Init(poolSize, item);
        return(pool);
    }
Example #6
0
    private void _DestroyAudioObject()
    {
        //Debug.Log( "Destroy:" + audio.clip.name );
#if AUDIO_TOOLKIT_DEMO
        GameObject.Destroy(gameObject);
#else
        ObjectPoolController.Destroy(gameObject);
#endif
        _destroyIfNotPlaying = false;
    }
Example #7
0
    private void Awake()
    {
        ObjectPool.InitializeMain();

        ObjectPoolController poolController = FindObjectOfType <ObjectPoolController>();

        if (poolController != null)
        {
            poolController.LoadAll();
        }
    }
 public void GetWorldControllers()
 {
     boardController      = GetComponent <BoardController>();
     playerController     = GetComponent <PlayerController>();
     npcController        = GetComponent <NpcController>();
     sessionLogger        = GetComponent <SessionLogger>();
     combatLogger         = GetComponent <CombatLogger>();
     dialogueManager      = GetComponent <DialogueManager>();
     objectPoolController = GetComponent <ObjectPoolController>();
     translator           = GetComponent <Translator>();
     hudCanvas            = GameObject.Find("HUDCanvas");
 }
Example #9
0
    public virtual void OnDisable()
    {
        ObjectPoolController opc = ObjectPoolController.SharedInstance;

        if (opc == null)
        {
            Destroy(gameObject);
            return;
        }

        opc.ReturnToPool(sourcePoolName, gameObject);
    }
    // MonoBehaviour's interface

    protected override void Awake()
    {
        base.Awake();

        // Get Component.

        m_ObjectPoolController = GetComponent <ObjectPoolController>();

        // UI

        if (m_CountdownPanelPrefab != null)
        {
            tnPanel_Countdown countdownPanel = Instantiate <tnPanel_Countdown>(m_CountdownPanelPrefab);
            countdownPanel.transform.SetParent(transform, true);

            m_CountdownPanel = countdownPanel;
        }

        if (m_EndGamePanelPrefab != null)
        {
            tnPanel_EndGame endGamePanel = Instantiate <tnPanel_EndGame>(m_EndGamePanelPrefab);
            endGamePanel.transform.SetParent(transform, true);

            m_EndGamePanel = endGamePanel;
        }

        if (m_FlatBackgroundPanelPrefab != null)
        {
            tnPanel_FlatBackground flatBackgroundPanel = Instantiate <tnPanel_FlatBackground>(m_FlatBackgroundPanelPrefab);
            flatBackgroundPanel.transform.SetParent(transform, true);

            m_FlatBackgroundPanel = flatBackgroundPanel;
        }

        if (m_PauseMenuPanelPrefab != null)
        {
            tnPanel_PauseMenu pauseMenuPanel = Instantiate <tnPanel_PauseMenu>(m_PauseMenuPanelPrefab);
            pauseMenuPanel.transform.SetParent(transform, true);

            m_PauseMenuPanel = pauseMenuPanel;
        }

        if (m_InGameOptionsPanelPrefab != null)
        {
            tnPanel_InGameOptions inGameOptionsPanel = Instantiate <tnPanel_InGameOptions>(m_InGameOptionsPanelPrefab);
            inGameOptionsPanel.transform.SetParent(transform, true);

            m_InGameOptionsPanel = inGameOptionsPanel;
        }

        m_LoadingPanel = GameObjectUtils.FindObjectWithTag <UIController>(s_Loading_Tag);
    }
Example #11
0
 protected override void DoInit()
 {
     base.DoInit();
     objectPoolController      = new ObjectPoolController(objectPoolParents);
     scoreController           = new ScoreController();
     cameraStartPos            = Camera.main.transform.position;
     _cameraController         = new TracerCameraController();
     _cameraController.traceX  = false;
     _cameraController.ySmooth = 0;
     _cameraController.yMargin = 0;
     continuePoints            = continuePointsParent.GetComponentsInChildren <ContinuePoint>();
     InitPool();
 }
Example #12
0
        protected override void DoInit()
        {
            base.DoInit();

            isMousePressed     = false;
            lines              = new List <Line> ();
            OnLineUpdateEvent += MyOnLineUpdateEvent;
//			linePrefab = Resources.Load ("Prefabs/Line", typeof(Line)) as Line;
            _touchDetector = new TouchDetector(null);
            _touchDetector.OnTouchEvent += OnTouchEventCall;
            _objectPoolController        = new ObjectPoolController(lineCopiesParent);

            _objectPoolController.InitPool <Line> ("line", linePrefab, 15);
        }
Example #13
0
    static private void _DetachChildrenAndDestroy(Transform transform, bool destroyImmediate)
    {
        var po = transform.GetComponent <PoolableObject>();

        if (transform.childCount > 0)
        {
            List <PoolableObject> poolableChilds = new List <PoolableObject>();
            transform.GetComponentsInChildren <PoolableObject>(true, poolableChilds);

            if (po != null)
            {
                poolableChilds.Remove(po);
            }

            //first destroy all poolable childs.
            for (int i = 0; i < poolableChilds.Count; i++)
            {
                if (poolableChilds[i] == null || poolableChilds[i]._isInPool)
                {
                    continue;                                                                 //can happen when a poolable is a child of another poolable
                }
                if (destroyImmediate)
                {
                    ObjectPoolController.DestroyImmediate(poolableChilds[i].gameObject);
                }
                else
                {
                    ObjectPoolController.Destroy(poolableChilds[i].gameObject);
                }
            }
        }

        if (po != null)
        {
            //move poolable Object to pool
            po._PutIntoPool();
        }
        else
        {
            //destroy non-poolable object itself
            if (destroyImmediate)
            {
                GameObject.DestroyImmediate(transform.gameObject);
            }
            else
            {
                GameObject.Destroy(transform.gameObject);
            }
        }
    }
Example #14
0
    /// <summary>
    /// Destroys the audio object (using <see cref="ObjectPoolController"/> if pooling is enabled)
    /// </summary>
    public void DestroyAudioObject()
    {
        if (audio.isPlaying)
        {
            _Stop();
        }

        //Debug.Log( "Destroy:" + audio.clip.name );
#if AUDIO_TOOLKIT_DEMO
        GameObject.Destroy(gameObject);
#else
        ObjectPoolController.Destroy(gameObject);
#endif
        _destroyIfNotPlaying = false;
    }
Example #15
0
 // Start is called before the first frame update
 void Start()
 {
     OBJ_POOLER = ObjectPoolController.SharedInstance;
     OBJ_POOLER.CreateObjPool(PLAYER_PROJECTILE_POOL_NAME, bulletPrefabs[0], true);
     _EC.SetVelocityFunctions(OverrideVelocities, CompoundVelocities, MultiplyVelocities);
     _EC.SetEventFunctions(OnLanding, WhileInAir);
     jumps      = maxJumps;
     dashAction = gameObject.AddComponent <ActionTimer>();
     dashAction.Init(null, EndDash, dashTime, dashCooldown, 0f);
     attackAction = gameObject.AddComponent <ActionTimer>();
     attackAction.Init(null, null, 0f, 0f, 0f);
     swingHitbox.SetActive(false);
     heatUIEffect.SetMax(maxHeat);
     _EC.faction = FactionList.PLAYER;
 }
        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go != null)
            {
                ObjectPoolController poolController = go.GetComponent <ObjectPoolController>();
                if (poolController != null)
                {
                    poolController.LoadAll();
                }
            }

            Finish();
        }
Example #17
0
    private void Awake()
    {
        SharedInstance = this;

        if (objectList == null)
        {
            Debug.LogError("No object list assigned to " + this.gameObject);
        }
        else
        {
            //Take the list and setup the pool with all the valid objects
            //Ignore objects with no object set or with no tag included - error log any that do have this issue
            PoolObjects();
        }
    }
Example #18
0
        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go != null)
            {
                ObjectPoolController poolController = go.GetComponent <ObjectPoolController>();
                if (poolController != null)
                {
                    poolController.UnloadAll();
                }
            }

            ObjectPool.ReleaseSpawnedMain(); // Release all spawner objects.

            Finish();
        }
Example #19
0
    /**
     * START
     */
    void Start()
    {
        rb            = GetComponent <Rigidbody2D>();
        blobFragments = new List <GameObject>();

        Physics2D.IgnoreLayerCollision(blobFragmentLayer, blobFragmentLayer);
        int numberOfFragments = Random.Range(3, 7);

        for (int i = 0; i < numberOfFragments; i++)
        {
            blobFragments.Add(
                ObjectPoolController.InstantiateFromPool(blobFragmentPrefab, transform.position, transform.rotation)
                );
            blobFragments[i].transform.parent = gameObject.transform;
            blobFragments[i].transform.Rotate(0.0f, 0.0f, Random.Range(0.0f, 360.0f));
        }

        rb.velocity = Random.insideUnitCircle * moveSpeed;
    }
Example #20
0
    /// <summary>
    /// Destroys the audio object (using <see cref="ObjectPoolController"/> if pooling is enabled)
    /// </summary>
    public void DestroyAudioObject()
    {
        if (IsPlaying())
        {
            _Stop();
        }

#if OUYA_PAUSE_SYSTEM
        OuyaSDK.unregisterPauseListener(this);
        OuyaSDK.unregisterResumeListener(this);
#endif

        //Debug.Log( "Destroy:" + _audioSource.clip.name );
#if AUDIO_TOOLKIT_DEMO
        GameObject.Destroy(gameObject);
#else
        ObjectPoolController.Destroy(gameObject);
#endif
        _IsInactive = true;
    }
Example #21
0
    private void Awake()
    {
        Instance   = this;
        _poolGroup = new List <ObjectPoolGroup>();
        foreach (var e in _poolEntries)
        {
            var groupContainer = new GameObject(e.PrefabObject.name);
            groupContainer.transform.parent = transform;
            var group = new ObjectPoolGroup
            {
                PrefabObject    = e.PrefabObject,
                PooledInstances = new Dictionary <int, ObjectPoolInstance>(),
                Parent          = groupContainer.transform
            };

            for (int i = 0; i < e.PrefabDefaultInstances; i++)
            {
                CreateInstanceInGroup(group);
            }

            _poolGroup.Add(group);
        }
    }
Example #22
0
    static private void _DetachChildrenAndDestroy(Transform transform)
    {
        int childCount = transform.childCount;

        Transform[] children = new Transform[childCount];

        int i;

        for (i = 0; i < childCount; i++)
        {
            children[i] = transform.GetChild(i);
        }
        transform.DetachChildren();

        for (i = 0; i < childCount; i++)
        {
            GameObject obj = children[i].gameObject;
            if (obj)
            {
                ObjectPoolController.Destroy(obj);
            }
        }
    }
Example #23
0
    public void ConstructGird()
    {
        this.m_GridSpriteList = new List <tk2dSprite>();
        for (int i = 0; i < ClientSystemConstants.BUILDING_TILE_MAP_SIZE.height; i++)
        {
            for (int j = 0; j < ClientSystemConstants.BUILDING_TILE_MAP_SIZE.width; j++)
            {
                if (BattleMapData.Instance.GridArray[i, j] != GridType.Out)
                {
                    float      depth      = this.m_GridPrefab.transform.position.z;
                    GameObject gridObject = (GameObject)ObjectPoolController.InstantiateWithoutPool(this.m_GridPrefab);                    //GameObject.Instantiate(this.m_GridPrefab) as GameObject;
                    Vector3    position   = PositionConvertor.GetWorldPositionFromBuildingTileIndex
                                                (new TilePosition(j, i));
                    gridObject.transform.position = new Vector3(position.x, position.y, depth);
                    gridObject.transform.parent   = this.m_ParentNode;
                    tk2dSprite gridSprite = gridObject.GetComponentInChildren <tk2dSprite>();
                    gridSprite.spriteId = gridSprite.GetSpriteIdByName(BattleMapData.Instance.GridArray[i, j].ToString());
                    this.m_GridSpriteList.Add(gridSprite);
                }
            }
        }

        this.DisplayGrid();
    }
 public void SetPool(ObjectPoolController pool)
 {
 }
Example #25
0
    public void Initialize()
    {
        _edgeFlames   = new List <GridItem>();
        _activeFlames = new List <GridItem>();

        _flamePrefab = Resources.Load <FlameController>("Prefabs/Flame");
        Vector3 floorSize = gameObject.transform.localScale;
        float   height    = floorSize.z;
        float   width     = floorSize.x;
        Vector3 itemSize  = new Vector3(width / _columns, 1.1f, height / _rows);

        _flamePrefab.transform.localScale = itemSize;


        _flamePool = GameMaster.InstantiatePool(_firePoolSize, _flamePrefab, "FlamePool");


        _fireGrid = new GridController(_rows, _columns, _payloadDepth, gameObject);

        _fireGrid.InitVariable("intensity", 0d, item =>
        {
            var g           = new Gradient();
            var gColor      = new GradientColorKey[4];
            gColor[0].color = Color.white;
            gColor[0].time  = 0f;
            gColor[1].color = Color.gray;
            gColor[1].time  = 0.25f;
            gColor[2].color = Color.yellow;
            gColor[2].time  = 0.5f;
            gColor[3].color = Color.red;
            gColor[3].time  = 1f;
            var gAlpha      = new GradientAlphaKey[1];
            gAlpha[0].alpha = 1f;
            gAlpha[0].time  = 0f;
            g.SetKeys(gColor, gAlpha);

            var main = item.GetPayload <FlameController>(0)
                       .GetComponent <ParticleSystem>().main;

            main.startColor = g.Evaluate(
                (float)(item.GetVariable <double>("intensity") / (_maxFlameIntensity))
                );
        });

        _fireGrid.InitVariable <bool>("flammable", item =>
        {
            Vector3 pos = _fireGrid.GetPosition(item._gridCoords);

            var posLeft = new Vector3(
                pos.x + _fireGrid._itemWidth / 2,
                0.2f,
                pos.y
                );

            var posDown = new Vector3(
                pos.x,
                0.2f,
                pos.y + _fireGrid._itemHeight / 2
                );

            var rayLeft = new Ray(posLeft, Vector3.left);
            var rayDown = new Ray(posDown, Vector3.back);

            Debug.DrawRay(rayLeft.origin, rayLeft.direction * _fireGrid._itemWidth, Color.white, 30000);
            Debug.DrawRay(rayDown.origin, rayDown.direction * _fireGrid._itemHeight, Color.white, 30000);

            var flammable = !(Physics.Raycast(rayDown, _fireGrid._itemHeight) ||
                              Physics.Raycast(rayLeft, _fireGrid._itemWidth));
            return(flammable);
        });

        _fireGrid.InitVariable("onfire", false);


        foreach (Vector2 coords in _startingFlames)
        {
            FlameController flame = _flamePool.Spawn() as FlameController;
            if (!flame)
            {
                throw new Exception("Can't start a fire! Someone bring more matches!!");
            }
            var gridCoords = _fireGrid.GetPosition(coords);
            flame.transform.position = new Vector3(
                gridCoords.x,
                _verticalOffset,
                gridCoords.y
                );
            var cell = _fireGrid.GetGridItem(coords.x, coords.y);
            cell.SetPayload(flame, 0);
            cell.SetVariable("intensity", _startIntensity);
            cell.SetVariable("onfire", true);
            _activeFlames.Add(cell);
            _edgeFlames.Add(cell);
            _fireGrid.UpdateGridItem(cell._gridCoords, cell);
        }

        _tick = Time.time;

        var orgSpreadChange = _spreadChance;

        _spreadChance = 1f;

        for (int i = 0; i < _prewarm; i++)
        {
            Spread();
            Grow();
        }

        _spreadChance = orgSpreadChange;

        _levelManager.GameMaster.ResetUi();

        initialized = true;
    }
Example #26
0
 private void Awake()
 {
     current = this;
 }
 private void Awake()
 {
     Self = this;
 }
Example #28
0
    // MonoBehaviour's interface

    protected override void Awake()
    {
        base.Awake();

        // Add players to process request handler.

        PhotonPlayer[] photonPlayers = PhotonNetwork.playerList;
        for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Length; ++photonPlayerIndex)
        {
            PhotonPlayer photonPlayer   = photonPlayers[photonPlayerIndex];
            int          photonPlayerId = photonPlayer.ID;
            m_ProceedRequestHandler.AddPlayer(photonPlayerId);
        }

        // Get component.

        m_PhotonView           = GetComponent <PhotonView>();
        m_ObjectPoolController = GetComponent <ObjectPoolController>();

        // UI

        if (m_CountdownPanelPrefab != null)
        {
            tnPanel_Countdown countdownPanel = Instantiate <tnPanel_Countdown>(m_CountdownPanelPrefab);
            countdownPanel.transform.SetParent(transform, true);

            m_CountdownPanel = countdownPanel;
        }

        if (m_EndGamePanelPrefab != null)
        {
            tnPanel_EndGame endGamePanel = Instantiate <tnPanel_EndGame>(m_EndGamePanelPrefab);
            endGamePanel.transform.SetParent(transform, true);

            m_EndGamePanel = endGamePanel;
        }

        if (m_DialogPanelPrefab != null)
        {
            tnPanel_Dialog dialogPanel = Instantiate <tnPanel_Dialog>(m_DialogPanelPrefab);
            dialogPanel.transform.SetParent(transform, true);

            m_DialogPanel = dialogPanel;
        }

        if (m_FlatBackgroundPanelPrefab != null)
        {
            tnPanel_FlatBackground flatBackgroundPanel = Instantiate <tnPanel_FlatBackground>(m_FlatBackgroundPanelPrefab);
            flatBackgroundPanel.transform.SetParent(transform, true);

            m_FlatBackgroundPanel = flatBackgroundPanel;
        }

        if (m_PauseMenuPanelPrefab != null)
        {
            tnPanel_PauseMenu pauseMenuPanel = Instantiate <tnPanel_PauseMenu>(m_PauseMenuPanelPrefab);
            pauseMenuPanel.transform.SetParent(transform, true);

            m_PauseMenuPanel = pauseMenuPanel;
        }

        if (m_InGameOptionsPanelPrefab != null)
        {
            tnPanel_InGameOptions inGameOptionsPanel = Instantiate <tnPanel_InGameOptions>(m_InGameOptionsPanelPrefab);
            inGameOptionsPanel.transform.SetParent(transform, true);

            m_InGameOptionsPanel = inGameOptionsPanel;
        }

        m_LoadingPanel = GameObjectUtils.FindObjectWithTag <UIController>(s_Loading_Tag);
    }
Example #29
0
 private void Initialize(Scene arg0, LoadSceneMode arg1)
 {
     _poolController = GameMaster.InstantiatePool(_numberPoolSize, _numberPrefab, _poolName);
     _lastSpawn      = Time.time;
     PoolCount       = _poolController.ObjectCount();
 }
Example #30
0
 private void Awake()
 {
     Instance = this;
 }