public override void OnInspectorGUI() { UMAMaterial source = target as UMAMaterial; serializedObject.Update(); //base.OnInspectorGUI(); //Feature, lets list the available Tex2D properties in the selected shader if (source.material != null && source.material.shader != null) { if (_lastSelectedShader == null) { _shaderProperties = FindTexProperties(source.material.shader); _lastSelectedShader = source.material.shader; } } EditorGUILayout.PropertyField(serializedObject.FindProperty("material"), new GUIContent("Material", "The Unity Material to link to.")); EditorGUILayout.PropertyField(serializedObject.FindProperty("materialType"), new GUIContent("Material Type", "To atlas or not to atlas- that is the question.")); GUILayout.Space(20); DrawChannelList(serializedObject.FindProperty("channels")); GUILayout.Space(20); EditorGUILayout.PropertyField(serializedObject.FindProperty("clothProperties"), new GUIContent("Cloth Properties", "The cloth properties asset to apply to this material. Use this only if planning to use the cloth component with this material.")); EditorGUILayout.PropertyField(serializedObject.FindProperty("RequireSeperateRenderer"), new GUIContent("Require Separate Renderer", "Toggle this to force UMA to create a new renderer for meshes using this material.")); serializedObject.ApplyModifiedProperties(); }
void OnGUI() { GUILayout.Label("UMA Slot Builder"); GUILayout.Space(20); normalReferenceMesh = EditorGUILayout.ObjectField("Seams Mesh (Optional) ", normalReferenceMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer; slotMesh = EditorGUILayout.ObjectField("Slot Mesh ", slotMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer; slotMaterial = EditorGUILayout.ObjectField("UMAMaterial ", slotMaterial, typeof(UMAMaterial), false) as UMAMaterial; slotFolder = EditorGUILayout.ObjectField("Slot Destination Folder", slotFolder, typeof(UnityEngine.Object), false) as UnityEngine.Object; EnforceFolder(ref slotFolder); RootBone = EditorGUILayout.TextField("Root Bone (ex:'Global')", RootBone); slotName = EditorGUILayout.TextField("Element Name", slotName); if (GUILayout.Button("Create Slot")) { Debug.Log("Processing..."); if (CreateSlot() != null) { Debug.Log("Success."); } } GUILayout.Label("", EditorStyles.boldLabel); Rect dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(dropArea, "Drag meshes here"); GUILayout.Label("Automatic Drag and Drop processing", EditorStyles.boldLabel); relativeFolder = EditorGUILayout.ObjectField("Relative Folder", relativeFolder, typeof(UnityEngine.Object), false) as UnityEngine.Object; EnforceFolder(ref relativeFolder); DropAreaGUI(dropArea); }
public void Initilize() { string comBundle = "common/common.assetbundle"; string[] dependencies = obj.GetDependencies(); for (int i = 0; i < dependencies.Length; i++) { IObjectBase dep = new ObjectBase(dependencies[i]); if (dep.Type == ".png") { if (dep.Name.Contains("_" + CharacterConst.Common)) { dep.SetAssetbundleName(comBundle); } else { dep.SetAssetbundleName(null); } } else if (dep.Type == ".asset") { dep.SetAssetbundleName(null); UMAMaterial mat = dep.Load() as UMAMaterial; if (mat != null) { dep.SetAssetbundleName(comBundle); } } dep.Save(); } }
public SlotEditor(SkinnedMeshRenderer _slotMesh, string _name, string _foldpath, EditorUmaMaterial _uMaterial) { slotMesh = _slotMesh; assetName = _name; foldpath = _foldpath; slotMaterial = _uMaterial.Load(); }
private void FindMatchingOverlayDataAssets() { HashSet <Object> selectedAssets = new HashSet <Object>(); string[] guids = AssetDatabase.FindAssets("t:OverlayDataAsset"); //TODO add progress bar. for (int i = 0; i < guids.Length; i++) { OverlayDataAsset overlay = AssetDatabase.LoadAssetAtPath <OverlayDataAsset>(AssetDatabase.GUIDToAssetPath(guids[i])); if (overlay == null) { continue; } if (UMAMaterial.Equals(overlay.material, target as UMAMaterial)) { selectedAssets.Add(overlay); } } if (selectedAssets.Count > 0) { Debug.Log(selectedAssets.Count + " matching OverlayDataAssets found."); Object[] selected = new Object[selectedAssets.Count]; selectedAssets.CopyTo(selected); Selection.objects = selected; } else { EditorUtility.DisplayDialog("None found", "No matching OverlayDataAssets were found.", "OK"); } }
public override void OnInspectorGUI() { UMAMaterial source = target as UMAMaterial; serializedObject.Update(); if (_centeredStyle == null) { _centeredStyle = new GUIStyle(GUI.skin.label); _centeredStyle.alignment = TextAnchor.MiddleCenter; _centeredStyle.fontStyle = FontStyle.Bold; } //base.OnInspectorGUI(); //Feature, lets list the available Tex2D properties in the selected shader if (source.material != null && source.material.shader != null) { if (_lastSelectedShader == null) { _shaderProperties = FindTexProperties(source.material.shader); _lastSelectedShader = source.material.shader; } } EditorGUILayout.PropertyField(serializedObject.FindProperty("material"), new GUIContent("Material", "The Unity Material to link to.")); EditorGUILayout.PropertyField(serializedObject.FindProperty("materialType"), new GUIContent("Material Type", "To atlas or not to atlas- that is the question.")); GUILayout.Space(20); EditorGUILayout.LabelField("Generated Texture Settings", _centeredStyle); EditorGUILayout.BeginVertical("HelpBox"); EditorGUILayout.PropertyField(serializedObject.FindProperty("MipMapBias"), new GUIContent("Mip Map Bias", "Negative values have sharper bias")); EditorGUILayout.PropertyField(serializedObject.FindProperty("AnisoLevel"), new GUIContent("Aniso Level", "Anisotropic level")); EditorGUILayout.PropertyField(serializedObject.FindProperty("MatFilterMode"), new GUIContent("Texture Filter Mode", "Select the filter mode of Point, Bilinear or Trilinear")); //EditorGUILayout.PropertyField(serializedObject.FindProperty("Compression"), new GUIContent("Texture Compression", "Compress the atlas texture to DXT1 or DXT5")); EditorGUILayout.EndVertical(); GUILayout.Space(20); DrawChannelList(serializedObject.FindProperty("channels")); GUILayout.Space(20); EditorGUILayout.PropertyField(serializedObject.FindProperty("clothProperties"), new GUIContent("Cloth Properties", "The cloth properties asset to apply to this material. Use this only if planning to use the cloth component with this material.")); EditorGUILayout.PropertyField(serializedObject.FindProperty("RequireSeperateRenderer"), new GUIContent("Require Separate Renderer", "Toggle this to force UMA to create a new renderer for meshes using this material.")); GUILayout.Space(20); if (GUILayout.Button(new GUIContent("Select Matching OverlayDataAssets", "This will select all OverlayDataAssets found in the project that use this UMAMaterial."), GUILayout.Height(40))) { FindMatchingOverlayDataAssets(); } serializedObject.ApplyModifiedProperties(); }
//Maybe eventually we can use the new IMGUI classes once older unity version are no longer supported. private void DrawChannelList(SerializedProperty list) { EditorGUILayout.PropertyField(list, new GUIContent("Texture Channels", "List of texture channels to be used in this material.")); EditorGUI.indentLevel += 1; if (list.isExpanded) { EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size")); for (int i = 0; i < list.arraySize; i++) { SerializedProperty channel = list.GetArrayElementAtIndex(i); SerializedProperty materialPropertyName = channel.FindPropertyRelative("materialPropertyName");//Let's get this eary to be able to use it in the element header. EditorGUILayout.PropertyField(channel, new GUIContent("Channel " + i + ": " + materialPropertyName.stringValue)); EditorGUI.indentLevel += 1; if (channel.isExpanded) { EditorGUILayout.PropertyField(channel.FindPropertyRelative("channelType"), new GUIContent("Channel Type", "The channel type. Affects the texture atlassing process.")); EditorGUILayout.PropertyField(channel.FindPropertyRelative("textureFormat"), new GUIContent("Texture Format", "Format used for the texture in this channel.")); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(materialPropertyName, new GUIContent("Material Property Name", "The name of the property this texture corresponds to in the shader used by this material."), GUILayout.MinWidth(300)); if (_shaderProperties != null) { int selection = EditorGUILayout.Popup(0, _shaderProperties, GUILayout.MinWidth(100), GUILayout.MaxWidth(200)); if (selection > 0) { materialPropertyName.stringValue = _shaderProperties[selection]; } } EditorGUILayout.EndHorizontal(); UMAMaterial source = target as UMAMaterial; if (source.material != null) { if (!source.material.HasProperty(materialPropertyName.stringValue)) { EditorGUILayout.HelpBox("This name is not found in the shader! Are you sure it is correct?", MessageType.Warning); } } EditorGUILayout.PropertyField(channel.FindPropertyRelative("sourceTextureName"), new GUIContent("Source Texture Name", "For use with procedural materials, leave empty otherwise.")); } EditorGUI.indentLevel -= 1; } } EditorGUI.indentLevel -= 1; }
public static OverlayDataAsset CreateOverlayData(Texture[] textures, string assetName, string overlayFolder, UMAMaterial umamaterial = null) { var overlay = ScriptableObject.CreateInstance <OverlayDataAsset>(); overlay.overlayName = assetName; overlay.textureList = textures; #region ÉèÖÃUMAMaterial UMAMaterial o = (UMAMaterial)AssetDatabase.LoadAssetAtPath("Assets/Character/UMA/Content/UMA/Legacy/MaterialSamples/UMALegacy.asset", typeof(UnityEngine.Object)); if (umamaterial != null) { o = umamaterial; } overlay.material = o; #endregion AssetDatabase.CreateAsset(overlay, overlayFolder + "/" + assetName + "_" + UMAUtils.Overlay + ".asset"); AssetDatabase.SaveAssets(); return(overlay); }
void MenuBar(Rect rect) { #if UMA_ADDRESSABLES if (AddressablesMenu.GetItemCount() == 1) { SetupMenus(); } #endif Rect MenuRect = new Rect(rect); MenuRect.width = 60; if (EditorGUI.DropdownButton(MenuRect, new GUIContent("File"), FocusType.Passive, EditorStyles.toolbarDropDown)) { FileMenu.DropDown(new Rect(MenuRect)); } MenuRect.x += 60; MenuRect.width = 100; if (EditorGUI.DropdownButton(MenuRect, new GUIContent("Addressables"), FocusType.Passive, EditorStyles.toolbarDropDown)) { AddressablesMenu.DropDown(new Rect(MenuRect)); } MenuRect.x += 100; MenuRect.width = 70; if (EditorGUI.DropdownButton(MenuRect, new GUIContent("Items"), FocusType.Passive, EditorStyles.toolbarDropDown)) { ItemsMenu.DropDown(new Rect(MenuRect)); } MenuRect.x += 70; MenuRect.width = 100; if (GUI.Button(MenuRect, new GUIContent("Collapse All"), EditorStyles.toolbarButton)) { treeView.CollapseAll(); } MenuRect.x += 100; MenuRect.width = 100; if (GUI.Button(MenuRect, new GUIContent("Expand All"), EditorStyles.toolbarButton)) { treeView.ExpandAll(); } MenuRect.x += 100; MenuRect.width = 100; bool newShowUtilities = GUI.Toggle(MenuRect, ShowUtilities, "Show Utilities", EditorStyles.toolbarButton); if (newShowUtilities != ShowUtilities) { ShowUtilities = newShowUtilities; Repaint(); } Rect FillRect = new Rect(rect); FillRect.x += 530; FillRect.width -= 530; GUI.Box(FillRect, "", EditorStyles.toolbar); if (ShowUtilities) { rect.y += rect.height; GUI.Box(rect, ""); GUILayout.BeginArea(rect); GUILayout.BeginHorizontal(); if (GUILayout.Button("Apply UMAMaterials to Selection", GUILayout.Width(259))) { UpdateMaterials(); AssetDatabase.SaveAssets(); } Replacement = EditorGUILayout.ObjectField("", Replacement, typeof(UMAMaterial), false, GUILayout.Width(250)) as UMAMaterial; GUILayout.EndHorizontal(); GUILayout.EndArea(); } }
void OnGUI() { GUILayout.Label("UMA Slot Builder"); GUILayout.Space(20); normalReferenceMesh = EditorGUILayout.ObjectField("Seams Mesh (Optional) ", normalReferenceMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer; slotMesh = EditorGUILayout.ObjectField("Slot Mesh ", slotMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer; slotMaterial = EditorGUILayout.ObjectField("UMAMaterial ", slotMaterial, typeof(UMAMaterial), false) as UMAMaterial; slotFolder = EditorGUILayout.ObjectField("Slot Destination Folder", slotFolder, typeof(UnityEngine.Object), false) as UnityEngine.Object; EnforceFolder(ref slotFolder); RootBone = EditorGUILayout.TextField("Root Bone (ex:'Global')", RootBone); slotName = EditorGUILayout.TextField("Element Name", slotName); EditorGUILayout.BeginHorizontal(); createOverlay = EditorGUILayout.Toggle("Create Overlay", createOverlay); EditorGUILayout.LabelField(slotName + "_Overlay"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); createRecipe = EditorGUILayout.Toggle("Create Wardrobe Recipe ", createRecipe); EditorGUILayout.LabelField(slotName + "_Recipe"); EditorGUILayout.EndHorizontal(); addToGlobalLibrary = EditorGUILayout.Toggle("Add To Global Library", addToGlobalLibrary); if (UMAContext.Instance != null) { if (UMAContext.Instance.slotLibrary != null) { addToLocalLibrary = EditorGUILayout.Toggle("Add to Scene Library", addToLocalLibrary); } } if (GUILayout.Button("Create Slot")) { Debug.Log("Processing..."); SlotDataAsset sd = CreateSlot(); if (sd != null) { Debug.Log("Success."); string AssetPath = AssetDatabase.GetAssetPath(sd.GetInstanceID()); if (addToGlobalLibrary) { UMAAssetIndexer.Instance.EvilAddAsset(typeof(SlotDataAsset), sd); } if (addToLocalLibrary && UMAContext.Instance != null) { if (UMAContext.Instance.slotLibrary != null) { UMAContext.Instance.slotLibrary.AddSlotAsset(sd); } } if (createOverlay) { CreateOverlay(AssetPath.Replace(sd.name, sd.slotName + "_Overlay"), sd); } if (createRecipe) { CreateRecipe(AssetPath.Replace(sd.name, sd.slotName + "_Recipe")); } } } if (slotMesh != null) { if (slotMesh.localBounds.size.x > 10.0f || slotMesh.localBounds.size.y > 10.0f || slotMesh.localBounds.size.z > 10.0f) { EditorGUILayout.HelpBox("This slot's size is very large. It's import scale may be incorrect!", MessageType.Warning); } if (slotMesh.localBounds.size.x < 0.01f || slotMesh.localBounds.size.y < 0.01f || slotMesh.localBounds.size.z < 0.01f) { EditorGUILayout.HelpBox("This slot's size is very small. It's import scale may be incorrect!", MessageType.Warning); } } GUILayout.Label("", EditorStyles.boldLabel); Rect dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(dropArea, "Drag meshes here"); GUILayout.Label("Automatic Drag and Drop processing", EditorStyles.boldLabel); relativeFolder = EditorGUILayout.ObjectField("Relative Folder", relativeFolder, typeof(UnityEngine.Object), false) as UnityEngine.Object; EnforceFolder(ref relativeFolder); DropAreaGUI(dropArea); }
//Maybe eventually we can use the new IMGUI classes once older unity version are no longer supported. private void DrawChannelList(SerializedProperty list) { EditorGUILayout.PropertyField(list, new GUIContent("Texture Channels", "List of texture channels to be used in this material.")); EditorGUI.indentLevel += 1; if (list.isExpanded) { EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size")); for (int i = 0; i < list.arraySize; i++) { SerializedProperty channel = list.GetArrayElementAtIndex(i); SerializedProperty materialPropertyName = channel.FindPropertyRelative("materialPropertyName");//Let's get this eary to be able to use it in the element header. EditorGUILayout.PropertyField(channel, new GUIContent("Channel " + i + ": " + materialPropertyName.stringValue)); EditorGUI.indentLevel += 1; if (channel.isExpanded) { EditorGUILayout.PropertyField(channel.FindPropertyRelative("channelType"), new GUIContent("Channel Type", "The channel type. Affects the texture atlassing process.")); EditorGUILayout.PropertyField(channel.FindPropertyRelative("textureFormat"), new GUIContent("Texture Format", "Format used for the texture in this channel.")); if (channel.FindPropertyRelative("textureFormat") != null && i < ((UMAMaterial)target).channels.Length) { RenderTextureFormat format = ((UMAMaterial)target).channels[i].textureFormat; if (!SystemInfo.SupportsRenderTextureFormat(format)) { EditorGUILayout.HelpBox("This Texture Format is not supported on this system!", MessageType.Error); } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(materialPropertyName, new GUIContent("Material Property Name", "The name of the property this texture corresponds to in the shader used by this material."), GUILayout.MinWidth(300)); if (_shaderProperties != null) { int selection = EditorGUILayout.Popup(0, _shaderProperties, GUILayout.MinWidth(100), GUILayout.MaxWidth(200)); if (selection > 0) { materialPropertyName.stringValue = _shaderProperties[selection]; } } EditorGUILayout.EndHorizontal(); UMAMaterial source = target as UMAMaterial; if (source.material != null) { if (!source.material.HasProperty(materialPropertyName.stringValue)) { EditorGUILayout.HelpBox("This name is not found in the shader! Are you sure it is correct?", MessageType.Warning); } } EditorGUILayout.PropertyField(channel.FindPropertyRelative("ConvertRenderTexture"), new GUIContent("Convert RenderTexture", "Convert the Render Texture to a Texture2D (so it can be compressed)")); SerializedProperty ConvertRenderTextureProperty = channel.FindPropertyRelative("ConvertRenderTexture"); if (ConvertRenderTextureProperty.boolValue == true) { EditorGUILayout.PropertyField(channel.FindPropertyRelative("Compression"), new GUIContent("Texture Compression", "Compress the atlas texture to DXT1 or DXT5")); } EditorGUILayout.PropertyField(channel.FindPropertyRelative("DownSample"), new GUIContent("Down Sample", "Decrease size to save texture memory")); EditorGUILayout.PropertyField(channel.FindPropertyRelative("sourceTextureName"), new GUIContent("Source Texture Name", "For use with procedural materials, leave empty otherwise.")); } EditorGUI.indentLevel -= 1; } } EditorGUI.indentLevel -= 1; }
public override void OnInspectorGUI() { UMAMaterial source = target as UMAMaterial; serializedObject.Update(); if (_centeredStyle == null) { _centeredStyle = new GUIStyle(GUI.skin.label); _centeredStyle.alignment = TextAnchor.MiddleCenter; _centeredStyle.fontStyle = FontStyle.Bold; } //base.OnInspectorGUI(); //Feature, lets list the available Tex2D properties in the selected shader if (source.material != null && source.material.shader != null) { if (_lastSelectedShader == null) { _shaderProperties = FindTexProperties(source.material.shader); _lastSelectedShader = source.material.shader; } } EditorGUILayout.PropertyField(serializedObject.FindProperty("material"), new GUIContent("Material", "The Unity Material to link to.")); EditorGUILayout.PropertyField(serializedObject.FindProperty("materialType"), new GUIContent("Material Type", "To atlas or not to atlas- that is the question.")); GUILayout.Space(20); EditorGUILayout.LabelField("Generated Texture Settings", _centeredStyle); EditorGUILayout.BeginVertical("HelpBox"); EditorGUILayout.PropertyField(serializedObject.FindProperty("MipMapBias"), new GUIContent("Mip Map Bias", "Negative values have sharper bias")); EditorGUILayout.PropertyField(serializedObject.FindProperty("AnisoLevel"), new GUIContent("Aniso Level", "Anisotropic level")); EditorGUILayout.PropertyField(serializedObject.FindProperty("MatFilterMode"), new GUIContent("Texture Filter Mode", "Select the filter mode of Point, Bilinear or Trilinear")); EditorGUILayout.PropertyField(serializedObject.FindProperty("MaskWithCurrentColor"), new GUIContent("Mask with Current Color", "When this is checked, the background of the atlas is filled with this color for alpha blending.")); EditorGUILayout.PropertyField(serializedObject.FindProperty("maskMultiplier"), new GUIContent("Mask Multiplier", "When Masking with current color, the current color is multiplied by this color.")); //EditorGUILayout.PropertyField(serializedObject.FindProperty("Compression"), new GUIContent("Texture Compression", "Compress the atlas texture to DXT1 or DXT5")); EditorGUILayout.EndVertical(); GUILayout.Space(20f); shaderParmsFoldout = EditorGUILayout.Foldout(shaderParmsFoldout, "Shader Parameter Mapping", true); if (shaderParmsFoldout) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(_shaderParms, true); EditorGUI.indentLevel--; } GUILayout.Space(20); DrawChannelList(serializedObject.FindProperty("channels")); GUILayout.Space(20); if (GUILayout.Button(new GUIContent("Select Matching OverlayDataAssets", "This will select all OverlayDataAssets found in the project that use this UMAMaterial."), GUILayout.Height(40))) { FindMatchingOverlayDataAssets(); } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Updates an Existing SlotDataAsset. /// </summary> /// <param name="slot">The existing SlotDataAsset to be updated</param> /// <param name="mesh">Mesh.</param> /// <param name="material">Material.</param> /// <param name="prefabMesh">Prefab mesh.</param> /// <param name="rootBone">Root bone.</param> public static void UpdateSlotData(SlotDataAsset slot, SkinnedMeshRenderer mesh, UMAMaterial material, SkinnedMeshRenderer prefabMesh, string rootBone) { string path = UMAUtils.GetAssetFolder(AssetDatabase.GetAssetPath(slot)); string assetName = slot.slotName; if (path.Length <= 0) { Debug.LogWarning("CreateSlotData: Path to existing asset is empty!"); return; } GameObject tempGameObject = UnityEngine.Object.Instantiate(mesh.transform.parent.gameObject) as GameObject; var resultingSkinnedMeshes = tempGameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); SkinnedMeshRenderer resultingSkinnedMesh = null; foreach (var skinnedMesh in resultingSkinnedMeshes) { if (skinnedMesh.name == mesh.name) { resultingSkinnedMesh = skinnedMesh; } } Mesh resultingMesh; if (prefabMesh != null) { resultingMesh = SeamRemoval.PerformSeamRemoval(resultingSkinnedMesh, prefabMesh, 0.0001f); resultingSkinnedMesh.sharedMesh = resultingMesh; SkinnedMeshAligner.AlignBindPose(prefabMesh, resultingSkinnedMesh); } else { resultingMesh = (Mesh)GameObject.Instantiate(resultingSkinnedMesh.sharedMesh); } //CountBoneweights(resultingMesh); var usedBonesDictionary = CompileUsedBonesDictionary(resultingMesh, new List <int>()); if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingMesh = BuildNewReduceBonesMesh(resultingMesh, usedBonesDictionary); } //CountBoneweights(resultingMesh); string meshAssetName = path + '/' + mesh.name + ".asset"; AssetDatabase.CreateAsset(resultingMesh, meshAssetName); tempGameObject.name = mesh.transform.parent.gameObject.name; Transform[] transformList = tempGameObject.GetComponentsInChildren <Transform>(); GameObject newObject = new GameObject(); for (int i = 0; i < transformList.Length; i++) { if (transformList[i].name == rootBone) { transformList[i].parent = newObject.transform; } else if (transformList[i].name == mesh.name) { transformList[i].parent = newObject.transform; } } GameObject.DestroyImmediate(tempGameObject); resultingSkinnedMesh = newObject.GetComponentInChildren <SkinnedMeshRenderer>(); if (resultingSkinnedMesh) { if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingSkinnedMesh.bones = BuildNewReducedBonesList(resultingSkinnedMesh.bones, usedBonesDictionary); } resultingSkinnedMesh.sharedMesh = resultingMesh; //CountBoneweights(resultingMesh); } string SkinnedName = path + '/' + assetName + "_Skinned.prefab"; #if UNITY_2018_3_OR_NEWER var skinnedResult = PrefabUtility.SaveAsPrefabAsset(newObject, SkinnedName); #else var skinnedResult = UnityEditor.PrefabUtility.CreatePrefab(SkinnedName, newObject); #endif GameObject.DestroyImmediate(newObject); var meshgo = skinnedResult.transform.Find(mesh.name); var finalMeshRenderer = meshgo.GetComponent <SkinnedMeshRenderer>(); slot.UpdateMeshData(finalMeshRenderer, rootBone); slot.meshData.SlotName = slot.slotName; var cloth = mesh.GetComponent <Cloth>(); if (cloth != null) { slot.meshData.RetrieveDataFromUnityCloth(cloth); } AssetDatabase.SaveAssets(); AssetDatabase.DeleteAsset(SkinnedName); AssetDatabase.DeleteAsset(meshAssetName); }
public static bool MaterialIsValid(UMAMaterial material) { return(material != null && !string.IsNullOrEmpty(material.name)); }
public static SlotDataAsset CreateSlotData(string slotFolder, string assetFolder, string assetName, SkinnedMeshRenderer mesh, UMAMaterial material, SkinnedMeshRenderer prefabMesh, string rootBone) { if (!System.IO.Directory.Exists(slotFolder + '/' + assetFolder)) { System.IO.Directory.CreateDirectory(slotFolder + '/' + assetFolder); } if (!System.IO.Directory.Exists(slotFolder + '/' + assetName)) { System.IO.Directory.CreateDirectory(slotFolder + '/' + assetName); } GameObject tempGameObject = UnityEngine.Object.Instantiate(mesh.transform.parent.gameObject) as GameObject; PrefabUtility.DisconnectPrefabInstance(tempGameObject); var resultingSkinnedMeshes = tempGameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); SkinnedMeshRenderer resultingSkinnedMesh = null; foreach (var skinnedMesh in resultingSkinnedMeshes) { if (skinnedMesh.name == mesh.name) { resultingSkinnedMesh = skinnedMesh; } } Mesh resultingMesh; if (prefabMesh != null) { resultingMesh = SeamRemoval.PerformSeamRemoval(resultingSkinnedMesh, prefabMesh, 0.0001f); resultingSkinnedMesh.sharedMesh = resultingMesh; SkinnedMeshAligner.AlignBindPose(prefabMesh, resultingSkinnedMesh); } else { resultingMesh = (Mesh)GameObject.Instantiate(resultingSkinnedMesh.sharedMesh); } var usedBonesDictionary = CompileUsedBonesDictionary(resultingMesh); if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingMesh = BuildNewReduceBonesMesh(resultingMesh, usedBonesDictionary); } AssetDatabase.CreateAsset(resultingMesh, slotFolder + '/' + assetName + '/' + mesh.name + ".asset"); tempGameObject.name = mesh.transform.parent.gameObject.name; Transform[] transformList = tempGameObject.GetComponentsInChildren <Transform>(); GameObject newObject = new GameObject(); for (int i = 0; i < transformList.Length; i++) { if (transformList[i].name == rootBone) { transformList[i].parent = newObject.transform; } else if (transformList[i].name == mesh.name) { transformList[i].parent = newObject.transform; } } GameObject.DestroyImmediate(tempGameObject); resultingSkinnedMesh = newObject.GetComponentInChildren <SkinnedMeshRenderer>(); if (resultingSkinnedMesh) { if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingSkinnedMesh.bones = BuildNewReducedBonesList(resultingSkinnedMesh.bones, usedBonesDictionary); } resultingSkinnedMesh.sharedMesh = resultingMesh; } var skinnedResult = UnityEditor.PrefabUtility.CreatePrefab(slotFolder + '/' + assetName + '/' + assetName + "_Skinned.prefab", newObject); GameObject.DestroyImmediate(newObject); var meshgo = skinnedResult.transform.Find(mesh.name); var finalMeshRenderer = meshgo.GetComponent <SkinnedMeshRenderer>(); var slot = ScriptableObject.CreateInstance <SlotDataAsset>(); slot.slotName = assetName; //Make sure slots get created with a name hash slot.nameHash = UMAUtils.StringToHash(slot.slotName); slot.material = material; slot.UpdateMeshData(finalMeshRenderer, rootBone); var cloth = mesh.GetComponent <Cloth>(); if (cloth != null) { slot.meshData.RetrieveDataFromUnityCloth(cloth); } AssetDatabase.CreateAsset(slot, slotFolder + '/' + assetName + '/' + assetName + "_Slot.asset"); for (int i = 1; i < slot.meshData.subMeshCount; i++) { var additionalSlot = ScriptableObject.CreateInstance <SlotDataAsset>(); additionalSlot.slotName = string.Format("{0}_{1}", assetName, i); additionalSlot.material = material; additionalSlot.UpdateMeshData(finalMeshRenderer, rootBone); additionalSlot.subMeshIndex = i; AssetDatabase.CreateAsset(additionalSlot, slotFolder + '/' + assetName + '/' + assetName + "_" + i + "_Slot.asset"); } AssetDatabase.SaveAssets(); return(slot); }
public bool ShowArray(System.Type CurrentType, string Filter) { bool HasFilter = false; bool NotFound = false; string actFilter = Filter.Trim().ToLower(); if (actFilter.Length > 0) { HasFilter = true; } Dictionary <string, AssetItem> TypeDic = UAI.GetAssetDictionary(CurrentType); if (!TypeCheckboxes.ContainsKey(CurrentType)) { TypeCheckboxes.Add(CurrentType, new List <bool>()); } List <AssetItem> Items = new List <AssetItem>(); Items.AddRange(TypeDic.Values); int NotInBuild = 0; int VisibleItems = 0; foreach (AssetItem ai in Items) { if (ai._SerializedItem == null) { NotInBuild++; } string Displayed = ai.ToString(UMAAssetIndexer.SortOrder); if (HasFilter && (!Displayed.ToLower().Contains(actFilter))) { continue; } VisibleItems++; } if (TypeCheckboxes[CurrentType].Count != VisibleItems) { TypeCheckboxes[CurrentType].Clear(); TypeCheckboxes[CurrentType].AddRange(new bool[VisibleItems]); } NotInBuildCount += NotInBuild; GUILayout.BeginHorizontal(EditorStyles.toolbarButton); GUILayout.Space(10); Toggles[CurrentType] = EditorGUILayout.Foldout(Toggles[CurrentType], CurrentType.Name + ": " + VisibleItems + "/" + TypeDic.Count + " Item(s). " + NotInBuild + " Not in build."); GUILayout.EndHorizontal(); if (Toggles[CurrentType]) { Items.Sort(); GUIHelper.BeginVerticalPadded(5, new Color(0.75f, 0.875f, 1f)); GUILayout.BeginHorizontal(); GUILayout.Label("Sorted By: " + UMAAssetIndexer.SortOrder, GUILayout.MaxWidth(160)); foreach (string s in UMAAssetIndexer.SortOrders) { if (GUILayout.Button(s, GUILayout.Width(80))) { UMAAssetIndexer.SortOrder = s; } } GUILayout.EndHorizontal(); int CurrentVisibleItem = 0; foreach (AssetItem ai in Items) { string lblBuild = "B-"; string lblVal = ai.ToString(UMAAssetIndexer.SortOrder); if (HasFilter && (!lblVal.ToLower().Contains(actFilter))) { continue; } if (ai._Name == "< Not Found!>") { NotFound = true; } GUILayout.BeginHorizontal(EditorStyles.textField); TypeCheckboxes[CurrentType][CurrentVisibleItem] = EditorGUILayout.Toggle(TypeCheckboxes[CurrentType][CurrentVisibleItem++], GUILayout.Width(20)); if (ai._SerializedItem == null) { lblVal += "<Not in Build>"; lblBuild = "B+"; } if (GUILayout.Button(lblVal, EditorStyles.label)) { Object o = AssetDatabase.LoadMainAssetAtPath(ai._Path); EditorGUIUtility.PingObject(o); Selection.activeObject = o; } if (GUILayout.Button(lblBuild, GUILayout.Width(35))) { if (ai._SerializedItem == null) { if (!ai.IsAssetBundle) { ai.CachSerializedItem(); } } else { ai.ReleaseItem(); } } if (GUILayout.Button("-", GUILayout.Width(20.0f))) { DeletedDuringGUI.Add(ai); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (NotFound) { GUILayout.Label("Warning - Some items not found!"); } else { GUILayout.Label("All Items appear OK"); } GUILayout.EndHorizontal(); if (CurrentType == typeof(SlotDataAsset) || CurrentType == typeof(OverlayDataAsset)) { GUIHelper.BeginVerticalPadded(5, new Color(0.65f, 0.65f, 0.65f)); GUILayout.Label("Utilities"); GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Select All")) { ProcessItems(CurrentType, null, HasFilter, actFilter, Items, SelectItems); } if (GUILayout.Button("Select None")) { ProcessItems(CurrentType, null, HasFilter, actFilter, Items, DeselectItems); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Remove Checked")) { ProcessItems(CurrentType, TypeCheckboxes[CurrentType], HasFilter, actFilter, Items, RemoveChecked); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); SelectedMaterial = (UMAMaterial)EditorGUILayout.ObjectField(SelectedMaterial, typeof(UMAMaterial), false); GUILayout.Label("Apply to checked: "); if (GUILayout.Button("Unassigned")) { ProcessItems(CurrentType, TypeCheckboxes[CurrentType], HasFilter, actFilter, Items, SetItemNullMaterial); } if (GUILayout.Button("All")) { ProcessItems(CurrentType, TypeCheckboxes[CurrentType], HasFilter, actFilter, Items, SetItemMaterial); } EditorGUILayout.EndHorizontal(); GUIHelper.EndVerticalPadded(5); } GUIHelper.EndVerticalPadded(5); } return(NotFound); }
public static SlotDataAsset CreateSlotData(string slotFolder, string assetFolder, string assetName, string slotName, bool nameByMaterial, SkinnedMeshRenderer slotMesh, UMAMaterial material, SkinnedMeshRenderer seamsMesh, List <string> KeepList, string rootBone, bool binarySerialization = false) { if (!System.IO.Directory.Exists(slotFolder + '/' + assetFolder)) { System.IO.Directory.CreateDirectory(slotFolder + '/' + assetFolder); } if (!System.IO.Directory.Exists(slotFolder + '/' + assetName)) { System.IO.Directory.CreateDirectory(slotFolder + '/' + assetName); } GameObject tempGameObject = UnityEngine.Object.Instantiate(slotMesh.transform.parent.gameObject) as GameObject; var resultingSkinnedMeshes = tempGameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); SkinnedMeshRenderer resultingSkinnedMesh = null; foreach (var skinnedMesh in resultingSkinnedMeshes) { if (skinnedMesh.name == slotMesh.name) { resultingSkinnedMesh = skinnedMesh; //CountBoneweights(skinnedMesh.sharedMesh); } } Transform[] bones = resultingSkinnedMesh.bones; List <int> KeepBoneIndexes = new List <int>(); for (int i = 0; i < bones.Length; i++) { Transform t = bones[i]; foreach (string keep in KeepList) { if (t.name.Contains(keep)) { KeepBoneIndexes.Add(i); break; // only add to keeplist once. } } } Mesh resultingMesh; if (seamsMesh != null) { resultingMesh = SeamRemoval.PerformSeamRemoval(resultingSkinnedMesh, seamsMesh, 0.0001f); resultingSkinnedMesh.sharedMesh = resultingMesh; //CountBoneweights(resultingMesh); SkinnedMeshAligner.AlignBindPose(seamsMesh, resultingSkinnedMesh); } else { resultingMesh = (Mesh)GameObject.Instantiate(resultingSkinnedMesh.sharedMesh); //CountBoneweights(resultingMesh); } var usedBonesDictionary = CompileUsedBonesDictionary(resultingMesh, KeepBoneIndexes); if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingMesh = BuildNewReduceBonesMesh(resultingMesh, usedBonesDictionary); //CountBoneweights(resultingMesh); } string theMesh = slotFolder + '/' + assetName + '/' + slotMesh.name + ".asset"; if (binarySerialization) { //Work around for mesh being serialized as project format settings (text) when binary is much faster. //If Unity introduces a way to set mesh as binary serialization then this becomes unnecessary. BinaryAssetWrapper binaryAsset = ScriptableObject.CreateInstance <BinaryAssetWrapper>(); AssetDatabase.CreateAsset(binaryAsset, theMesh); AssetDatabase.AddObjectToAsset(resultingMesh, binaryAsset); } else { AssetDatabase.CreateAsset(resultingMesh, theMesh); } tempGameObject.name = slotMesh.transform.parent.gameObject.name; Transform[] transformList = tempGameObject.GetComponentsInChildren <Transform>(); GameObject newObject = new GameObject(); for (int i = 0; i < transformList.Length; i++) { if (transformList[i].name == rootBone) { transformList[i].parent = newObject.transform; } else if (transformList[i].name == slotMesh.name) { transformList[i].parent = newObject.transform; } } GameObject.DestroyImmediate(tempGameObject); resultingSkinnedMesh = newObject.GetComponentInChildren <SkinnedMeshRenderer>(); //CountBoneweights(resultingSkinnedMesh.sharedMesh); if (resultingSkinnedMesh) { if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingSkinnedMesh.bones = BuildNewReducedBonesList(resultingSkinnedMesh.bones, usedBonesDictionary); } resultingSkinnedMesh.sharedMesh = resultingMesh; //CountBoneweights(resultingMesh); } string SkinnedName = slotFolder + '/' + assetName + '/' + assetName + "_Skinned.prefab"; #if UNITY_2018_3_OR_NEWER var skinnedResult = PrefabUtility.SaveAsPrefabAsset(newObject, SkinnedName); #else var skinnedResult = UnityEditor.PrefabUtility.CreatePrefab(SkinnedName, newObject); #endif GameObject.DestroyImmediate(newObject); var meshgo = skinnedResult.transform.Find(slotMesh.name); var finalMeshRenderer = meshgo.GetComponent <SkinnedMeshRenderer>(); var slot = ScriptableObject.CreateInstance <SlotDataAsset>(); slot.slotName = slotName; //Make sure slots get created with a name hash slot.nameHash = UMAUtils.StringToHash(slot.slotName); slot.material = material; slot.UpdateMeshData(finalMeshRenderer, rootBone); var cloth = slotMesh.GetComponent <Cloth>(); if (cloth != null) { slot.meshData.RetrieveDataFromUnityCloth(cloth); } AssetDatabase.CreateAsset(slot, slotFolder + '/' + assetName + '/' + slotName + "_Slot.asset"); for (int i = 1; i < slot.meshData.subMeshCount; i++) { string theSlotName = string.Format("{0}_{1}", slotName, i); if (i < slotMesh.sharedMaterials.Length && nameByMaterial) { if (!string.IsNullOrEmpty(slotMesh.sharedMaterials[i].name)) { string titlecase = slotMesh.sharedMaterials[i].name.ToTitleCase(); if (!string.IsNullOrWhiteSpace(titlecase)) { theSlotName = titlecase; } } } var additionalSlot = ScriptableObject.CreateInstance <SlotDataAsset>(); additionalSlot.slotName = theSlotName; // string.Format("{0}_{1}", slotName, i); additionalSlot.material = material; additionalSlot.UpdateMeshData(finalMeshRenderer, rootBone); additionalSlot.subMeshIndex = i; AssetDatabase.CreateAsset(additionalSlot, slotFolder + '/' + assetName + '/' + theSlotName + "_Slot.asset"); } AssetDatabase.SaveAssets(); AssetDatabase.DeleteAsset(SkinnedName); AssetDatabase.DeleteAsset(theMesh); return(slot); }
void OnGUI() { GUILayout.Label("UMA Race Updater"); GUILayout.Space(10); RaceData lastRace = Race; Race = EditorGUILayout.ObjectField("Race to Update ", Race, typeof(RaceData), false) as RaceData; Material = EditorGUILayout.ObjectField("New Material ", Material, typeof(UMAMaterial), false) as UMAMaterial; if (Race != lastRace) { Refresh(); } GUILayout.Space(10); if (Slots.Count < 1) { GUILayout.Label("No slots found"); } else { GUILayout.Label("Process these slots"); foreach (CheckedSlot kp in Slots) { kp.Checked = GUILayout.Toggle(kp.Checked, kp.Slot.slotName + " (" + kp.Slot.asset.material.name + ")"); } GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("Change Materials")) { if (Material == null) { EditorUtility.DisplayDialog("Error", "Must Select an UMA Material", "OK"); } else { foreach (CheckedSlot checkedSlot in Slots) { if (checkedSlot.Checked) { checkedSlot.Slot.asset.material = Material; EditorUtility.SetDirty(checkedSlot.Slot.asset); // also update the overlay slots foreach (var overlaySlot in checkedSlot.Slot.GetOverlayList()) { overlaySlot.asset.material = Material; EditorUtility.SetDirty(overlaySlot.asset); } } } AssetDatabase.SaveAssets(); } } if (GUILayout.Button("Refresh List")) { Refresh(); } GUILayout.EndHorizontal(); } }
public static SlotDataAsset CreateSlotData(string slotFolder, string assetName, SkinnedMeshRenderer mesh, UMAMaterial material, SkinnedMeshRenderer prefabMesh) { GameObject tempGameObject = UnityEngine.Object.Instantiate(mesh.transform.parent.gameObject) as GameObject; PrefabUtility.DisconnectPrefabInstance(tempGameObject); var resultingSkinnedMeshes = tempGameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); SkinnedMeshRenderer resultingSkinnedMesh = null; foreach (var skinnedMesh in resultingSkinnedMeshes) { if (skinnedMesh.name == mesh.name) { resultingSkinnedMesh = skinnedMesh; } } Mesh resultingMesh; if (prefabMesh != null) { resultingMesh = SeamRemoval.PerformSeamRemoval(resultingSkinnedMesh, prefabMesh, 0.0001f); resultingSkinnedMesh.sharedMesh = resultingMesh; SkinnedMeshAligner.AlignBindPose(prefabMesh, resultingSkinnedMesh); } else { resultingMesh = (Mesh)GameObject.Instantiate(resultingSkinnedMesh.sharedMesh); } var usedBonesDictionary = CompileUsedBonesDictionary(resultingMesh); if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingMesh = BuildNewReduceBonesMesh(resultingMesh, usedBonesDictionary); } AssetDatabase.CreateAsset(resultingMesh, slotFolder + '/' + assetName + ".asset"); tempGameObject.name = mesh.transform.parent.gameObject.name; Transform[] transformList = tempGameObject.GetComponentsInChildren <Transform>(); GameObject newObject = new GameObject(); for (int i = 0; i < transformList.Length; i++) { if (transformList[i].name == "Global") { transformList[i].parent = newObject.transform; } else if (transformList[i].name == mesh.name) { transformList[i].parent = newObject.transform; } } GameObject.DestroyImmediate(tempGameObject); resultingSkinnedMesh = newObject.GetComponentInChildren <SkinnedMeshRenderer>(); if (resultingSkinnedMesh) { if (usedBonesDictionary.Count != resultingSkinnedMesh.bones.Length) { resultingSkinnedMesh.bones = BuildNewReducedBonesList(resultingSkinnedMesh.bones, usedBonesDictionary); } resultingSkinnedMesh.sharedMesh = resultingMesh; resultingSkinnedMesh.sharedMaterials = new Material[0]; } var skinnedResult = UnityEditor.PrefabUtility.CreatePrefab(slotFolder + '/' + assetName + "_Skinned.prefab", newObject); GameObject.DestroyImmediate(newObject); var meshgo = skinnedResult.transform.Find(mesh.name); var finalMeshRenderer = meshgo.GetComponent <SkinnedMeshRenderer>(); var slot = ScriptableObject.CreateInstance <SlotDataAsset>(); slot.slotName = assetName; slot.material = material; slot.UpdateMeshData(finalMeshRenderer); AssetDatabase.CreateAsset(slot, slotFolder + '/' + assetName + "_" + UMAUtils.Slot + ".asset"); AssetDatabase.SaveAssets(); return(slot); }
void OnGUI() { GUILayout.Label("UMA Slot Builder"); GUILayout.Space(20); normalReferenceMesh = EditorGUILayout.ObjectField("Seams Mesh (Optional) ", normalReferenceMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer; var newslotMesh = EditorGUILayout.ObjectField("Slot Mesh ", slotMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer; if (newslotMesh != slotMesh) { errmsg = ""; slotMesh = newslotMesh; } slotMaterial = EditorGUILayout.ObjectField("UMAMaterial ", slotMaterial, typeof(UMAMaterial), false) as UMAMaterial; slotFolder = EditorGUILayout.ObjectField("Slot Destination Folder", slotFolder, typeof(UnityEngine.Object), false) as UnityEngine.Object; EnforceFolder(ref slotFolder); // // For now, we will disable this option. // It doesn't work in most cases. // RootBone = EditorGUILayout.TextField("Root Bone (ex:'Global')", RootBone); // slotName = EditorGUILayout.TextField("Slot Name", slotName); binarySerialization = EditorGUILayout.Toggle(new GUIContent("Binary Serialization", "Forces the created Mesh object to be serialized as binary. Recommended for large meshes and blendshapes."), binarySerialization); GUILayout.BeginHorizontal(EditorStyles.toolbarButton); GUILayout.Space(10); showTags = EditorGUILayout.Foldout(showTags, "Tags"); GUILayout.EndHorizontal(); if (showTags) { GUIHelper.BeginVerticalPadded(10, new Color(0.75f, 0.875f, 1f)); // Draw the button area GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Tag", GUILayout.Width(80))) { Tags.Add(""); Repaint(); } GUILayout.Label(Tags.Count + " Tags defined"); GUILayout.EndHorizontal(); if (Tags.Count == 0) { GUILayout.Label("No tags defined", EditorStyles.helpBox); } else { int del = -1; for (int i = 0; i < Tags.Count; i++) { GUILayout.BeginHorizontal(); Tags[i] = GUILayout.TextField(Tags[i]); if (GUILayout.Button("\u0078", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { del = i; } GUILayout.EndHorizontal(); } if (del >= 0) { Tags.RemoveAt(del); Repaint(); } } // Draw the tags (or "No tags defined"); GUIHelper.EndVerticalPadded(10); } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.BeginHorizontal(); createOverlay = EditorGUILayout.Toggle("Create Overlay", createOverlay); EditorGUILayout.LabelField(slotName + "_Overlay"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); createRecipe = EditorGUILayout.Toggle("Create Wardrobe Recipe ", createRecipe); EditorGUILayout.LabelField(slotName + "_Recipe"); EditorGUILayout.EndHorizontal(); addToGlobalLibrary = EditorGUILayout.Toggle("Add To Global Library", addToGlobalLibrary); if (GUILayout.Button("Verify Slot")) { if (slotMesh == null) { errmsg = "Slot is null."; } else { Vector2[] uv = slotMesh.sharedMesh.uv; foreach (Vector2 v in uv) { if (v.x > 1.0f || v.x < 0.0f || v.y > 1.0f || v.y < 0.0f) { errmsg = "UV Coordinates are out of range and will likely have issues with atlassed materials. Textures should not be tiled unless using non-atlassed materials."; break; } } if (string.IsNullOrEmpty(errmsg)) { errmsg = "No errors found"; } } } if (!string.IsNullOrEmpty(errmsg)) { EditorGUILayout.HelpBox(errmsg, MessageType.Warning); } if (GUILayout.Button("Create Slot")) { Debug.Log("Processing..."); SlotDataAsset sd = CreateSlot(); if (sd != null) { Debug.Log("Success."); string AssetPath = AssetDatabase.GetAssetPath(sd.GetInstanceID()); if (addToGlobalLibrary) { UMAAssetIndexer.Instance.EvilAddAsset(typeof(SlotDataAsset), sd); } OverlayDataAsset od = null; if (createOverlay) { od = CreateOverlay(AssetPath.Replace(sd.name, sd.slotName + "_Overlay"), sd); } if (createRecipe) { CreateRecipe(AssetPath.Replace(sd.name, sd.slotName + "_Recipe"), sd, od); } } } if (slotMesh != null) { if (slotMesh.localBounds.size.x > 10.0f || slotMesh.localBounds.size.y > 10.0f || slotMesh.localBounds.size.z > 10.0f) { EditorGUILayout.HelpBox("This slot's size is very large. It's import scale may be incorrect!", MessageType.Warning); } if (slotMesh.localBounds.size.x < 0.01f || slotMesh.localBounds.size.y < 0.01f || slotMesh.localBounds.size.z < 0.01f) { EditorGUILayout.HelpBox("This slot's size is very small. It's import scale may be incorrect!", MessageType.Warning); } if (slotName == null || slotName == "") { slotName = slotMesh.name; } if (RootBone == null || RootBone == "") { RootBone = "Global"; } } GUILayout.Label("", EditorStyles.boldLabel); Rect dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(dropArea, "Drag meshes here"); GUILayout.Label("Automatic Drag and Drop processing", EditorStyles.boldLabel); relativeFolder = EditorGUILayout.ObjectField("Relative Folder", relativeFolder, typeof(UnityEngine.Object), false) as UnityEngine.Object; EnforceFolder(ref relativeFolder); DropAreaGUI(dropArea); }
//Maybe eventually we can use the new IMGUI classes once older unity version are no longer supported. private void DrawChannelList(SerializedProperty list) { // EditorGUILayout.PropertyField(list, new GUIContent("Texture Channels", "List of texture channels to be used in this material.")); channelListExpanded = GUIHelper.FoldoutBar(channelListExpanded, "Texture Channels"); if (channelListExpanded) { GUIHelper.BeginVerticalPadded(10, new Color(0.75f, 0.875f, 1f)); EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size")); if (channelExpanded.Length != list.arraySize) { channelExpanded = new bool[list.arraySize]; } for (int i = 0; i < list.arraySize; i++) { SerializedProperty channel = list.GetArrayElementAtIndex(i); SerializedProperty materialPropertyName = channel.FindPropertyRelative("materialPropertyName"); //Let's get this eary to be able to use it in the element header. // EditorGUILayout.PropertyField(channel, new GUIContent("Channel " + i + ": " + materialPropertyName.stringValue)); // EditorGUILayout.LabelField(new GUIContent("Channel " + i + ": " + materialPropertyName.stringValue),EditorStyles.toolbar); channelExpanded[i] = GUIHelper.FoldoutBar(channelExpanded[i], "Channel " + i + ": " + materialPropertyName.stringValue); if (channelExpanded[i]) { GUIHelper.BeginVerticalPadded(10, new Color(0.85f, 0.85f, 0.85f)); EditorGUILayout.PropertyField(channel.FindPropertyRelative("channelType"), new GUIContent("Channel Type", "The channel type. Affects the texture atlassing process.")); EditorGUILayout.PropertyField(channel.FindPropertyRelative("textureFormat"), new GUIContent("Texture Format", "Format used for the texture in this channel.")); if (channel.FindPropertyRelative("textureFormat") != null && i < ((UMAMaterial)target).channels.Length) { RenderTextureFormat format = ((UMAMaterial)target).channels[i].textureFormat; if (!SystemInfo.SupportsRenderTextureFormat(format)) { EditorGUILayout.HelpBox("This Texture Format is not supported on this system!", MessageType.Error); } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(materialPropertyName, new GUIContent("Material Property Name", "The name of the property this texture corresponds to in the shader used by this material."), GUILayout.MinWidth(300)); if (_shaderProperties != null) { int selection = EditorGUILayout.Popup(0, _shaderProperties, GUILayout.MinWidth(100), GUILayout.MaxWidth(200)); if (selection > 0) { materialPropertyName.stringValue = _shaderProperties[selection]; } } EditorGUILayout.EndHorizontal(); SerializedProperty NonShaderProperty = channel.FindPropertyRelative("NonShaderTexture"); UMAMaterial source = target as UMAMaterial; if (source.material != null) { if (!source.material.HasProperty(materialPropertyName.stringValue) && !NonShaderProperty.boolValue) { EditorGUILayout.HelpBox("This name is not found in the shader! Are you sure it is correct?", MessageType.Warning); } } EditorGUILayout.PropertyField(channel.FindPropertyRelative("ConvertRenderTexture"), new GUIContent("Convert RenderTexture", "Convert the Render Texture to a Texture2D (so it can be compressed)")); SerializedProperty ConvertRenderTextureProperty = channel.FindPropertyRelative("ConvertRenderTexture"); if (ConvertRenderTextureProperty.boolValue == true) { EditorGUILayout.PropertyField(channel.FindPropertyRelative("Compression"), new GUIContent("Texture Compression", "Compress the atlas texture to DXT1 or DXT5")); } EditorGUILayout.PropertyField(channel.FindPropertyRelative("DownSample"), new GUIContent("Down Sample", "Decrease size to save texture memory")); EditorGUILayout.PropertyField(channel.FindPropertyRelative("sourceTextureName"), new GUIContent("Source Texture Name", "For use with procedural materials, leave empty otherwise.")); EditorGUILayout.PropertyField(NonShaderProperty, new GUIContent("NonShader Texture", "For having a texture get merged by the UMA texture merging process but not used in a shader. E.G. Pixel/UV based ID lookup. The Material Property Name should be empty when this is true.")); if (NonShaderProperty.boolValue && !string.IsNullOrEmpty(materialPropertyName.stringValue)) { EditorGUILayout.HelpBox("A NonShader Texture shouldn't have a Material Property Name value.", MessageType.Warning); } GUIHelper.EndVerticalPadded(10); } GUILayout.Space(8); } GUIHelper.EndVerticalPadded(10); } }
public bool ShowArray(System.Type CurrentType, string Filter) { bool HasFilter = false; bool NotFound = false; string actFilter = Filter.Trim().ToLower(); if (actFilter.Length > 0) { HasFilter = true; } Dictionary <string, AssetItem> TypeDic = UAI.GetAssetDictionary(CurrentType); List <AssetItem> Items = new List <AssetItem>(); Items.AddRange(TypeDic.Values); int NotInBuild = 0; int VisibleItems = 0; foreach (AssetItem ai in Items) { if (ai._SerializedItem == null) { NotInBuild++; } string Displayed = ai.ToString(UMAAssetIndexer.SortOrder); if (HasFilter && (!Displayed.ToLower().Contains(actFilter))) { continue; } VisibleItems++; } NotInBuildCount += NotInBuild; GUILayout.BeginHorizontal(EditorStyles.toolbarButton); GUILayout.Space(10); Toggles[CurrentType] = EditorGUILayout.Foldout(Toggles[CurrentType], CurrentType.Name + ": " + VisibleItems + "/" + TypeDic.Count + " Item(s). " + NotInBuild + " Not in build."); GUILayout.EndHorizontal(); if (Toggles[CurrentType]) { Items.Sort(); GUIHelper.BeginVerticalPadded(5, new Color(0.75f, 0.875f, 1f)); GUILayout.BeginHorizontal(); GUILayout.Label("Sorted By: " + UMAAssetIndexer.SortOrder, GUILayout.MaxWidth(160)); foreach (string s in UMAAssetIndexer.SortOrders) { if (GUILayout.Button(s, GUILayout.Width(80))) { UMAAssetIndexer.SortOrder = s; } } GUILayout.EndHorizontal(); foreach (AssetItem ai in Items) { string lblBuild = "B-"; string lblVal = ai.ToString(UMAAssetIndexer.SortOrder); if (HasFilter && (!lblVal.ToLower().Contains(actFilter))) { continue; } if (ai._Name == "< Not Found!>") { NotFound = true; } GUILayout.BeginHorizontal(EditorStyles.textField); if (ai._SerializedItem == null) { lblVal += "<Not in Build>"; lblBuild = "B+"; } if (GUILayout.Button(lblVal /* ai._Name + " (" + ai._AssetBaseName + ")" */, EditorStyles.label)) { EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath(ai._Path)); } if (GUILayout.Button(lblBuild, GUILayout.Width(35))) { if (ai._SerializedItem == null) { // Force the item to load. Object o = ai.Item; } else { ai.ReleaseItem(); } } if (GUILayout.Button("-", GUILayout.Width(20.0f))) { DeletedDuringGUI.Add(ai); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (NotFound) { GUILayout.Label("Warning - Some items not found!"); } else { GUILayout.Label("All Items appear OK"); } GUILayout.EndHorizontal(); if (CurrentType == typeof(SlotDataAsset) || CurrentType == typeof(OverlayDataAsset)) { GUIHelper.BeginVerticalPadded(5, new Color(0.65f, 0.65f, 0.65f)); GUILayout.Label("Utilities"); GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); SelectedMaterial = (UMAMaterial)EditorGUILayout.ObjectField(SelectedMaterial, typeof(UMAMaterial), false); GUILayout.Label("Assign To"); if (GUILayout.Button("Unassigned")) { foreach (AssetItem ai in Items) { string lblVal = ai.ToString(UMAAssetIndexer.SortOrder); if (HasFilter && (!lblVal.ToLower().Contains(actFilter))) { continue; } if (ai._Type == typeof(SlotDataAsset)) { if ((ai.Item as SlotDataAsset).material != null) { continue; } (ai.Item as SlotDataAsset).material = SelectedMaterial; } if (ai._Type == typeof(OverlayDataAsset)) { if ((ai.Item as OverlayDataAsset).material != null) { continue; } (ai.Item as OverlayDataAsset).material = SelectedMaterial; } } } if (GUILayout.Button("All")) { foreach (AssetItem ai in Items) { string lblVal = ai.ToString(UMAAssetIndexer.SortOrder); if (HasFilter && (!lblVal.ToLower().Contains(actFilter))) { continue; } if (ai._Type == typeof(SlotDataAsset)) { (ai.Item as SlotDataAsset).material = SelectedMaterial; } if (ai._Type == typeof(OverlayDataAsset)) { (ai.Item as OverlayDataAsset).material = SelectedMaterial; } } } EditorGUILayout.EndHorizontal(); GUIHelper.EndVerticalPadded(5); } GUIHelper.EndVerticalPadded(5); } return(NotFound); }