article Songyang
This article is from the Asura road , prohibited for commercial purposes, reproduced please indicate the source.
original link:replaceme
/p>
Undo
In the Unity3d editor extension, it is often necessary to work with undo as follows: Cmd/Ctrl + z . Undo.RecordObjectsThis work can be done in the Unity3d corresponding interface.
Packaging
Since its parameters require the components of the object we manipulate, I have encapsulated an operation class for him. Called by a managed method.
Realize
The implementation functions are as follows:
using unityengine;using system.collections;using system.collections.generic;using Unityeditor;/*usage:var go = selection.activetransform; undooperate BC = new Undooperate ("Batch Operate"); Bc. Add (Go, () =>{go.localposition = new Vector3 (1,2,1); Go.localscale = new Vector3 (1,2,1); }); var comp = go. Getcomponent<test> (); Bc. ADD (comp, () =>{comp.str= "Hello Songyang"; }); Bc. Flush (); */public class Undooperate {public delegate void Callback (); list<object> targetlist = new list<object> (); list<callback> calllist = new list<callback> (); String M_name; Public undooperate (string name) {m_name = name; } public void Add (Object obj,callback call) {Targetlist.add (obj); Calllist.add (call); } public void Flush () {undo.recordobjects (Targetlist.toarray (), m_name); foreach (var. calllist) {each (); } }};
If you think this article is helpful to you, you can take a Top , not only do not want to be a father, but also let more people can see it ...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Unity3d Development (v) Undo Action for editor