André McGrail
4 年前
当前提交
d00579aa
共有 5 个文件被更改,包括 1139 次插入 和 45 次删除
-
72Assets/Scripts/Environment/CloudRenderer.cs
-
1001Assets/Objects/environment/Clouds/CloudMeshes.asset
-
8Assets/Objects/environment/Clouds/CloudMeshes.asset.meta
-
92Assets/Scripts/Utility/SpriteMeshGenerator.cs
-
11Assets/Scripts/Utility/SpriteMeshGenerator.cs.meta
1001
Assets/Objects/environment/Clouds/CloudMeshes.asset
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 8b7e5305947554a418af3eb802471592 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
[CreateAssetMenu(fileName = "SpriteMeshGenerator.asset", menuName = "2D/Sprite Mesh Generator", order = 1)] |
|||
public class SpriteMeshGenerator : ScriptableObject |
|||
{ |
|||
public Sprite[] sprites; |
|||
[SerializeField] private string hash; |
|||
private void OnValidate() |
|||
{ |
|||
if (sprites != null && sprites.Length > 0) |
|||
{ |
|||
Debug.Log("doing things"); |
|||
var curHash = ""; |
|||
foreach (var sprite in sprites) |
|||
{ |
|||
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(sprite, out var guid, out long _)) |
|||
{ |
|||
curHash += guid; |
|||
} |
|||
} |
|||
|
|||
if (hash == curHash) return; |
|||
GenerateAndSaveMesh(); |
|||
hash = curHash; |
|||
} |
|||
} |
|||
|
|||
void GenerateAndSaveMesh() |
|||
{ |
|||
try |
|||
{ |
|||
AssetDatabase.StartAssetEditing(); |
|||
CleanSubassets(); |
|||
foreach (var sprite in sprites) |
|||
{ |
|||
if(sprite == null) continue; |
|||
var mesh = GenerateMeshFromSprite(sprite); |
|||
AssetDatabase.AddObjectToAsset(mesh, this); |
|||
} |
|||
} |
|||
finally |
|||
{ |
|||
AssetDatabase.StopAssetEditing(); |
|||
} |
|||
} |
|||
|
|||
public static Mesh GenerateMeshFromSprite(Sprite sprite) |
|||
{ |
|||
// verts
|
|||
var verts = new List<Vector3>(); |
|||
sprite.vertices.ToList().ForEach(x => verts.Add(new Vector3(x.x, x.y, 0.0f))); |
|||
// triangles
|
|||
var tris = new List<int>(); |
|||
sprite.triangles.ToList().ForEach(x => tris.Add(x)); |
|||
// normals
|
|||
var normals = new Vector3[verts.Count]; |
|||
for (var index = 0; index < normals.Length; index++) |
|||
{ |
|||
normals[index] = Vector3.forward; |
|||
} |
|||
|
|||
var mesh = new Mesh |
|||
{ |
|||
name = sprite.name.Replace('.', '_'), |
|||
vertices = verts.ToArray(), |
|||
triangles = tris.ToArray(), |
|||
normals = normals.ToArray(), |
|||
colors32 = new Color32[verts.Count], |
|||
uv = sprite.uv |
|||
}; |
|||
|
|||
return mesh; |
|||
} |
|||
|
|||
void CleanSubassets() |
|||
{ |
|||
var subassets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(this)); |
|||
|
|||
foreach (var t in subassets) |
|||
{ |
|||
if(t == this) continue; |
|||
Debug.Log(t); |
|||
DestroyImmediate(t, true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: efd71620d53b04fe4b35207444f01def |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue