1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | import System; import System.IO; class NeoMaterialSearch extends ScriptableWizard { private static var startTex : Texture; private static var textureToSearch : Texture = Selection.activeObject as Texture; private var groupEnabled = false; private var showInspector = true; private static var materials : Array = new Array(); private static var mainTexture = true; private static var bampTexture = true; private static var fileInfo : FileInfo[]; @MenuItem("NeoTools/Textures/Get All Materials from Texture") static function CreateWizard () { ScriptableWizard.DisplayWizard("Get All Materials from Texture", NeoMaterialSearch, "Find"); var dir : DirectoryInfo = DirectoryInfo(Application.dataPath); fileInfo = dir.GetFiles("*.mat", SearchOption.AllDirectories); } function OnWizardUpdate() { textureToSearch = Selection.activeObject as Texture; } static function Search() { if (!textureToSearch) return; startTex = textureToSearch; materials.Clear(); var mat : Material; var tex : Texture; var added = false; var fileUtil :FileUtil = new FileUtil(); var path : int = Application.dataPath.length+1; for ( var file : FileInfo in fileInfo) { mat = EditorUtility.FindAsset(file.ToString().Remove(0,path), Material); if (mat) { if (mainTexture && mat.HasProperty("_MainTex")) { tex = mat.GetTexture("_MainTex"); if (tex) { if (tex.name == textureToSearch.name) { materials.Add(mat); added = true; } } } if (bampTexture && mat.HasProperty("_BampMap")) { tex = mat.GetTexture("_BampMap"); if (tex) { if (tex.name == textureToSearch.name && !added) { materials.Add(mat); } } } } added = false; tex = null; } } function OnDestroy () { textureToSearch = null; materials.Clear(); } function OnGUI () { DragAndDrop.AcceptDrag(); showInspector = EditorGUI.InspectorTitlebar(Rect(0,0,512,50),showInspector,textureToSearch); if (!showInspector) return; // textureToSearch = Selection.activeObject as Texture; GUILayout.BeginVertical(); GUILayout.Space (55); GUILayout.Box (textureToSearch,GUILayout.MinWidth(256), GUILayout.MaxWidth(512), GUILayout.MinHeight(256), GUILayout.MaxHeight(512), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.EndVertical(); EditorGUILayout.Separator(); groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled); EditorGUILayout.BeginHorizontal(); mainTexture = EditorGUILayout.Toggle ("Find mine texture", mainTexture); bampTexture = EditorGUILayout.Toggle ("Find bamp map", bampTexture); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndToggleGroup (); EditorGUILayout.Separator(); textureToSearch = EditorGUILayout.ObjectField( GUIContent(textureToSearch), textureToSearch, Texture,GUILayout.MinWidth(40), GUILayout.MaxWidth(512), GUILayout.MinHeight(40), GUILayout.MaxHeight(40), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); if (startTex != textureToSearch) Search(); EditorGUILayout.BeginVertical(); EditorGUILayout.Separator(); /* if (GUILayout.Button("Search")) { Search(); } */ if (materials.length > 0) { EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); GUILayout.Label("Total materials found : " + fileInfo.length); GUILayout.Label(" and "); GUILayout.Label("Materials with selected texture found : " + materials.length); GUILayout.EndHorizontal(); EditorGUILayout.Separator(); GUILayout.FlexibleSpace(); var l : float = materials.length; var mat : Material; for (var i : int = 0; i < l; i++) { GUILayout.BeginHorizontal(); mat = materials[i]; EditorGUILayout.ObjectField(mat, Material); if (i+1 < l) { mat = materials[++i]; EditorGUILayout.ObjectField(mat, Material); } GUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); EditorGUILayout.Separator(); if(GUILayout.Button("Developed by Neodrop"))Application.OpenURL("http://www.unity3d.ru"); EditorGUILayout.Separator(); if (GUILayout.Button("Close this window")) Close(); } } |
Один комментарий на «Wizard : поиск материалов по текстуре.»
Ваш отзыв
Вы должны войти, чтобы оставлять комментарии.
23 Дек 2013 в 13:12
lewisohn@dora.progandist” rel=”nofollow”>.…
спс….