浏览代码

add utility for reverting transform hierarchy, simplify hash compare

/main
Lasse Jon Fuglsang Pedersen 5 年前
当前提交
fa818f98
共有 4 个文件被更改,包括 78 次插入9 次删除
  1. 13
      Editor/Utility/PrefabTransformHierarchyEditor.cs
  2. 5
      Runtime/SkinAttachment.cs
  3. 6
      Runtime/SkinAttachmentTarget.cs
  4. 63
      Runtime/Utility/PrefabTransformHierarchy.cs

13
Editor/Utility/PrefabTransformHierarchyEditor.cs


var root = target as PrefabTransformHierarchy;
if (root != null)
{
EditorGUI.BeginDisabledGroup(Application.isPlaying);
if (GUILayout.Button("Revert transform hierarchy"))
if (GUILayout.Button("Revert transform hierarchy"))
if (Application.isPlaying)
{
root.LoadDefaults();
}
else
{
var transforms = root.GetComponentsInChildren<Transform>(includeInactive: true);
for (int i = 0; i != transforms.Length; i++)

PrefabUtility.RevertObjectOverride(transforms[i], InteractionMode.UserAction);
}
}
}
EditorUtility.ClearProgressBar();
}
EditorUtility.ClearProgressBar();
EditorGUI.EndDisabledGroup();
}
}
}

5
Runtime/SkinAttachment.cs


return new Hash128(checksum0, checksum1);
}
public bool ChecksumCompare(in SkinAttachmentData data)
{
return (checksum0 == data.checksum0) && (checksum1 == data.checksum1);
}
public void RevertVertexData()
{
if (meshAsset != null)

6
Runtime/SkinAttachmentTarget.cs


for (int i = 0, n = subjects.Count; i != n; i++)
{
if (subjects[i].Checksum() != attachData.Checksum())
if (subjects[i].ChecksumCompare(attachData) == false)
return true;
}

for (int i = 0, n = subjects.Count; i != n; i++)
{
var subject = subjects[i];
if (subject.Checksum() != attachData.Checksum())
if (subject.ChecksumCompare(attachData) == false)
continue;
int attachmentIndex = subject.attachmentIndex;

for (int i = 0, n = subjects.Count; i != n; i++)
{
var subject = subjects[i];
if (subject.Checksum() != attachData.Checksum())
if (subject.ChecksumCompare(attachData) == false)
continue;
var stillRunning = (stagingJobs[i].IsCompleted == false);

63
Runtime/Utility/PrefabTransformHierarchy.cs


using UnityEngine;
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor.Experimental.SceneManagement;
#endif
[Serializable]
public struct TransformDefaults
{
public Transform transform;
public Vector3 localPosition;
public Quaternion localRotation;
}
public TransformDefaults[] data;
public void LoadDefaults()
{
if (data == null)
return;
for (int i = 0; i != data.Length; i++)
{
if (data[i].transform == null)
continue;
data[i].transform.localPosition = data[i].localPosition;
data[i].transform.localRotation = data[i].localRotation;
}
}
public void SaveDefaults()
{
var transforms = this.transform.GetComponentsInChildren<Transform>(includeInactive: true);
var transformCount = transforms.Length;
data = new TransformDefaults[transformCount];
for (int i = 0; i != transformCount; i++)
{
data[i].transform = transforms[i];
data[i].localPosition = transforms[i].localPosition;
data[i].localRotation = transforms[i].localRotation;
}
}
#if UNITY_EDITOR
static PrefabTransformHierarchy()
{
PrefabStage.prefabSaving += (GameObject prefab) =>
{
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage != null)
{
var roots = prefab.GetComponentsInChildren<PrefabTransformHierarchy>(includeInactive: true);
foreach (var root in roots)
{
root.SaveDefaults();
}
}
};
}
#endif
}
}
正在加载...
取消
保存