private static void OnObjectChanged(ref ObjectChangeEventStream stream) { for (int i = 0; i < stream.length; ++i) { var eventType = stream.GetEventType(i); switch (eventType) { case ObjectChangeKind.ChangeGameObjectOrComponentProperties: { stream.GetChangeGameObjectOrComponentPropertiesEvent(i, out var e); OnGameObjectChanged(TryGetGameObject(e.instanceId)); } break; case ObjectChangeKind.ChangeGameObjectParent: { stream.GetChangeGameObjectParentEvent(i, out var e); if (e.previousParentInstanceId != 0) { OnGameObjectChanged(TryGetGameObject(e.previousParentInstanceId)); } if (e.newParentInstanceId != 0) { OnGameObjectChanged(TryGetGameObject(e.newParentInstanceId)); } } break; case ObjectChangeKind.ChangeGameObjectStructure: { stream.GetChangeGameObjectStructureEvent(i, out var e); OnGameObjectChanged(TryGetGameObject(e.instanceId)); } break; case ObjectChangeKind.ChangeGameObjectStructureHierarchy: { stream.GetChangeGameObjectStructureHierarchyEvent(i, out var e); OnGameObjectChanged(TryGetGameObject(e.instanceId)); } break; case ObjectChangeKind.UpdatePrefabInstances: { stream.GetUpdatePrefabInstancesEvent(i, out var e); for (int index = 0; index < e.instanceIds.Length; index++) { OnGameObjectChanged(TryGetGameObject(e.instanceIds[index])); } } break; case ObjectChangeKind.CreateGameObjectHierarchy: { stream.GetCreateGameObjectHierarchyEvent(i, out var e); GameObject go = TryGetGameObject(e.instanceId); if (go != null && go.transform.parent) { go = go.transform.parent.gameObject; OnGameObjectChanged(go); } } break; case ObjectChangeKind.DestroyGameObjectHierarchy: { stream.GetDestroyGameObjectHierarchyEvent(i, out var e); GameObject goParent = TryGetGameObject(e.parentInstanceId); if (goParent != null) { OnGameObjectChanged(goParent); } } break; } } }
private void OnObjectChanged(ref ObjectChangeEventStream stream) { if (m_SceneQueryEngine == null) { return; } for (int i = 0; i < stream.length; ++i) { var eventType = stream.GetEventType(i); switch (eventType) { case ObjectChangeKind.None: case ObjectChangeKind.CreateAssetObject: case ObjectChangeKind.DestroyAssetObject: case ObjectChangeKind.ChangeAssetObjectProperties: break; case ObjectChangeKind.ChangeScene: case ObjectChangeKind.CreateGameObjectHierarchy: case ObjectChangeKind.DestroyGameObjectHierarchy: InvalidateScene(); break; case ObjectChangeKind.ChangeGameObjectStructureHierarchy: { stream.GetChangeGameObjectStructureHierarchyEvent(i, out var e); InvalidateObject(e.instanceId, RefreshFlags.StructureChanged); } break; case ObjectChangeKind.ChangeGameObjectStructure: { stream.GetChangeGameObjectStructureEvent(i, out var e); InvalidateObject(e.instanceId, RefreshFlags.StructureChanged); } break; case ObjectChangeKind.ChangeGameObjectParent: { stream.GetChangeGameObjectParentEvent(i, out var e); InvalidateObject(e.instanceId); } break; case ObjectChangeKind.ChangeGameObjectOrComponentProperties: { stream.GetChangeGameObjectOrComponentPropertiesEvent(i, out var e); InvalidateObject(e.instanceId); } break; case ObjectChangeKind.UpdatePrefabInstances: { stream.GetUpdatePrefabInstancesEvent(i, out var e); for (int idIndex = 0; idIndex < e.instanceIds.Length; ++idIndex) { InvalidateObject(e.instanceIds[idIndex]); } } break; } } }
void OnEditorChangeEvents(ref ObjectChangeEventStream stream) { for (int i = 0; i < stream.length; i++) { var type = stream.GetEventType(i); switch (type) { case ObjectChangeKind.None: break; case ObjectChangeKind.ChangeScene: { stream.GetChangeSceneEvent(i, out var evt); if (evt.scene.IsValid()) { GetLiveLink(evt.scene)?.RequestCleanConversion(); } break; } case ObjectChangeKind.CreateGameObjectHierarchy: { stream.GetCreateGameObjectHierarchyEvent(i, out var evt); GetLiveLink(evt.scene)?.ChangeTracker.MarkReconvertHierarchy(evt.instanceId); break; } case ObjectChangeKind.ChangeGameObjectStructureHierarchy: { stream.GetChangeGameObjectStructureHierarchyEvent(i, out var evt); GetLiveLink(evt.scene)?.ChangeTracker.MarkReconvertHierarchy(evt.instanceId); break; } case ObjectChangeKind.ChangeGameObjectStructure: { stream.GetChangeGameObjectStructureEvent(i, out var evt); GetLiveLink(evt.scene)?.ChangeTracker.MarkChanged(evt.instanceId); break; } case ObjectChangeKind.ChangeGameObjectParent: { stream.GetChangeGameObjectParentEvent(i, out var evt); if (evt.newScene != evt.previousScene) { GetLiveLink(evt.newScene)?.ChangeTracker.MarkReconvertHierarchy(evt.instanceId); GetLiveLink(evt.previousScene)?.ChangeTracker.MarkRemoved(evt.instanceId); } else { GetLiveLink(evt.newScene)?.ChangeTracker.MarkParentChanged(evt.instanceId, evt.newParentInstanceId); } break; } case ObjectChangeKind.ChangeGameObjectOrComponentProperties: { stream.GetChangeGameObjectOrComponentPropertiesEvent(i, out var evt); var target = EditorUtility.InstanceIDToObject(evt.instanceId); if (target is Component c) { GetLiveLink(evt.scene)?.ChangeTracker.MarkComponentChanged(c); } else { GetLiveLink(evt.scene)?.ChangeTracker.MarkChanged(evt.instanceId); } break; } case ObjectChangeKind.DestroyGameObjectHierarchy: { stream.GetDestroyGameObjectHierarchyEvent(i, out var evt); GetLiveLink(evt.scene)?.ChangeTracker.MarkRemoved(evt.instanceId); break; } case ObjectChangeKind.CreateAssetObject: { stream.GetCreateAssetObjectEvent(i, out var evt); MarkAssetChanged(evt.instanceId, evt.scene); break; } case ObjectChangeKind.DestroyAssetObject: { stream.GetDestroyAssetObjectEvent(i, out var evt); MarkAssetChanged(evt.instanceId, evt.scene); break; } case ObjectChangeKind.ChangeAssetObjectProperties: { stream.GetChangeAssetObjectPropertiesEvent(i, out var evt); MarkAssetChanged(evt.instanceId, evt.scene); break; } case ObjectChangeKind.UpdatePrefabInstances: { stream.GetUpdatePrefabInstancesEvent(i, out var evt); var diffGenerator = GetLiveLink(evt.scene); if (diffGenerator != null) { for (int k = 0; k < evt.instanceIds.Length; k++) { diffGenerator.ChangeTracker.MarkReconvertHierarchy(evt.instanceIds[k]); } } break; } default: throw new ArgumentOutOfRangeException(); } } EditorUpdateUtility.EditModeQueuePlayerLoopUpdate(); }
static void ObjectChangeEvent(ref ObjectChangeEventStream stream) { for (int i = 0; i != stream.length; i++) { switch (stream.GetEventType(i)) { case ObjectChangeKind.ChangeGameObjectOrComponentProperties: { stream.GetChangeGameObjectOrComponentPropertiesEvent(i, out var evt); var lodGroup = Resources.InstanceIDToObject(evt.instanceId) as LODGroup; if (lodGroup != null && lodGroup.GetComponent <HLOD>()) { _Manager.UpdateLODData(lodGroup.GetComponent <HLOD>()); } var hlod = Resources.InstanceIDToObject(evt.instanceId) as HLOD; if (hlod != null) { DirtyStructure(hlod.gameObject); } break; } case ObjectChangeKind.CreateGameObjectHierarchy: { stream.GetCreateGameObjectHierarchyEvent(i, out var evt); DirtyStructure(Resources.InstanceIDToObject(evt.instanceId) as GameObject); break; } case ObjectChangeKind.ChangeGameObjectStructureHierarchy: { stream.GetChangeGameObjectStructureHierarchyEvent(i, out var evt); DirtyStructure(Resources.InstanceIDToObject(evt.instanceId) as GameObject); break; } case ObjectChangeKind.ChangeGameObjectStructure: { stream.GetChangeGameObjectStructureEvent(i, out var evt); DirtyStructure(Resources.InstanceIDToObject(evt.instanceId) as GameObject); break; } case ObjectChangeKind.ChangeGameObjectParent: { stream.GetChangeGameObjectParentEvent(i, out var evt); DirtyStructure(Resources.InstanceIDToObject(evt.newParentInstanceId) as GameObject); DirtyStructure(Resources.InstanceIDToObject(evt.previousParentInstanceId) as GameObject); break; } case ObjectChangeKind.DestroyGameObjectHierarchy: { stream.GetDestroyGameObjectHierarchyEvent(i, out var evt); DirtyStructure(Resources.InstanceIDToObject(evt.instanceId) as GameObject); break; } case ObjectChangeKind.UpdatePrefabInstances: { stream.GetUpdatePrefabInstancesEvent(i, out var evt); for (int c = 0; c != evt.instanceIds.Length; c++) { DirtyStructure(Resources.InstanceIDToObject(evt.instanceIds[c]) as GameObject); } break; } } } }