コード例 #1
0
        /// <summary>
        /// Use this method to initialize the terrain generator
        /// </summary>
        public void Initialize()
        {
            env = VoxelPlayEnvironment.instance;
            if (env == null)
            {
                return;
            }
            world = env.world;
            if (world == null)
            {
                return;
            }

            // Migration introduced in v4.0: TODO: remove in the future
                        #if UNITY_EDITOR
            if (seaLevel >= 0 && !Application.isPlaying)
            {
                waterLevel = (int)(seaLevel * maxHeight);
                seaLevel   = -1;
                UnityEditor.EditorUtility.SetDirty(this);
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
            }
                        #endif

            env.waterLevel = waterLevel;
            Init();
            isInitialized = true;
        }
コード例 #2
0
        protected void Init()
        {
            m_AudioSource = GetComponent <AudioSource> ();
            m_StepCycle   = 0f;
            m_NextStep    = m_StepCycle / 2f;

            env = VoxelPlayEnvironment.instance;
            if (env == null)
            {
                Debug.LogError("Voxel Play Environment must be added first.");
            }
            else
            {
                env.characterController = this;
            }
            m_LastNonCollidingCharacterPos = Misc.vector3max;

            // Check player can collide with voxels
#if UNITY_EDITOR
            if (env != null && Physics.GetIgnoreLayerCollision(gameObject.layer, env.layerVoxels))
            {
                Debug.LogError("Player currently can't collide with voxels. Please check physics collision matrix in Project settings or change Voxels Layer in VoxelPlayEnvironment component.");
            }
                        #endif
        }
コード例 #3
0
        /// <summary>
        /// Initialization method. Called by Voxel Play at startup.
        /// </summary>
        public override void Init()
        {
            env         = VoxelPlayEnvironment.instance;
            wormBorn    = new Dictionary <Vector3, bool> (100);
            texSize     = 1024;
            noiseValues = new float[texSize];
            const int octaves = 4;

            for (int o = 1; o <= octaves; o++)
            {
                float v = 0;
                for (int k = 0; k < texSize; k++)
                {
                    v += (Random.value - 0.5f) * o / 10f;
                    noiseValues [k] = (noiseValues [k] + v) * 0.5f;
                }
            }
            // Clamp
            for (int k = 0; k < texSize; k++)
            {
                if (noiseValues [k] < -0.5f)
                {
                    noiseValues [k] = -0.5f;
                }
                else if (noiseValues [k] > 0.5f)
                {
                    noiseValues [k] = 0.5f;
                }
            }
            worms = new List <HoleWorm> (100);
        }
コード例 #4
0
        void Start()
        {
            env = VoxelPlayEnvironment.instance;
            if (env == null)
            {
                DestroyImmediate(this);
                return;
            }
            lastPosition = transform.position;
            lastX        = int.MaxValue;

            if (enableVoxelLight)
            {
                MeshRenderer mr = GetComponent <MeshRenderer> ();
                if (mr != null)
                {
                    mat = mr.sharedMaterial;
                    useMaterialColor = !mat.name.Contains("VP Model");
                    if (useMaterialColor)
                    {
                        mat               = Instantiate(mat) as Material;
                        mat.hideFlags     = HideFlags.DontSave;
                        mr.sharedMaterial = mat;
                        normalMatColor    = mat.color;
                    }
                }
                UpdateLighting();
            }

            CheckNearChunks(transform.position);
        }
コード例 #5
0
 public void Init(VoxelPlayEnvironment env)
 {
     this.env = env;
     if (env != null)
     {
         env.OnVoxelBeforePlace += ApplyRule;
     }
 }
コード例 #6
0
        void OnValidate()
        {
            VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;

            if (env != null)
            {
                env.UpdateMaterialProperties();
            }
        }
コード例 #7
0
 public void Start()
 {
     env = VoxelPlayEnvironment.instance;
     if (env != null)
     {
         VoxelPlayInteractiveObjectsManager.instance.InteractiveObjectRegister(this);
     }
     OnStart();
 }
コード例 #8
0
        public virtual void Init(int threadId, int poolSize, VoxelPlayEnvironment env)
        {
            this.threadId        = threadId;
            this.env             = env;
            this.enableColliders = env.enableColliders;
            this.enableNavMesh   = env.enableNavMesh;
            this.enableTinting   = env.enableTinting;
            this.virtualChunk    = env.virtualChunk;
            this.denseTrees      = env.denseTrees;
            bool lowMemoryMode = env.lowMemoryMode;

            faceColors = new Color32 [4];
            for (int k = 0; k < faceColors.Length; k++)
            {
                faceColors[k] = Misc.color32White;
            }


#if UNITY_WEBGL
            meshJobs = new MeshJobData[384];
#else
            meshJobs = new MeshJobData [poolSize];
#endif
            meshJobMeshLastIndex                = poolSize - 1;
            meshJobMeshDataGenerationIndex      = poolSize - 1;
            meshJobMeshDataGenerationReadyIndex = poolSize - 1;
            meshJobMeshUploadIndex              = poolSize - 1;
            int initialCapacity = 15000;
            for (int k = 0; k < meshJobs.Length; k++)
            {
                meshJobs [k].vertices = Misc.GetList <Vector3> (lowMemoryMode, initialCapacity);
                meshJobs [k].uv0      = Misc.GetList <Vector4> (lowMemoryMode, initialCapacity);
                meshJobs [k].colors   = Misc.GetList <Color32> (lowMemoryMode, enableTinting ? initialCapacity : 4);
                meshJobs [k].buffers  = new MeshJobBuffer [VoxelPlayEnvironment.MAX_MATERIALS_PER_CHUNK];
                meshJobs [k].normals  = Misc.GetList <Vector3> (lowMemoryMode, initialCapacity);
                for (int j = 0; j < meshJobs [k].buffers.Length; j++)
                {
                    meshJobs [k].buffers [j].indices = new List <int> ();
                }
                if (enableColliders)
                {
                    meshJobs [k].colliderVertices = Misc.GetList <Vector3> (lowMemoryMode, 2700);
                    meshJobs [k].colliderIndices  = Misc.GetList <int> (lowMemoryMode, 4000);
                }
                if (enableNavMesh)
                {
                    meshJobs [k].navMeshVertices = Misc.GetList <Vector3> (lowMemoryMode, 2700);
                    meshJobs [k].navMeshIndices  = Misc.GetList <int> (lowMemoryMode, 4000);
                }
                meshJobs [k].mivs = new FastList <ModelInVoxel> ();
            }

            greedyCollider  = new VoxelPlayGreedyMesher();
            greedyNavMesh   = new VoxelPlayGreedyMesher();
            chunk9          = new Voxel [27] [];
            neighbourChunks = new VoxelChunk [27];
        }
コード例 #9
0
 void CheckTintColorFeature()
 {
     if (tintColor.colorValue.r != 1f || tintColor.colorValue.g != 1f || tintColor.colorValue.b != 1f)
     {
         VoxelPlayEnvironment e = env;
         if (e != null)
         {
             if (!e.enableTinting)
             {
                 EditorGUILayout.HelpBox("Tint Color shader feature is disabled in Voxel Play Environment component.", MessageType.Warning);
             }
         }
     }
 }
コード例 #10
0
        /// <summary>
        /// Initialization method. Called by Voxel Play at startup.
        /// </summary>
        public override void Init()
        {
            env = VoxelPlayEnvironment.instance;
            buildingPositions = new Dictionary <Vector3, BuildingStatus>(100);

            // Fill models with empty blocks so they clear any terrain or vegetation inside them when placing on the world
            if (buildings != null && buildings.Length > 0)
            {
                for (int k = 0; k < buildings.Length; k++)
                {
                    env.ModelFillInside(buildings[k]);
                }
            }
        }
コード例 #11
0
        void Start()
        {
            env = VoxelPlayEnvironment.instance;
            if (env == null)
            {
                DestroyImmediate(this);
                return;
            }
            env.OnChunkRender += ChunkRender;
            lastPosition       = transform.position;
            lastX              = int.MaxValue;

            if (enableVoxelLight)
            {
                FetchMaterials();
            }

            CheckNearChunks(transform.position);
        }
コード例 #12
0
        IEnumerator Consolidate()
        {
            if (gameObject == null)
            {
                yield break;
            }
            WaitForSeconds       w = new WaitForSeconds(1f);
            VoxelChunk           targetChunk;
            VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;

            if (env.GetChunk(transform.position, out targetChunk, false))
            {
                const float maxDist = 100 * 100;
                while (FastVector.SqrDistanceByValue(targetChunk.position, env.cameraMain.transform.position) < maxDist && env.ChunkIsInFrustum(targetChunk))
                {
                    yield return(w);
                }
                env.VoxelCancelDynamic(this);
            }
        }
コード例 #13
0
        public static void Init()
        {
            if (_instance != null)
            {
                return;
            }

            _instance = FindObjectOfType <VoxelPlayUI> ();
            if (_instance != null)
            {
                return;
            }

            VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;

            if (env == null)
            {
                return;
            }

            if (env.UICanvasPrefab == null)
            {
                env.UICanvasPrefab = Resources.Load <GameObject> ("VoxelPlay/UI/Voxel Play UI Canvas");
                if (env.UICanvasPrefab == null)
                {
                    return;
                }
            }

            GameObject canvas = Instantiate <GameObject> (env.UICanvasPrefab);

            canvas.name = env.UICanvasPrefab.name;
            if (canvas == null)
            {
                return;
            }

            _instance = canvas.GetComponent <VoxelPlayUI> ();
        }
コード例 #14
0
        void Start()
        {
            rb = GetComponent <Rigidbody> ();
            if (rb == null || rb.isKinematic)
            {
                return;
            }

            // If chunk is not rendered and have a rigidbody, wait until ready
            env = VoxelPlayEnvironment.instance;
            if (env == null)
            {
                return;
            }

            VoxelChunk chunk;

            if (!env.GetChunk(transform.position, out chunk, false) || !chunk.isRendered)
            {
                rb.isKinematic = true;
                StartCoroutine(WaitForChunk(chunk));
            }
        }
コード例 #15
0
 void Start()
 {
     if (rb == null)
     {
         rb = GetComponent <Rigidbody> ();
     }
     env = VoxelPlayEnvironment.instance;
     if (persistentItem)
     {
         // Clone material to support voxel lighting
         Renderer renderer = GetComponent <Renderer> ();
         if (renderer != null)
         {
             mat = renderer.sharedMaterial;
             if (mat != null)
             {
                 mat = Instantiate <Material> (mat);
                 renderer.sharedMaterial = mat;
             }
         }
         ManageItem();
     }
 }
コード例 #16
0
        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");

            loadModel       = serializedObject.FindProperty("loadModel");
            constructorSize = serializedObject.FindProperty("constructorSize");

            fps = (VoxelPlayFirstPersonController)target;
            env = VoxelPlayEnvironment.instance;
        }
コード例 #17
0
        /// <summary>
        /// Use this method to initialize the terrain generator
        /// </summary>
        public void Initialize()
        {
            env = VoxelPlayEnvironment.instance;
            if (env == null)
            {
                return;
            }
            world = env.world;
            if (world == null)
            {
                return;
            }

            // Migration introduced in v4.0: TODO: remove in the future
            if (seaLevel >= 0)
            {
                waterLevel = (int)(seaLevel * maxHeight);
                seaLevel   = -1;
            }

            env.waterLevel = waterLevel;
            Init();
            isInitialized = true;
        }
コード例 #18
0
        public static Material GetDefaultMaterial(this RenderType o, VoxelPlayEnvironment context)
        {
            string name;
            bool   shadowsOnWater = context.shadowsOnWater && !context.draftModeActive;

            switch (o)
            {
            case RenderType.Opaque:
            case RenderType.Opaque6tex:
                name = "VP Voxel Triangle Opaque";
                break;

            case RenderType.OpaqueAnimated:
                name = "VP Voxel Triangle Opaque Animated";
                break;

            case RenderType.Cutout:
                name = "VP Voxel Triangle Cutout";
                break;

            case RenderType.CutoutCross:
                name = "VP Voxel Triangle Cutout Cross";
                break;

            case RenderType.Water:
                if (context.realisticWater)
                {
                    if (shadowsOnWater)
                    {
                        name = "VP Voxel Triangle Water Realistic";
                    }
                    else
                    {
                        name = "VP Voxel Triangle Water Realistic No Shadows";
                    }
                }
                else
                {
                    if (shadowsOnWater)
                    {
                        name = "VP Voxel Triangle Water";
                    }
                    else
                    {
                        name = "VP Voxel Triangle Water No Shadows";
                    }
                }
                break;

            case RenderType.Transp6tex:
                if (context.doubleSidedGlass)
                {
                    name = "VP Voxel Triangle Transp Double Sided";
                }
                else
                {
                    name = "VP Voxel Triangle Transp";
                }
                break;

            case RenderType.Cloud:
                name = "VP Voxel Triangle Cloud";
                break;

            case RenderType.OpaqueNoAO:
                name = "VP Voxel Triangle Opaque No AO";
                break;

            default:
                Debug.LogError("Unknown Render type?");
                return(null);
            }
            return(Resources.Load <Material>("VoxelPlay/Materials/" + name));
        }
コード例 #19
0
ファイル: VoxelPlayUI.cs プロジェクト: jisuhyun/mobileTest
        void CheckReferences()
        {
            if (env == null)
            {
                env = VoxelPlayEnvironment.instance;
            }

            sb      = new StringBuilder(1000);
            sbDebug = new StringBuilder(1000);

            if (canvas == null)
            {
                if (env.UICanvasPrefab == null)
                {
                    Debug.LogError("Voxel Play: UI Canvas not defined.");
                    return;
                }
                else
                {
                    canvas = GameObject.Find(UI_CANVAS_NAME);
                    if (canvas == null)
                    {
                        canvas      = Instantiate <GameObject> (env.UICanvasPrefab);
                        canvas.name = UI_CANVAS_NAME;
                        canvas.transform.SetParent(env.worldRoot, false);
                    }
                }
            }
            CheckEventSystem();
            rtCanvas = canvas.GetComponent <RectTransform> ();
            selectedItemPlaceholder    = canvas.transform.Find("ItemPlaceholder").gameObject;
            selectedItem               = selectedItemPlaceholder.transform.Find("ItemImage").GetComponent <RawImage> ();
            selectedItemName           = selectedItemPlaceholder.transform.Find("ItemName").GetComponent <Text> ();
            selectedItemNameShadow     = selectedItemPlaceholder.transform.Find("ItemNameShadow").GetComponent <Text> ();
            selectedItemQuantity       = selectedItemPlaceholder.transform.Find("QuantityShadow/QuantityText").GetComponent <Text> ();
            selectedItemQuantityShadow = selectedItemPlaceholder.transform.Find("QuantityShadow").GetComponent <Text> ();
            fpsShadow = canvas.transform.Find("FPSShadow").GetComponent <Text> ();
            fpsText   = fpsShadow.transform.Find("FPSText").GetComponent <Text> ();
            fpsShadow.gameObject.SetActive(env.showFPS);
            console = canvas.transform.Find("Console").gameObject;
            console.GetComponent <Image> ().color = env.consoleBackgroundColor;
            consoleText            = canvas.transform.Find("Console/Scroll View/Viewport/ConsoleText").GetComponent <Text> ();
            status                 = canvas.transform.Find("Status").gameObject;
            statusBackground       = status.GetComponent <Image> ();
            statusBackground.color = env.statusBarBackgroundColor;
            statusText             = canvas.transform.Find("Status/StatusText").GetComponent <Text> ();
            debug = canvas.transform.Find("Debug").gameObject;
            debug.GetComponent <Image> ().color = env.consoleBackgroundColor;
            debugText  = canvas.transform.Find("Debug/Scroll View/Viewport/DebugText").GetComponent <Text> ();
            inputField = canvas.transform.Find("Status/InputField").GetComponent <InputField> ();
            inputField.onEndEdit.AddListener(delegate {
                UserConsoleCommandHandler();
            });
            inventoryPlaceholder       = canvas.transform.Find("InventoryPlaceholder").gameObject;
            inventoryItemTemplate      = inventoryPlaceholder.transform.Find("ItemButtonTemplate").gameObject;
            inventoryTitle             = inventoryPlaceholder.transform.Find("Title").gameObject;
            inventoryTitleText         = inventoryPlaceholder.transform.Find("Title/Text").GetComponent <Text> ();
            inventoryUIShouldBeRebuilt = true;
            initPanel    = canvas.transform.Find("InitPanel").gameObject;
            initProgress = initPanel.transform.Find("Box/Progress").transform;
            initText     = initPanel.transform.Find("StatusText").GetComponent <Text> ();
        }
コード例 #20
0
        void OnGUI()
        {
            if (env == null)
            {
                env = VoxelPlayEnvironment.instance;
                if (env == null)
                {
                    world = null;
                }
                EditorGUILayout.HelpBox("Biome Explorer cannot find a Voxel Play Environment instance in the current scene.", MessageType.Error);
                GUIUtility.ExitGUI();
            }
            else
            {
                world = env.world;
            }

            if (world == null)
            {
                EditorGUILayout.HelpBox("Assign a World Definition to the Voxel Play Environment instance.", MessageType.Warning);
                GUIUtility.ExitGUI();
            }

            if (terrainTex == null || moistureTex == null)
            {
                RefreshTextures();
                GUIUtility.ExitGUI();
            }

            GUIStyle labelStyle = new GUIStyle(GUI.skin.label);

            if (titleLabelStyle == null)
            {
                titleLabelStyle = new GUIStyle(EditorStyles.label);
            }
            titleLabelStyle.normal.textColor = titleColor;
            titleLabelStyle.fontStyle        = FontStyle.Bold;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.HelpBox("Preview terrain generation and biome distribution based on current settings.", MessageType.Info);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Min X", GUILayout.Width(100));
            proposedMinX = EditorGUILayout.FloatField(proposedMinX, GUILayout.MaxWidth(120));
            EditorGUILayout.LabelField("Max X", GUILayout.Width(100));
            proposedMaxX = EditorGUILayout.FloatField(proposedMaxX, GUILayout.MaxWidth(120));
            if (GUILayout.Button("<<", GUILayout.Width(40)))
            {
                float shift = (maxX - minX) * 0.5f;
                proposedMinX  -= shift;
                proposedMaxX  -= shift;
                requestRefresh = true;
            }
            if (GUILayout.Button("<", GUILayout.Width(40)))
            {
                float shift = (maxX - minX) * 0.1f;
                proposedMinX  -= shift;
                proposedMaxX  -= shift;
                requestRefresh = true;
            }
            if (GUILayout.Button(">", GUILayout.Width(40)))
            {
                float shift = (maxX - minX) * 0.1f;
                proposedMinX  += shift;
                proposedMaxX  += shift;
                requestRefresh = true;
            }
            if (GUILayout.Button(">>", GUILayout.Width(40)))
            {
                float shift = (maxX - minX) * 0.5f;
                proposedMinX  += shift;
                proposedMaxX  += shift;
                requestRefresh = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Min Z", GUILayout.Width(100));
            proposedMinZ = EditorGUILayout.FloatField(proposedMinZ, GUILayout.MaxWidth(120));
            EditorGUILayout.LabelField("Max Z", GUILayout.Width(100));
            proposedMaxZ = EditorGUILayout.FloatField(proposedMaxZ, GUILayout.MaxWidth(120));
            if (GUILayout.Button("<<", GUILayout.Width(40)))
            {
                float shift = (maxZ - minZ) * 0.5f;
                proposedMinZ  -= shift;
                proposedMaxZ  -= shift;
                proposedSliceZ = (proposedMinZ + proposedMaxZ) * 0.5f;
                requestRefresh = true;
            }
            if (GUILayout.Button("<", GUILayout.Width(40)))
            {
                float shift = (maxZ - minZ) * 0.1f;
                proposedMinZ  -= shift;
                proposedMaxZ  -= shift;
                proposedSliceZ = (proposedMinZ + proposedMaxZ) * 0.5f;
                requestRefresh = true;
            }
            if (GUILayout.Button(">", GUILayout.Width(40)))
            {
                float shift = (maxZ - minZ) * 0.1f;
                proposedMinZ  += shift;
                proposedMaxZ  += shift;
                proposedSliceZ = (proposedMinZ + proposedMaxZ) * 0.5f;
                requestRefresh = true;
            }
            if (GUILayout.Button(">>", GUILayout.Width(40)))
            {
                float shift = (maxZ - minZ) * 0.5f;
                proposedMinZ  += shift;
                proposedMaxZ  += shift;
                proposedSliceZ = (proposedMinZ + proposedMaxZ) * 0.5f;
                requestRefresh = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Slice Z", GUILayout.Width(100));
            proposedSliceZ = EditorGUILayout.FloatField(proposedSliceZ, GUILayout.MaxWidth(120));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Refresh Window", "Refresh textures to reflect new filters."), GUILayout.Width(140)))
            {
                requestRefresh = true;
            }
            if (GUILayout.Button(new GUIContent("-> World Definition", "Show World Definition in the inspector."), GUILayout.Width(140)))
            {
                Selection.activeObject = world;
            }
            if (GUILayout.Button(new GUIContent("-> Terrain Generator", "Show Terrain Generator in the inspector."), GUILayout.Width(140)))
            {
                Selection.activeObject = tg;
            }
            if (GUILayout.Button(new GUIContent("-> Environment", "Show Voxel Play Environment in the inspector."), GUILayout.Width(140)))
            {
                Selection.activeGameObject = env.gameObject;
            }
            if (GUILayout.Button(new GUIContent("Reload Config", "Resets heightmaps and biome cache and initializes terrain generator."), GUILayout.Width(140)))
            {
                env.NotifyTerrainGeneratorConfigurationChanged();
                requestRefresh = true;
                GUIUtility.ExitGUI();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            Rect space;

            if (previewTextureMat == null)
            {
                previewTextureMat = Resources.Load <Material> ("VoxelPlay/PreviewTexture");
            }

            // Draw heightmap distribution
            if (terrainTex != null)
            {
                EditorGUILayout.LabelField(new GUIContent("Height Map Preview"), titleLabelStyle);
                space        = EditorGUILayout.BeginVertical();
                space.width -= 20;
                GUILayout.Space(terrainTex.height);
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15);
                space.position += new Vector2(15, 0);
                EditorGUI.DrawPreviewTexture(space, terrainTex, previewTextureMat);
                GUILayout.Space(5);
                EditorGUILayout.EndHorizontal();

                // Draw 0-1 range
                space.position -= new Vector2(15, 0);
                EditorGUI.LabelField(space, "1");
                space.position += new Vector2(0, space.height - 10f);
                EditorGUI.LabelField(space, "0");

                // Draw x-axis labels
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15);
                EditorGUILayout.LabelField("Min X = " + minX);
                labelStyle.alignment = TextAnchor.MiddleCenter;
                EditorGUILayout.LabelField("Slize Z = " + sliceZ + " / Min Y = " + calcMinAltitude.ToString("F3") + " / Max Y = " + calcMaxAltitude.ToString("F3"), labelStyle);
                labelStyle.alignment = TextAnchor.MiddleRight;
                EditorGUILayout.LabelField("Max X = " + maxX, labelStyle);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();


            // Draw moisture distribution
            if (terrainTex != null)
            {
                EditorGUILayout.LabelField(new GUIContent("Moisture Preview"), titleLabelStyle);
                space        = EditorGUILayout.BeginVertical();
                space.width -= 20;
                GUILayout.Space(moistureTex.height);
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15);
                space.position += new Vector2(15, 0);
                EditorGUI.DrawPreviewTexture(space, moistureTex, previewTextureMat);
                GUILayout.Space(5);
                EditorGUILayout.EndHorizontal();

                // Draw 0-1 range
                space.position -= new Vector2(15, 0);
                EditorGUI.LabelField(space, "1");
                space.position += new Vector2(0, space.height - 10f);
                EditorGUI.LabelField(space, "0");

                // Draw x-axis labels
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15);
                EditorGUILayout.LabelField("Min X = " + minX);
                labelStyle.alignment = TextAnchor.MiddleCenter;
                EditorGUILayout.LabelField("Slize Z = " + sliceZ + " / Min Y = " + calcMinMoisture.ToString("F3") + " / Max Y = " + calcMaxMoisture.ToString("F3"), labelStyle);
                labelStyle.alignment = TextAnchor.MiddleRight;
                EditorGUILayout.LabelField("Max X = " + maxX, labelStyle);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();


            if (world.biomes != null && biomeTex != null)
            {
                // Draw heightmap texture
                EditorGUILayout.LabelField(new GUIContent("Biome Map Preview"), titleLabelStyle);

                EditorGUILayout.BeginHorizontal();

                // Biome legend
                EditorGUILayout.BeginVertical(GUILayout.MaxWidth(180));
                EditorGUILayout.Separator();
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Hide All", GUILayout.Width(80)))
                {
                    ToggleBiomes(false);
                    requestRefresh = true;
                }
                if (GUILayout.Button("Show All", GUILayout.Width(80)))
                {
                    ToggleBiomes(true);
                    requestRefresh = true;
                }
                if (GUILayout.Button("Default Colors", GUILayout.Width(120)))
                {
                    env.SetBiomeDefaultColors(true);
                    requestRefresh = true;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUI.BeginChangeCheck();
                for (int k = 0; k < world.biomes.Length; k++)
                {
                    BiomeDefinition biome = world.biomes [k];
                    if (biome == null)
                    {
                        continue;
                    }
                    float perc = 100f * (float)biome.biomeMapOccurrences / (biomeTex.width * biomeTex.height);
                    DrawLegend(biome.biomeMapColor, biome.name + " (" + perc.ToString("F2") + "%)", biome);
                }
                DrawLegend(waterColor, "Water", null);

                if (EditorGUI.EndChangeCheck())
                {
                    requestRefresh = true;
                }
                EditorGUILayout.Separator();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Grid Size", GUILayout.Width(100));
                gridStep = EditorGUILayout.IntField(gridStep, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Texture Size", GUILayout.Width(100));
                mapResolution = EditorGUILayout.IntField(mapResolution, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Separator();
                EditorGUILayout.Separator();
                // Tester
                EditorGUILayout.LabelField(new GUIContent("Biome Tester"), titleLabelStyle);
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Altitude?", GUILayout.Width(100));
                inputAltitude = EditorGUILayout.Slider(inputAltitude, 0, 1, GUILayout.Width(130));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Moisture?", GUILayout.Width(100));
                inputMoisture = EditorGUILayout.Slider(inputMoisture, 0, 1, GUILayout.Width(130));
                EditorGUILayout.EndHorizontal();
                if (EditorGUI.EndChangeCheck())
                {
                    CalcBiome();
                }
                EditorGUILayout.LabelField(biomeTestResult);
                EditorGUILayout.EndVertical();

                // Biome map
                space = EditorGUILayout.BeginVertical();
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
                EditorGUI.DrawPreviewTexture(space, biomeTex, previewTextureMat, ScaleMode.ScaleToFit);

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Separator();
            }

            if (requestRefresh)
            {
                RefreshTextures();
            }
        }
コード例 #21
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();
        }