Пример #1
0
        /// <summary>
        /// Places a brickWall voxel in front of player. Can be executed in game entering in the console "Invoke Demo PlaceBrick"
        /// </summary>
        void PlaceBrick()
        {
            // Instead of using Raycast like in the SummonDeer function, will reuse the crosshair data (just another way of doing the same)
            VoxelPlayFirstPersonController fpsController = VoxelPlayFirstPersonController.instance;

            if (fpsController.crosshairOnBlock)
            {
                Vector3         pos       = fpsController.crosshairHitInfo.voxelCenter + fpsController.crosshairHitInfo.normal;
                VoxelDefinition brickWall = env.GetVoxelDefinition("VoxelBrickWall");
                env.VoxelPlace(pos, brickWall);
            }
        }
Пример #2
0
        /// <summary>
        /// Converts voxel on the crosshair into a dynamic gameobject
        /// </summary>
        void LevitateVoxel()
        {
            VoxelPlayFirstPersonController fpsController = VoxelPlayFirstPersonController.instance;

            if (fpsController.crosshairOnBlock)
            {
                VoxelChunk chunk      = fpsController.crosshairHitInfo.chunk;
                int        voxelIndex = fpsController.crosshairHitInfo.voxelIndex;
                GameObject obj        = env.VoxelGetDynamic(chunk, voxelIndex, true);
                if (obj != null)
                {
                    Rigidbody rb = obj.GetComponent <Rigidbody> ();
                    rb.AddForce(Vector3.up * 500f);
                }
            }
        }
Пример #3
0
        void Start()
        {
            env = VoxelPlayEnvironment.instance;

            // Position player on the scene and setup orbit parameters
            fps = VoxelPlayFirstPersonController.instance;

            // Create scene objects
            CreateCube();
            CreateLabels();
            CreateColorSwatch();

            // Color the voxel in black when clicked OR place a new voxel
            env.OnVoxelClick += (chunk, voxelIndex, buttonIndex) => {
                if (buttonIndex == 0)
                {
                    if (!eraseMode)
                    {
                        // If left click, change the color of voxel to white
                        env.VoxelSetColor(chunk, voxelIndex, currentColor);
                    }
                }
                else
                {
                    // If right click, places a new voxel on top of this in the direction of the plane
                    Vector3 position = fps.crosshairHitInfo.voxelCenter + fps.crosshairHitInfo.normal;
                    env.VoxelPlace(position, Color.red, true);
                }
            };

            // Control erase mode
            env.OnVoxelDamaged += (VoxelChunk chunk, int voxelIndex, ref int damage) => {
                if (!eraseMode)
                {
                    damage = 0;
                }
            };
        }
Пример #4
0
        void Start()
        {
            env      = VoxelPlayEnvironment.instance;
            voxelLib = WoodenBlockVoxelLibrary.instance;

            // Position player on the scene and setup orbit parameters
            fps = VoxelPlayFirstPersonController.instance;

            // Create scene objects
            CreateCube();
            //CreateInputSwatch();

            // Color the voxel in black when clicked OR place a new voxel
            env.OnVoxelClick += (chunk, voxelIndex, buttonIndex, hitInfo) => {
                if (!EventSystem.current.IsPointerOverGameObject())
                {
                    if (false == voxelLib.isGridBlock(chunk, voxelIndex))
                    {
                        currentChunk      = chunk;
                        currentVoxelIndex = voxelIndex;
                        env.VoxelHighlight(hitInfo, Color.red, 30);
                    }
                    if (buttonIndex == 0)
                    {
                        switch (controlMode)
                        {
                        case ControlMode.BUILD:
                        {
                            if (voxelLib.isGridBlock(hitInfo))
                            {
                                if (hitInfo.normal.y == 1)           // only can make Top Direction
                                {
                                    Vector3 position = hitInfo.voxelCenter + hitInfo.normal;
                                    //env.VoxelPlace(position, newVoxelDefine, createColor, true);
                                    VoxelChunk chunk_;
                                    int        voxelIndex_;
                                    env.VoxelPlace(position, newVoxelDefine, currentColor, out chunk_, out voxelIndex_, true);
                                    currentChunk      = chunk_;
                                    currentVoxelIndex = voxelIndex_;

                                    hitInfo.voxelCenter = position;
                                    hitInfo.chunk       = chunk_;
                                    hitInfo.voxelIndex  = voxelIndex_;
                                    env.VoxelHighlight(hitInfo, Color.red, 30);
                                }
                            }
                            else
                            {
                                Vector3 position = hitInfo.voxelCenter + hitInfo.normal;
                                if (false == voxelLib.isGridBlock(position))
                                {
                                    //env.VoxelPlace(position, newVoxelDefine, createColor, true);
                                    VoxelChunk chunk_;
                                    int        voxelIndex_;
                                    env.VoxelPlace(position, newVoxelDefine, currentColor, out chunk_, out voxelIndex_, true);
                                    currentChunk      = chunk_;
                                    currentVoxelIndex = voxelIndex_;

                                    hitInfo.voxelCenter = position;
                                    hitInfo.chunk       = chunk_;
                                    hitInfo.voxelIndex  = voxelIndex_;
                                    env.VoxelHighlight(hitInfo, Color.red, 30);
                                }
                            }
                        }
                        break;

                        case ControlMode.COLOR:
                            //Vector2 pos = Camera.main.WorldToScreenPoint(hitInfo.voxelCenter);
                            //RectTransformUtility.ScreenPointToLocalPointInRectangle(uiCanvas.transform as RectTransform, pos, uiCanvas.worldCamera, out pos);
                            //colorPanel.transform.position = uiCanvas.transform.TransformPoint(pos);
                            //colorPanel.SetActive(true);
                            //isPropertyVisible = true;
                            env.VoxelSetColor(currentChunk, currentVoxelIndex, currentColor);
                            break;

                        case ControlMode.ERASE:
                            break;
                        }
                    }
                }
            };

            // Control erase mode
            env.OnVoxelDamaged += (VoxelChunk chunk, int voxelIndex, ref int damage) => {
                if (controlMode != ControlMode.ERASE)
                {
                    damage = 0;
                }
                else
                {
                    if (voxelLib.isGridBlock(chunk, voxelIndex))
                    {
                        damage = 0;
                    }
                }
            };

            var data = PlayerPrefs.GetString("0");

            if (string.IsNullOrEmpty(data))
            {
                SaveGame("0");
            }

            Camera[] cameras = GetComponentsInChildren <Camera>(true);
            for (int i = 0; i < cameras.Length; ++i)
            {
                cameras[i].gameObject.SetActive(true);
            }
        }