public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { float lineHeight = EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.singleLineHeight; const float w = 60f; const float sw = 70f; position.y += 6; float previewSize = lineHeight * 4f; Rect previewRect = new Rect(position.position, new Vector2(previewSize, previewSize)); previewRect.x += sw * 3 - 5f; previewRect.y += 2f; Rect box = new Rect(position.x - 2f, position.y - 4f, sw * 4f + 12f + previewSize, lineHeight * 3f + 14f); GUI.Box(box, GUIContent.none); position.height = lineHeight; position.width = w; EditorGUI.BeginChangeCheck(); Rect prevPosition = position; SerializedProperty tl = property.FindPropertyRelative("tl"); tl.boolValue = Toggle(position, tl.boolValue); position.x += sw; SerializedProperty t = property.FindPropertyRelative("t"); t.boolValue = Toggle(position, t.boolValue); position.x += sw; SerializedProperty tr = property.FindPropertyRelative("tr"); tr.boolValue = Toggle(position, tr.boolValue); position = prevPosition; position.y += lineHeight + 2f; prevPosition = position; SerializedProperty l = property.FindPropertyRelative("l"); l.boolValue = Toggle(position, l.boolValue); position.x += sw; SerializedProperty texture = property.FindPropertyRelative("texture"); EditorGUI.ObjectField(position, texture, GUIContent.none); EditorGUI.LabelField(previewRect, new GUIContent((Texture2D)texture.objectReferenceValue)); position.x += sw; SerializedProperty r = property.FindPropertyRelative("r"); r.boolValue = Toggle(position, r.boolValue); position = prevPosition; position.y += lineHeight + 2f; SerializedProperty bl = property.FindPropertyRelative("bl"); bl.boolValue = Toggle(position, bl.boolValue); position.x += sw; SerializedProperty b = property.FindPropertyRelative("b"); b.boolValue = Toggle(position, b.boolValue); position.x += sw; SerializedProperty br = property.FindPropertyRelative("br"); br.boolValue = Toggle(position, br.boolValue); position.x += sw * 2 + 10f; if (GUI.Button(position, "Delete")) { if (EditorUtility.DisplayDialog("", "Delete this entry?", "Yes", "No")) { ConnectedTexture ct = (ConnectedTexture)property.serializedObject.targetObject; List <ConnectedTextureConfig> od = new List <ConnectedTextureConfig> (ct.config); int index = property.GetArrayIndex(); od.RemoveAt(index); ct.config = od.ToArray(); GUI.changed = true; } } if ((EditorGUI.EndChangeCheck() || GUI.enabled) && !Application.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene()); } }
void LoadWorldTextures() { requireTextureArrayUpdate = false; // Init texture array if (worldTextures == null) { worldTextures = new List <WorldTexture> (); } else { worldTextures.Clear(); } if (worldTexturesDict == null) { worldTexturesDict = new Dictionary <Texture2D, int> (); } else { worldTexturesDict.Clear(); } // Clear definitions if (voxelDefinitions != null) { // Voxel Definitions no longer are added to the dictionary, clear the index field. for (int k = 0; k < voxelDefinitionsCount; k++) { if (voxelDefinitions [k] != null) { voxelDefinitions [k].Reset(); } } } else { voxelDefinitions = new VoxelDefinition [128]; } voxelDefinitionsCount = 0; if (voxelDefinitionsDict == null) { voxelDefinitionsDict = new Dictionary <string, VoxelDefinition> (); } else { voxelDefinitionsDict.Clear(); } if (sessionUserVoxels == null) { sessionUserVoxels = new List <VoxelDefinition> (); } // The null voxel definition VoxelDefinition nullVoxelDefinition = ScriptableObject.CreateInstance <VoxelDefinition> (); nullVoxelDefinition.name = "Null"; nullVoxelDefinition.hidden = true; nullVoxelDefinition.canBeCollected = false; nullVoxelDefinition.ignoresRayCast = true; nullVoxelDefinition.renderType = RenderType.Empty; AddVoxelTextures(nullVoxelDefinition); // Check default voxel if (defaultVoxel == null) { defaultVoxel = Resources.Load <VoxelDefinition> ("VoxelPlay/Defaults/DefaultVoxel"); } AddVoxelTextures(defaultVoxel); // Add all biome textures if (world.biomes != null) { for (int k = 0; k < world.biomes.Length; k++) { BiomeDefinition biome = world.biomes [k]; if (biome == null) { continue; } if (biome.voxelTop != null) { AddVoxelTextures(biome.voxelTop); if (biome.voxelTop.biomeDirtCounterpart == null) { biome.voxelTop.biomeDirtCounterpart = biome.voxelDirt; } } AddVoxelTextures(biome.voxelDirt); if (biome.vegetation != null) { for (int v = 0; v < biome.vegetation.Length; v++) { AddVoxelTextures(biome.vegetation [v].vegetation); } } if (biome.trees != null) { for (int t = 0; t < biome.trees.Length; t++) { ModelDefinition tree = biome.trees [t].tree; if (tree == null) { continue; } for (int b = 0; b < tree.bits.Length; b++) { AddVoxelTextures(tree.bits [b].voxelDefinition); } } } if (biome.ores != null) { for (int v = 0; v < biome.ores.Length; v++) { // ensure proper size if (biome.ores [v].veinMinSize == biome.ores [v].veinMaxSize && biome.ores [v].veinMaxSize == 0) { biome.ores [v].veinMinSize = 2; biome.ores [v].veinMaxSize = 6; biome.ores [v].veinsCountMin = 1; biome.ores [v].veinsCountMax = 2; } AddVoxelTextures(biome.ores [v].ore); } } } } // Special voxels if (enableClouds) { if (world.cloudVoxel == null) { world.cloudVoxel = Resources.Load <VoxelDefinition> ("VoxelPlay/Defaults/VoxelCloud"); } AddVoxelTextures(world.cloudVoxel); } // Add additional world voxels if (world.moreVoxels != null) { for (int k = 0; k < world.moreVoxels.Length; k++) { AddVoxelTextures(world.moreVoxels [k]); } } // Add all items' textures are available if (world.items != null) { int itemCount = world.items.Length; for (int k = 0; k < itemCount; k++) { ItemDefinition item = world.items [k]; if (item != null && item.category == ItemCategory.Voxel) { AddVoxelTextures(item.voxelType); } } } // Add any other voxel found inside Defaults VoxelDefinition [] vdd = Resources.LoadAll <VoxelDefinition> ("VoxelPlay/Defaults"); for (int k = 0; k < vdd.Length; k++) { AddVoxelTextures(vdd [k]); } // Add any other voxel found inside World directory if (!string.IsNullOrEmpty(world.name)) { vdd = Resources.LoadAll <VoxelDefinition> ("Worlds/" + world.name); for (int k = 0; k < vdd.Length; k++) { AddVoxelTextures(vdd [k]); } // Add any other voxel found inside a resource directory with same name of world (if not placed into Worlds directory) vdd = Resources.LoadAll <VoxelDefinition> (world.name); for (int k = 0; k < vdd.Length; k++) { AddVoxelTextures(vdd [k]); } } // Add any other voxel found inside a resource directory under the world definition asset if (!string.IsNullOrEmpty(world.resourceLocation)) { vdd = Resources.LoadAll <VoxelDefinition> (world.resourceLocation); for (int k = 0; k < vdd.Length; k++) { AddVoxelTextures(vdd [k]); } } // Add connected textures ConnectedTexture [] ctt = Resources.LoadAll <ConnectedTexture> (""); for (int k = 0; k < ctt.Length; k++) { ConnectedTexture ct = ctt [k]; VoxelDefinition vd = ctt [k].voxelDefinition; if (vd == null || vd.index == 0) { continue; } for (int j = 0; j < ct.config.Length; j++) { ct.config [j].textureIndex = AddTexture(ct.config [j].texture, null, null, null); } ct.Init(); } // Add user provided voxels during playtime int count = sessionUserVoxels.Count; for (int k = 0; k < count; k++) { AddVoxelTextures(sessionUserVoxels [k]); } sessionUserVoxelsLastIndex = voxelDefinitionsCount - 1; // Add transparent voxel definitions for the see-through effect if (seeThrough) { int lastOne = voxelDefinitionsCount; // this loop will add voxels so end at the last regular voxel definition (don't process see-through versions) for (int k = 0; k < lastOne; k++) { VoxelDefinition vd = voxelDefinitions [k]; if (vd.renderType == RenderType.CutoutCross) { vd.seeThroughMode = SeeThroughMode.FullyInvisible; } else { if (vd.seeThroughMode == SeeThroughMode.Transparency) { if (vd.renderType.supportsAlphaSeeThrough()) { vd.seeThroughVoxelTempTransp = CreateSeeThroughVoxelDefinition(vd); } else { vd.seeThroughMode = SeeThroughMode.FullyInvisible; } } } } } // Create array texture int textureCount = worldTextures.Count; if (textureCount > 0) { Texture2DArray pointFilterTextureArray = new Texture2DArray(textureSize, textureSize, textureCount, TextureFormat.ARGB32, hqFiltering); if (enableReliefMapping || !enableSmoothLighting) { pointFilterTextureArray.wrapMode = TextureWrapMode.Repeat; } else { pointFilterTextureArray.wrapMode = TextureWrapMode.Clamp; } pointFilterTextureArray.filterMode = hqFiltering ? FilterMode.Bilinear : FilterMode.Point; pointFilterTextureArray.mipMapBias = -mipMapBias; for (int k = 0; k < textureCount; k++) { if (worldTextures [k].colorsAndEmission != null) { pointFilterTextureArray.SetPixels32(worldTextures [k].colorsAndEmission, k); } else if (worldTextures [k].normalsAndElevation != null) { pointFilterTextureArray.SetPixels32(worldTextures [k].normalsAndElevation, k); } } worldTextures.Clear(); pointFilterTextureArray.Apply(hqFiltering, true); // Assign textures to materials if (renderingMaterials != null) { for (int k = 0; k < renderingMaterials.Length; k++) { if (renderingMaterials [k].usesTextureArray) { Material mat = renderingMaterials [k].material; if (mat != null && mat.HasProperty("_MainTex")) { mat.SetTexture("_MainTex", pointFilterTextureArray); } } } } matDynamicOpaque.SetTexture("_MainTex", pointFilterTextureArray); matDynamicCutout.SetTexture("_MainTex", pointFilterTextureArray); if (modelHighlightMat == null) { modelHighlightMat = Instantiate <Material> (Resources.Load <Material> ("VoxelPlay/Materials/VP Highlight Model")) as Material; } modelHighlightMat.SetTexture("_MainTex", pointFilterTextureArray); } }