您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
73 行
1.6 KiB
73 行
1.6 KiB
using System;
|
|
using UnityEngine;
|
|
#if UNITY_EDITOR
|
|
#if UNITY_2021_2_OR_NEWER
|
|
using UnityEditor.SceneManagement;
|
|
#else
|
|
using UnityEditor.Experimental.SceneManagement;
|
|
#endif
|
|
#endif
|
|
|
|
namespace Unity.DemoTeam.DigitalHuman
|
|
{
|
|
public class PrefabTransformHierarchy : MonoBehaviour
|
|
{
|
|
[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
|
|
}
|
|
}
|