public static UndoActionObject FromJson(string json) { // // Here be dragons. Thou art forewarned // var serialized = FlaxEngine.Json.JsonSerializer.Deserialize <SerializedUndoActionObject>(json); UndoActionObject undoActionObject = (UndoActionObject)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(UndoActionObject)); TargetInstanceField.SetValue(undoActionObject, serialized.TargetInstance); DataField.SetValue(undoActionObject, serialized.Data); var memberInfoPaths = new MemberInfoPath[serialized.MemberStacks.Length]; for (int i = 0; i < memberInfoPaths.Length; i++) { // Prepare the stack entries var entries = new MemberInfoPath.Entry[serialized.MemberStacks[i].Length]; for (int j = 0; j < entries.Length; j++) { var serializedEntry = serialized.MemberStacks[i][j]; Type type = Type.GetType(serializedEntry.AssemblyQualifiedName); MemberInfo memberInfo; if (serializedEntry.MemberInfoType == typeof(MethodInfo)) { memberInfo = type.GetMethod(serializedEntry.Path); } else if (serializedEntry.MemberInfoType == typeof(FieldInfo)) { memberInfo = type.GetField(serializedEntry.Path); } else if (serializedEntry.MemberInfoType == typeof(PropertyInfo)) { memberInfo = type.GetProperty(serializedEntry.Path); } else { throw new Exception("Unexpected MemberInfoType: " + serializedEntry.MemberInfoType); } entries[j] = new MemberInfoPath.Entry(new ScriptMemberInfo(memberInfo), serializedEntry.Index); } // MemberInfoPath is a struct, we have to jump through some hoops to set a private field object boxedMemberInfoPath = memberInfoPaths[i]; StackField.SetValue(boxedMemberInfoPath, entries); memberInfoPaths[i] = (MemberInfoPath)boxedMemberInfoPath; } MembersField.SetValue(undoActionObject, memberInfoPaths); return(undoActionObject); }
/// <summary> /// Container Class for all the properties for organization. /// </summary> /// <param name="c"></param> public TorqueScriptTemplate(ref dnTorque c) { m_ts = c; _mConsoleobject = new ConsoleObject(ref c); _mMathobject = new tMath(ref c); _mUtil = new UtilObject(ref c); _mHTTPObject = new HTTPObjectObject(ref c); _mTCPObject = new TCPObjectObject(ref c); _mDynamicConsoleMethodComponent = new DynamicConsoleMethodComponentObject(ref c); _mSimComponent = new SimComponentObject(ref c); _mArrayObject = new ArrayObjectObject(ref c); _mConsoleLogger = new ConsoleLoggerObject(ref c); _mFieldBrushObject = new FieldBrushObjectObject(ref c); _mPersistenceManager = new PersistenceManagerObject(ref c); _mSimDataBlock = new SimDataBlockObject(ref c); _mSimObject = new SimObjectObject(ref c); _mSimPersistSet = new SimPersistSetObject(ref c); _mSimSet = new SimSetObject(ref c); _mSimXMLDocument = new SimXMLDocumentObject(ref c); _mFileObject = new FileObjectObject(ref c); _mFileStreamObject = new FileStreamObjectObject(ref c); _mStreamObject = new StreamObjectObject(ref c); _mZipObject = new ZipObjectObject(ref c); _mDecalRoad = new DecalRoadObject(ref c); _mMeshRoad = new MeshRoadObject(ref c); _mRiver = new RiverObject(ref c); _mScatterSky = new ScatterSkyObject(ref c); _mSkyBox = new SkyBoxObject(ref c); _mSun = new SunObject(ref c); _mGuiRoadEditorCtrl = new GuiRoadEditorCtrlObject(ref c); _mForest = new ForestObject(ref c); _mForestWindEmitter = new ForestWindEmitterObject(ref c); _mForestBrush = new ForestBrushObject(ref c); _mForestBrushTool = new ForestBrushToolObject(ref c); _mForestEditorCtrl = new ForestEditorCtrlObject(ref c); _mForestSelectionTool = new ForestSelectionToolObject(ref c); _mCubemapData = new CubemapDataObject(ref c); _mDebugDrawer = new DebugDrawerObject(ref c); _mGuiTSCtrl = new GuiTSCtrlObject(ref c); _mGuiBitmapButtonCtrl = new GuiBitmapButtonCtrlObject(ref c); _mGuiButtonBaseCtrl = new GuiButtonBaseCtrlObject(ref c); _mGuiCheckBoxCtrl = new GuiCheckBoxCtrlObject(ref c); _mGuiIconButtonCtrl = new GuiIconButtonCtrlObject(ref c); _mGuiSwatchButtonCtrl = new GuiSwatchButtonCtrlObject(ref c); _mGuiToolboxButtonCtrl = new GuiToolboxButtonCtrlObject(ref c); _mGuiAutoScrollCtrl = new GuiAutoScrollCtrlObject(ref c); _mGuiDynamicCtrlArrayControl = new GuiDynamicCtrlArrayControlObject(ref c); _mGuiFormCtrl = new GuiFormCtrlObject(ref c); _mGuiFrameSetCtrl = new GuiFrameSetCtrlObject(ref c); _mGuiPaneControl = new GuiPaneControlObject(ref c); _mGuiRolloutCtrl = new GuiRolloutCtrlObject(ref c); _mGuiScrollCtrl = new GuiScrollCtrlObject(ref c); _mGuiStackControl = new GuiStackControlObject(ref c); _mGuiTabBookCtrl = new GuiTabBookCtrlObject(ref c); _mGuiBitmapCtrl = new GuiBitmapCtrlObject(ref c); _mGuiColorPickerCtrl = new GuiColorPickerCtrlObject(ref c); _mGuiDirectoryFileListCtrl = new GuiDirectoryFileListCtrlObject(ref c); _mGuiFileTreeCtrl = new GuiFileTreeCtrlObject(ref c); _mGuiGameListMenuCtrl = new GuiGameListMenuCtrlObject(ref c); _mGuiGameListOptionsCtrl = new GuiGameListOptionsCtrlObject(ref c); _mGuiGradientCtrl = new GuiGradientCtrlObject(ref c); _mGuiListBoxCtrl = new GuiListBoxCtrlObject(ref c); _mGuiMaterialCtrl = new GuiMaterialCtrlObject(ref c); _mGuiMLTextCtrl = new GuiMLTextCtrlObject(ref c); _mGuiPopUpMenuCtrl = new GuiPopUpMenuCtrlObject(ref c); _mGuiPopUpMenuCtrlEx = new GuiPopUpMenuCtrlExObject(ref c); _mGuiSliderCtrl = new GuiSliderCtrlObject(ref c); _mGuiTabPageCtrl = new GuiTabPageCtrlObject(ref c); _mGuiTextCtrl = new GuiTextCtrlObject(ref c); _mGuiTextEditCtrl = new GuiTextEditCtrlObject(ref c); _mGuiTextListCtrl = new GuiTextListCtrlObject(ref c); _mGuiTreeViewCtrl = new GuiTreeViewCtrlObject(ref c); _mGuiCanvas = new GuiCanvasObject(ref c); _mGuiControl = new GuiControlObject(ref c); _mGuiControlProfile = new GuiControlProfileObject(ref c); _mDbgFileView = new DbgFileViewObject(ref c); _mGuiEditCtrl = new GuiEditCtrlObject(ref c); _mGuiFilterCtrl = new GuiFilterCtrlObject(ref c); _mGuiGraphCtrl = new GuiGraphCtrlObject(ref c); _mGuiImageList = new GuiImageListObject(ref c); _mGuiInspector = new GuiInspectorObject(ref c); _mGuiInspectorTypeFileName = new GuiInspectorTypeFileNameObject(ref c); _mGuiInspectorTypeBitMask32 = new GuiInspectorTypeBitMask32Object(ref c); _mGuiMenuBar = new GuiMenuBarObject(ref c); _mGuiParticleGraphCtrl = new GuiParticleGraphCtrlObject(ref c); _mGuiShapeEdPreview = new GuiShapeEdPreviewObject(ref c); _mGuiInspectorDynamicField = new GuiInspectorDynamicFieldObject(ref c); _mGuiInspectorDynamicGroup = new GuiInspectorDynamicGroupObject(ref c); _mGuiInspectorField = new GuiInspectorFieldObject(ref c); _mGuiVariableInspector = new GuiVariableInspectorObject(ref c); _mGuiMessageVectorCtrl = new GuiMessageVectorCtrlObject(ref c); _mGuiProgressBitmapCtrl = new GuiProgressBitmapCtrlObject(ref c); _mGuiTickCtrl = new GuiTickCtrlObject(ref c); _mGuiTheoraCtrl = new GuiTheoraCtrlObject(ref c); _mMessageVector = new MessageVectorObject(ref c); _mEditTSCtrl = new EditTSCtrlObject(ref c); _mGuiMissionAreaCtrl = new GuiMissionAreaCtrlObject(ref c); _mMECreateUndoAction = new MECreateUndoActionObject(ref c); _mMEDeleteUndoAction = new MEDeleteUndoActionObject(ref c); _mWorldEditor = new WorldEditorObject(ref c); _mLangTable = new LangTableObject(ref c); _mPathedInterior = new PathedInteriorObject(ref c); _mMaterial = new MaterialObject(ref c); _mSimResponseCurve = new SimResponseCurveObject(ref c); _mMenuBar = new MenuBarObject(ref c); _mPopupMenu = new PopupMenuObject(ref c); _mFileDialog = new FileDialogObject(ref c); _mPostEffect = new PostEffectObject(ref c); _mRenderBinManager = new RenderBinManagerObject(ref c); _mRenderPassManager = new RenderPassManagerObject(ref c); _mRenderPassStateToken = new RenderPassStateTokenObject(ref c); _mSceneObject = new SceneObjectObject(ref c); _mSFXController = new SFXControllerObject(ref c); _mSFXParameter = new SFXParameterObject(ref c); _mSFXProfile = new SFXProfileObject(ref c); _mSFXSource = new SFXSourceObject(ref c); _mActionMap = new ActionMapObject(ref c); _mNetConnection = new NetConnectionObject(ref c); _mNetObject = new NetObjectObject(ref c); _mAIClient = new AIClientObject(ref c); _mAIConnection = new AIConnectionObject(ref c); _mAIPlayer = new AIPlayerObject(ref c); _mCamera = new CameraObject(ref c); _mDebris = new DebrisObject(ref c); _mGroundPlane = new GroundPlaneObject(ref c); _mGuiMaterialPreview = new GuiMaterialPreviewObject(ref c); _mGuiObjectView = new GuiObjectViewObject(ref c); _mItem = new ItemObject(ref c); _mLightBase = new LightBaseObject(ref c); _mLightDescription = new LightDescriptionObject(ref c); _mLightFlareData = new LightFlareDataObject(ref c); _mMissionArea = new MissionAreaObject(ref c); _mSpawnSphere = new SpawnSphereObject(ref c); _mPathCamera = new PathCameraObject(ref c); _mPhysicalZone = new PhysicalZoneObject(ref c); _mPlayer = new PlayerObject(ref c); _mPortal = new PortalObject(ref c); _mProjectile = new ProjectileObject(ref c); _mProximityMine = new ProximityMineObject(ref c); _mShapeBaseData = new ShapeBaseDataObject(ref c); _mShapeBase = new ShapeBaseObject(ref c); _mStaticShape = new StaticShapeObject(ref c); _mTrigger = new TriggerObject(ref c); _mTSStatic = new TSStaticObject(ref c); _mZone = new ZoneObject(ref c); _mRenderMeshExample = new RenderMeshExampleObject(ref c); _mLightning = new LightningObject(ref c); _mParticleData = new ParticleDataObject(ref c); _mParticleEmitterData = new ParticleEmitterDataObject(ref c); _mParticleEmitterNode = new ParticleEmitterNodeObject(ref c); _mPrecipitation = new PrecipitationObject(ref c); _mGameBase = new GameBaseObject(ref c); _mGameConnection = new GameConnectionObject(ref c); _mPhysicsDebrisData = new PhysicsDebrisDataObject(ref c); _mPhysicsForce = new PhysicsForceObject(ref c); _mPhysicsShape = new PhysicsShapeObject(ref c); _mAITurretShape = new AITurretShapeObject(ref c); _mTurretShape = new TurretShapeObject(ref c); _mFlyingVehicle = new FlyingVehicleObject(ref c); _mWheeledVehicle = new WheeledVehicleObject(ref c); _mTerrainBlock = new TerrainBlockObject(ref c); _mSettings = new SettingsObject(ref c); _mCompoundUndoAction = new CompoundUndoActionObject(ref c); _mUndoManager = new UndoManagerObject(ref c); _mUndoAction = new UndoActionObject(ref c); _mEventManager = new EventManagerObject(ref c); _mMessage = new MessageObject(ref c); }
public static string ToJson(UndoActionObject undoActionObject) { // // Here be dragons. Thou art forewarned // var serialized = new SerializedUndoActionObject(); // Serialize the target object serialized.TargetInstance = TargetInstanceField.GetValue(undoActionObject); if (serialized.TargetInstance != null && !(serialized.TargetInstance is FlaxEngine.Object)) { throw new Exception("Expected targetInstance to be a 'GUID reference type'!"); } // Serialize the Data serialized.Data = (string)DataField.GetValue(undoActionObject); // Serialize the MemberInfoPaths (which properties/fields got modified) var members = (MemberInfoPath[])MembersField.GetValue(undoActionObject); serialized.MemberStacks = new SerializedUndoActionObject.SerializedStackEntry[members.Length][]; // The members need a lot of special handling for (int i = 0; i < members.Length; i++) { var stack = (MemberInfoPath.Entry[])StackField.GetValue(members[i]); serialized.MemberStacks[i] = new SerializedUndoActionObject.SerializedStackEntry[stack.Length]; // Now handle those stack entries correctly for (int j = 0; j < stack.Length; j++) { serialized.MemberStacks[i][j] = new SerializedUndoActionObject.SerializedStackEntry(); if (stack[j].Member.IScriptMemberInfo != null) { Debug.LogError("Serializing IScriptMemberInfo not supported"); } if (stack[j].Member.Type is MethodInfo) { serialized.MemberStacks[i][j].MemberInfoType = typeof(MethodInfo); } else if (stack[j].Member.Type is FieldInfo) { serialized.MemberStacks[i][j].MemberInfoType = typeof(FieldInfo); } else if (stack[j].Member.Type is PropertyInfo) { serialized.MemberStacks[i][j].MemberInfoType = typeof(PropertyInfo); } else { throw new Exception("Unexpected entry.Member.Type: " + stack[j].Member.Type?.DeclaringType?.AssemblyQualifiedName); } // serialized.MemberStacks[i][j].AssemblyQualifiedName = stack[j].Member.DeclaringType.AssemblyQualifiedName; serialized.MemberStacks[i][j].Path = stack[j].Member.Name; serialized.MemberStacks[i][j].Index = stack[j].Index; } } return(FlaxEngine.Json.JsonSerializer.Serialize(serialized)); }