public bool SaveBinaryData(Scoring_Block blk)
 {
     return(BinarySerializor.SerializeToBinary <Scoring_Block>(Application.streamingAssetsPath + "/Data/ScoreSystem.sco", blk));
 }
Exemplo n.º 2
0
    //Don't use this at runtime. PLEASE.
    public void SaveScene(bool edit = false)
    {
        int world, level;

        if (!edit)
        {
            //If the scenes are the deprecated scenes we are using.
            if (EditorSceneManager.GetActiveScene().name.Contains("Level"))
            {
                //OLD METHOD
                Vector2 temp = updateinternalworldlevel();

                world = (int)temp.x;
                level = (int)temp.y;
            }
            else
            {
                //this must be the new method, aka using the masterscene
                world = new_world;
                level = new_level;
                GameObject GameSystem = GameObject.FindGameObjectWithTag("GameController");
                GameSystem.GetComponent <ScoreSystem>().World = world;
                GameSystem.GetComponent <ScoreSystem>().level = level;
            }
        }
        else
        {
            world = Current_World;
            level = Current_Level;
            GameObject GameSystem = GameObject.FindGameObjectWithTag("GameController");
            GameSystem.GetComponent <ScoreSystem>().World = world;
            GameSystem.GetComponent <ScoreSystem>().level = level;
            SaveParentFolder = Application.streamingAssetsPath + "/Data";
        }

        Scene_Block saveData = new Scene_Block();


        //find all the blocks
        List <Transform>  blks      = new List <Transform>();
        List <block_data> temp_blks = new List <block_data>();

        Transform[] allobj = GameObject.FindObjectsOfType <Transform>();
        foreach (Transform obj in allobj)
        {
            if (obj.gameObject.activeInHierarchy)
            {
                //we use game component snapobject to identify if its a block...
                if (obj.GetComponent <SnapObject>() != null || obj.CompareTag("PlacedWallBlock"))
                {
                    if (obj.root != GameObject.Find("FakeScene").transform)
                    {
                        blks.Add(obj);
                    }
                }
            }
        }
        //create and place each new block_data
        foreach (Transform blk in blks)
        {
            block_data data = new block_data();
            data.pos   = new custom_vector_4(blk.transform.position);
            data.scale = new custom_vector_4(blk.transform.localScale);
            data.type  = ParseBlockType(blk.gameObject);

            //hardcore handle portals
            if (data.type == blockType.portal)
            {
                data.portal_ref_pos = new custom_vector_4(blk.GetComponent <Portal>().OtherPortal.transform.position);
            }

            if (blk.GetComponent <OneWayBlock>() != null)
            {
                data.direction = blk.GetComponent <OneWayBlock>().currentDirection;
            }
            else if (blk.GetComponent <OneWayGate>() != null)
            {
                data.direction = blk.GetComponent <OneWayGate>().currentDirection;
            }
            temp_blks.Add(data);
        }
        saveData.blocks = temp_blks.ToArray();
        saveData.world  = world; saveData.level = level;
        //now we actually save the data.
        if (BinarySerializor.SerializeToBinary <Scene_Block>(SaveParentFolder + "/" + world + "-" + level + ".dat", saveData))
        {
            Debug.Log("Successfully saved");
        }
    }
 public Scoring_Block LoadBinaryData()
 {
     return(BinarySerializor.DeserializeFromBinary <Scoring_Block>(Application.streamingAssetsPath + "/Data/ScoreSystem.sco"));
 }
Exemplo n.º 4
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
    }