private GetPrefabParent ( Object source ) : Object | ||
source | Object | |
리턴 | Object |
/// <summary> /// Connect copied objects to prefabs if original object is connected, and sets helper reference back to new prefab reference /// Also recursively calls itself in all children /// </summary> /// <param name="toMine">Whether we are copying theirs to mine (true) or mie to theirs (false)</param> void ConnectPrefabsAfterCopy(bool toMine) { var original = toMine ? theirs : mine; var copy = toMine ? mine : theirs; if (Util.IsPrefabParent(original) && PrefabUtility.GetPrefabType(original) == PrefabType.PrefabInstance) { copy = PrefabUtility.ConnectGameObjectToPrefab(copy, (GameObject)PrefabUtility.GetPrefabParent(original)); copy.name = original.name; // ConnectPrefab will rename to prefab name // ConnectPrefab will override transform var copyTransform = copy.transform; var originalTransform = original.transform; copyTransform.localPosition = originalTransform.localPosition; copyTransform.localRotation = originalTransform.localRotation; copyTransform.localScale = originalTransform.localScale; } if (toMine) { mine = copy; } else { theirs = copy; } if (children != null) { foreach (var child in children) { child.ConnectPrefabsAfterCopy(toMine); } } }