コード例 #1
0
    //public delegate void gameStateHandler(GameStateController.gameState newState);
    //public static event gameStateHandler onStateChange;

    public void Awake()
    {
        Instance     = this;
        currentState = gameState.idle;

        destroyUnit = DestroyChainedUnit.Instance;
        puzzleGen   = GeneratingPuzzle.Instance;

        gameOverPanelRectTransform  = gameOverPanel.GetComponent <RectTransform>();
        pauseGamePanelRectTransform = pauseGamePanel.GetComponent <RectTransform>();
    }
コード例 #2
0
    void Start()
    {
        puzzleGen    = GeneratingPuzzle.Instance;
        destroyUnit  = DestroyChainedUnit.Instance;
        _unitLayer   = LayerMask.GetMask("Unit");
        _unitsHolder = GeneratingPuzzle.Instance._unitsHolder;

        _unitHighLight.SetActive(false);
        _horizontalHighlightBeginPos = puzzleGen._unitPosARR[0, 0].x;
        _horizontalHighlightEndPos   = puzzleGen._unitPosARR[puzzleGen._columns - 1, 0].x + puzzleGen._unitWidth;
        _verticalHighlightBeginPos   = puzzleGen._unitPosARR[0, 0].y;
        _verticalHighlightEndPos     = puzzleGen._unitPosARR[0, puzzleGen._rows - 1].y + puzzleGen._unitHeight;

        StartCoroutine(controlMovingUnits());
    }
コード例 #3
0
    void Start()
    {
        puzzleGen = GeneratingPuzzle.Instance;
        destroyUnit = DestroyChainedUnit.Instance;
        _unitLayer = LayerMask.GetMask("Unit");
        _unitsHolder = GeneratingPuzzle.Instance._unitsHolder;

        _unitHighLight.SetActive(false);
        _horizontalHighlightBeginPos = puzzleGen._unitPosARR[0, 0].x;
        _horizontalHighlightEndPos = puzzleGen._unitPosARR[puzzleGen._columns - 1, 0].x + puzzleGen._unitWidth;
        _verticalHighlightBeginPos = puzzleGen._unitPosARR[0, 0].y;
        _verticalHighlightEndPos = puzzleGen._unitPosARR[0, puzzleGen._rows - 1].y + puzzleGen._unitHeight;

        StartCoroutine(controlMovingUnits());
    }
コード例 #4
0
 //private InputHandler inputHandler;
 //==============================================
 // Unity Methods
 //==============================================
 void Awake()
 {
     Instance = this;
 }
コード例 #5
0
    void Start()
    {
        destroyUnit = DestroyChainedUnit.Instance;

        _unitsHolder = new GameObject("Units Holder").transform;
        _borderHolder = new GameObject("Borders Holder").transform;

        // Identify some information of the Puzzle
        _unitHeight = _unitPrefabsContainer[0].GetComponent<SpriteRenderer>().bounds.size.y;
        _unitWidth = _unitPrefabsContainer[0].GetComponent<SpriteRenderer>().bounds.size.x;
        float cameraHeight = Camera.main.orthographicSize * 2;
        float cameraWidth = cameraHeight * Camera.main.aspect;
        _YOffset = (cameraHeight - _unitHeight * _rows) / 2;
        _XOffset = (cameraWidth - _unitWidth * _columns) / 2;

        // Generating value matrix
        _valueARR = generateValueMatrix();

        // Init Unit position Array
        _unitPosARR = new Vector3[_columns, _rows];

        // Init Unit gameobject Array
        _unitARR = new GameObject[_columns, _rows];

        // Identify each Unit infomation and Instantiate It
        for (int YIndex = 0; YIndex < _rows; YIndex++)
        {
            for (int XIndex = 0; XIndex < _columns; XIndex++)
            {
                // Identify position for each Unit
                _unitPosARR[XIndex, YIndex] = new Vector3(_XOffset + _unitWidth * XIndex,
                                                        _YOffset + _unitHeight * YIndex,
                                                        _unitPrefabsContainer[0].transform.position.z);
                // Instantiate Unit
                _unitARR[XIndex, YIndex] = Instantiate(_unitPrefabsContainer[_valueARR[XIndex, YIndex]._value],
                                                    _unitPosARR[XIndex, YIndex],
                                                    Quaternion.identity) as GameObject;
                _unitARR[XIndex, YIndex].transform.SetParent(_unitsHolder);
                // Set information for each Unit
                _unitARR[XIndex, YIndex].GetComponent<UnitInfo>()._value = _valueARR[XIndex, YIndex]._value;
                _unitARR[XIndex, YIndex].GetComponent<UnitInfo>()._XIndex = XIndex;
                _unitARR[XIndex, YIndex].GetComponent<UnitInfo>()._YIndex = YIndex;
            }
        }

        #region Insantiate Puzzle border

        // Left side border
        for (int Yindex = 0; Yindex < _rows; Yindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[0, Yindex].x, _unitPosARR[0, Yindex].y + _unitHeight),
                                                Quaternion.Euler(0, 0, 180)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Right side border
        for (int Yindex = 0; Yindex < _rows; Yindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[_columns - 1, Yindex].x + _unitWidth, _unitPosARR[_columns - 1, Yindex].y),
                                                Quaternion.identity) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Lower side border
        for (int Xindex = 0; Xindex < _columns; Xindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[Xindex, 0].x, _unitPosARR[Xindex, 0].y),
                                                Quaternion.Euler(0, 0, -90)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Upper side border
        for (int Xindex = 0; Xindex < _columns; Xindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[Xindex, _rows - 1].x + _unitWidth, _unitPosARR[Xindex, _rows - 1].y + _unitHeight),
                                                Quaternion.Euler(0, 0, 90)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Four border corner
        GameObject portalCorner = Instantiate(_portalCornerPrefab,
                                                new Vector2(_unitPosARR[0, 0].x - _unitWidth, _unitPosARR[0, 0].y - _unitHeight),
                                                Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[_columns - 1, 0].x + _unitWidth, _unitPosARR[_columns - 1, 0].y - _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[0, _rows - 1].x - _unitWidth, _unitPosARR[0, _rows - 1].y + _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[_columns - 1, _rows - 1].x + _unitWidth, _unitPosARR[_columns - 1, _rows - 1].y + _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        #endregion
    }
コード例 #6
0
    void Start()
    {
        destroyUnit = DestroyChainedUnit.Instance;

        _unitsHolder  = new GameObject("Units Holder").transform;
        _borderHolder = new GameObject("Borders Holder").transform;

        // Identify some information of the Puzzle
        _unitHeight = _unitPrefabsContainer[0].GetComponent <SpriteRenderer>().bounds.size.y;
        _unitWidth  = _unitPrefabsContainer[0].GetComponent <SpriteRenderer>().bounds.size.x;
        float cameraHeight = Camera.main.orthographicSize * 2;
        float cameraWidth  = cameraHeight * Camera.main.aspect;

        _YOffset = (cameraHeight - _unitHeight * _rows) / 2;
        _XOffset = (cameraWidth - _unitWidth * _columns) / 2;

        // Generating value matrix
        _valueARR = generateValueMatrix();

        // Init Unit position Array
        _unitPosARR = new Vector3[_columns, _rows];

        // Init Unit gameobject Array
        _unitARR = new GameObject[_columns, _rows];

        // Identify each Unit infomation and Instantiate It
        for (int YIndex = 0; YIndex < _rows; YIndex++)
        {
            for (int XIndex = 0; XIndex < _columns; XIndex++)
            {
                // Identify position for each Unit
                _unitPosARR[XIndex, YIndex] = new Vector3(_XOffset + _unitWidth * XIndex,
                                                          _YOffset + _unitHeight * YIndex,
                                                          _unitPrefabsContainer[0].transform.position.z);
                // Instantiate Unit
                _unitARR[XIndex, YIndex] = Instantiate(_unitPrefabsContainer[_valueARR[XIndex, YIndex]._value],
                                                       _unitPosARR[XIndex, YIndex],
                                                       Quaternion.identity) as GameObject;
                _unitARR[XIndex, YIndex].transform.SetParent(_unitsHolder);
                // Set information for each Unit
                _unitARR[XIndex, YIndex].GetComponent <UnitInfo>()._value  = _valueARR[XIndex, YIndex]._value;
                _unitARR[XIndex, YIndex].GetComponent <UnitInfo>()._XIndex = XIndex;
                _unitARR[XIndex, YIndex].GetComponent <UnitInfo>()._YIndex = YIndex;
            }
        }

        #region Insantiate Puzzle border

        // Left side border
        for (int Yindex = 0; Yindex < _rows; Yindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[0, Yindex].x, _unitPosARR[0, Yindex].y + _unitHeight),
                                                Quaternion.Euler(0, 0, 180)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Right side border
        for (int Yindex = 0; Yindex < _rows; Yindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[_columns - 1, Yindex].x + _unitWidth, _unitPosARR[_columns - 1, Yindex].y),
                                                Quaternion.identity) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Lower side border
        for (int Xindex = 0; Xindex < _columns; Xindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[Xindex, 0].x, _unitPosARR[Xindex, 0].y),
                                                Quaternion.Euler(0, 0, -90)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Upper side border
        for (int Xindex = 0; Xindex < _columns; Xindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[Xindex, _rows - 1].x + _unitWidth, _unitPosARR[Xindex, _rows - 1].y + _unitHeight),
                                                Quaternion.Euler(0, 0, 90)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Four border corner
        GameObject portalCorner = Instantiate(_portalCornerPrefab,
                                              new Vector2(_unitPosARR[0, 0].x - _unitWidth, _unitPosARR[0, 0].y - _unitHeight),
                                              Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[_columns - 1, 0].x + _unitWidth, _unitPosARR[_columns - 1, 0].y - _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[0, _rows - 1].x - _unitWidth, _unitPosARR[0, _rows - 1].y + _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[_columns - 1, _rows - 1].x + _unitWidth, _unitPosARR[_columns - 1, _rows - 1].y + _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        #endregion
    }
コード例 #7
0
    //private InputHandler inputHandler;

    //==============================================
    // Unity Methods
    //==============================================

    void Awake()
    {
        Instance = this;
    }
コード例 #8
0
    void Start()
    {
        destroyUnit           = DestroyChainedUnit.Instance;
        unitImageControl      = UnitImageController.Instance;
        _unitPrefabsContainer = unitImageControl.UnitsPrefabsContainer;

        _unitsHolder  = new GameObject("Units Holder").transform;
        _borderHolder = new GameObject("Borders Holder").transform;

        // Identify some information of the Puzzle
        _unitHeight = _unitPrefabsContainer[0].GetComponent <SpriteRenderer>().bounds.size.y;
        _unitWidth  = _unitPrefabsContainer[0].GetComponent <SpriteRenderer>().bounds.size.x;
        float cameraHeight = Camera.main.orthographicSize * 2;
        float cameraWidth  = cameraHeight * Camera.main.aspect;

        float _pixelUnitHeight  = _unitPrefabsContainer[0].GetComponent <SpriteRenderer>().sprite.texture.height;
        float _pixelUnitWidth   = _unitPrefabsContainer[0].GetComponent <SpriteRenderer>().sprite.texture.width;
        float pixelCameraHeight = Camera.main.pixelHeight;
        float pixelCameraWidth  = Camera.main.pixelWidth;

        // Puzzle starting's position
        float pixelYOffset = (cameraHeight - _unitHeight * _rows) / 2 * (pixelCameraHeight / cameraHeight);
        float pixelXOffset = (cameraWidth - _unitWidth * _columns) / 2 * (pixelCameraWidth / cameraWidth);

        _YOffset = Camera.main.ScreenToWorldPoint(new Vector3(0, pixelYOffset, 0)).y;
        _XOffset = Camera.main.ScreenToWorldPoint(new Vector3(pixelXOffset, 0, 0)).x;

        // Scale foreground covering to fit current puzzle
        float fillSize = cameraHeight - (_unitHeight * (_rows + 1) + _YOffset);

        _coverForeground.GetComponent <Image>().fillAmount = (fillSize / cameraHeight);

        // Generating value matrix
        _valueARR = generateValueMatrix();

        // Init Unit position Array
        _unitPosARR = new Vector3[_columns, _rows];

        // Init Unit gameobject Array
        _unitARR = new GameObject[_columns, _rows];

        // Identify each Unit infomation and Instantiate It
        for (int YIndex = 0; YIndex < _rows; YIndex++)
        {
            for (int XIndex = 0; XIndex < _columns; XIndex++)
            {
                // Identify position for each Unit
                _unitPosARR[XIndex, YIndex] = new Vector3(_XOffset + _unitWidth * XIndex,
                                                          _YOffset + _unitHeight * YIndex,
                                                          _unitPrefabsContainer[0].transform.position.z);
                // Instantiate Unit
                _unitARR[XIndex, YIndex] = Instantiate(_unitPrefabsContainer[_valueARR[XIndex, YIndex]._value],
                                                       _unitPosARR[XIndex, YIndex],
                                                       Quaternion.identity) as GameObject;
                _unitARR[XIndex, YIndex].transform.SetParent(_unitsHolder);
                // Set information for each Unit
                _unitARR[XIndex, YIndex].GetComponent <UnitInfo>()._value  = _valueARR[XIndex, YIndex]._value;
                _unitARR[XIndex, YIndex].GetComponent <UnitInfo>()._XIndex = XIndex;
                _unitARR[XIndex, YIndex].GetComponent <UnitInfo>()._YIndex = YIndex;
            }
        }

        #region Insantiate Puzzle border

        // Left side border
        for (int Yindex = 0; Yindex < _rows; Yindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[0, Yindex].x, _unitPosARR[0, Yindex].y + _unitHeight),
                                                Quaternion.Euler(0, 0, 180)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Right side border
        for (int Yindex = 0; Yindex < _rows; Yindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[_columns - 1, Yindex].x + _unitWidth, _unitPosARR[_columns - 1, Yindex].y),
                                                Quaternion.identity) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Lower side border
        for (int Xindex = 0; Xindex < _columns; Xindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[Xindex, 0].x, _unitPosARR[Xindex, 0].y),
                                                Quaternion.Euler(0, 0, -90)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Upper side border
        for (int Xindex = 0; Xindex < _columns; Xindex++)
        {
            GameObject portalGate = Instantiate(_portalGatePrefab,
                                                new Vector2(_unitPosARR[Xindex, _rows - 1].x + _unitWidth, _unitPosARR[Xindex, _rows - 1].y + _unitHeight),
                                                Quaternion.Euler(0, 0, 90)) as GameObject;
            portalGate.transform.SetParent(_borderHolder);
        }
        // Four border corner
        GameObject portalCorner = Instantiate(_portalCornerPrefab,
                                              new Vector2(_unitPosARR[0, 0].x - _unitWidth, _unitPosARR[0, 0].y - _unitHeight),
                                              Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[_columns - 1, 0].x + _unitWidth, _unitPosARR[_columns - 1, 0].y - _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[0, _rows - 1].x - _unitWidth, _unitPosARR[0, _rows - 1].y + _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        portalCorner = Instantiate(_portalCornerPrefab,
                                   new Vector2(_unitPosARR[_columns - 1, _rows - 1].x + _unitWidth, _unitPosARR[_columns - 1, _rows - 1].y + _unitHeight),
                                   Quaternion.identity) as GameObject;
        portalCorner.transform.SetParent(_borderHolder);
        #endregion
    }