public EventEntry GetEntry (IBehaviourContext character) { if (this.SourceNode == null) return defaultEntry; EventEntry foundEntry; if (ContextCahce == null) ContextCahce = new Dictionary<IBehaviourContext, EventEntry> (); bool result = ContextCahce.TryGetValue (character, out foundEntry); EventOutput sourceOutput = (EventOutput)SourceSocket; EventEntry connectionEntry = sourceOutput.GetEntry (character); if (!result) { foundEntry = new EventEntry (); connectionEntry.OnEventFired += () => { if (foundEntry != null) foundEntry.OnEventFired (); }; ContextCahce.Add (character, foundEntry); } return foundEntry; }
protected override void OnSetup(IBehaviourContext context) { ConnectionEntry <RPGCharacter> targetInput = Target.GetEntry(context); ConnectionEntry <int> damageTakenOutput = DamageTaken.GetEntry(context); EventEntry onHitOutput = OnHit.GetEntry(context); bool isActive = false; Action eventHandler = () => { if (targetInput.Value.States.CurrentHealth.Delta >= 1.0f) { damageTakenOutput.Value = (int)targetInput.Value.States.CurrentHealth.Delta; onHitOutput.Invoke(); } }; Action subscriber = () => { if (targetInput.Value == null) { isActive = false; return; } if (!isActive) { targetInput.Value.States.CurrentHealth.OnValueChanged += eventHandler; } isActive = true; }; subscriber(); targetInput.OnBeforeChanged += () => { if (targetInput.Value == null) { return; } if (isActive) { targetInput.Value.States.CurrentHealth.OnValueChanged -= eventHandler; } }; targetInput.OnAfterChanged += subscriber; }
public void TryUse(ItemSurrogate context, RPGCharacter character) { ConnectionEntry <int> manaCostInput = ManaCost.GetEntry(context); ConnectionEntry <int> quantityCostInput = QuantityCost.GetEntry(context); EventEntry onActivateOutput = OnActivate.GetEntry(context); if (CanCharacterUse(context, character)) { context.owner.Value.States.CurrentMana.Value -= manaCostInput.Value; context.Quantity -= quantityCostInput.Value; onActivateOutput.OnEventFired(); AudioManager.Play(ActivateSound); } }
protected override void OnSetup(IBehaviourContext context) { object fieldInputObject = Field.GetConnectionObject(context); // Debug.Log (fieldInputObject); ConnectionEntry fieldInput = (ConnectionEntry)fieldInputObject; EventEntry onChangedOutput = onChanged.GetEntry(context); Action eventHandler = () => { onChangedOutput.Invoke(); }; fieldInput.OnAfterChanged += eventHandler; }
protected override void OnSetup(IBehaviourContext context) { ConnectionEntry <RPGCharacter> targetInput = Target.GetEntry(context); ConnectionEntry <RPGCharacter> hitTargetOutput = HitTarget.GetEntry(context); EventEntry onHitOutput = OnHit.GetEntry(context); bool isActive = false; Action <RPGCharacter> eventHandler = (RPGCharacter target) => { hitTargetOutput.Value = target; onHitOutput.Invoke(); }; Action subscriber = () => { if (targetInput.Value == null) { isActive = false; return; } if (!isActive) { targetInput.Value.OnHit += eventHandler; } isActive = true; }; subscriber(); targetInput.OnBeforeChanged += () => { if (targetInput.Value == null) { return; } if (isActive) { targetInput.Value.OnHit -= eventHandler; } }; targetInput.OnAfterChanged += subscriber; }