Example #1
0
        public void SetPreviewGrassTexture()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (localSettings.hasMasterTerrain)
            {
                if (selectIndex < localSettings.masterTerrain.terrainData.detailPrototypes.Length && selectIndex >= 0)
                {
                    DetailPrototype detailPrototype = localSettings.masterTerrain.terrainData.detailPrototypes[selectIndex];
                    if (detailPrototype.usePrototypeMesh)
                    {
                        #if UNITY_EDITOR
                        preview.tex = UnityEditor.AssetPreview.GetAssetPreview(detailPrototype.prototype);
                        #endif
                    }
                    else
                    {
                        preview.tex = detailPrototype.prototypeTexture;
                    }
                    if (preview.tex != null)
                    {
                        name = Mathw.CutString(preview.tex.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
        }
Example #2
0
        public void SetPreviewTreeTexture()
        {
            #if UNITY_EDITOR
            TC_Settings settings = TC_Settings.instance;

            if (settings.hasMasterTerrain)
            {
                TreePrototype[] treePrototypes = settings.masterTerrain.terrainData.treePrototypes;
                if (selectIndex < treePrototypes.Length && selectIndex >= 0)
                {
                    if (treePrototypes[selectIndex].prefab)
                    {
                        preview.tex = UnityEditor.AssetPreview.GetAssetPreview(treePrototypes[selectIndex].prefab);
                        name        = Mathw.CutString(treePrototypes[selectIndex].prefab.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
            #endif
        }
Example #3
0
        public void SetPreviewSplatTexture()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (localSettings.hasMasterTerrain)
            {
                Texture2D splatTexture;
                int       length = TC.GetTerrainSplatTexture(localSettings.masterTerrain, selectIndex, out splatTexture);

                if (selectIndex < length && selectIndex >= 0)
                {
                    preview.tex = splatTexture;
                    if (preview.tex != null)
                    {
                        name = Mathw.CutString(preview.tex.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
        }
Example #4
0
 static public void AutoGenerate(Rect generateRect, bool waitForNextFrame = true)
 {
     // Debug.Log("Auto Generate");
     if (TC_Generate.instance != null)
     {
         TC_Generate.instance.cmdGenerate      = true;
         TC_Generate.instance.autoGenerateRect = Mathw.ClampRect(generateRect, new Rect(0, 0, 1, 1));
     }
 }
Example #5
0
        public void SetPreviewObjectTexture()
        {
            #if UNITY_EDITOR
            if (spawnObject == null)
            {
                preview.tex = null; return;
            }
            if (spawnObject.go == null)
            {
                // Debug.Log("preview tex is set to null");
                preview.tex = null;
                return;
            }
            // Debug.Log("Yes");
            preview.tex = UnityEditor.AssetPreview.GetAssetPreview(spawnObject.go);
            name        = Mathw.CutString(spawnObject.go.name, TC.nodeLabelLength);
            #endif

            // Debug.Log("SetPreviewObjectTexture");
        }
Example #6
0
        public void SetPixel(float v)
        {
            x = TC_Area2D.current.previewPos.x;
            y = TC_Area2D.current.previewPos.y;

            int px = (int)x;
            int py = (int)y;

            if (px > 127 || px < 0)
            {
                return;
            }
            if (py > 127 || py < 0)
            {
                return;
            }

            py *= 512;
            px *= 4;

            Color32 color = Color.white * v;

            if (v > 1)
            {
                color = Color.Lerp(Color.red, new Color(1, 0, 1), Mathw.Clamp01(v - 1));
            }
            else if (v < 0)
            {
                color = Color.Lerp(Color.cyan, Color.blue, Mathw.Clamp01(v * -1));
            }

            bytes[px + py]     = (byte)(color.r);
            bytes[px + py + 1] = (byte)(color.g);
            bytes[px + py + 2] = (byte)(color.b);
            bytes[px + py + 3] = 1;
        }
Example #7
0
        public void SetPreviewSplatTexture()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (localSettings.hasMasterTerrain)
            {
                if (selectIndex < localSettings.masterTerrain.terrainData.splatPrototypes.Length && selectIndex >= 0)
                {
                    preview.tex = localSettings.masterTerrain.terrainData.splatPrototypes[selectIndex].texture;
                    if (preview.tex != null)
                    {
                        name = Mathw.CutString(preview.tex.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
        }
Example #8
0
        public bool SetCurrentArea(TCUnityTerrain tcTerrain, int outputId)
        {
            // Debug.Log(tcTerrain.terrain.name);
            Terrain terrain = currentTerrain = tcTerrain.terrain;

            currentTCUnityTerrain = tcTerrain;
            currentTCTerrain      = tcTerrain;
            currentTerrainArea    = terrainAreas[0];

            if (!currentTCUnityTerrain.active)
            {
                return(false);
            }

            intResolution = new Int2();
            Int2 resolution2 = new Int2();

            if (terrain.terrainData.heightmapResolution > 2049)
            {
                resExpandBorder     = 0;
                resExpandBorderSize = 0;
            }
            else
            {
                resExpandBorder     = Mathf.RoundToInt((terrain.terrainData.heightmapResolution - 1) * resExpandBorderPercentage);
                resExpandBorderSize = terrain.terrainData.size.x * resExpandBorderPercentage;
            }

            // Debug.Log(resExpandBorder);
            // Debug.Log(resExpandBorderSize);

            if (outputId == TC.heightOutput)
            {
                intResolution.x = intResolution.y = (terrain.terrainData.heightmapResolution) + (resExpandBorder * 2);
                resolution2     = new Int2(terrain.terrainData.heightmapResolution, terrain.terrainData.heightmapResolution);
            }
            else if (outputId == TC.splatOutput)
            {
                intResolution.x = intResolution.y = terrain.terrainData.alphamapResolution;
                resolution2     = intResolution;
                splatLength     = currentTerrain.terrainData.splatPrototypes.Length;
                splatmapLength  = currentTerrain.terrainData.alphamapTextures.Length;
            }
            else if (outputId == TC.treeOutput)
            {
                intResolution.x = intResolution.y = (int)(terrain.terrainData.size.x / terrainLayer.treeResolutionPM); resolution2 = intResolution;
            }
            else if (outputId == TC.grassOutput)
            {
                intResolution.x = intResolution.y = terrain.terrainData.detailResolution; resolution2 = intResolution;
            }
            else if (outputId == TC.objectOutput)
            {
                intResolution.x = intResolution.y = (int)(terrain.terrainData.size.x / terrainLayer.objectResolutionPM); resolution2 = intResolution;
                //if (false)
                //{
                //    area.center = new Vector2((int)terrainLayer.objectTransform.position.x, (int)terrainLayer.objectTransform.position.z);
                //    area.size = new Vector2(terrainLayer.objectResolutionPM, terrainLayer.objectResolutionPM);
                //    totalArea.position = area.position;
                //    totalArea.size = terrainLayer.objectAreaSize;
                //    resolutionPM = new Vector2(terrainLayer.objectAreaSize.x / (resolution2.x), terrainLayer.objectAreaSize.y / (resolution2.y));
                //}
            }
            else if (outputId == TC.colorOutput)
            {
                intResolution.x = intResolution.y = terrainLayer.colormapResolution; resolution2 = intResolution;
            }

            outputOffsetV2 = new Vector2(terrainLayer.layerGroups[outputId].t.position.x, terrainLayer.layerGroups[outputId].t.position.z);
            outputOffsetV3 = new Vector3(outputOffsetV2.x, 0, outputOffsetV2.y);

            resolution = intResolution.ToVector2();

            if (intResolution.x < TC_Settings.instance.previewResolution)
            {
                previewResolution = intResolution.x; TC_Reporter.Log("From " + TC_Settings.instance.previewResolution + " To " + previewResolution);
            }
            else
            {
                previewResolution = TC_Settings.instance.previewResolution;
            }

            resToPreview = new Vector2((previewResolution - 0) / (totalArea.width + 0), (previewResolution - 0) / (totalArea.height + 0));

            if (outputId == TC.heightOutput || outputId == TC.splatOutput)
            {
                resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 1), terrain.terrainData.size.z / (resolution2.y - 1));
            }
            else
            {
                resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 0), terrain.terrainData.size.z / (resolution2.y - 0));
            }

            // if (outputId == TC.objectOutput) Debug.Log(resolutionPM);

            // resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 1), terrain.terrainData.size.z / (resolution2.y - 1));

            if (outputId == TC.heightOutput)
            {
                // area = new Rect(terrain.transform.position.x - resolutionPM.x, terrain.transform.position.z - resolutionPM.y, intResolution.x - 0, intResolution.y - 0);
                area = new Rect(terrain.transform.position.x - (resolutionPM.x * resExpandBorder), terrain.transform.position.z - (resolutionPM.y * resExpandBorder), intResolution.x - 0, intResolution.y - 0);
            }
            else
            {
                // resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x), terrain.terrainData.size.z / (resolution2.y));
                Vector2 posSnap;
                posSnap.x = Mathw.Snap(terrain.transform.position.x, resolutionPM.x);
                posSnap.y = Mathw.Snap(terrain.transform.position.z, resolutionPM.y);

                if (outputId == TC.treeOutput || outputId == TC.objectOutput)
                {
                    // posSnap += resolutionPM / 2;
                }
                area = new Rect(posSnap.x, posSnap.y, intResolution.x, intResolution.y);

                snapOffsetUV    = (new Vector2(terrain.transform.position.x, terrain.transform.position.z) - posSnap);
                snapOffsetUV.x /= terrain.terrainData.size.x;
                snapOffsetUV.y /= terrain.terrainData.size.z;

                // Debug.Log(area);
            }

            bounds      = new Bounds(terrain.transform.position + terrain.terrainData.size / 2, terrain.terrainData.size);
            startPos    = new Vector3(area.xMin, terrain.transform.position.y, area.yMin);
            terrainSize = terrain.terrainData.size;

            return(true);
        }
        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            if (resetTextures)
            {
                DisposeTextures();
            }

            itemList.Clear();

            totalActive = 0;

            int listIndex = 0;

            for (int i = t.childCount - 1; i >= 0; i--)
            {
                Transform child = t.GetChild(i);

                TC_SelectItem selectItem = child.GetComponent <TC_SelectItem>();
                if (selectItem == null)
                {
                    TC.MoveToDustbin(child);
                }
                else
                {
                    selectItem.SetParameters(this, listIndex);
                    selectItem.parentItem = this;

                    selectItem.active = selectItem.visible;

                    if (outputId == TC.splatOutput && selectItem.splatCustom)
                    {
                        if (TC_Settings.instance.hasMasterTerrain)
                        {
                            if (selectItem.splatCustomValues.Length != TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length)
                            {
                                selectItem.splatCustomValues = Mathw.ResizeArray <float>(selectItem.splatCustomValues, TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length);
                            }
                        }
                        selectItem.CalcSplatCustomTotal();
                    }

                    selectItem.SetPreviewItemTexture(); // Put deactive if listIndex is out of bounds

                    if (selectItem.active)
                    {
                        ++totalActive;
                    }

                    if (outputId == TC.treeOutput)
                    {
                        if (selectItem.tree == null)
                        {
                            selectItem.tree = new TC_SelectItem.Tree();
                        }

                        if (selectItem.active)
                        {
                            bool addToList = true;

                            List <TC_SelectItem> treeSelectItems = TC_Area2D.current.terrainLayer.treeSelectItems;

                            if (!rebuildGlobalLists)
                            {
                                int index = treeSelectItems.IndexOf(selectItem);
                                if (index != -1)
                                {
                                    addToList = false; selectItem.globalListIndex = index;
                                }
                            }

                            if (addToList)
                            {
                                treeSelectItems.Add(selectItem);
                                selectItem.globalListIndex = treeSelectItems.Count - 1;
                            }
                        }
                    }
                    else if (outputId == TC.objectOutput)
                    {
                        if (selectItem.spawnObject == null)
                        {
                            selectItem.spawnObject = new TC_SelectItem.SpawnObject();
                        }
                        if (selectItem.spawnObject.go == null)
                        {
                            selectItem.active = false;
                            TC_Area2D.current.terrainLayer.objectSelectItems.Remove(selectItem);
                            // Debug.Log("Remove from list");
                        }

                        if (selectItem.active)
                        {
                            bool addToList = true;

                            List <TC_SelectItem> objectSelectItems = TC_Area2D.current.terrainLayer.objectSelectItems;

                            if (!rebuildGlobalLists)
                            {
                                int index = objectSelectItems.IndexOf(selectItem);
                                if (index != -1)
                                {
                                    addToList = false; selectItem.globalListIndex = index;
                                }
                            }

                            if (addToList)
                            {
                                objectSelectItems.Add(selectItem);
                                selectItem.globalListIndex = objectSelectItems.Count - 1;
                            }
                            selectItem.selectIndex = listIndex;
                        }
                    }

                    selectItem.SetPreviewItemTexture();
                    selectItem.SetPreviewColor();

                    itemList.Add(selectItem);
                    listIndex++;
                }
            }

            if (refreshRangeItem != null || refreshRanges)
            {
                refreshRanges = false;
                RefreshRanges();
                refreshRangeItem = null;
            }
            else if (refresh || TC.refreshPreviewImages)
            {
                CalcPreview();
            }
        }