// Extension method for calling GetInstance of ActionLogicBase from // any class derived from ScriptableObject. public static T GetInstance <T>(this ScriptableObject scriptableObject, ActionRecorder actionRecorder) where T : ActionLogicBase { T instance = ActionLogicBase.CreateInstance <T>(); instance._actionRecorder = actionRecorder; return(instance); }
/// <summary> /// Return description for next Redo Action. /// </summary> public string NxtRedoDsc() { string nxtRedoDsc = null; //Check if there is anything in the Redo Stack: if (_redoActionStack != null && _redoActionStack.Count() > 0) { ActionLogicBase action = _redoActionStack.Peek(); nxtRedoDsc = action.GetActionDesc(); } else { nxtRedoDsc = "redoStack is empty!"; } return(nxtRedoDsc); }
private void OnEventRaised() { //Debug.Log("Event raised"); // First clear the response object ActionRecorder.Response.Clear(); //Check if we are in Edit mode, if we aren't send back a failed response object if (!ActionRecorder.InEditMode(ref ActionRecorder.Response)) { return; } // Get new model instance _actionLogic = ActionLogicBase.GetInstance <T>(ActionRecorder); // Passing Data from View to Model ViewToModelParams(_actionLogic); // Perform the action ActionRecorder.PerformAction(_actionLogic); }
/// <summary> /// Undo Command to be linked to the /// Undo button in the editor window /// </summary> public ResponseObject Undo() { // Clear the Response Object Response.Clear(); //Check if we are in Edit mode, if we aren't send back a failed response object if (!InEditMode(ref Response)) { return(Response); } // Check stuck size if (_undoActionStack.Count() == 0) { Response.Result = ResponseEnums.Failed; Response.StringResponse = "UndoStack is empty!"; return(Response); } // Peek ActionClass from UndoActionStack (We aren't removing it from the stack yet!) ActionLogicBase action = _undoActionStack.Peek(); // Validate Undo Command feasibility action.ValidateBeforeUndo(ref Response); //Check if response object was set to null by mistake? NullResponselCheck(ref Response); //Unable to perform Undo action if (Response.Result == ResponseEnums.Failed) { // Set response.StringResponse if it's null or empty. if (string.IsNullOrEmpty(Response.StringResponse)) { Response.StringResponse = "Couldn't perform Undo Action!"; } } else { try { // Perform Undo Action action.UndoAction(); } catch (Exception e) { //Console.WriteLine(e); Response.Result = ResponseEnums.Failed; Response.StringResponse = "Couldn't perform Undo Action!"; return(Response); } // Pop this action off the undo stack _undoActionStack.Pop(); // Push The Action to the RedoActionStack _redoActionStack.Push(action); } return(Response); }