Пример #1
0
    void OnEnable()
    {
        projPool = PoolManager.Instance.GetPoolByRepresentative(projectile);
        float initSpeed = Random.Range(initSpeedMin, initSpeedMax);

        rigidbody2D.velocity        = -Vector2.right * initSpeed;
        rigidbody2D.angularVelocity = RandomUtil.GetRandomElement(new int[] { -1, 1 }) * initSpeed * 5;
    }
Пример #2
0
 public Sprite GetTile(string type)
 {
     if (mixedTiles)
     {
         return(RandomUtil.GetRandomElement(tiles[type]));
     }
     else
     {
         return(GetTile(type, currentGroup));
     }
 }
Пример #3
0
 void SetPanelTextures(GameObject p, TileSet tileSet)
 {
     MeshRenderer[] cRenderers = p.GetComponentsInChildren <MeshRenderer>();
     foreach (MeshRenderer renderer in cRenderers)
     {
         renderer.material = RandomUtil.GetRandomElement(tileSet.backdrops);
         renderer.material.mainTextureScale = new Vector2(RandomUtil.GetRandomElement(textureScales),
                                                          RandomUtil.GetRandomElement(textureScales));
         //renderer.material.mainTextureOffset = new Vector2(Random.Range (0f,0.25f), Random.Range (0f,0.25f));
     }
 }
Пример #4
0
    public void CreateBackgroundObj(TileSet tileSet, Vector3 center)
    {
        GameObject rep    = null;
        Transform  parent = null;
        Vector2    pos    = center + RandomUtil.RandomInsideBounds(spawnArea);

        if (tileSet.backgroundObj.Count > 0 && tileSet.middlegroundObj.Count > 0 &&
            numBackgroundActive < numBackgroundObj && numMiddlegroundActive < numMiddlegroundObj)
        {
            if (Random.value < 0.5)
            {
                rep    = RandomUtil.GetRandomElement(tileSet.backgroundObj);
                parent = backLayer;
            }
            else
            {
                rep    = RandomUtil.GetRandomElement(tileSet.middlegroundObj);
                parent = middleLayer;
            }
        }
        else if (tileSet.backgroundObj.Count > 0 && numBackgroundActive < numBackgroundObj)
        {
            rep    = RandomUtil.GetRandomElement(tileSet.backgroundObj);
            parent = backLayer;
        }
        else if (tileSet.middlegroundObj.Count > 0 && numMiddlegroundActive < numMiddlegroundObj)
        {
            rep    = RandomUtil.GetRandomElement(tileSet.middlegroundObj);
            parent = middleLayer;
        }
        if (rep != null && parent != null)
        {
            GameObject obj = PoolManager.Instance.GetPoolByRepresentative(rep).GetPooled();
            obj.transform.parent = parent;
            //move into position using any offsets on the rep
            obj.transform.position   = new Vector3(pos.x, pos.y, parent.position.z + rep.transform.position.z);
            obj.transform.localScale = rep.transform.localScale;
            if (parent.GetInstanceID() == middleLayer.GetInstanceID())
            {
                obj.GetComponent <SpriteRenderer>().sortingLayerName = "Middleground";
                numMiddlegroundActive++;
            }
            else
            {
                obj.GetComponent <SpriteRenderer>().sortingLayerName = "Background";
                numBackgroundActive++;
            }
            obj.SetActive(true);
            Debug.Log("In tileset " + tileSet.name + " creating " + rep.name);
        }
    }
Пример #5
0
 void GenAirObstacle(float width)
 {
     if (tileSet.airObstacles.Count > 0)
     {
         GameObject obstRep = RandomUtil.GetRandomElement(tileSet.airObstacles);
         Vector2    pos     = nextPos + new Vector2(Random.Range(-width / 2, width / 2), Random.Range(4f, 6f));
         GameObject obst    = PoolManager.Instance.GetPoolByRepresentative(obstRep).GetPooled();
         if (obst != null)
         {
             obst.transform.position = pos;
             obst.SetActive(true);
             activeObst++;
         }
     }
 }
Пример #6
0
 void GenPlatformObstacle(float width)
 {
     if (tileSet.platformObstacles.Count > 0)
     {
         GameObject obstRep = RandomUtil.GetRandomElement(tileSet.platformObstacles);
         Vector2    pos     = nextPos + new Vector2(Random.Range(-width / 2, width / 2), 3);
         GameObject obst    = PoolManager.Instance.GetPoolByRepresentative(obstRep).GetPooled();
         if (obst != null)
         {
             obst.transform.position = pos;
             //TODO properly move the obst up so it's above the platform
             obst.SetActive(true);
             activeObst++;
         }
     }
 }
Пример #7
0
    void SetSprites()
    {
        if (tiles.Count < width)
        {
            AddSpriteRenderers(tiles, width - tiles.Count);
        }
        Sprite nextTile;

        tileSet.SetGroupRandom();
        if (width == 1)
        {
            nextTile = tileSet.GetTile("Block");
        }
        else
        {
            nextTile = tileSet.GetTile("Left");
        }
        for (int i = 0; i < width; i++)
        {
            tiles[i].enabled            = true;
            tiles[i].sprite             = nextTile;
            tiles[i].transform.position = transform.position -
                                          new Vector3(actualWidth / 2 - tileSet.tileWidth / 2 - i * tileSet.tileWidth, 0);
            if (i == width - 2)
            {
                nextTile = tileSet.GetTile("Right");
            }
            else
            {
                nextTile = tileSet.GetTile("Mid");
            }
        }
        //create a base for the platform, if it exists
        int baseHeight = 15;

        if (tileSet.platformBases != null && tileSet.platformBases.Count > 0)
        {
            AddSpriteRenderers(tiles, (baseHeight + width) - tiles.Count);
            for (int i = width; i < width + baseHeight; i++)
            {
                tiles[i].sprite             = RandomUtil.GetRandomElement(tileSet.platformBases);
                tiles[i].enabled            = true;
                tiles[i].transform.position = transform.position - new Vector3(0, boxCollider.size.y / 2 + tileSet.tileWidth * (i - width));
                tiles[i].sortingOrder       = -2;
            }
        }
    }