-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from refiaa/revert_instance_info_saving
Revert instance info saving
- Loading branch information
Showing
5 changed files
with
189 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
public static class MeshRevertManager | ||
{ | ||
private static Dictionary<string, Mesh> originalMeshMap = new Dictionary<string, Mesh>(); | ||
|
||
public static void StoreOriginalMesh(Mesh decimatedMesh, Mesh originalMesh) | ||
{ | ||
string key = GetMeshKey(decimatedMesh); | ||
if (!originalMeshMap.ContainsKey(key)) | ||
{ | ||
originalMeshMap.Add(key, originalMesh); | ||
} | ||
} | ||
|
||
public static Mesh GetOriginalMesh(Mesh decimatedMesh) | ||
{ | ||
string key = GetMeshKey(decimatedMesh); | ||
if (originalMeshMap.TryGetValue(key, out Mesh originalMesh)) | ||
{ | ||
return originalMesh; | ||
} | ||
return null; | ||
} | ||
|
||
private static string GetMeshKey(Mesh mesh) | ||
{ | ||
string assetPath = AssetDatabase.GetAssetPath(mesh); | ||
if (string.IsNullOrEmpty(assetPath)) | ||
{ | ||
return mesh.name; | ||
} | ||
else | ||
{ | ||
return $"{assetPath}:{mesh.name}"; | ||
} | ||
} | ||
|
||
private static string GetMeshUniqueID(Mesh mesh) | ||
{ | ||
string guid; | ||
long localId; | ||
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(mesh, out guid, out localId)) | ||
{ | ||
return $"{guid}_{localId}"; | ||
} | ||
else | ||
{ | ||
return mesh.GetInstanceID().ToString(); | ||
} | ||
} | ||
|
||
public static void StoreDecimateLevel(Mesh mesh, float decimateLevel) | ||
{ | ||
string uniqueID = GetMeshUniqueID(mesh); | ||
if (!string.IsNullOrEmpty(uniqueID)) | ||
{ | ||
EditorPrefs.SetFloat("DecimateLevel_" + uniqueID, decimateLevel); | ||
} | ||
} | ||
|
||
public static float GetDecimateLevel(Mesh mesh) | ||
{ | ||
string uniqueID = GetMeshUniqueID(mesh); | ||
if (!string.IsNullOrEmpty(uniqueID)) | ||
{ | ||
return EditorPrefs.GetFloat("DecimateLevel_" + uniqueID, 1.0f); | ||
} | ||
return 1.0f; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters