unity怎麼切割圖片
Ⅰ 有酬勞,寫一個unity3d可使用的C#方法,按照模板動態切割圖片
這個好像有點難哦, 模版是什麼文件類型, 是一個圖片嗎? 請嫁我口扣:肆吳吧無四令零思吾
Ⅱ Unity3d 如何將Game試圖中所呈現的3d物體截取成圖片,並保存,顯示在GUI上
使用函數 :
Application.CaptureScreenshot
有2個重載,使用第一個就好
static function CaptureScreenshot (filename : String) : void
static function CaptureScreenshot (filename : String, superSize : int = 0) : void
註:在web player下此函數不版工作~權~
Ⅲ unity sprite怎麼獲取切割後的圖
假設有一張png/tga圖集,導入到Unity,放置目錄"Assets/Resources/UI"(UI文件夾可替換成其他的,重要的是要在"Assets/Resources/"路徑下),
為了可以使用Unity自帶的精靈切割,要將紋理類型改成"Sprite","Sprite Mode"改成"Multiple","Format"改成"Truecolor",點擊"Apply"按鈕進行應用。
接著,點擊"Sprite Editor"打開精靈編輯器,點擊左上角的"Slice"按鈕,彈出切片設置,再次點擊裡面的"Slice"按鈕,就會自動對圖片進行切割
在對切割不完整的地方進行修正後,點擊右上角的"Apply"按鈕,進行保存。可以看到Project視圖下這個圖集,已經被分割出許多小圖了
接下來,因為要對圖片進行讀寫操作,要更改圖片的屬性才能進行,否則會提示如下:
UnityException: Texture 'testUI' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
將圖片紋理類型更改為"Advanced",將"Read/Write Enabled"屬性進行打勾,如下圖所示:
創建一個腳本文件,代碼如下:
using UnityEngine;
using UnityEditor;
public class TestSaveSprite
{
(MenuItem("Tools/導出精靈"))
static void SaveSprite()
{
string resourcesPath = "Assets/Resources/";
foreach (Object obj in Selection.objects)
{
string selectionPath = AssetDatabase.GetAssetPath(obj);
// 必須最上級是"Assets/Resources/"
if (selectionPath.StartsWith(resourcesPath))
{
string selectionExt = System.IO.Path.GetExtension(selectionPath);
if (selectionExt.Length == 0)
{
continue;
}
// 從路徑"Assets/Resources/UI/testUI.png"得到路徑"UI/testUI"
string loadPath = selectionPath.Remove(selectionPath.Length - selectionExt.Length);
loadPath = loadPath.Substring(resourcesPath.Length);
// 載入此文件下的所有資源
Sprite()sprites = Resources.LoadAll<Sprite>(loadPath);
if (sprites.Length > 0)
{
// 創建導出文件夾
string outPath = Application.dataPath + "/outSprite/" + loadPath;
System.IO.Directory.CreateDirectory(outPath);
foreach (Sprite sprite in sprites)
{
// 創建單獨的紋理
Texture2D tex = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height, sprite.texture.format, false);
tex.SetPixels(sprite.texture.GetPixels((int)sprite.rect.xMin, (int)sprite.rect.yMin,
(int)sprite.rect.width, (int)sprite.rect.height));
tex.Apply();
// 寫入成PNG文件
System.IO.File.WriteAllBytes(outPath + "/" + sprite.name + ".png", tex.EncodeToPNG());
}
Debug.Log("SaveSprite to " + outPath);
}
}
}
Debug.Log("SaveSprite Finished");
}
}
在Unity編輯器將會看到Tools菜單下多了"導出精靈"項,選中圖集,然後點擊"導出精靈"菜單項,即可導出子圖成功。
Ⅳ unity3d的ugui怎麼切圖
Create games in the way of samurai. 將圖片邊界設大一個像素。 如果用的是類似TexturePacker的工具可以將extrude設為1。 這樣就可以避免黑線問題。
Ⅳ Unity怎麼在腳本中分割精靈圖集,不是在SpriteEditor里
你可以使用Rigidbody2D來實現 AddForce 然後ForceMode中找到Impulse的枚舉值
你也可以使用CharacterController的來進行,操作但是這個回類並沒有重力答功能,需要你自己實現從起跳到落地時角色運動的軌跡
Ⅵ 想問問,unity17.1里,用sprite editor切割圖時,slice是灰色用不了,怎麼辦啊
你圖片的模式對不對 如果是上面那個的話是九宮格拉伸模式 下面這個才能用來切片
Ⅶ 如何在Unity中截圖
據我所知,可以用下面的方法:
1 內置方法(簡單有效,但是貌似不能夠自定義存儲路徑等等):
Application.CaptureScreenshot ("Screenshot.png");
2 自己寫一個方法讀點(用的是類似流的思路還算比較靈活,但是存大圖會卡,推薦圖像類型慎重選擇)
IEnumerator OnScreenCapture ()
{
yield return new WaitForEndOfFrame();//等待這一幀畫完了才能截圖
try
{
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D ( width, height, TextureFormat.RGB24, false);//新建一張圖
tex.ReadPixels (new Rect (0, 0, width, height), 0, 0, true);//從屏幕開始讀點
byte[] imagebytes = tex.EncodeToJPG ();//用的是JPG(這種比較小)
//使用它壓縮實時產生的紋理,壓縮過的紋理使用更少的顯存並可以更快的被渲染
//通過true為highQuality參數將抖動壓縮期間源紋理,這有助於減少壓縮偽像
//因為壓縮後的圖像不作為紋理使用,只是一張用於展示的圖
//但稍微慢一些這個小功能暫時貌似還用不到
tex.Compress (false);
tex.Apply();
Texture2D mScreenShotImgae = tex;
File.WriteAllBytes ( @"E:\Screenshot.png", imagebytes);
}
catch (System.Exception e)
{
Debug.Log ("ScreenCaptrueError:" + e);
}
}
Ⅷ Unity3d中的幾種截圖方法
很抱歉所知甚少,目前我僅知道兩種截圖方式「
第一種,用自帶的API來做,靈活性一般:Application.CaptureScreenshot ("Screenshot.png");
第二種,讀屏幕的圖像並保存,需要在協程裡面等待一幀,示例如下:
IEnumerator OnScreenCapture ()
{
yield return new WaitForEndOfFrame();//等待這一幀畫完了才能截圖
try
{
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D ( width, height, TextureFormat.RGB24, false);//新建一張圖
tex.ReadPixels (new Rect (0, 0, width, height), 0, 0, true);//從屏幕開始讀點
byte[] imagebytes = tex.EncodeToJPG ();//用的是JPG(這種比較小)
tex.Compress (false);
tex.Apply();
Texture2D mScreenShotImgae = tex;
File.WriteAllBytes ( @"E:\Screenshot.png", imagebytes);
}
catch (System.Exception e)
{
Debug.Log ("ScreenCaptrueError:" + e);
}
}
如果有路過的大神知道其他的截圖方法,請一定要告知我,萬分感謝。
Ⅸ Unity能否進行圖片的不規則切割
用polygon collider
Ⅹ unity3d 怎麼對貼圖進行裁切
您好 max的模型抄導入Unity3d裡面,導入的時候只是導入模型而已。 至於把貼圖也導入的話,您可以試試把模型導出為FBX的格式,然後再把貼圖文件和FBX的模型文件放到同一個文件夾中,然後扔到Unity3D里頭就可以了。貼圖的名字不要有中文,不然Unity。