public override void Destroy(bool isDestroyedByBoundry)
    {
        onDestroy();
        if (!isDestroyedByBoundry) // && WorldBoundsArea.instance.IsInWordBounrds(transform.position))
        {
            if (spawnAll)
            {
                foreach (GameObject gameObjectToInit in objectsToRespawnOnDestroyPrefs)
                {
                    GameObject spawnedObj = SpawnsPoolManager.instance.SpawnableObject(gameObjectToInit);
                    spawnedObj.transform.position = transform.position;
                }
            }
            else
            {
                GameObject spawnedObj   = null;
                int        indexToSpawn = CalcTool.GetNumberAccordingToDistribution(spawnDistribution);
                if (indexToSpawn != -1)
                {
                    spawnedObj = SpawnsPoolManager.instance.SpawnableObject(objectsToRespawnOnDestroyPrefs[indexToSpawn]);
                    spawnedObj.transform.position = transform.position;
                }
            }
        }

        SpawnsPoolManager.instance.AddUnactivateObject(this);
        gameObject.SetActive(false);
    }
示例#2
0
    /// <summary>
    /// Return a random astroid with respect to the defined distribution probabilies
    /// </summary>
    /// <returns>GameObject of Astroid Prefab, or null if none was selected</returns>
    private GameObject SpawnAstroidWithRespecdToDistribution()
    {
        GameObject asteroid     = null;
        int        indexToSpawn = CalcTool.GetNumberAccordingToDistribution(spawnDistribution);

        if (indexToSpawn != -1)
        {
            asteroid = SpawnsPoolManager.instance.SpawnableObject(astroidsTypes[indexToSpawn]);
            InitAstroid(asteroid);
            return(asteroid);
        }
        return(asteroid);
    }
示例#3
0
    /// <summary>
    /// Setting the 8 borders and the game bound locations and dimentions.
    /// </summary>
    private void InitBordersRange()
    {
        (float, float)screenDimentions = CalcTool.GetScreenSize();
        float frustumWidth  = screenDimentions.Item1;
        float frustumHeight = screenDimentions.Item2;
        float x             = 2f * Camera.main.orthographicSize * Camera.main.aspect;

        // calculating the ui dimention according to it precent of the screen sizes.
        Vector3 rightUIDimentionsRatio = leftPanelReactTran.anchorMax - leftPanelReactTran.anchorMin;
        Vector3 leftUIDimentionsRatio  = rightPanelReactTran.anchorMax - rightPanelReactTran.anchorMin;
        Vector3 rightUIDimentions      = new Vector3(frustumWidth * rightUIDimentionsRatio.x, frustumHeight * rightUIDimentionsRatio.y, 1);
        Vector3 leftUIDimentions       = new Vector3(frustumWidth * leftUIDimentionsRatio.x, frustumHeight * leftUIDimentionsRatio.y, 1);
        Vector3 camPos = Camera.main.transform.position;

        // setting borders widht
        rightBorder.size  = rightUIDimentions;
        leftBorder.size   = leftUIDimentions;
        topBorder.size    = new Vector3(frustumWidth - rightUIDimentions.x - leftUIDimentions.x, 1, 1);
        bottomBorder.size = new Vector3(frustumWidth - rightUIDimentions.x - leftUIDimentions.x, 1, 1);

        topRightBorder.size    = new Vector3(rightBorder.size.x, topBorder.size.y, 0);
        topLeftBorder.size     = new Vector3(leftBorder.size.x, topBorder.size.y, 0);
        bottomRightBorder.size = new Vector3(rightBorder.size.x, bottomBorder.size.y, 0);
        bottomLeftBorder.size  = new Vector3(leftBorder.size.x, bottomBorder.size.y, 0);
        // Setting borders pos
        topBorder.transform.position    = new Vector3(0, camPos.y + frustumHeight / 2 + topBorder.size.y / 2, 0);
        bottomBorder.transform.position = new Vector3(0, camPos.y - (frustumHeight / 2 + bottomBorder.size.y / 2), 0);
        rightBorder.transform.position  = new Vector3(camPos.x + frustumWidth / 2 - rightBorder.size.x / 2, 0, 0);
        leftBorder.transform.position   = new Vector3(camPos.x - (frustumWidth / 2 - leftBorder.size.x / 2), 0, 0);

        topRightBorder.transform.position    = new Vector3(rightBorder.transform.position.x, topBorder.transform.position.y, 0);
        topLeftBorder.transform.position     = new Vector3(leftBorder.transform.position.x, topBorder.transform.position.y, 0);
        bottomRightBorder.transform.position = new Vector3(rightBorder.transform.position.x, bottomBorder.transform.position.y, 0);
        bottomLeftBorder.transform.position  = new Vector3(leftBorder.transform.position.x, bottomBorder.transform.position.y, 0);

        // setting game playing area
        worldBounds.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, 0);
        worldBounds.size = new Vector3(frustumWidth /*- _spaceshipSize*/ - rightUIDimentions.x - leftUIDimentions.x, frustumHeight /*- _spaceshipSize*/, 1f);
    }