예제 #1
0
 void NewModel(VoxelPlayFirstPersonController fps)
 {
     if (!EditorUtility.DisplayDialog("New Model", "Discard any change and start a new model definition?", "Ok", "Cancel"))
     {
         return;
     }
     fps.NewModel();
 }
예제 #2
0
 void EnableCursor(bool state)
 {
     if (env.initialized)
     {
         VoxelPlayFirstPersonController controller = VoxelPlayFirstPersonController.instance;
         if (controller != null)
         {
             controller.mouseLook.SetCursorLock(!state);
             controller.enabled = !state;
         }
     }
 }
        void OnEnable()
        {
            startOnFlat           = serializedObject.FindProperty("startOnFlat");
            startOnFlatIterations = serializedObject.FindProperty("startOnFlatIterations");
            _characterHeight      = serializedObject.FindProperty("_characterHeight");

            crosshairScale         = serializedObject.FindProperty("crosshairScale");
            targetAnimationScale   = serializedObject.FindProperty("targetAnimationScale");
            targetAnimationSpeed   = serializedObject.FindProperty("targetAnimationSpeed");
            crosshairNormalColor   = serializedObject.FindProperty("crosshairNormalColor");
            crosshairOnTargetColor = serializedObject.FindProperty("crosshairOnTargetColor");
            changeOnBlock          = serializedObject.FindProperty("changeOnBlock");
            autoInvertColors       = serializedObject.FindProperty("autoInvertColors");

            voxelHighlight      = serializedObject.FindProperty("voxelHighlight");
            voxelHighlightColor = serializedObject.FindProperty("voxelHighlightColor");
            voxelHighlightEdge  = serializedObject.FindProperty("voxelHighlightEdge");

            fps = (VoxelPlayFirstPersonController)target;
        }
예제 #4
0
        void OnGUI()
        {
            VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;

            if (env == null)
            {
                EditorGUILayout.HelpBox("Constructor tools require Voxel Play Environment in the scene..", MessageType.Info);
                return;
            }
            VoxelPlayFirstPersonController fps = VoxelPlayFirstPersonController.instance;

            if (fps == null)
            {
                EditorGUILayout.HelpBox("Constructor tools require Voxel Play First Person Controller in the scene..", MessageType.Info);
                return;
            }
            if (!Application.isPlaying)
            {
                EditorGUILayout.HelpBox("Constructor tools are only available during Play Mode.", MessageType.Info);
                return;
            }

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Toggle Constructor Mode", GUILayout.Width(250), GUILayout.Height(30)))
            {
                fps.ToggleConstructor();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (!env.constructorMode)
            {
                return;
            }

            OpenSection();
            fps.constructorSize = EditorGUILayout.IntField("Default Constructor Size", fps.constructorSize);
            EditorGUI.BeginChangeCheck();
            model = (ModelDefinition)EditorGUILayout.ObjectField("Model", model, typeof(ModelDefinition), false);
            if (EditorGUI.EndChangeCheck())
            {
                if (model != null)
                {
                    fps.LoadModel(model);
                }
            }
            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("New Model"))
            {
                fps.NewModel();
                model = fps.loadModel;
            }
            GUI.enabled = model != null;
            if (GUILayout.Button("Load"))
            {
                fps.LoadModel(model);
            }
            if (GUILayout.Button("Save"))
            {
                fps.SaveModel(false);
                GUIUtility.ExitGUI();
            }
            GUI.enabled = true;
            if (GUILayout.Button("Save As New..."))
            {
                if (fps.SaveModel(true))
                {
                    model = fps.loadModel;
                }
                GUIUtility.ExitGUI();
            }
            EditorGUILayout.EndHorizontal();
            CloseSection();

            OpenSection();
            EditorGUILayout.BeginHorizontal();
            DrawHeaderLabel("Displace");
            if (GUILayout.Button("<X"))
            {
                fps.DisplaceModel(-1, 0, 0);
            }

            if (GUILayout.Button("X>"))
            {
                fps.DisplaceModel(1, 0, 0);
            }
            if (GUILayout.Button("<Y"))
            {
                fps.DisplaceModel(0, -1, 0);
            }

            if (GUILayout.Button("Y>"))
            {
                fps.DisplaceModel(0, 1, 0);
            }

            if (GUILayout.Button("<Z"))
            {
                fps.DisplaceModel(0, 0, -1);
            }

            if (GUILayout.Button("Z>"))
            {
                fps.DisplaceModel(0, 0, 1);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            DrawHeaderLabel("Resize Area");
            if (GUILayout.Button("-X"))
            {
                fps.ResizeModel(-1, 0, 0);
            }

            if (GUILayout.Button("+X"))
            {
                fps.ResizeModel(1, 0, 0);
            }
            if (GUILayout.Button("-Y"))
            {
                fps.ResizeModel(0, -1, 0);
            }

            if (GUILayout.Button("+Y"))
            {
                fps.ResizeModel(0, 1, 0);
            }

            if (GUILayout.Button("-Z"))
            {
                fps.ResizeModel(0, 0, -1);
            }

            if (GUILayout.Button("+Z"))
            {
                fps.ResizeModel(0, 0, 1);
            }
            EditorGUILayout.EndHorizontal();

            CloseSection();
        }
        void LoadGameBinaryFileFormat_7(BinaryReader br, bool preservePlayerPosition = false)
        {
            // Character controller transform position & rotation
            Vector3 pos    = DecodeVector3Binary(br);
            Vector3 angles = DecodeVector3Binary(br);

            if (characterController != null)
            {
                if (!preservePlayerPosition)
                {
                    characterController.transform.position = pos;
                    characterController.transform.rotation = Quaternion.Euler(angles);
                }
            }
            // Character controller's camera local rotation
            angles = DecodeVector3Binary(br);
            if (!preservePlayerPosition)
            {
                cameraMain.transform.localRotation = Quaternion.Euler(angles);
                // Pass initial rotation to mouseLook script
                if (characterController != null)
                {
                    VoxelPlayFirstPersonController fps = characterController.GetComponent <VoxelPlayFirstPersonController> ();
                    if (fps != null)
                    {
                        fps.mouseLook.Init(characterController.transform, cameraMain.transform, null);
                    }
                }
            }

            InitSaveGameStructs();
            // Read voxel definition table
            int vdCount = br.ReadInt16();

            for (int k = 0; k < vdCount; k++)
            {
                saveVoxelDefinitionsList.Add(br.ReadString());
            }
            // Read item definition table
            int idCount = br.ReadInt16();

            for (int k = 0; k < idCount; k++)
            {
                saveItemDefinitionsList.Add(br.ReadString());
            }

            int             numChunks       = br.ReadInt32();
            VoxelDefinition voxelDefinition = defaultVoxel;
            int             prevVdIndex     = -1;
            Color32         voxelColor      = Misc.color32White;

            for (int c = 0; c < numChunks; c++)
            {
                // Read chunks
                // Get chunk position
                Vector3    chunkPosition  = DecodeVector3Binary(br);
                VoxelChunk chunk          = GetChunkUnpopulated(chunkPosition);
                byte       isAboveSurface = br.ReadByte();
                chunk.isAboveSurface = isAboveSurface == 1;
                chunk.back           = chunk.bottom = chunk.left = chunk.right = chunk.forward = chunk.top = null;
                chunk.allowTrees     = false;
                chunk.modified       = true;
                chunk.isPopulated    = true;
                chunk.voxelSignature = chunk.lightmapSignature = -1;
                chunk.renderState    = ChunkRenderState.Pending;
                SetChunkOctreeIsDirty(chunkPosition, false);
                ChunkClearFast(chunk);
                // Read voxels
                int numWords = br.ReadInt16();
                for (int k = 0; k < numWords; k++)
                {
                    // Voxel definition
                    int vdIndex = br.ReadInt16();
                    if (prevVdIndex != vdIndex)
                    {
                        if (vdIndex >= 0 && vdIndex < vdCount)
                        {
                            voxelDefinition = GetVoxelDefinition(saveVoxelDefinitionsList [vdIndex]);
                            prevVdIndex     = vdIndex;
                        }
                    }
                    // RGB
                    voxelColor.r = br.ReadByte();
                    voxelColor.g = br.ReadByte();
                    voxelColor.b = br.ReadByte();
                    // Voxel index
                    int voxelIndex = br.ReadInt16();
                    // Repetitions
                    int repetitions = br.ReadInt16();

                    byte flags             = br.ReadByte();
                    byte hasCustomRotation = br.ReadByte();

                    if (voxelDefinition == null)
                    {
                        continue;
                    }

                    // Custom voxel flags
                    if (voxelDefinition.renderType == RenderType.Custom)
                    {
                        if (hasCustomRotation == 1)
                        {
                            Vector3 voxelAngles = DecodeVector3Binary(br);
                            saveVoxelCustomRotations.Add(GetVoxelPosition(chunkPosition, voxelIndex), voxelAngles);
                        }
                    }
                    for (int i = 0; i < repetitions; i++)
                    {
                        chunk.voxels [voxelIndex + i].Set(voxelDefinition, voxelColor);
                        if (voxelDefinition.renderType == RenderType.Water || voxelDefinition.renderType.supportsTextureRotation())
                        {
                            chunk.voxels [voxelIndex + i].SetFlags(flags);
                        }
                    }
                }
                // Read light sources
                int          lightCount = br.ReadInt16();
                VoxelHitInfo hitInfo    = new VoxelHitInfo();
                for (int k = 0; k < lightCount; k++)
                {
                    // Voxel index
                    hitInfo.voxelIndex = br.ReadInt16();
                    // Voxel center
                    hitInfo.voxelCenter = GetVoxelPosition(chunkPosition, hitInfo.voxelIndex);
                    // Normal
                    hitInfo.normal = DecodeVector3Binary(br);
                    hitInfo.chunk  = chunk;
                    TorchAttach(hitInfo);
                }
                // Read items
                int itemCount = br.ReadInt16();
                for (int k = 0; k < itemCount; k++)
                {
                    // Voxel index
                    int itemIndex = br.ReadInt16();
                    if (itemIndex < 0 || itemIndex >= idCount)
                    {
                        continue;
                    }
                    string  itemDefinitionName = saveItemDefinitionsList [itemIndex];
                    Vector3 itemPosition       = DecodeVector3Binary(br);
                    int     quantity           = br.ReadInt16();
                    ItemSpawn(itemDefinitionName, itemPosition, quantity);
                }
            }
        }