/// <summary> /// Updates contents of the scene object specific fields (name, position, rotation, etc.) /// </summary> /// <param name="forceUpdate">If true, the GUI elements will be updated regardless of whether a change was /// detected or not.</param> internal void RefreshSceneObjectFields(bool forceUpdate) { if (activeSO == null) { return; } soNameInput.Text = activeSO.Name; soActiveToggle.Value = activeSO.Active; soMobility.Value = (ulong)activeSO.Mobility; SceneObject prefabParent = PrefabUtility.GetPrefabParent(activeSO); // Ignore prefab parent if scene root, we only care for non-root prefab instances bool hasPrefab = prefabParent != null && prefabParent.Parent != null; if (soHasPrefab != hasPrefab || forceUpdate) { int numChildren = soPrefabLayout.ChildCount; for (int i = 0; i < numChildren; i++) { soPrefabLayout.GetChild(0).Destroy(); } GUILabel prefabLabel = new GUILabel(new LocEdString("Prefab"), GUIOption.FixedWidth(50)); soPrefabLayout.AddElement(prefabLabel); if (hasPrefab) { GUIButton btnApplyPrefab = new GUIButton(new LocEdString("Apply"), GUIOption.FixedWidth(60)); GUIButton btnRevertPrefab = new GUIButton(new LocEdString("Revert"), GUIOption.FixedWidth(60)); GUIButton btnBreakPrefab = new GUIButton(new LocEdString("Break"), GUIOption.FixedWidth(60)); btnApplyPrefab.OnClick += () => { PrefabUtility.ApplyPrefab(activeSO); }; btnRevertPrefab.OnClick += () => { GameObjectUndo.RecordSceneObject(activeSO, true, "Reverting \"" + activeSO.Name + "\" to prefab."); PrefabUtility.RevertPrefab(activeSO); GameObjectUndo.ResolveDiffs(); EditorApplication.SetSceneDirty(); }; btnBreakPrefab.OnClick += () => { UndoRedo.BreakPrefab(activeSO, "Breaking prefab link for " + activeSO.Name); EditorApplication.SetSceneDirty(); }; soPrefabLayout.AddElement(btnApplyPrefab); soPrefabLayout.AddElement(btnRevertPrefab); soPrefabLayout.AddElement(btnBreakPrefab); } else { GUILabel noPrefabLabel = new GUILabel("None"); soPrefabLayout.AddElement(noPrefabLabel); } soHasPrefab = hasPrefab; } Vector3 position; Quaternion rotation; if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World) { position = activeSO.Position; rotation = activeSO.Rotation; } else { position = activeSO.LocalPosition; rotation = activeSO.LocalRotation; } Vector3 scale = activeSO.LocalScale; if (!soPos.HasInputFocus || forceUpdate) { soPos.Value = position; } // Avoid updating the rotation unless actually changed externally, since switching back and forth between // quaternion and euler angles can cause weird behavior if ((!soRot.HasInputFocus && rotation != lastRotation) || forceUpdate) { soRot.Value = rotation.ToEuler(); lastRotation = rotation; } if (!soScale.HasInputFocus || forceUpdate) { soScale.Value = scale; } }
/// <summary> /// Finishes recording an undo command started via <see cref="StartUndo(string)"/>. If any changes are detected on /// the field an undo command is recorded onto the undo-redo stack, otherwise nothing is done. /// </summary> private void EndUndo() { GameObjectUndo.ResolveDiffs(); }