Skip to content

Instantly share code, notes, and snippets.

@beardordie
Created November 7, 2019 03:37
Show Gist options
  • Save beardordie/0b4d7200332c6513320d152e2cc38a85 to your computer and use it in GitHub Desktop.
Save beardordie/0b4d7200332c6513320d152e2cc38a85 to your computer and use it in GitHub Desktop.
Corgi Engine Events - Debug Tool: Use the Console to easily determine which events Corgi Engine is firing, filtered by type. Tested with Corgi Engine version 6.1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.CorgiEngine;
using MoreMountains.Tools;
using System.Text;
using MoreMountains.InventoryEngine;
public class DebugLogCorgiEvents : MonoBehaviour,
MMEventListener<MMGameEvent>,
MMEventListener<CorgiEngineEvent>,
MMEventListener<MMAchievementUnlockedEvent>,
MMEventListener<CorgiEnginePointsEvent>,
MMEventListener<CorgiEngineStarEvent>,
MMEventListener<MMBeatEvent>,
MMEventListener<MMCameraEvent>,
MMEventListener<MMCharacterEvent>,
MMEventListener<MMDamageTakenEvent>,
MMEventListener<MMStateChangeEvent<Weapon.WeaponStates>>,
MMEventListener<MMStateChangeEvent<CharacterStates.CharacterConditions>>,
MMEventListener<MMStateChangeEvent<CharacterStates.MovementStates>>,
MMEventListener<ControlsModeEvent>,
MMEventListener<LedgeEvent>,
MMEventListener<MMFadeEvent>,
MMEventListener<MMInventoryEvent>,
MMEventListener<PickableItemEvent>
{
public bool enableLogging = true;
[Space]
[Header("Log Event Types")]
public bool game = true;
public bool corgiEngine = true;
public bool achievement = true;
public bool points = true;
public bool star = true;
public bool beat = true;
public new bool camera = true;
public bool character = true;
public bool damageTaken = true;
public bool weaponState = true;
public bool characterCondition = true;
public bool movementState = true;
public bool controlsMode = true;
public bool ledge = true;
public bool fade = true;
public bool inventory = true;
public bool pickableItem = true;
private void OnEnable()
{
this.MMEventStartListening<MMGameEvent>();
this.MMEventStartListening<CorgiEngineEvent>();
this.MMEventStartListening<MMAchievementUnlockedEvent>();
this.MMEventStartListening<CorgiEnginePointsEvent>();
this.MMEventStartListening<CorgiEngineStarEvent>();
this.MMEventStartListening<MMBeatEvent>();
this.MMEventStartListening<MMCameraEvent>();
this.MMEventStartListening<MMCharacterEvent>();
this.MMEventStartListening<MMDamageTakenEvent>();
this.MMEventStartListening<MMStateChangeEvent<Weapon.WeaponStates>>();
this.MMEventStartListening<MMStateChangeEvent<CharacterStates.CharacterConditions>>();
this.MMEventStartListening<MMStateChangeEvent<CharacterStates.MovementStates>>();
this.MMEventStartListening<ControlsModeEvent>();
this.MMEventStartListening<LedgeEvent>();
this.MMEventStartListening<MMFadeEvent>();
this.MMEventStartListening<MMInventoryEvent>();
this.MMEventStartListening<PickableItemEvent>();
}
private void OnDisable()
{
this.MMEventStopListening<MMGameEvent>();
this.MMEventStopListening<CorgiEngineEvent>();
this.MMEventStopListening<MMAchievementUnlockedEvent>();
this.MMEventStopListening<CorgiEnginePointsEvent>();
this.MMEventStopListening<CorgiEngineStarEvent>();
this.MMEventStopListening<MMBeatEvent>();
this.MMEventStopListening<MMCameraEvent>();
this.MMEventStopListening<MMCharacterEvent>();
this.MMEventStopListening<MMDamageTakenEvent>();
this.MMEventStopListening<MMStateChangeEvent<Weapon.WeaponStates>>();
this.MMEventStopListening<MMStateChangeEvent<CharacterStates.CharacterConditions>>();
this.MMEventStopListening<MMStateChangeEvent<CharacterStates.MovementStates>>();
this.MMEventStopListening<ControlsModeEvent>();
this.MMEventStopListening<LedgeEvent>();
this.MMEventStopListening<MMFadeEvent>();
this.MMEventStopListening<MMInventoryEvent>();
this.MMEventStopListening<PickableItemEvent>();
}
public void HandleEvent(string logText)
{
Debug.Log(logText);
}
public void OnMMEvent(MMGameEvent eventType)
{
if (!enableLogging) return;
if (!game) return;
HandleEvent("MMEvent: " + eventType.EventName);
}
public void OnMMEvent(CorgiEngineEvent eventType)
{
if (!enableLogging) return;
if (!corgiEngine) return;
HandleEvent("CorgiEngineEvent: " + eventType.EventType.ToString());
}
public void OnMMEvent(MMAchievementUnlockedEvent eventType)
{
if (!enableLogging) return;
if (!achievement) return;
HandleEvent("AchievementUnlockedEvent: " + eventType.Achievement.Title);
}
public void OnMMEvent(CorgiEnginePointsEvent eventType)
{
if (!enableLogging) return;
if (!points) return;
HandleEvent("Points Event: " + eventType.Points.ToString() + " / Method: " + eventType.PointsMethod.ToString());
}
public void OnMMEvent(CorgiEngineStarEvent eventType)
{
if (!enableLogging) return;
if (!star) return;
HandleEvent("Star Event: " + eventType.ToString());
}
public void OnMMEvent(MMBeatEvent eventType)
{
if (!enableLogging) return;
if (!beat) return;
HandleEvent("Beat Event: " + eventType.ToString());
}
public void OnMMEvent(MMCameraEvent eventType)
{
if (!enableLogging) return;
if (!camera) return;
HandleEvent("Camera Event: " + eventType.EventType.ToString());
}
public void OnMMEvent(MMCharacterEvent eventType)
{
if (!enableLogging) return;
if (!character) return;
HandleEvent("Character Event: " + eventType.EventType.ToString());
}
public void OnMMEvent(MMDamageTakenEvent eventType)
{
if (!enableLogging) return;
if (!damageTaken) return;
var debugString = new StringBuilder();
debugString.Append("Damage Taken Event: ");
if (eventType.Instigator != null)
{
debugString.Append(" / Instigator: ");
debugString.Append(eventType.Instigator.name);
}
if (eventType.AffectedCharacter != null)
{
debugString.Append(" / AffectedCharacter: ");
debugString.Append(eventType.AffectedCharacter.name);
}
debugString.Append(" / DamageCaused: ");
debugString.Append(eventType.DamageCaused);
HandleEvent(debugString.ToString());
}
public void OnMMEvent(MMStateChangeEvent<Weapon.WeaponStates> eventType)
{
if (!enableLogging) return;
if (!weaponState) return;
HandleEvent("Weapon State Change: FROM: " + eventType.PreviousState.ToString() + " TO: " + eventType.NewState.ToString());
}
public void OnMMEvent(MMStateChangeEvent<CharacterStates.CharacterConditions> eventType)
{
if (!enableLogging) return;
if (!characterCondition) return;
HandleEvent("CharacterConditions State Change: FROM: " + eventType.PreviousState.ToString() + " TO: " + eventType.NewState.ToString());
}
public void OnMMEvent(MMStateChangeEvent<CharacterStates.MovementStates> eventType)
{
if (!enableLogging) return;
if (!movementState) return;
HandleEvent("MovementStates State Change: FROM: " + eventType.PreviousState.ToString() + " TO: " + eventType.NewState.ToString());
}
public void OnMMEvent(PickableItemEvent eventType)
{
if (!enableLogging) return;
if (!pickableItem) return;
HandleEvent("Pickable Event: " + eventType.PickedItem.ToString());
}
public void OnMMEvent(ControlsModeEvent eventType)
{
if (!enableLogging) return;
if (!controlsMode) return;
HandleEvent("Controls Mode Event: " + eventType.MovementControl.ToString());
}
public void OnMMEvent(LedgeEvent eventType)
{
if (!enableLogging) return;
if (!ledge) return;
HandleEvent("Ledge Event: " + eventType.ToString());
}
public void OnMMEvent(MMFadeEvent eventType)
{
if (!enableLogging) return;
if (!fade) return;
HandleEvent("Fade Event: " + eventType.ToString());
}
public void OnMMEvent(MMInventoryEvent eventType)
{
if (!enableLogging) return;
if (!inventory) return;
HandleEvent("Inventory Event: " + eventType.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment