コード例 #1
0
    void PlayDestroyBlockSound(m_voxelType type)
    {
        switch ((int)type)
        {
        case 1:
            audio.PlayOneShot(m_grassRm);
            break;

        case 2:
            audio.PlayOneShot(m_stoneRm);
            break;

        case 3:
            audio.PlayOneShot(m_dirtRm);
            break;

        case 4:
            audio.PlayOneShot(m_sandRm);
            break;

        default:
            audio.PlayOneShot(m_grassRm);
            break;
        }
    }
コード例 #2
0
    // play the place block sound
    void PlayPlaceBlockSound(m_voxelType type)
    {
        {
            switch ((int)type)
            {
            case 1:
                audio.PlayOneShot(m_grassPl);
                break;

            case 2:
                audio.PlayOneShot(m_stonePl);
                break;

            case 3:
                audio.PlayOneShot(m_dirtPl);
                break;

            case 4:
                audio.PlayOneShot(m_sandPl);
                break;

            default:
                audio.PlayOneShot(m_grassPl);
                break;
            }
        }
    }
コード例 #3
0
ファイル: ChunkBuilder.cs プロジェクト: Thaon/Chiara
    [RPC] public void SetBlock(Vector3 index, int voxelType) //overloading for the network scene (as enums are not serialisable)
    {
        if ((index.x >= 0 && index.x < m_terrainArray.GetLength(0)) && (index.y >= 0 && index.y < m_terrainArray.GetLength(1)) && (index.z >= 0 && index.z < m_terrainArray.GetLength(2)))
        {
            //clear the previous mesh data
            m_voxelGenerator.ClearPreviousData();
            // Change the block to the required type
            m_terrainArray[(int)index.x, (int)index.y, (int)index.z] = (int)voxelType;
            // Create the new mesh
            DisplayTerrain();
            // Update the mesh data
            m_voxelGenerator.UpdateWorld();

            m_voxelType vType = m_voxelType.grass;
            switch (voxelType)
            {
            case 1:
                vType = m_voxelType.grass;
                break;

            case 2:
                vType = m_voxelType.dirt;
                break;

            case 3:
                vType = m_voxelType.stone;
                break;

            case 4:
                vType = m_voxelType.sand;
                break;
            }
            m_world.BlockChanged(vType);
        }
    }
コード例 #4
0
ファイル: AudioManager.cs プロジェクト: Thaon/Chiara
    void PlayDestroyBlockSound(m_voxelType type)
    {
        switch((int)type)
        {
            case 1:
                audio.PlayOneShot(m_grassRm);
            break;

            case 2:
                audio.PlayOneShot(m_stoneRm);
            break;

            case 3:
                audio.PlayOneShot(m_dirtRm);
            break;

            case 4:
                audio.PlayOneShot(m_sandRm);
            break;

            default:
                audio.PlayOneShot(m_grassRm);
            break;
        }
    }
コード例 #5
0
ファイル: AudioManager.cs プロジェクト: Thaon/Chiara
    // play the place block sound
    void PlayPlaceBlockSound(m_voxelType type)
    {
        {
            switch ((int)type)
            {
                case 1:
                    audio.PlayOneShot(m_grassPl);
                    break;

                case 2:
                    audio.PlayOneShot(m_stonePl);
                    break;

                case 3:
                    audio.PlayOneShot(m_dirtPl);
                    break;

                case 4:
                    audio.PlayOneShot(m_sandPl);
                    break;

                default:
                    audio.PlayOneShot(m_grassPl);
                    break;
            }

        }
    }
コード例 #6
0
    //public void CreateWorld()//ChunkBuilder[,] newChunks)
    //{
    //newChunks = new ChunkBuilder[m_worldXSize, m_worldZSize];
    //for (int z = 0; z < m_worldZSize; z++)
    //{
    //    for (int x = 0; x < m_worldZSize; x++)
    //    {
    //        //create the new chunk
    //        GameObject newChunk = new GameObject();
    //        newChunk.name = "Chunk at: " + x + " : " + z;
    //        newChunk.AddComponent<ChunkBuilder>();
    //        newChunk.AddComponent<MeshGenerator>();

    //        //put new chunk in position
    //        newChunk.transform.position = new Vector3(x * m_chunkSize, 0, z * m_chunkSize);

    //        //customise the new chunk
    //        ChunkBuilder cb = newChunk.GetComponent<ChunkBuilder>();
    //        cb.m_chunkSize = m_chunkSize;
    //        cb.m_chunkHeight = m_chunkHeight;
    //        cb.m_world = this;
    //        cb.GenerateChunk();
    //        newChunks[x, z] = cb;
    //    }
    //}

    //place the player in the middle of the chunk
    //GameObject.FindWithTag("Player").transform.position = transform.position + new Vector3((m_chunkSize * m_worldXSize) / 2, 5, (m_chunkSize * m_worldZSize) / 2);
    //m_chunks = newChunks;
    //}

    public void BlockChanged(m_voxelType type)//ADD AGAIN AFTER GETTING THE SOUNDS!!!
    {
        if (type == m_voxelType.empty)
        {
            OnEventBlockDestroyed(m_voxelType.empty);
        }
        else
        {
            OnEventBlockPlaced(type);
        }
    }
コード例 #7
0
ファイル: ChunkWorldBuilder.cs プロジェクト: Thaon/Chiara
 //ADD AGAIN AFTER GETTING THE SOUNDS!!!
 //public void CreateWorld()//ChunkBuilder[,] newChunks)
 //{
 //newChunks = new ChunkBuilder[m_worldXSize, m_worldZSize];
 //for (int z = 0; z < m_worldZSize; z++)
 //{
 //    for (int x = 0; x < m_worldZSize; x++)
 //    {
 //        //create the new chunk
 //        GameObject newChunk = new GameObject();
 //        newChunk.name = "Chunk at: " + x + " : " + z;
 //        newChunk.AddComponent<ChunkBuilder>();
 //        newChunk.AddComponent<MeshGenerator>();
 //        //put new chunk in position
 //        newChunk.transform.position = new Vector3(x * m_chunkSize, 0, z * m_chunkSize);
 //        //customise the new chunk
 //        ChunkBuilder cb = newChunk.GetComponent<ChunkBuilder>();
 //        cb.m_chunkSize = m_chunkSize;
 //        cb.m_chunkHeight = m_chunkHeight;
 //        cb.m_world = this;
 //        cb.GenerateChunk();
 //        newChunks[x, z] = cb;
 //    }
 //}
 //place the player in the middle of the chunk
 //GameObject.FindWithTag("Player").transform.position = transform.position + new Vector3((m_chunkSize * m_worldXSize) / 2, 5, (m_chunkSize * m_worldZSize) / 2);
 //m_chunks = newChunks;
 //}
 public void BlockChanged(m_voxelType type)
 {
     if (type == m_voxelType.empty)
     {
         OnEventBlockDestroyed(m_voxelType.empty);
     }
     else
     {
         OnEventBlockPlaced(type);
     }
 }
コード例 #8
0
ファイル: ChunkBuilder.cs プロジェクト: Thaon/Chiara
 public void SetBlock(Vector3 index, m_voxelType voxelType)
 {
     if ((index.x >= 0 && index.x < m_terrainArray.GetLength(0)) && (index.y >= 0 && index.y < m_terrainArray.GetLength(1)) && (index.z >= 0 && index.z < m_terrainArray.GetLength(2)))
     {
         //clear the previous mesh data
         m_voxelGenerator.ClearPreviousData();
         // Change the block to the required type
         m_terrainArray[(int)index.x, (int)index.y, (int)index.z] = (int)voxelType;
         // Create the new mesh
         DisplayTerrain();
         // Update the mesh data
         m_voxelGenerator.UpdateWorld();
         m_world.BlockChanged(voxelType);
     }
 }
コード例 #9
0
    void Update()
    {
        if (!networkView.isMine)
        {
            m_syncTime += Time.deltaTime;
            if (m_syncTime < m_syncDelay)
            {
                transform.position = Vector3.Lerp(m_startPosition, m_endPosition, m_syncTime / m_syncDelay);
            }
        }
        else
        {
            if (Input.GetButtonDown("Jump"))
            {
                Vector3      v;
                ChunkBuilder vcs;
                if (PickThisBlock(out v, out vcs, 4))
                {
                    NetworkView nv = vcs.GetComponent <NetworkView>();
                    if (nv != null)
                    {
                        int         iType = vcs.m_terrainArray[(int)v.x, (int)v.y, (int)v.z];
                        m_voxelType vType = m_voxelType.grass;
                        switch (iType)
                        {
                        case 1:
                            vType = m_voxelType.grass;
                            break;

                        case 2:
                            vType = m_voxelType.dirt;
                            break;

                        case 3:
                            vType = m_voxelType.stone;
                            break;

                        case 4:
                            vType = m_voxelType.sand;
                            break;
                        }
                        vcs.SpawnSmallVoxel(v, vType);
                        nv.RPC("SetBlock", RPCMode.All, v, (int)m_voxelType.empty);
                    }
                }
            }
        }
    }
コード例 #10
0
    void Update()
    {
        if (m_state != m_previousState) //if we changed state
        {
            if (m_state == State.inventory)
            {
                GetComponent <FPSInputController>().enabled = false;
                GetComponent <CharacterMotor>().enabled     = false;
                foreach (MouseLook ml in GetComponentsInChildren <MouseLook>())
                {
                    ml.enabled = false;
                }

                Screen.showCursor = true;
                Screen.lockCursor = false;
                m_inventoryCanvas.SetActive(true);
                GetComponent <InventoryManager>().RefreshInventory();
            }

            if (m_state == State.playing)
            {
                GetComponent <FPSInputController>().enabled = true;
                GetComponent <CharacterMotor>().enabled     = true;
                foreach (MouseLook ml in GetComponentsInChildren <MouseLook>())
                {
                    ml.enabled = true;
                }

                Screen.showCursor = false;
                Screen.lockCursor = true;
                m_inventoryCanvas.SetActive(false);
            }

            m_previousState = m_state;
        }

        if (m_state == State.playing)
        {
            //select block with 1 - 4 keys
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                m_selectedBlock = 1;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                m_selectedBlock = 2;
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                m_selectedBlock = 3;
            }
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                m_selectedBlock = 4;
            }

            //remove and place blocks
            if (Input.GetButtonDown("Fire1"))
            {
                Vector3 v;
                if (PickThisBlock(out v, 4))
                {
                    int iType = m_activeChunk.m_terrainArray[(int)v.x, (int)v.y, (int)v.z];
                    //print(iType);

                    m_activeChunk.SetBlock(v, m_voxelType.empty);

                    m_voxelType vType = m_voxelType.grass;
                    switch (iType)
                    {
                    case 1:
                        vType = m_voxelType.grass;
                        break;

                    case 2:
                        vType = m_voxelType.dirt;
                        break;

                    case 3:
                        vType = m_voxelType.stone;
                        break;

                    case 4:
                        vType = m_voxelType.sand;
                        break;
                    }
                    //spawn block there
                    m_activeChunk.SpawnSmallVoxel(v, vType);
                }
            }
            else if (Input.GetButtonDown("Fire2"))
            {
                Vector3 v;
                if (PickEmptyBlock(out v, 4))
                {
                    m_voxelType vType = m_voxelType.grass;
                    switch (m_selectedBlock)
                    {
                    case 1:
                        vType = m_voxelType.grass;
                        break;

                    case 2:
                        vType = m_voxelType.stone;
                        break;

                    case 3:
                        vType = m_voxelType.dirt;
                        break;

                    case 4:
                        vType = m_voxelType.sand;
                        break;
                    }
                    //Debug.Log(v);
                    m_activeChunk.SetBlock(v, vType);
                }
            }
            else if (Input.GetButtonUp("Inventory"))
            {
                m_state = State.inventory;
            }
        }
        else if (Input.GetButtonUp("Inventory")) //if we are in the inventory screen already, we start playing
        {
            m_state = State.playing;
        }
    }
コード例 #11
0
ファイル: ChunkBuilder.cs プロジェクト: Thaon/Chiara
    public void SpawnSmallVoxel(Vector3 index, m_voxelType voxelType)
    {
        GameObject voxel = new GameObject();

        voxel.AddComponent <MeshGenerator>();
        voxel.AddComponent <Rigidbody>();
        voxel.GetComponent <MeshCollider>().convex = true;
        voxel.AddComponent <SmallVoxel>();

        voxel.transform.position = index;
        voxel.transform.Translate(0.25f, 0, 0.25f); //center the voxel

        voxel.GetComponent <MeshGenerator>().WorldInit();
        //print(voxel.transform.position);

        //get texture
        string tex;
        Sprite spr;

        switch (voxelType)
        {
        case m_voxelType.grass:
            tex = "Grass";
            spr = m_grassSpr;
            break;

        case m_voxelType.stone:
            tex = "Stone";
            spr = m_stoneSpr;
            break;

        case m_voxelType.dirt:
            tex = "Dirt";
            spr = m_dirtSpr;
            break;

        case m_voxelType.sand:
            tex = "Sand";
            spr = m_sandSpr;
            break;

        default:
            tex = "Grass";
            spr = m_grassSpr;
            break;
        }
        //print(voxelType);
        voxel.GetComponent <MeshGenerator>().m_voxelScale = 0.5f;
        //x
        voxel.GetComponent <MeshGenerator>().CreateNegativeXFace(0, 0, 0, voxel.GetComponent <MeshGenerator>().GetAssociatedVector(tex));
        voxel.GetComponent <MeshGenerator>().CreatePositiveXFace(0, 0, 0, voxel.GetComponent <MeshGenerator>().GetAssociatedVector(tex));
        //y
        voxel.GetComponent <MeshGenerator>().CreateNegativeYFace(0, 0, 0, voxel.GetComponent <MeshGenerator>().GetAssociatedVector(tex));
        voxel.GetComponent <MeshGenerator>().CreatePositiveYFace(0, 0, 0, voxel.GetComponent <MeshGenerator>().GetAssociatedVector(tex));
        //z
        voxel.GetComponent <MeshGenerator>().CreateNegativeZFace(0, 0, 0, voxel.GetComponent <MeshGenerator>().GetAssociatedVector(tex));
        voxel.GetComponent <MeshGenerator>().CreatePositiveZFace(0, 0, 0, voxel.GetComponent <MeshGenerator>().GetAssociatedVector(tex));

        voxel.GetComponent <MeshGenerator>().UpdateWorld();
        //print(voxel.transform.position);

        voxel.GetComponent <SmallVoxel>().m_sprite = spr;
        voxel.GetComponent <SmallVoxel>().m_name   = tex;

        voxel = null; //lose reference to the voxel
    }
コード例 #12
0
ファイル: ChunkBuilder.cs プロジェクト: Thaon/Chiara
    public void SpawnSmallVoxel(Vector3 index, m_voxelType voxelType)
    {
        GameObject voxel = new GameObject();
        voxel.AddComponent<MeshGenerator>();
        voxel.AddComponent<Rigidbody>();
        voxel.GetComponent<MeshCollider>().convex = true;
        voxel.AddComponent<SmallVoxel>();

        voxel.transform.position = index;
        voxel.transform.Translate(0.25f, 0, 0.25f); //center the voxel

        voxel.GetComponent<MeshGenerator>().WorldInit();
        //print(voxel.transform.position);

        //get texture
        string tex;
        Sprite spr;
        switch (voxelType)
        {
            case m_voxelType.grass:
            tex = "Grass";
            spr = m_grassSpr;
            break;
            case m_voxelType.stone:
            tex = "Stone";
            spr = m_stoneSpr;
            break;
            case m_voxelType.dirt:
            tex = "Dirt";
            spr = m_dirtSpr;
            break;
            case m_voxelType.sand:
            tex = "Sand";
            spr = m_sandSpr;
            break;
            default:
            tex = "Grass";
            spr = m_grassSpr;
            break;
        }
        //print(voxelType);
        voxel.GetComponent<MeshGenerator>().m_voxelScale = 0.5f;
        //x
        voxel.GetComponent<MeshGenerator>().CreateNegativeXFace(0,0,0, voxel.GetComponent<MeshGenerator>().GetAssociatedVector(tex));
        voxel.GetComponent<MeshGenerator>().CreatePositiveXFace(0, 0, 0, voxel.GetComponent<MeshGenerator>().GetAssociatedVector(tex));
        //y
        voxel.GetComponent<MeshGenerator>().CreateNegativeYFace(0, 0, 0, voxel.GetComponent<MeshGenerator>().GetAssociatedVector(tex));
        voxel.GetComponent<MeshGenerator>().CreatePositiveYFace(0, 0, 0, voxel.GetComponent<MeshGenerator>().GetAssociatedVector(tex));
        //z
        voxel.GetComponent<MeshGenerator>().CreateNegativeZFace(0, 0, 0, voxel.GetComponent<MeshGenerator>().GetAssociatedVector(tex));
        voxel.GetComponent<MeshGenerator>().CreatePositiveZFace(0, 0, 0, voxel.GetComponent<MeshGenerator>().GetAssociatedVector(tex));

        voxel.GetComponent<MeshGenerator>().UpdateWorld();
        //print(voxel.transform.position);

        voxel.GetComponent<SmallVoxel>().m_sprite = spr;
        voxel.GetComponent<SmallVoxel>().m_name = tex;

        voxel = null; //lose reference to the voxel
    }
コード例 #13
0
ファイル: ChunkBuilder.cs プロジェクト: Thaon/Chiara
 public void SetBlock(Vector3 index, m_voxelType voxelType)
 {
     if ((index.x >= 0 && index.x < m_terrainArray.GetLength(0)) && (index.y >= 0 && index.y < m_terrainArray.GetLength(1)) && (index.z >= 0 && index.z < m_terrainArray.GetLength(2)))
     {
         //clear the previous mesh data
         m_voxelGenerator.ClearPreviousData();
         // Change the block to the required type
         m_terrainArray[(int)index.x, (int)index.y, (int)index.z] = (int)voxelType;
         // Create the new mesh
         DisplayTerrain();
         // Update the mesh data
         m_voxelGenerator.UpdateWorld();
         m_world.BlockChanged(voxelType);
     }
 }