コード例 #1
0
ファイル: UndoHistorian.cs プロジェクト: Oletus/puddleknights
        private void RestoreOne(HistoryState state, GameObject obj)
        {
            Component[]   components    = obj.GetComponents(typeof(Component));
            UndoHistorian thisHistorian = null;

            foreach (Component comp in components)
            {
                if (comp.GetType() == typeof(UndoHistorian))
                {
                    thisHistorian = comp as UndoHistorian;
                    continue;
                }
                foreach (FieldInfo f in comp.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    foreach (Attribute a in f.GetCustomAttributes(false))
                    {
                        if (a is UndoHistoryable)
                        {
                            f.SetValue(comp, state.storedFields[comp.GetInstanceID()][f.Name]);
                        }
                    }
                }
                foreach (PropertyInfo p in comp.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    foreach (Attribute a in p.GetCustomAttributes(false))
                    {
                        if (a is UndoHistoryable)
                        {
                            p.SetValue(comp, state.storedFields[comp.GetInstanceID()][p.Name]);
                        }
                    }
                }
            }
            if (thisHistorian != null)
            {
                if (thisHistorian.config.includeParent)
                {
                    obj.transform.SetParent(state.transformData[obj.GetInstanceID()].parent, true);
                }
                if (thisHistorian.config.includePosition)
                {
                    obj.transform.position = state.transformData[obj.GetInstanceID()].position;
                }
                if (thisHistorian.config.includeRotation)
                {
                    obj.transform.rotation = state.transformData[obj.GetInstanceID()].rotation;
                }
            }
        }
コード例 #2
0
ファイル: UndoHistorian.cs プロジェクト: Oletus/puddleknights
        private void CommitOne(HistoryState state, GameObject obj)
        {
            Component[]   components    = obj.GetComponents(typeof(Component));
            UndoHistorian thisHistorian = null;

            foreach (Component comp in components)
            {
                if (comp.GetType() == typeof(UndoHistorian))
                {
                    thisHistorian = comp as UndoHistorian;
                    continue;
                }
                foreach (FieldInfo f in comp.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    foreach (Attribute a in f.GetCustomAttributes(false))
                    {
                        if (a is UndoHistoryable)
                        {
                            if (!state.storedFields.ContainsKey(comp.GetInstanceID()))
                            {
                                state.storedFields[comp.GetInstanceID()] = new Dictionary <string, object>();
                            }
                            state.storedFields[comp.GetInstanceID()][f.Name] = f.GetValue(comp);
                        }
                    }
                }
                foreach (PropertyInfo p in comp.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    foreach (Attribute a in p.GetCustomAttributes(false))
                    {
                        if (a is UndoHistoryable)
                        {
                            if (!state.storedFields.ContainsKey(comp.GetInstanceID()))
                            {
                                state.storedFields[comp.GetInstanceID()] = new Dictionary <string, object>();
                            }
                            state.storedFields[comp.GetInstanceID()][p.Name] = p.GetValue(comp);
                        }
                    }
                }
            }

            if (thisHistorian != null)
            {
                HistoryTransformData transformDataState = new HistoryTransformData();

                if (thisHistorian.config.includeParent)
                {
                    transformDataState.parent = obj.transform.parent;
                }
                if (thisHistorian.config.includePosition)
                {
                    transformDataState.position = obj.transform.position;
                }
                if (thisHistorian.config.includeRotation)
                {
                    transformDataState.rotation = obj.transform.rotation;
                }
                state.transformData[obj.GetInstanceID()] = transformDataState;
            }
        }