I'm not privy to how Chronos works, so can't say myself - though be aware that AC does control Unity's Time.timeScale value directly when you enter and exit pause mode, so you may have to account for that.
You can use events to run code whenever AC changes its internal "GameState" enum variable to and from GameState.Paused by hooking up to the OnEnterGameState event. A tutorial on working with events can be found here.
As Chronos by Ludiq is now free for everyone, so I was trying my first some custom action coding attempts this afternoon. The ability to control the time opens the way for some nice Matrix Movie Style Effects. Here is a custom action script for changing the Local Clock for a single Game Object:
using UnityEngine;
using System.Collections.Generic;
using Chronos;
if UNITY_EDITOR
using UnityEditor;
endif
namespace AC
{
[System.Serializable]
public class ActionLocalClock : Action
{
// Declare variables here
public GameObject objectToAffect;
public float newTimeScale;
public float LerpDuration;
//public string nameOfGlobalClock;
//Clock clock = Timekeeper.instance.Clock("Enemies");
public ActionLocalClock ()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Chronos Local Clock";
description = "Changes the Local Clock of the Game Object";
}
public override float Run ()
{
if (objectToAffect && objectToAffect.GetComponent<Clock>())
{
objectToAffect.GetComponent<Clock>().LerpTimeScale(newTimeScale, LerpDuration);
}
return 0f;
}
public override void Skip ()
{
Run ();
}
#if UNITY_EDITOR
public override void ShowGUI ()
{
// Action-specific Inspector GUI code here
objectToAffect = (GameObject)EditorGUILayout.ObjectField("GameObject to affect:", objectToAffect, typeof(GameObject), true);
newTimeScale = EditorGUILayout.FloatField("New Time Scale:", newTimeScale);
LerpDuration = EditorGUILayout.FloatField("Seconds to smooth into new Timescale:", LerpDuration);
AfterRunningOption ();
}
public override string SetLabel ()
{
// (Optional) Return a string used to describe the specific action's job.
if (objectToAffect)
{
return (" (" + objectToAffect.name + " - " + newTimeScale.ToString() + ")");
}
return "";
}
#endif
}
}
I have also tried to do a custom action for the global clock to control for example a group of enemies but somehow when I start the action list then the entered key of type string gets overwritten and then it falls back to change the global root clock instead. If anyone knows the problem in my script below, please let me know.
using UnityEngine;
using System.Collections.Generic;
using Chronos;
if UNITY_EDITOR
using UnityEditor;
endif
namespace AC
{
[System.Serializable]
public class ActionGlobalClock : Action
{
// Declare variables here
public Clock GameClockToEffect;
public float newTimeScale;
public float lerpDuration;
public string ClockName;
public void Start()
{
GameClockToEffect = Timekeeper.instance.Clock(ClockName);
}
public ActionGlobalClock ()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Chronos Global Clock";
description = "Changes the time scale of a specific Global Clock in the Time Keeper";
}
public override float Run ()
{
GameClockToEffect.LerpTimeScale(newTimeScale, lerpDuration);
return 0f;
}
public override void Skip ()
{
Run ();
}
#if UNITY_EDITOR
public override void ShowGUI ()
{
// Action-specific Inspector GUI code here
GameClockToEffect = (Clock)EditorGUILayout.ObjectField("Time keeper object:", GameClockToEffect, typeof(Clock), true);
ClockName = EditorGUILayout.TextField("Global Clock Key Name:", ClockName);
newTimeScale = EditorGUILayout.FloatField("New Time Scale:", newTimeScale);
lerpDuration = EditorGUILayout.FloatField("Seconds to smooth to new Timescale", lerpDuration);
AfterRunningOption ();
}
public override string SetLabel ()
{
// (Optional) Return a string used to describe the specific action's job.
if (GameClockToEffect)
{
return (" (" + GameClockToEffect.name + " - " + newTimeScale.ToString() + ")");
}
return "";
}
#endif
}
Actions do not derive from MonoBehaviour - so Start functions won't be called automatically. Try this:
using UnityEngine;
using Chronos;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionGlobalClock : Action
{
public Clock GameClockToEffect;
public float newTimeScale;
public float lerpDuration;
public string ClockName;
public ActionGlobalClock ()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Chronos Global Clock";
description = "Changes the time scale of a specific Global Clock in the Time Keeper";
}
public override float Run ()
{
GameClockToEffect = Timekeeper.instance.Clock(ClockName);
GameClockToEffect.LerpTimeScale(newTimeScale, lerpDuration);
return 0f;
}
#if UNITY_EDITOR
public override void ShowGUI ()
{
// Action-specific Inspector GUI code here
GameClockToEffect = (Clock)EditorGUILayout.ObjectField("Time keeper object:", GameClockToEffect, typeof(Clock), true);
ClockName = EditorGUILayout.TextField("Global Clock Key Name:", ClockName);
newTimeScale = EditorGUILayout.FloatField("New Time Scale:", newTimeScale);
lerpDuration = EditorGUILayout.FloatField("Seconds to smooth to new Timescale", lerpDuration);
AfterRunningOption ();
}
#endif
}
}
Comments
You can use events to run code whenever AC changes its internal "GameState" enum variable to and from GameState.Paused by hooking up to the OnEnterGameState event. A tutorial on working with events can be found here.
As Chronos by Ludiq is now free for everyone, so I was trying my first some custom action coding attempts this afternoon. The ability to control the time opens the way for some nice Matrix Movie Style Effects. Here is a custom action script for changing the Local Clock for a single Game Object:
using UnityEngine;
using System.Collections.Generic;
using Chronos;
if UNITY_EDITOR
using UnityEditor;
endif
namespace AC
{
}
I have also tried to do a custom action for the global clock to control for example a group of enemies but somehow when I start the action list then the entered key of type string gets overwritten and then it falls back to change the global root clock instead. If anyone knows the problem in my script below, please let me know.
using UnityEngine;
using System.Collections.Generic;
using Chronos;
if UNITY_EDITOR
using UnityEditor;
endif
namespace AC
{
}
Actions do not derive from MonoBehaviour - so Start functions won't be called automatically. Try this:
Thank you very much Chris! The script works perfectly!