知识点
尺寸变化(Scale
其中$s_x$代表x轴的缩放,$s_y$代表y轴的缩放
$$\left[\begin{matrix}x'\\y'\end{matrix}\right]=\left[\begin{matrix}s_{x} & 0\\0 & s_{y}\end{matrix}\right]\left[\begin{matrix}x\\y\end{matrix}\right]$$
其中$s_x$代表x轴的缩放,$s_y$代表y轴的缩放
$$\left[\begin{matrix}x'\\y'\end{matrix}\right]=\left[\begin{matrix}s_{x} & 0\\0 & s_{y}\end{matrix}\right]\left[\begin{matrix}x\\y\end{matrix}\right]$$
string image_path = EditorUtility.OpenFilePanel("Overwrite with png", "", "png");
path
就是读取的地址,可用于文件读取操作。
public Sprite load_sprite(string path)
{
if (string.IsNullOrEmpty(path)) return null;
if (System.IO.File.Exists(path))
{
byte[] bytes = System.IO.File.ReadAllBytes(path);
Texture2D texture = new Texture2D(1, 1);
texture.LoadImage(bytes);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
return sprite;
}
return null;
}
当我们在unity中,可能会遇到这样的道具:一个需要反复使用的GameObject。虽然直接重新创建一个GameObject也可行,但当它的结构足够复杂时,我们更期望有一个能够直接复制的GameObject。这个GameObject就是Prefab。
首先,我们需要像正常创建GameObject一样,先在Hierarchy创建我们需要的GameObject,然后将其从Hierarchy拖到Assets窗口中,然后这个GameObject的图标就会变蓝。就说明它已经是一个合格的Prefab了。