using UnityEngine;
using System.Collections.Generic;

namespace DaburuTools
{
	namespace Action
	{
		public class #SCRIPTNAME# : Action
		{
			// 1: Declare your other variables such as Transforms, Graphs, etc.

			// LEAVE THIS HERE: Variables to track time.
			float mfActionDuration;
			float mfElapsedDuration;

			// 2: Constructor.
			// DO NOT FORGET YOUR OTHER PARAMETERS!
			public #SCRIPTNAME#(float _actionDuration)
			{
				SetActionDuration(_actionDuration);
				SetupAction();
			}

			// 3: Whatever you want to do to intialise your variables.
			// Isolate these steps into a public function so that your users can easily reconfigure your Action after creation.

			// For standard Actions in DaburuTools, we used one function per parameter.
			// E.g. SetGraph(Graph _graph) to change the graph after construction.
			// Below, we are making a function to set the ActionDuration.
			public void SetActionDuration(float _newActionDuration)
			{
				mfActionDuration = _newActionDuration;
			}
			private void SetupAction()
			{
				// 4: Declare what you want to be dont just before the Action runs.
				// Commonly used to grab position or transform values at the start of the Action.
				// This is to prevent errors when an Action is not immediately run the same frame of initialisation.
				// Here, we always re-set the mfElapsedDuration to 0f;
				mfElapsedDuration = 0f;
			}
			protected override void OnActionBegin()
			{
				base.OnActionBegin();

				SetupAction(); 
			}



			public override void RunAction()
			{
				base.RunAction();

				mfElapsedDuration += ActionDeltaTime(mbIsUnscaledDeltaTime);
				// 5: Implementation of the Action's "update" function goes here.

				// Remove self after action is finished.
				if (mfElapsedDuration >= mfActionDuration)
				{
					// 6: Snapping your action to end desired value.

					OnActionEnd();
					mParent.Remove(this);
				}
			}
			public override void MakeResettable(bool _bIsResettable)
			{
				base.MakeResettable(_bIsResettable);
			}
			public override void Reset()
			{
				SetupAction();
			}
			public override void StopAction(bool _bSnapToDesired)
			{
				if (!mbIsRunning)
					return;

				// Prevent it from Resetting.
				MakeResettable(false);

				// Simulate the action has ended. Does not really matter by how much.
				mfElapsedDuration = mfActionDuration;

				if (_bSnapToDesired)
				{
					// 6: Implement how to snap to the desired end values should the parameter _bSnapToDesired be set true.

				}

				OnActionEnd();
				mParent.Remove(this);
			}
		}
	}
}
