Esempio n. 1
0
        public void StartGame()
        {
            running = true;

            mBlockPool.createMoreIfNeeded = true;
            mBlockPool.Initialize(tetriminoBlockPrefab, tetriminoParent);

            mTetriminoPool.createMoreIfNeeded = true;
            mTetriminoPool.Initialize(tetriminoHolderPrefab, tetriminoParent);
            mTetriminoPool.OnObjectCreationCallBack += x =>
            {
                x.OnDestroyTetrimoView = DestroyTetrimino;
                x.blockPool            = mBlockPool;
            };

            //Checks for the json file
            var settingsFile = Resources.Load <TextAsset>(JSON_PATH);

            if (settingsFile == null)
            {
                throw new System.Exception(string.Format("GameSettings.json could not be found inside {0}. Create one in Window>GameSettings Creator.", JSON_PATH));
            }

            //Loads the GameSettings Json
            var json = settingsFile.text;

            mGameSettings = JsonUtility.FromJson <GameSettings>(json);
            mGameSettings.CheckValidSettings();
            timeToStep = mGameSettings.timeToStep;

            mPlayfield.setUpPlayfield(mGameSettings);
            mPlayfield.OnCurrentPieceReachBottom = CreateTetrimino;
            mPlayfield.OnGameOver    = SetGameOver;
            mPlayfield.OnDestroyLine = DestroyLine;

            if (multiplayer)
            {
                gameOverObject.SetActive(false);
                //GameOver.instance.HideScreen();
                //Score.instance.HideScreen();
            }
            else
            {
                GameOver.instance.HideScreen(0f);
                Score.instance.HideScreen();
            }

            //Display player controls from json file
            string controlsText = $"Rotate right: {mGameSettings.rotateRightKey}\n" +
                                  $"Rotate left: {mGameSettings.rotateLeftKey}\n" +
                                  $"Move: {mGameSettings.moveLeftKey}/{mGameSettings.moveRightKey}\n" +
                                  $"Lower: {mGameSettings.moveDownKey}\n" +
                                  $"Discard block: {mGameSettings.discardPieceKey}";

            controlsDisplay.text = controlsText;

            RestartGame();
            newGame = false;
        }
Esempio n. 2
0
        //Regular Unity Start method
        //Responsable for initiating all the pooling systems and the playfield
        public void Start()
        {
            if (!pv.IsMine)
            {
                return;
            }
            mBlockPool.createMoreIfNeeded = true;
            mBlockPool.Initialize(tetriminoBlockPrefab, null);

            mTetriminoPool.createMoreIfNeeded = true;
            mTetriminoPool.Initialize(new GameObject("BlockHolder", typeof(RectTransform)), tetriminoParent);
            mTetriminoPool.OnObjectCreationCallBack += x =>
            {
                x.OnDestroyTetrimoView = DestroyTetrimino;
                x.blockPool            = mBlockPool;
            };

            //Checks for the json file
            var settingsFile = Resources.Load <TextAsset>(JSON_PATH);

            if (settingsFile == null)
            {
                throw new System.Exception(string.Format("GameSettings.json could not be found inside {0}. Create one in Window>GameSettings Creator.", JSON_PATH));
            }

            //Loads the GameSettings Json
            var json = settingsFile.text;

            mGameSettings = JsonUtility.FromJson <GameSettings>(json);
            mGameSettings.CheckValidSettings();
            timeToStep = mGameSettings.timeToStep;
            Timer.instance.TimeRemaining = mGameSettings.timeAttackTime;

            mPlayfield.setUpPlayfield(mGameSettings);
            mPlayfield.OnCurrentPieceReachBottom = CreateTetrimino;
            mPlayfield.OnGameOver    = SetGameOver;
            mPlayfield.OnDestroyLine = DestroyLine;

            //GameOver.instance.HideScreen(0f);
            Score.instance.HideScreen();

            RestartGame();
        }
Esempio n. 3
0
        // Initiates pooling systems and playfield.
        public void Begin()
        {
            mBlockPool.createMoreIfNeeded = true;
            mBlockPool.Initialize(tetriminoBlockPrefab, null);

            mTetriminoPool.createMoreIfNeeded = true;
            mTetriminoPool.Initialize(new GameObject("BlockHolder", typeof(RectTransform)), tetriminoParent);
            mTetriminoPool.OnObjectCreationCallBack += x =>
            {
                x.OnDestroyTetrimoView = DestroyTetrimino;
                x.blockPool            = mBlockPool;
            };

            mPlayfield = new Playfield(mGameSettings);
            mPlayfield.OnCurrentPieceReachBottom = CreateTetrimino;
            mPlayfield.OnGameOver    = SetGameOver;
            mPlayfield.OnDestroyLine = DestroyLine;

            RestartGame();
        }
Esempio n. 4
0
        //Regular Unity Start method
        //Responsable for initiating all the pooling systems and the playfield
        public void Start()
        {
            mBlockPool.createMoreIfNeeded = true;
            mBlockPool.Initialize(tetriminoBlockPrefab, null);

            mTetriminoPool.createMoreIfNeeded = true;
            mTetriminoPool.Initialize(new GameObject("BlockHolder", typeof(RectTransform)), tetriminoParent);
            mTetriminoPool.OnObjectCreationCallBack += x =>
            {
                x.OnDestroyTetrimoView = DestroyTetrimino;
                x.blockPool            = mBlockPool;
            };

            //Checks for the json file
            if (!System.IO.File.Exists(JSON_PATH))
            {
                throw new System.Exception(string.Format("GameSettings.json could not be found inside {0}. Create one in Window>GameSettings Creator.", JSON_PATH));
            }

            //Loads the GameSettings Json
            var json = System.IO.File.ReadAllText(JSON_PATH);

            mGameSettings = JsonUtility.FromJson <GameSettings>(json);
            mGameSettings.CheckValidSettings();
            timeToStep = mGameSettings.timeToStep;

            mPlayfield = new Playfield(mGameSettings);
            mPlayfield.OnCurrentPieceReachBottom = CreateTetrimino;
            mPlayfield.OnGameOver    = SetGameOver;
            mPlayfield.OnDestroyLine = DestroyLine;

            GameOver.instance.HideScreen(0f);
            Score.instance.HideScreen();

            RestartGame();
        }
Esempio n. 5
0
        public void Initiate(DynamicScrollRect scrollRect, IList <T> infoList, int startIndex, GameObject objReference, bool createMoreIfNeeded = true, int?forceAmount = null)
        {
            ScrollRect = scrollRect;
            if (ScrollRect == null)
            {
                throw new Exception("No scroll rect in gameObject.");
            }

            if (objReference == null)
            {
                throw new Exception("No Reference GameObject setted.");
            }

            this.infoList = infoList;

            ScrollRect.onValueChanged.AddListener(OnScroll);
            ScrollRect.onBeginDrag.AddListener(OnBeginDrag);
            ScrollRect.onEndDrag.AddListener(OnEndDrag);
            ScrollRect.onStopMoving.AddListener(OnStopMoving);

            mMovementType = ScrollRect.movementType;
            ScrollRect.realMovementType = ScrollRect.movementType;
            ScrollRect.movementType     = UnityEngine.UI.ScrollRect.MovementType.Unrestricted;

            if (ScrollRect.content.GetComponent <VerticalLayoutGroup>() != null)
            {
                mVerticalLayoutGroup         = ScrollRect.content.GetComponent <VerticalLayoutGroup>();
                mVerticalLayoutGroup.spacing = spacing;
            }

            if (ScrollRect.content.GetComponent <HorizontalLayoutGroup>() != null)
            {
                mHorizontalLayoutGroup         = ScrollRect.content.GetComponent <HorizontalLayoutGroup>();
                mHorizontalLayoutGroup.spacing = spacing;
            }

            if (ScrollRect.content.GetComponent <GridLayoutGroup>() != null)
            {
                mGridLayoutGroup         = ScrollRect.content.GetComponent <GridLayoutGroup>();
                mGridLayoutGroup.spacing = new Vector2(spacing, spacing);
            }

            if (ScrollRect.content.GetComponent <ContentSizeFitter>() != null)
            {
                mContentSizeFitter = ScrollRect.content.GetComponent <ContentSizeFitter>();
            }

            mIsHorizontal = ScrollRect.horizontal;
            mIsVertical   = ScrollRect.vertical;

            objectPool.createMoreIfNeeded = createMoreIfNeeded;
            objectPool.Initialize(forceAmount ?? 0, objReference, ScrollRect.content);

            CreateList(startIndex);

            objectPool.ForEach(x =>
            {
                x.SetRefreshListAction(RefreshPosition);
                x.OnObjectIsNotCentralized();
            });

            SetCentralizedObject();
            DisableGridComponents();

            if (!mIsHorizontal || !mIsVertical)
            {
                return;
            }
            Debug.LogError("DynamicScroll doesn't support scrolling in both directions, please choose one direction (horizontal or vertical)");
            mIsHorizontal = false;
        }
Esempio n. 6
0
        public void Initiate(ScrollRect scrollRect, T[] infoList, int startIndex, GameObject objReference, int initialAmount, bool createMoreIfNeeded = true)
        {
            mScrollRect = scrollRect;
            if (mScrollRect == null)
            {
                throw new Exception("No scroll rect in gameObject.");
            }

            if (objReference == null)
            {
                throw new Exception("No Reference GameObject setted.");
            }

            mInitialAmount = initialAmount;

            mInfoList = infoList;
            var currentIndex = startIndex;

            mScrollRect.onValueChanged.AddListener(OnScroll);
            mScrollRect.movementType = ScrollRect.MovementType.Unrestricted;

            if (mScrollRect.content.GetComponent <VerticalLayoutGroup>() != null)
            {
                mVerticalLayoutGroup         = mScrollRect.content.GetComponent <VerticalLayoutGroup>();
                mVerticalLayoutGroup.spacing = spacing;
            }

            if (mScrollRect.content.GetComponent <HorizontalLayoutGroup>() != null)
            {
                mHorizontalLayoutGroup         = mScrollRect.content.GetComponent <HorizontalLayoutGroup>();
                mHorizontalLayoutGroup.spacing = spacing;
            }

            if (mScrollRect.content.GetComponent <GridLayoutGroup>() != null)
            {
                mGridLayoutGroup         = mScrollRect.content.GetComponent <GridLayoutGroup>();
                mGridLayoutGroup.spacing = new Vector2(spacing, spacing);
            }

            if (mScrollRect.content.GetComponent <ContentSizeFitter>() != null)
            {
                mContentSizeFitter = mScrollRect.content.GetComponent <ContentSizeFitter>();
            }

            mIsHorizontal = mScrollRect.horizontal;
            mIsVertical   = mScrollRect.vertical;

            objectPool.createMoreIfNeeded = createMoreIfNeeded;
            objectPool.Initialize(Mathf.Min(initialAmount, infoList.Length), objReference, mScrollRect.content);

            float totalSize          = 0f;
            int   toCreate           = Mathf.Min(initialAmount, infoList.Length);
            var   lastObjectPosition = Vector2.zero;

            for (var i = 0; i < toCreate; i++)
            {
                var obj = objectPool.Collect();
                obj.updateScrollObject(mInfoList[currentIndex + i], currentIndex + i);
                var rect = obj.GetComponent <RectTransform>();
                var posX = i > 0 ? lastObjectPosition.x + (mIsHorizontal ? +spacing : 0) : 0;
                var posY = i > 0 ? lastObjectPosition.y - (mIsVertical ? spacing : 0) : 0;
                rect.anchoredPosition = new Vector2(posX, posY);
                lastObjectPosition    = new Vector2(posX + (mIsHorizontal ? obj.currentWidth : 0), posY - (mIsVertical ? obj.currentHeight : 0));

                totalSize += (mIsVertical) ? obj.currentHeight : obj.currentWidth;
            }

            totalSize = (totalSize / (float)toCreate) * infoList.Length;
            bool canDrag = (mIsHorizontal && totalSize > mScrollRect.content.rect.width) || (mIsVertical && totalSize > mScrollRect.content.rect.height);

            ToggleScroll(canDrag);

            DisableGridComponents();

            objectPool.ForEach(x => x.SetRefreshListAction(RefreshPosition));

            if (!mIsHorizontal || !mIsVertical)
            {
                return;
            }
            Debug.LogError("AssukarSynamicScroll doesn't support scrolling in both directions, please choose one direction (horizontal or vertical)");
            mIsHorizontal = false;
        }
Esempio n. 7
0
 void Start()
 {
     mPooling.OnObjectCreationCallBack += OnCreateObject;
     mPooling.Initialize(10, referenceObject, transform);
 }