public Scoring_Block LoadBinaryData()
 {
     return(BinarySerializor.DeserializeFromBinary <Scoring_Block>(Application.streamingAssetsPath + "/Data/ScoreSystem.sco"));
 }
Esempio n. 2
0
    public bool LoadScene(string path)
    {
        ClearSceneBlocks();
#if UNITY_EDITOR
        path = "file:///" + path;
#endif
#if UNITY_ANDROID
        //quick hack to get an object to start the coroutine
        return(LoadLevel_Android_Coroutine(path));
#else
        if (goal_block == null)
        {
            Init();
        }
        List <Portal_And_Reference_Pair> portals = new List <Portal_And_Reference_Pair>();
#if UNITY_EDITOR
        if (!EditorSceneManager.GetActiveScene().name.Contains(StaticString.MasterGameScene))
        {
            EditorSceneManager.OpenScene("Assets/Scenes/MasterGameScene.unity");
        }
        else
        {
            ClearSceneBlocks();
        }
#endif
        scene = BinarySerializor.DeserializeFromBinary <Scene_Block>(path);

        Direction currentDirection = Direction.none;
        Transform grid             = GameObject.Find("Grid").transform;
        Transform fakegrid         = GameObject.Find("FakeGrid").transform;
        fakegrid.transform.position = grid.position;
        GameObject objectToSpawn;
        foreach (block_data data in scene.blocks)
        {
            //identify the block we are working with.
            switch (data.type)
            {
            case blockType.goal:
                objectToSpawn = goal_block;
                break;

            case blockType.iron:
                objectToSpawn = iron_block;
                break;

            case blockType.one_way_b:
                objectToSpawn    = oneway_block_b;
                currentDirection = data.direction;
                break;

            case blockType.one_way_g:
                objectToSpawn    = oneway_block_g;
                currentDirection = data.direction;
                break;

            case blockType.portal:
                objectToSpawn = portal_block;
                break;

            case blockType.vortex:
                objectToSpawn = vortex_block;
                break;

            case blockType.walls:
                objectToSpawn = wall_block;
                break;

            case blockType.wooden:
                objectToSpawn = wood_block;
                break;

            default:
                Debug.LogWarning("block type unknown");
                objectToSpawn = null;
                break;
            }
            GameObject obj = GameObject.Instantiate(objectToSpawn, new Vector3(data.pos.x, data.pos.y, data.pos.z), Quaternion.identity, grid);
            obj.transform.localScale = new Vector3(data.scale.x, data.scale.y, data.scale.z);
            if (currentDirection != Direction.none)
            {
                if (data.type == blockType.one_way_b)
                {
                    obj.GetComponent <OneWayBlock>().currentDirection = data.direction;
                }
                else if (data.type == blockType.one_way_g)
                {
                    obj.GetComponent <OneWayGate>().currentDirection = data.direction;
                }
            }
            if (data.type == blockType.portal)
            {
                portals.Add(new Portal_And_Reference_Pair(obj.GetComponent <Portal>(), new Vector3(data.portal_ref_pos.x, data.portal_ref_pos.y, data.portal_ref_pos.z)));
            }
            GameObject.Instantiate(obj, fakegrid);
        }
        //Handle Portals if any

        for (int count = 0; count < portals.Count; count++)
        {
            Portal otherPortal = null;
            for (int k = 0; k < portals.Count; k++)
            {
                if (portals[k].portal.transform.position == portals[count].Pos)
                {
                    otherPortal = portals[k].portal;
                    break;
                }
            }
            if (otherPortal == null)
            {
                Debug.LogWarning("Cannot find ref portal. Error!");
            }
            portals[count].portal.OtherPortal = otherPortal;
        }


        Debug.Log("Successfully loaded");
        Current_World = scene.world; Current_Level = scene.level;

        PlayerPrefs.SetInt(StaticString.CurrentWorld, Current_World);
        PlayerPrefs.SetInt(StaticString.CurrentLevel, Current_Level);

        fakegrid.localPosition = Vector3.zero;
        #endif
    }