public void OnEnable() { instance = (AmplifyImpostorBakePreset)target; ImpostorBakingTools.LoadDefaults(); AlphaIcon = EditorGUIUtility.IconContent("PreTextureAlpha"); AlphaIcon.tooltip = "Alpha output selection"; AddList(); }
private void OnEnable() { m_instance = (target as AmplifyImpostor); if (m_instance.Data == null) { m_currentData = ScriptableObject.CreateInstance <AmplifyImpostorAsset>(); m_currentData.ImpostorType = (ImpostorType)Enum.Parse(typeof(ImpostorType), EditorPrefs.GetString(ImpostorBakingTools.PrefDataImpType, m_currentData.ImpostorType.ToString())); m_currentData.SelectedSize = EditorPrefs.GetInt(ImpostorBakingTools.PrefDataTexSizeSelected, m_currentData.SelectedSize); m_currentData.LockedSizes = EditorPrefs.GetBool(ImpostorBakingTools.PrefDataTexSizeLocked, m_currentData.LockedSizes); m_currentData.TexSize.x = EditorPrefs.GetFloat(ImpostorBakingTools.PrefDataTexSizeX, m_currentData.TexSize.x); m_currentData.TexSize.y = EditorPrefs.GetFloat(ImpostorBakingTools.PrefDataTexSizeY, m_currentData.TexSize.y); m_currentData.DecoupleAxisFrames = EditorPrefs.GetBool(ImpostorBakingTools.PrefDataDecoupledFrames, m_currentData.DecoupleAxisFrames); m_currentData.HorizontalFrames = EditorPrefs.GetInt(ImpostorBakingTools.PrefDataXFrames, m_currentData.HorizontalFrames); m_currentData.VerticalFrames = EditorPrefs.GetInt(ImpostorBakingTools.PrefDataYFrames, m_currentData.VerticalFrames); m_currentData.PixelPadding = EditorPrefs.GetInt(ImpostorBakingTools.PrefDataPixelBleeding, m_currentData.PixelPadding); m_currentData.Tolerance = EditorPrefs.GetFloat(ImpostorBakingTools.PrefDataTolerance, m_currentData.Tolerance); m_currentData.NormalScale = EditorPrefs.GetFloat(ImpostorBakingTools.PrefDataNormalScale, m_currentData.NormalScale); m_currentData.MaxVertices = EditorPrefs.GetInt(ImpostorBakingTools.PrefDataMaxVertices, m_currentData.MaxVertices); } else { m_currentData = m_instance.Data; } ImpostorBakingTools.LoadDefaults(); Shader alphaShader = AssetDatabase.LoadAssetAtPath <Shader>(AssetDatabase.GUIDToAssetPath(AlphaGUID)); m_alphaMaterial = new Material(alphaShader); if (m_instance.m_cutMode == CutMode.Automatic) { m_recalculateMesh = true; } if (m_instance.RootTransform == null) { m_instance.RootTransform = m_instance.transform; } // should we skip some renderers here? if (m_instance.LodGroup == null) { m_instance.LodGroup = m_instance.GetComponent <LODGroup>(); if ((m_instance.Renderers == null || m_instance.Renderers.Length == 0) && m_instance.RootTransform != null) { if (m_instance.LodGroup != null) { LOD[] lods = m_instance.LodGroup.GetLODs(); // is last lod a billboard? int vertexCount = 0; Renderer[] rend = lods[lods.Length - 1].renderers; for (int i = 0; i < rend.Length; i++) { MeshFilter mf = rend[i].GetComponent <MeshFilter>(); if (mf != null) { vertexCount += mf.sharedMesh.vertexCount; } } int lastIndex = lods.Length - 1; if (vertexCount < 8) { lastIndex--; } for (int i = lastIndex - 1; i >= 0; i--) { if (lods[i].renderers != null && lods[i].renderers.Length > 0) { m_instance.Renderers = lods[i].renderers; break; } } m_instance.m_insertIndex = lastIndex; if (vertexCount < 8) { m_instance.m_lodReplacement = LODReplacement.ReplaceLast; } } else { m_instance.Renderers = m_instance.RootTransform.GetComponentsInChildren <Renderer>(); } } } m_renderers = serializedObject.FindProperty("m_renderers"); }