Exemplo n.º 1
0
 //get prefab from shape&surface
 public GameObject GetPlatformPrefab(Platform.e_platformShape _shape, Platform.e_platformSurface _surface)
 {
     foreach (GameObject prefab in platformPrefabs)
     {
         Platform platformScr = prefab.GetComponent <Platform>();
         if (platformScr.platformShape == _shape && platformScr.platformSurface == _surface)
         {
             return(prefab);
         }
     }
     //Debug.Log(platformScr.platformShape + " = " + _shape + " --- " + platformScr.platformSurface + " = " + _surface);
     Debug.Log(_shape + " " + _surface);
     return(null);
 }
Exemplo n.º 2
0
    void LoadMovablePlatforms(int _category, int _level)
    {
        LevelDesignInfo levelDesign = LevelDesignInfo.LoadLevelDesign(_category, _level);

        if (levelDesign == null || levelDesign.platEnvironmentInfos == null || levelDesign.platMovableInfos == null)
        {
            return;
        }

        float distanceBtwObjects = 0.07f;
        float xSpaceTaken        = 0;

        //calculate x length that all movable objects will take + distance between every one
        foreach (PlatformMovableInfo platInfo in levelDesign.platMovableInfos)
        {
            Platform.e_platformShape   shape   = (Platform.e_platformShape)platInfo.shape;
            Platform.e_platformSurface surface = (Platform.e_platformSurface)platInfo.surface;
            float objLength = LevelObjectsPrefabHolder.s_instance.GetPlatformPrefab(shape, surface).GetComponent <SpriteRenderer>().bounds.size.x;
            xSpaceTaken += objLength + distanceBtwObjects;
        }

        Vector2 spawnPoint   = new Vector2(box.transform.position.x - xSpaceTaken / 2, box.transform.position.y);
        float   prevObjWidth = 0f;

        //create movable platforms
        foreach (PlatformMovableInfo platInfo in levelDesign.platMovableInfos)
        {
            Platform.e_platformShape   shape   = (Platform.e_platformShape)platInfo.shape;
            Platform.e_platformSurface surface = (Platform.e_platformSurface)platInfo.surface;
            GameObject platformPrefab          = LevelObjectsPrefabHolder.s_instance.GetPlatformPrefab(shape, surface);

            float thisObjectWidth = platformPrefab.GetComponent <SpriteRenderer>().bounds.size.x;
            spawnPoint = new Vector2(spawnPoint.x + thisObjectWidth / 2 + prevObjWidth / 2 + distanceBtwObjects, spawnPoint.y);
            GameObject platformInstance = (GameObject)Instantiate(platformPrefab, spawnPoint, Quaternion.identity);
            prevObjWidth = platformPrefab.GetComponent <SpriteRenderer>().bounds.size.x;

            platformInstance.GetComponent <TransformPositionInGame>().SetMovableObjectSettings();
            platformInstance.GetComponent <TransformRotationInGame>().SetMovableObjectSettings();
            list_movablePlatforms.Add(platformInstance);
        }
    }
Exemplo n.º 3
0
    void InitLevel(int _category, int _level)
    {
        if (!LevelDesignInfo.DoesLevelDesignExists(_category, _level))
        {
            Debug.Log("level does not exist in json");
            return;
        }
        //if exists get it...
        LevelDesignInfo levelDesign = LevelDesignInfo.LoadLevelDesign(_category, _level);

        //set current category and level
        world = levelDesign.categoryID;
        level = levelDesign.levelID;

        //set environment platforms
        foreach (PlatformEnvironmentInfo platInfo in levelDesign.platEnvironmentInfos)
        {
            Platform.e_platformShape   shape   = (Platform.e_platformShape)platInfo.shape;
            Platform.e_platformSurface surface = (Platform.e_platformSurface)platInfo.surface;
            GameObject platformPrefab          = LevelObjectsPrefabHolder.s_instance.GetPlatformPrefab(shape, surface);
            GameObject platformInstance        = (GameObject)Instantiate(platformPrefab, new Vector2((float)platInfo.posX, (float)platInfo.posY), Quaternion.identity);

            platformInstance.GetComponent <TransformPositionInGame>().SetEnvironmentObjectSettings();
            platformInstance.GetComponent <TransformRotationInGame>().SetEnvironmentObjectSettings();

            platformInstance.transform.eulerAngles = new Vector3(0, 0, (float)platInfo.rotZ);
            list_environmentPlatforms.Add(platformInstance);
        }

        //start/end line
        Vector2 startLinePos = new Vector2((float)levelDesign.startX, (float)levelDesign.startY);
        Vector2 endLinePos   = new Vector2((float)levelDesign.endX, (float)levelDesign.endY);

        startLine = (GameObject)Instantiate(LevelObjectsPrefabHolder.s_instance.GetStartLinePrefab(), startLinePos, Quaternion.identity);
        endLine   = (GameObject)Instantiate(LevelObjectsPrefabHolder.s_instance.GetEndLinePrefab(), endLinePos, Quaternion.identity);
        startLine.GetComponent <TransformPositionInGame>().SetEnvironmentObjectSettings();
        endLine.GetComponent <TransformPositionInGame>().SetEnvironmentObjectSettings();
    }