Unity代码分享Editor编辑器扩展Image和RawImage的相互转化
Posted avi9111
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity代码分享Editor编辑器扩展Image和RawImage的相互转化相关的知识,希望对你有一定的参考价值。
public class MenuUtils
{
[MenuItem("CONTEXT/RawImage/2 Image Slice(Dis Raycast)")]
static void ChangeRaw2ImageDisRaycast(MenuCommand cmd)
{
var img = ChangeRaw2Image(cmd);
img.raycastTarget = false;
}
[MenuItem("CONTEXT/RawImage/2 Image Slice")]
static Image ChangeRaw2Image(MenuCommand cmd)
{
var rawImage = cmd.context as RawImage;
var path = AssetDatabase.GetAssetPath(rawImage.mainTexture);
var go = rawImage.gameObject;
Object.DestroyImmediate(rawImage);
var img = go.AddComponent<Image>();
img.type = Image.Type.Sliced;
img.sprite = AssetDatabase.LoadAssetAtPath<Sprite>(path);
string optmizeMatPath = AssetDatabase.GUIDToAssetPath("");
if (optmizeMatPath != "")
{
var mat = AssetDatabase.LoadAssetAtPath<Material>(optmizeMatPath);
if (mat != null)
img.material = mat;
}
EditorUtility.SetDirty(go);
return img;
}
}
以上是关于Unity代码分享Editor编辑器扩展Image和RawImage的相互转化的主要内容,如果未能解决你的问题,请参考以下文章
Unity记一次Amplify Shader Editor-编辑器扩展开发Canvas框架
Unity Amplify Shader Editor-编辑器扩展开发Canvas框架
Unity尝试一下Editor编辑器扩展直接挂载material编辑器