Exemple #1
0
 private void OnDisable()
 {
     this.SendEvent("ObjectSelectorClosed", false);
     if (this.m_ListArea != null)
     {
         this.m_StartGridSize.value = this.m_ListArea.gridSize;
     }
     Undo.CollapseUndoOperations(this.m_ModalUndoGroup);
     if (ObjectSelector.s_SharedObjectSelector == this)
     {
         ObjectSelector.s_SharedObjectSelector = null;
     }
     if (this.m_EditorCache != null)
     {
         this.m_EditorCache.Dispose();
     }
     AssetPreview.ClearTemporaryAssetPreviews();
 }
Exemple #2
0
        void OnDisable()
        {
            NotifySelectorClosed(false);
            if (m_ListArea != null)
            {
                m_StartGridSize.value = m_ListArea.gridSize;
            }

            Undo.CollapseUndoOperations(m_ModalUndoGroup);

            if (s_SharedObjectSelector == this)
            {
                s_SharedObjectSelector = null;
            }
            if (m_EditorCache != null)
            {
                m_EditorCache.Dispose();
            }

            AssetPreview.ClearTemporaryAssetPreviews();

            m_Debounce = null;
        }
Exemple #3
0
        internal static void RemoveTerrainLayer(Terrain terrain, int index)
        {
            var terrainData = terrain.terrainData;
            int width       = terrainData.alphamapWidth;
            int height      = terrainData.alphamapHeight;

            float[,,] alphamap = terrainData.GetAlphamaps(0, 0, width, height);
            int alphaCount = alphamap.GetLength(2);

            int newAlphaCount = alphaCount - 1;

            float[,,] newalphamap = new float[height, width, newAlphaCount];

            // move further alphamaps one index below
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    for (int a = 0; a < index; ++a)
                    {
                        newalphamap[y, x, a] = alphamap[y, x, a];
                    }
                    for (int a = index + 1; a < alphaCount; ++a)
                    {
                        newalphamap[y, x, a - 1] = alphamap[y, x, a];
                    }
                }
            }

            // normalize weights in new alpha map
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    float sum = 0.0F;
                    for (int a = 0; a < newAlphaCount; ++a)
                    {
                        sum += newalphamap[y, x, a];
                    }
                    if (sum >= 0.01)
                    {
                        float multiplier = 1.0F / sum;
                        for (int a = 0; a < newAlphaCount; ++a)
                        {
                            newalphamap[y, x, a] *= multiplier;
                        }
                    }
                    else
                    {
                        // in case all weights sum to pretty much zero (e.g.
                        // removing splat that had 100% weight), assign
                        // everything to 1st splat texture (just like
                        // initial terrain).
                        for (int a = 0; a < newAlphaCount; ++a)
                        {
                            newalphamap[y, x, a] = (a == 0) ? 1.0f : 0.0f;
                        }
                    }
                }
            }

            // remove splat from terrain prototypes
            var layers    = terrainData.terrainLayers;
            var newSplats = new TerrainLayer[layers.Length - 1];

            for (int a = 0; a < index; ++a)
            {
                newSplats[a] = layers[a];
            }
            for (int a = index + 1; a < alphaCount; ++a)
            {
                newSplats[a - 1] = layers[a];
            }
            Undo.SetCurrentGroupName("Remove terrain layer");
            terrainData.SetTerrainLayersRegisterUndo(newSplats, "Remove Layer");
            var undoObjects = new List <UnityEngine.Object>();

            undoObjects.AddRange(terrainData.alphamapTextures);
            Undo.RegisterCompleteObjectUndo(undoObjects.ToArray(), "Apply Modified Alphamaps");
            Undo.CollapseUndoOperations(Undo.GetCurrentGroup());

            // set new alphamaps
            terrainData.SetAlphamaps(0, 0, newalphamap);
        }