文章17
标签2
分类9

图形-变换

知识点

尺寸变化(Scale

其中$s_x$代表x轴的缩放,$s_y$代表y轴的缩放
image-20220305171326805
$$\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]$$


unity的c#http服务器实例

HttpServer.cs文件:


c#的HTTP服务器

源码


Unity调用File Explorer读取文件地址

读取文件地址

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 Prefab的使用

什么是Prefab

 当我们在unity中,可能会遇到这样的道具:一个需要反复使用的GameObject。虽然直接重新创建一个GameObject也可行,但当它的结构足够复杂时,我们更期望有一个能够直接复制的GameObject。这个GameObject就是Prefab。

怎么创建Prefab

 首先,我们需要像正常创建GameObject一样,先在Hierarchy创建我们需要的GameObject,然后将其从Hierarchy拖到Assets窗口中,然后这个GameObject的图标就会变蓝。就说明它已经是一个合格的Prefab了。


'