部分unity游戏素材拼接

方式一 ab包

private AssetBundle assett;
public List<UnityEngine.Object> objlist;
public  string path ;//ab包地址

 private void Start()
 {assett = AssetBundle.LoadFromFile(path_new[i]);//加载ab包
objlistt.AddRange(assett.LoadAllAssets<UnityEngine.Object>());//将ab包添加到列表
}

游戏本身已经将图片素材信息排列好了,只需按照名称排列显示就行,这里不做赘述。

方式二 读取锚点信息

通过AssetStudio导出Dump获取锚点信息,根据锚点信息标定素材位置。

下面是相关代码:

public void xiugaiwenli(string path, Vector2 x)//修改锚点函数
{
    TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;
    TextureImporterSettings texSettings = new TextureImporterSettings();
    ti.ReadTextureSettings(texSettings);
    texSettings.spriteMeshType = (int)SpriteMeshType.FullRect;
    texSettings.spriteAlignment = (int )SpriteAlignment.Custom;
    texSettings.spritePivot = x;//xnew Vector2(0.2f, 0.3f);
    ti.SetTextureSettings(texSettings);
    ti.SaveAndReimport();
}

最终效果图,修改锚点后拼接

新版本很多素材直接绑定在预制体中,可以直接生成预制体调整动画即可,如下图:

保存本地

通过截取区域像素保存本地

public Texture2D sp4;//用于纹理处理
public Rect reccc;//截图区域信息
public RectTransform rec;//挂载脚本物体的RectTransform
public Camera captureCamera; // 用于捕获的相机 
public RenderTexture captureTexture; // 渲染目标  
public Vector3 worldPosition; // 世界坐标的起点  
public Vector2 worldSize; // 世界坐标区域的大小  

 public IEnumerator SignatureSave(Rect rect)//参数传入截图区域
 {
     reccc.x = rec.anchoredPosition.x;
     reccc.y = rec.anchoredPosition.y;
     captureTexture.width = (int)rec.sizeDelta.x;
     captureTexture.height = (int)rec.sizeDelta.y;
     rec.gameObject.SetActive(false);
     // 设置相机参数以匹配世界坐标区域 
     yield return new WaitForEndOfFrame();

     // 设置相机的渲染目标为RenderTexture  
     captureCamera.targetTexture = captureTexture;

     // 渲染相机到RenderTexture  
     captureCamera.Render();

     // 从RenderTexture获取像素数据并创建Texture2D  
     sp4 = new Texture2D(captureTexture.width, captureTexture.height, TextureFormat.ARGB32, false);
     sp4.ReadPixels(rect, 0, 0);
     sp4.Apply();


     // 清理RenderTexture资源  
     captureCamera.targetTexture = null;
     captureTexture.Release();
     bytes = sp4.EncodeToPNG();

     File.WriteAllBytes("保存路径", bytes);
     rec.gameObject.SetActive(true);
    
 }

导出后效果图

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值