Ejemplo n.º 1
0
    private void MakeStation(string str)
    {
        string[] data = str.Split(',');
        for (int j = 0; j < data.Length; j++)
        {
            switch (data[j])
            {
            case "0":
                break;

            case "1":
                m_blockManager.AddBlock(j - 2, m_iStageLength);
                break;

            case "2":
                m_blockManager.AddBlock(j - 2, m_iStageLength);
                m_itemManager.AddCoin(j - 2, m_iStageLength);
                break;

            case "3":
                m_blockManager.AddBlock(j - 2, m_iStageLength);
                m_obstacleManager.AddObstacle(0, j - 2, m_iStageLength);
                break;

            case "4":
                m_blockManager.AddBlock(j - 2, m_iStageLength);
                m_obstacleManager.AddObstacle(1, j - 2, m_iStageLength);
                break;
            }
        }
        m_blockManager.AddSideBlock();
        m_iStageLength++;
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Tell the block manager that replication is completed for the given
 /// pipeline.
 /// </summary>
 /// <exception cref="System.IO.IOException"/>
 private void FulfillPipeline(BlockInfoContiguous blockInfo, DatanodeStorageInfo[]
                              pipeline)
 {
     for (int i = 1; i < pipeline.Length; i++)
     {
         DatanodeStorageInfo storage = pipeline[i];
         bm.AddBlock(storage, blockInfo, null);
         blockInfo.AddStorage(storage);
     }
 }
    public static void Load(Scene scene, LoadSceneMode mode)
    {
        //Debug.Log("Loading file at: " + Application.persistentDataPath + "/" + filename + ".dat");
        if (File.Exists(Application.persistentDataPath + "/" + scene.name + ".dat"))
        {
            BinaryFormatter bf = new BinaryFormatter();

            FileStream file = File.Open(Application.persistentDataPath + "/" + scene.name + ".dat", FileMode.Open);
            
            List<SaveData> data = (List<SaveData>)bf.Deserialize(file);

            Debug.Log(SceneManager.GetActiveScene().name);
            //Instantiate all blocks in the blocklist, aside from the player
            for (int i = 0; i < data.Count - 1; i++)
            {
                GameObject loadedObj = Instantiate(
                    Resources.Load("Prefabs/Placeables/" + data[i].objectName, typeof(GameObject)),
                    new Vector3(
                        data[i].positionX,
                        data[i].positionY,
                        data[i].positionZ),
                    new Quaternion(
                        data[i].rotationX,
                        data[i].rotationY,
                        data[i].rotationZ,
                        data[i].rotationW
                        )
                    ) as GameObject;
                
                if (blockManager != null) blockManager.AddBlock(loadedObj);
            }

            //Destroy any duplicate player
            Destroy(GameObject.Find("Player"));

            //Instantiate the player
            GameObject player = Instantiate(
                Resources.Load("Prefabs/Player/" + data[data.Count - 1].objectName, typeof(GameObject)),
                new Vector3(
                    data[data.Count - 1].positionX,
                    data[data.Count - 1].positionY,
                    data[data.Count - 1].positionZ),
                new Quaternion(
                    data[data.Count - 1].rotationX,
                    data[data.Count - 1].rotationY,
                    data[data.Count - 1].rotationZ,
                    data[data.Count - 1].rotationW)
                ) as GameObject;
            file.Close();
        }
    }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        GetComponent <MeshFilter>().mesh = MeshUtility.CreateCube(1f, Vector3.zero);
        BlockManager.Init(chunkPrefab);
        TextureManager.Init(texMap, tileSize);

        for (int x = 0; x < 100; x++)
        {
            for (int y = 0; y < 100; y++)
            {
                IBlock block = new GrassBlock(Vector3.left * x + (Vector3.up * TerrainUtility.GetBlockHeight(x, y)) + Vector3.forward * y);
                for (int i = 0; i < block.Position.y; i++)
                {
                    IBlock block1 = new DirtBlock(new Vector3(block.Position.x, i, block.Position.z));
                    BlockManager.AddBlock(block1);
                }
                BlockManager.AddBlock(block);
            }
        }


        //Block block = new Block(Vector3.one);
        //BlockManager.AddBlock(block);
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        Vector3 movementVector = Vector3.zero;

        if (Input.GetKey(KeyCode.W))
        {
            movementVector += transform.forward;
        }
        if (Input.GetKey(KeyCode.S))
        {
            movementVector += -transform.forward;
        }
        if (Input.GetKey(KeyCode.A))
        {
            movementVector += -transform.right;
        }
        if (Input.GetKey(KeyCode.D))
        {
            movementVector += transform.right;
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            equippedBlockType = typeof(GrassBlock);
            equippedText.text = "Grass";
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            equippedBlockType = typeof(DirtBlock);
            equippedText.text = "Dirt";
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            equippedBlockType = typeof(GlassBlock);
            equippedText.text = "Glass";
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            equippedBlockType = typeof(StoneBlock);
            equippedText.text = "Stone";
        }
        else if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            equippedBlockType = typeof(GlowstoneBlock);
            equippedText.text = "Glowstone";
        }

        movementVector.Normalize();
        movementVector *= movementSpeed;

        if (Input.GetKey(KeyCode.Space) && rb.velocity.y < 0.001f)
        {
            movementVector += Vector3.up * jumpPower;
        }

        rb.velocity = new Vector3(movementVector.x, rb.velocity.y + movementVector.y, movementVector.z);

        //TODO: Make this original, credit https://answers.unity.com/questions/29741/mouse-look-script.html
        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationX  = ClampAngle(rotationX, minimumX, maximumX);
        rotationY  = ClampAngle(rotationY, minimumY, maximumY);
        Quaternion xQuaternion = Quaternion.Euler(rotationX * Vector3.up);
        Quaternion yQuaternion = Quaternion.Euler(rotationY * -Vector3.right);

        rb.MoveRotation(originalRotation * xQuaternion);
        cameraGameObject.transform.rotation = transform.rotation * yQuaternion;


        if (Input.GetKeyDown(KeyCode.Tab))
        {
            if (Cursor.lockState == CursorLockMode.Locked)
            {
                Cursor.lockState = CursorLockMode.None;
            }
            else
            {
                Cursor.lockState = CursorLockMode.Locked;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Display.main.renderingWidth / 2, Display.main.renderingHeight / 2));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1000))
            {
                if (!Physics.CheckBox(new Vector3(Mathf.Round(hit.point.x + (hit.normal.x * 0.01f)), Mathf.Round(hit.point.y + (hit.normal.y * 0.01f)), Mathf.Round(hit.point.z + (hit.normal.z * 0.01f))), Vector3.one * 0.45f))
                {
                    if (hit.collider.gameObject.CompareTag("Block"))
                    {
                        IBlock block = (IBlock)System.Activator.CreateInstance(equippedBlockType, new object[] { new Vector3(Mathf.Round(hit.point.x + (hit.normal.x * 0.01f)), Mathf.Round(hit.point.y + (hit.normal.y * 0.01f)), Mathf.Round(hit.point.z + (hit.normal.z * 0.01f))) }); //new DirtBlock(new Vector3(Mathf.Round(hit.point.x + (hit.normal.x * 0.01f)), Mathf.Round(hit.point.y + (hit.normal.y * 0.01f)), Mathf.Round(hit.point.z + (hit.normal.z * 0.01f))));
                        BlockManager.AddBlock(block);
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Display.main.renderingWidth / 2, Display.main.renderingHeight / 2));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1000))
            {
                Vector3 blockPos = new Vector3(Mathf.Round(hit.point.x + (hit.normal.x * -0.01f)), Mathf.Round(hit.point.y + (hit.normal.y * -0.01f)), Mathf.Round(hit.point.z + (hit.normal.z * -0.01f)));
                BlockManager.RemoveBlock(blockPos);
            }
        }
    }