static void RegisterCollection(tmTextureCollectionBase collection, List <tmTextureCollectionIndex> collections) { tmTextureCollectionIndex index = collections.Find(f => f.textureCollectionGUID.Equals(collection.collectionGuid)); if (index == null) { index = new tmTextureCollectionIndex(); collections.Add(index); } index.name = collection.name; index.assetGUID = collection.assetGuid; index.textureCollectionGUID = collection.collectionGuid; // index.editorLink = collection; collection.textureDefenitions.Sort((a, b) => (string.Compare(a.textureName, b.textureName, System.StringComparison.OrdinalIgnoreCase))); List <string> names = new List <string>(); List <string> guids = new List <string>(); foreach (tmTextureDefenition def in collection.textureDefenitions) { names.Add(def.textureName); guids.Add(def.assetGuid); } index.textureNames = names.ToArray(); index.textureGUIDs = guids.ToArray(); collections.Sort((a, b) => (string.Compare(a.name, b.name, System.StringComparison.OrdinalIgnoreCase))); UnityEditor.EditorUtility.SetDirty(tmIndex.Instance); }
public static void BuildCollectionsForModifiedAssets(string[] importedAssets) { AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); List <tmTextureCollection> modifiedCollections = new List <tmTextureCollection>(); foreach (string path in importedAssets) { tmTextureCollectionIndex index = tmIndex.Instance.CollectionIndexForTexturePath(path); if (index != null) { tmTextureCollection coll = tmEditorUtility.GUIDToAsset(index.assetGUID, typeof(tmTextureCollection)) as tmTextureCollection; if (coll != null && !modifiedCollections.Contains(coll)) { modifiedCollections.Add(coll); } } } foreach (tmTextureCollection collection in modifiedCollections) { BuildCollection(collection); } }
static bool CollectionPopup(string label, ref string collectionGUID) { int collectionIndex = 0; List <string> collectionNames = new List <string>(); collectionNames.Add("-"); for (int i = 0; i < tmIndex.Instance.TextureCollections.Count; i++) { tmTextureCollectionIndex collectionDescription = tmIndex.Instance.TextureCollections[i]; collectionNames.Add(collectionDescription.name); if (collectionDescription.textureCollectionGUID.Equals(collectionGUID)) { collectionIndex = i + 1; } } int lastCollectionIndex = collectionIndex; collectionIndex = EditorGUILayout.Popup(label, collectionIndex, collectionNames.ToArray()); if (collectionIndex != -1) { if (collectionIndex == 0) { collectionGUID = ""; } else { tmTextureCollectionIndex cd = tmIndex.Instance.TextureCollections[collectionIndex - 1]; collectionGUID = cd.textureCollectionGUID; } } return(lastCollectionIndex != collectionIndex); }
public static void Convert(GameObject target) { // GameObject target = Selection.activeGameObject; Mesh mesh = null; MeshFilter mf = target.GetComponent <MeshFilter>(); bool isSkinned = false; if (mf != null) { mesh = mf.sharedMesh; } else { SkinnedMeshRenderer smr = target.GetComponent <SkinnedMeshRenderer>(); if (smr != null) { isSkinned = true; mesh = smr.sharedMesh; } } int index = 0; for (int i = 0; i < target.GetComponent <Renderer>().sharedMaterials.Length; i++) { Material mat = target.GetComponent <Renderer>().sharedMaterials[i]; Texture main = mat.mainTexture; Texture lightmap = mat.GetLightmapTexture(); if (mat.name.Equals("Shadows_LOW")) { main = AssetUtility.GetAssetsAtPath <Texture2D>("Obstacles/Shadow_LOW")[0]; mat = AssetUtility.GetAssetsAtPath <Material>("Materials/Shadows")[0]; } if (mat.name.Equals("Shadows_MEDIUM")) { main = AssetUtility.GetAssetsAtPath <Texture2D>("Obstacles/Shadow_MEDIUM")[0]; mat = AssetUtility.GetAssetsAtPath <Material>("Materials/Shadows")[0]; } GameObject g = null; if (!isSkinned && target.GetComponent <Renderer>().sharedMaterials.Length > 1) { g = new GameObject(target.name + index, typeof(MeshRenderer), typeof(MeshFilter)); g.name = target.name + index; g.transform.parent = target.transform; g.transform.localPosition = Vector3.zero; g.transform.localScale = Vector3.one; g.transform.localRotation = Quaternion.identity; } else { g = target; } tmTextureRenderBase render = null; g.GetComponent <Renderer>().sharedMaterial = mat; if (g.GetComponent <ParticleSystem>()) { render = g.AddComponent <tmParticleSystemRender>(); } if (main != null) { string path = AssetDatabase.GetAssetPath(main); tmTextureCollectionIndex inst = tmIndex.Instance.CollectionIndexForTexturePath(path); if (inst != null) { if (render == null) { render = g.AddComponent <tmTextureRender>(); } render.MainTexCollectionGUID = inst.textureCollectionGUID; render.MainTextureID = render.MainTexCollection.GetTextureDefenitionByName(main.name).textureGuid; } } if (lightmap != null) { string path = AssetDatabase.GetAssetPath(lightmap); tmTextureCollectionIndex inst = tmIndex.Instance.CollectionIndexForTexturePath(path); if (inst != null) { if (render == null) { render = g.AddComponent <tmTextureRender>(); } render.LightmapCollectionGUID = inst.textureCollectionGUID; render.LightmapTextureID = render.LightmapCollection.GetTextureDefenitionByName(lightmap.name).textureGuid; } } if (target.GetComponent <Renderer>().sharedMaterials.Length == 1) { SetSharedMesh(g, mesh); if (render != null) { render.Mesh = mesh; } } else if (mesh != null) { string meshName = mesh.name + "_" + index; string[] guids = AssetDatabase.FindAssets(meshName); if (guids.Length > 0) { int indexCount = mesh.GetIndices(index).Length; Object[] meshes = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GUIDToAssetPath(guids[0])); foreach (Object submesh in meshes) { Mesh subm = submesh as Mesh; if (subm != null) { if (subm.GetIndices(0).Length == indexCount) { SetSharedMesh(g, subm); if (render != null) { render.Mesh = subm; } g.name = subm.name; } } } } } if (render != null) { render.Material = tmMaterialUtility.SharedMaterial(mat); } { tmBatchObject bb = g.GetComponent <tmBatchObject>(); if (bb == null) { bb = g.AddComponent <tmBatchObject>(); } bb.SetUp(); } index++; } }
public override void OnInspectorGUI() { // EyeDropper.GetPickedColor(); // System.Type eyeDropperType = GetType("EyeDropper"); // MethodInfo mi = eyeDropperType.GetMethod("GetPickedColor", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); // FieldInfo fi = eyeDropperType.GetField("s_PickCoordinates", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly); // Vector2 a = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); // fi.SetValue(null, a); // Debug.Log(fi); // Debug.Log(mi); // Color c = (Color)mi.Invoke(null, null); // // // EditorGUILayout.ColorField(Color.white); // Debug.Log( // "r:" + ((int)(c.r * 256)) + // " g:" + ((int)(c.g * 256)) + // " b:" + ((int)(c.b * 256)) + // " a:" + ((int)(c.a * 256)) // ); baseEditor.OnInspectorGUI(); GUILayout.Space(20); TextureImporter textureImporter = (TextureImporter)target; tmTextureCollectionIndex currentCollectionIndex = tmIndex.Instance.CollectionIndexForTexturePath(textureImporter.assetPath); string[] names = new string[tmIndex.Instance.TextureCollections.Count]; int index = -1; for (int i = 0; i < tmIndex.Instance.TextureCollections.Count; i++) { tmTextureCollectionIndex collectionIndex = tmIndex.Instance.TextureCollections[i]; names[i] = collectionIndex.name; if (collectionIndex.Equals(currentCollectionIndex)) { index = i; } } if (newIndex < -1) { newIndex = index; } newIndex = EditorGUILayout.Popup("Texture Atlas", newIndex, names); if (newIndex > 0) { tmTextureCollectionIndex collectionIndex = tmIndex.Instance.TextureCollections[newIndex]; string collectionGUID = collectionIndex.textureCollectionGUID; string collectionGuidPath = tmUtility.PathForPlatform(collectionGUID, tmSettings.Instance.CurrentPlatform); tmResourceCollectionLink link = tmUtility.ResourceLinkByGUID(collectionGuidPath); tmTextureCollectionPlatform collection = link.collectionInEditor; collection.LoadTexture(); Texture2D atlas = collection.Atlas; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(150f * atlas.width / atlas.height), GUILayout.Height(150f)); EditorGUI.DrawRect(rect, Color.black); EditorGUI.DrawTextureTransparent(rect, atlas, ScaleMode.ScaleToFit); EditorGUILayout.EndHorizontal(); Object asset = tmEditorUtility.GUIDToAsset(collection.AtlasAssetGUID, typeof(Object)); if (rect.Contains(Event.current.mousePosition)) { if (Event.current.clickCount == 1) { if (asset) { EditorGUIUtility.PingObject(asset); } Event.current.Use(); } } } GUILayout.BeginHorizontal(); { if (currentCollectionIndex != null) { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("Remove from atlas")) { newIndex = -1; } } GUILayout.FlexibleSpace(); bool enabled = GUI.enabled; GUI.enabled = index != newIndex; if (GUILayout.Button("Revert")) { newIndex = -2; } if (GUILayout.Button("Apply")) { if (currentCollectionIndex != null) { tmTextureCollection collection = tmEditorUtility.GUIDToAsset(currentCollectionIndex.assetGUID, typeof(tmTextureCollection)) as tmTextureCollection; Debug.Log(collection); if (collection) { tmTextureDefenition def = collection.GetTextureDefenitionByID(AssetDatabase.AssetPathToGUID(textureImporter.assetPath)); if (def != null) { Debug.Log(def.texture); collection.textureDefenitions.Remove(def); collection.Textures.Remove(def.texture); EditorUtility.SetDirty(collection); tmCollectionBuilder.BuildCollection(collection); } } } if (newIndex > 0) { tmTextureCollectionIndex newCollectionIndex = tmIndex.Instance.TextureCollections[newIndex]; tmTextureCollection collection = tmEditorUtility.GUIDToAsset(newCollectionIndex.assetGUID, typeof(tmTextureCollection)) as tmTextureCollection; collection.Textures.Add(AssetDatabase.LoadAssetAtPath(textureImporter.assetPath, typeof(Texture2D)) as Texture2D); EditorUtility.SetDirty(collection); tmCollectionBuilder.BuildCollection(collection); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } GUI.enabled = enabled; } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Description"); GUILayout.BeginHorizontal("Box"); { textureImporter.userData = GUILayout.TextField(textureImporter.userData, GUI.skin.label); } GUILayout.EndHorizontal(); // EditorGUILayout.LabelField("test label"); }