Пример #1
0
        public static IEnumerator Destroy(TerrainHLOD hlod)
        {
            var controller = hlod.GetComponent <HLODControllerBase>();

            if (controller == null)
            {
                yield break;
            }

            try
            {
                EditorUtility.DisplayProgressBar("Destroy HLOD", "Destroying HLOD files", 0.0f);
                var convertedPrefabObjects = hlod.ConvertedPrefabObjects;
                for (int i = 0; i < convertedPrefabObjects.Count; ++i)
                {
                    PrefabUtility.UnpackPrefabInstance(convertedPrefabObjects[i], PrefabUnpackMode.OutermostRoot,
                                                       InteractionMode.AutomatedAction);
                }


                var generatedObjects = hlod.GeneratedObjects;
                for (int i = 0; i < generatedObjects.Count; ++i)
                {
                    if (generatedObjects[i] == null)
                    {
                        continue;
                    }
                    var path = AssetDatabase.GetAssetPath(generatedObjects[i]);
                    if (string.IsNullOrEmpty(path) == false)
                    {
                        AssetDatabase.DeleteAsset(path);
                    }
                    else
                    {
                        //It means scene object.
                        //Destroy it.
                        Object.DestroyImmediate(generatedObjects[i]);
                    }

                    EditorUtility.DisplayProgressBar("Destroy HLOD", "Destroying HLOD files", (float)i / (float)generatedObjects.Count);
                }
                generatedObjects.Clear();
                Object.DestroyImmediate(controller);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            EditorUtility.SetDirty(hlod.gameObject);
            EditorUtility.SetDirty(hlod);
        }
Пример #2
0
        public static IEnumerator Create(TerrainHLOD hlod)
        {
            TerrainHLODCreator creator = new TerrainHLODCreator(hlod);

            yield return(creator.CreateImpl());
        }
Пример #3
0
 private TerrainHLODCreator(TerrainHLOD hlod)
 {
     m_hlod = hlod;
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();

            TerrainHLOD hlod = target as TerrainHLOD;

            if (hlod == null)
            {
                EditorGUILayout.LabelField("TerrainHLOD is null.");
                return;
            }
            isShowCommon = EditorGUILayout.BeginFoldoutHeaderGroup(isShowCommon, "Common");
            if (isShowCommon == true)
            {
                EditorGUILayout.PropertyField(m_TerrainDataProperty, Styles.SourceText);
                EditorGUILayout.PropertyField(m_DestoryTerrainProperty, Styles.DestoryTerrainText);
                EditorGUILayout.PropertyField(m_ChunkSizeProperty);

                m_ChunkSizeProperty.floatValue = HLODUtils.GetChunkSizePropertyValue(m_ChunkSizeProperty.floatValue);

                var bounds = hlod.GetBounds();
                int depth  = m_splitter.CalculateTreeDepth(bounds, m_ChunkSizeProperty.floatValue);
                EditorGUILayout.LabelField($"The HLOD tree will be created with {depth} levels.");
                if (depth > 5)
                {
                    EditorGUILayout.LabelField($"Node Level Count greater than 5 may cause a frozen Editor.", Styles.RedTextColor);
                    EditorGUILayout.LabelField($"Use a value less than 5.", Styles.RedTextColor);
                }


                EditorGUILayout.PropertyField(m_BorderVertexCountProperty);
                m_LODSlider.Draw();
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            isShowSimplifier = EditorGUILayout.BeginFoldoutHeaderGroup(isShowSimplifier, "Simplifier");
            if (isShowSimplifier == true)
            {
                if (m_SimplifierTypes.Length > 0)
                {
                    int simplifierIndex = Math.Max(Array.IndexOf(m_SimplifierTypes, hlod.SimplifierType), 0);
                    simplifierIndex     = EditorGUILayout.Popup("Simplifier", simplifierIndex, m_SimplifierNames);
                    hlod.SimplifierType = m_SimplifierTypes[simplifierIndex];

                    var info = m_SimplifierTypes[simplifierIndex].GetMethod("OnGUI");
                    if (info != null)
                    {
                        if (info.IsStatic == true)
                        {
                            info.Invoke(null, new object[] { hlod.SimplifierOptions });
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Can not find Simplifiers.");
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            isShowMaterial = EditorGUILayout.BeginFoldoutHeaderGroup(isShowMaterial, "Material");
            if (isShowMaterial == true)
            {
                Material mat     = null;
                string   matGUID = hlod.MaterialGUID;
                if (string.IsNullOrEmpty(matGUID) == false)
                {
                    string path = AssetDatabase.GUIDToAssetPath(matGUID);
                    mat = AssetDatabase.LoadAssetAtPath <Material>(path);
                }

                mat = EditorGUILayout.ObjectField("Material", mat, typeof(Material), false) as Material;
                if (mat != null)
                {
                    string path = AssetDatabase.GetAssetPath(mat);
                    hlod.MaterialGUID = AssetDatabase.AssetPathToGUID(path);
                }

                matGUID = hlod.MaterialLowGUID;
                if (string.IsNullOrEmpty(matGUID) == false)
                {
                    string path = AssetDatabase.GUIDToAssetPath(matGUID);
                    mat = AssetDatabase.LoadAssetAtPath <Material>(path);
                }

                mat = EditorGUILayout.ObjectField("MaterialLow", mat, typeof(Material), false) as Material;
                if (mat != null)
                {
                    string path = AssetDatabase.GetAssetPath(mat);
                    hlod.MaterialLowGUID = AssetDatabase.AssetPathToGUID(path);
                }

                hlod.TextureSize = EditorGUILayout.IntPopup("Size", hlod.TextureSize, Styles.TextureSizeStrings,
                                                            Styles.TextureSizes);
                //Output Property name
                //EditorGUILayout.
                if (mat == null)
                {
                    mat = new Material(Shader.Find("Standard"));
                }

                string[] outputTexturePropertyNames = mat.GetTexturePropertyNames();
                int      index = 0;
                isShowTexturePropertices = EditorGUILayout.Foldout(isShowTexturePropertices, "Texture propertices");

                if (isShowTexturePropertices == true)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Toggle(true, GUILayout.Width(20));
                    index = Array.IndexOf(outputTexturePropertyNames, hlod.AlbedoPropertyName);
                    index = EditorGUILayout.Popup("Albedo", index, outputTexturePropertyNames);
                    index = (index < 0) ? 0 : index;
                    hlod.AlbedoPropertyName = outputTexturePropertyNames[index];
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    hlod.UseNormal          = EditorGUILayout.Toggle(hlod.UseNormal, GUILayout.Width(20));
                    index                   = Array.IndexOf(outputTexturePropertyNames, hlod.NormalPropertyName);
                    index                   = EditorGUILayout.Popup("Normal", index, outputTexturePropertyNames);
                    index                   = (index < 0) ? 0 : index;
                    hlod.NormalPropertyName = outputTexturePropertyNames[index];
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    hlod.UseMask          = EditorGUILayout.Toggle(hlod.UseMask, GUILayout.Width(20));
                    index                 = Array.IndexOf(outputTexturePropertyNames, hlod.MaskPropertyName);
                    index                 = EditorGUILayout.Popup("Mask", index, outputTexturePropertyNames);
                    index                 = (index < 0) ? 0 : index;
                    hlod.MaskPropertyName = outputTexturePropertyNames[index];
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            isShowStreaming = EditorGUILayout.BeginFoldoutHeaderGroup(isShowStreaming, "Streaming");
            if (isShowStreaming == true)
            {
                if (m_StreamingTypes.Length > 0)
                {
                    int streamingIndex = Math.Max(Array.IndexOf(m_StreamingTypes, hlod.StreamingType), 0);
                    streamingIndex     = EditorGUILayout.Popup("Streaming", streamingIndex, m_StreamingNames);
                    hlod.StreamingType = m_StreamingTypes[streamingIndex];

                    var info = m_StreamingTypes[streamingIndex].GetMethod("OnGUI");
                    if (info != null)
                    {
                        if (info.IsStatic == true)
                        {
                            info.Invoke(null, new object[] { hlod.StreamingOptions });
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Can not find StreamingSetters.");
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            GUIContent generateButton = Styles.GenerateButtonEnable;
            GUIContent destroyButton  = Styles.DestroyButtonNotExists;

            if (hlod.GetComponent <HLODControllerBase>() != null)
            {
                generateButton = Styles.GenerateButtonExists;
                destroyButton  = Styles.DestroyButtonEnable;
            }



            EditorGUILayout.Space();

            GUI.enabled = generateButton == Styles.GenerateButtonEnable;
            if (GUILayout.Button(generateButton))
            {
                CoroutineRunner.RunCoroutine(TerrainHLODCreator.Create(hlod));
            }

            GUI.enabled = destroyButton == Styles.DestroyButtonEnable;
            if (GUILayout.Button(destroyButton))
            {
                CoroutineRunner.RunCoroutine(TerrainHLODCreator.Destroy(hlod));
            }

            GUI.enabled = true;

            serializedObject.ApplyModifiedProperties();
        }