版本: Unity 6 (6000.0)
语言English
  • C#

Undo.RegisterChildrenOrderUndo

建议修改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法采纳所有提交内容,但我们确实阅读了用户提出的每个修改建议,并在适用情况下进行更新。

关闭

提交失败

由于某些原因,您的修改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public static void RegisterChildrenOrderUndo(Object objectToUndo, string name);

参数

objectToUndo 应在撤消堆栈上记录其子级顺序的对象。
name 撤消操作的名称。

描述

在撤消堆栈上存储对象子级顺序的副本。

如果执行撤消,则对象子级的顺序将恢复到记录的状态。

using UnityEngine;
using UnityEditor;

public class UndoExamples { [MenuItem("Undo Examples/RegisterChildrenOrderUndo")] static void Example() { var parent = new GameObject("Parent"); for (int childIndex = 0; childIndex < 5; childIndex += 1) { var child = new GameObject($"Child{childIndex}"); child.transform.parent = parent.transform; }

// Store the states of the parent object. Undo.RegisterChildrenOrderUndo(parent.transform, "Set as last sibling"); parent.transform.GetChild(0).SetAsLastSibling();

// If you choose "Edit->Undo Set as last sibling" from the main menu now, the order of the children will be restored. } }
© . This site is unofficial and not affiliated with Unity Technologies.