Lasse Jon Fuglsang Pedersen
5 年前
当前提交
db37fb0b
共有 4 个文件被更改,包括 78 次插入 和 9 次删除
-
13Editor/Utility/PrefabTransformHierarchyEditor.cs
-
5Runtime/SkinAttachment.cs
-
6Runtime/SkinAttachmentTarget.cs
-
63Runtime/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
|
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue