override protected void OnInit() { mTexture = mWidget as UITexture; if (!string.IsNullOrEmpty(mTexture.MaterialPath) && mTexture.MaterialPath.StartsWith("Textures/UITexture/")) { mTexture.MaterialPath = mTexture.MaterialPath.Replace('\\', '/'); string[] splits = mTexture.MaterialPath.Split('/'); if (splits != null && splits.Length == 4) { pathSelection = splits[2]; textureSelection = splits[3]; if (mTexture.material == null) { Shader s = Shader.Find("Unlit/Transparent Colored"); mTexture.material = new Material(s); } Resources.UnloadAsset(mTexture.material.mainTexture); mTexture.material.mainTexture = mTexture.AysnLoadTex(mTexture.MaterialPath) as Texture; } } FolderList = NGUIEditorTools.GetSonDirectoryNameWithoutPath(UITextureParentPath); InsertOneAtHead <string>(ref FolderList, "None"); TextureList = NGUIEditorTools.GetFilesInDirectoryWithoutPathAndExtension(UITextureParentPath + pathSelection, ".png"); InsertOneAtHead <string>(ref TextureList, "None"); }
override protected bool OnDrawProperties() { /////////////////////////////////////////////////////////////////////////////// ////////////////////////////// New /////////////////////////////////////////// mTexture = mWidget as UITexture; mTexture.UVOffset = EditorGUILayout.Vector4Field("UV偏移", mTexture.UVOffset); mTexture.MarkAsChanged(); EditorGUILayout.LabelField("TexturePath", mTexture.MaterialPath); string path = NGUIEditorTools.DrawList("Panel", FolderList, pathSelection); if (path != pathSelection) { pathSelection = path; TextureList = NGUIEditorTools.GetFilesInDirectoryWithoutPathAndExtension(UITextureParentPath + pathSelection, ".png"); } string texture = NGUIEditorTools.DrawList("Texture", TextureList, textureSelection); if (texture != textureSelection) { if (texture != NONE) { textureSelection = texture; mTexture.MaterialPath = UITextureParentPathWithoutRes + pathSelection + "/" + textureSelection; mTexture.MaterialPath.Replace('\\', '/'); if (mTexture.material == null) { Shader s = Shader.Find("Unlit/Transparent Colored"); mTexture.material = new Material(s); } Resources.UnloadAsset(mTexture.material.mainTexture); Material tmpMat = new Material(mTexture.material); tmpMat.mainTexture = mTexture.AysnLoadTex(mTexture.MaterialPath) as Texture; mTexture.material = tmpMat; EditorUtility.SetDirty(mWidget); } } ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////// Before //////////////////////////////////////////////////////////////// if (mWidget.IsHidePanel != EditorGUILayout.Toggle("Hide Panel", mWidget.IsHidePanel)) { mWidget.IsHidePanel = !mWidget.IsHidePanel; EditorUtility.SetDirty(mWidget); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } Material mat = EditorGUILayout.ObjectField("Material", mWidget.material, typeof(Material), false) as Material; if (mWidget.material != mat) { NGUIEditorTools.RegisterUndo("Material Selection", mWidget); mWidget.material = mat; } return(true); }