導航:首頁 > 知識產權 > spritedatabase版權

spritedatabase版權

發布時間:2025-02-14 13:20:07

『壹』 unity sprite怎麼獲取切割後的圖

學習了一段時間的unity,對裡面的組件有一個大致的了解,但是具體操作來說還不是很熟悉,今天看了一片關於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菜單下多了"導出精靈"項,選中圖集,然後點擊"導出精靈"菜單項,即可導出子圖成功。

閱讀全文

與spritedatabase版權相關的資料

熱點內容
鄆城縣教育資源公共服務平台地 瀏覽:47
基本公共衛生服務年初工作計劃 瀏覽:790
維護疫情防控成果 瀏覽:771
夜間雜訊擾民投訴電話 瀏覽:40
知識產權法考試題目 瀏覽:539
實現擔保物權的管轄 瀏覽:499
暴走蘿莉羊年限定皮膚 瀏覽:999
儋馬電子證書 瀏覽:990
聿宏知識產權長沙辦事處電話 瀏覽:921
產業標准技術創新公共服務平台項目可研報告 瀏覽:676
怎麼投訴社區醫院 瀏覽:671
公共衛生服務項目開展情況匯報 瀏覽:75
廈門市力晨知識產權代理有限公司 瀏覽:779
超越極限19創造卷軸 瀏覽:687
創新預期成果 瀏覽:584
2014年公共衛生服務項目工作計劃 瀏覽:31
泰國蛇葯調經丸有效期 瀏覽:409
恆申知識產權事務所 瀏覽:267
廣州車位使用年限 瀏覽:648
商標侵權企業名稱沖突 瀏覽:921