コード例 #1
0
 void Start()
 {
     woodenBlock = GetComponent <WoodenBlock>();
     env         = VoxelPlayEnvironment.instance;
     voxelLib    = WoodenBlockVoxelLibrary.instance;
     // Create scene objects
     CreateColorSwatch();
     CreateSlotSwatch();
     CreateInputSwatch();
     InitMenuButtons();
 }
コード例 #2
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);
            }
        }