/// <summary> /// Applies <paramref name="operation"/> to <paramref name="item"/> and returns /// an <see cref="UndoableCommand"/> that can undo and redo the operation. /// </summary> /// <returns> /// An <see cref="UndoableCommand"/> if application of <paramref name="operation"/> /// resulted in a change to the internal state of <paramref name="item"/>, otherwise null. /// </returns> /// <remarks> /// Inheritors can override this method to do any additional processing and/or to /// modify the resulting command, if necessary. /// </remarks> protected virtual UndoableCommand Apply(IUndoableOperation <T> operation, T item) { if (operation.AppliesTo(item)) { IMemorable originator = operation.GetOriginator(item); if (originator != null) { object beginState = originator.CreateMemento(); if (beginState != null) { operation.Apply(item); object endState = originator.CreateMemento(); if (!Equals(beginState, endState)) { MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(originator); memorableCommand.BeginState = beginState; memorableCommand.EndState = endState; return(memorableCommand); } } } } return(null); }
public MemorableItem(IMemorable target) { this.target = target; lastOccurTime = Time.time; timeToFoget = 5.0f; sensorClass = ESensorClass.Unknown; lastOccurPosition = target.pos; }
/// <summary> /// Method which manages restoring field. /// </summary> /// <param name="gameField">The field to be restored.</param> public void Undo(IMemorable gameField) { if (ObjectValidator.IsGameObjectNull(gameField)) { throw new ArgumentNullException(GameFieldNullErrorMessage); } gameField.RestoreField(this.Memory); }
/// <summary> /// Method which manages saving field. /// </summary> /// <param name="gameField">The field to be saved.</param> public void Save(IMemorable gameField) { if (ObjectValidator.IsGameObjectNull(gameField)) { throw new ArgumentNullException(GameFieldNullErrorMessage); } this.Memory = gameField.SaveField(); }
public IMemorableItem Find(IMemorable memable) { foreach (IMemorableItem item in objs) { if (item.target == memable) { return(item); } } return(null); }
private void CaptureBeginState() { if (!CanPan()) { return; } _applicator = new ImageOperationApplicator(this.SelectedPresentationImage, _operation); IMemorable originator = GetSelectedImageTransform(); _memorableCommand = new MemorableUndoableCommand(originator); _memorableCommand.BeginState = originator.CreateMemento(); }
public void Notify(ISensible sensible) { SoundSensible soundSensible = sensible as SoundSensible; IMemorable memObj = soundSensible.GetComponent <IMemorable>(); IMemory memory = GetComponent <Memory>(); if (memObj != null && memory != null) { memory.Notify(memObj, this); } Debug.Log(name + "hear " + soundSensible.name); }
public void Notify(IMemorable memorable, ISensor sensor) { IMemorableItem item = Find(memorable); if (item != null) { item.timeToFoget = 5.0f; if (fogets.Contains(item)) { fogets.Remove(item); } } else { objs.Add(new MemorableItem(memorable)); } }
public override Status Update() { //BaseAIParameters param = self.GetComponent<BaseAIParameters>(); //if (!param || !param.destinationEnable) //{ // return Status.Failure; //} //if (Vector3.Distance(self.transform.position, param.destination) < param.endSeekingDistance) //{ // return Status.Success; //} Memory memory = self.GetComponent <Memory>(); if (!memory) { return(Status.Failure); } ITarget[] targets = memory.AllTargets(); bool hasTarget = targets.Length > 0; if (hasTarget) { ITarget target = targets[0]; IMemorable memorable = target as IMemorable; IMemorableItem memItem = memory.Find(memorable); Vector3 destination = memItem.lastOccurPosition; UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.SetDestination(destination); agent.Resume(); return(Status.Running); } else { UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Stop(); return(Status.Failure); } }
public MemorableCommandInfo(MemorableUndoableCommand command) : base(command) { _originator = _rfOriginatorField.GetValue(command) as IMemorable; _beginState = command.BeginState; _endState = command.EndState; }
public static void AddWatchable(IMemorable watchable) { _wathcables.Add(watchable); }
/// <summary> /// Constructor. /// </summary> /// <param name="originator">The originator is the object responsible for creating /// memento objects and restoring state from them.</param> public MemorableUndoableCommand(IMemorable originator) { Platform.CheckForNullReference(originator, "originator"); _originator = originator; }