using System;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class AMOrientationAction : AMAction
{
	public override string ToString(int codeLanguage, int frameRate)
	{
		if (this.endFrame == -1 || !this.startTarget)
		{
			return null;
		}
		string text;
		if (this.isLookFollow())
		{
			if (codeLanguage == 0)
			{
				text = string.Concat(new object[]
				{
					"AMTween.LookFollow (obj.gameObject, AMTween.Hash (\"delay\", ",
					base.getWaitTime(frameRate, 0f),
					"f, \"time\", ",
					this.getTime(frameRate),
					"f, "
				});
				text = text + "\"looktarget\", GameObject.Find(\"" + this.startTarget.gameObject.name + "\").transform";
				text += "));";
			}
			else
			{
				text = string.Concat(new object[]
				{
					"AMTween.LookFollow (obj.gameObject, {\"delay\": ",
					base.getWaitTime(frameRate, 0f),
					", \"time\": ",
					this.getTime(frameRate),
					", "
				});
				text = text + "\"looktarget\": GameObject.Find(\"" + this.startTarget.gameObject.name + "\").transform";
				text += "});";
			}
			return text;
		}
		if (!this.endTarget)
		{
			return null;
		}
		if (codeLanguage == 0)
		{
			text = string.Concat(new object[]
			{
				"AMTween.LookToFollow (obj.gameObject, AMTween.Hash (\"delay\", ",
				base.getWaitTime(frameRate, 0f),
				"f, \"time\", ",
				this.getTime(frameRate),
				"f, "
			});
			text = text + "\"looktarget\", GameObject.Find(\"" + this.endTarget.gameObject.name + "\").transform, ";
			if (this.isSetEndPosition)
			{
				string text2 = text;
				text = string.Concat(new object[]
				{
					text2,
					"\"endposition\", new Vector3(",
					this.endPosition.x,
					"f, ",
					this.endPosition.y,
					"f, ",
					this.endPosition.z,
					"f), "
				});
			}
			text += base.getEaseString(codeLanguage);
			text += "));";
		}
		else
		{
			text = string.Concat(new object[]
			{
				"AMTween.LookToFollow (obj.gameObject, {\"delay\": ",
				base.getWaitTime(frameRate, 0f),
				", \"time\": ",
				this.getTime(frameRate),
				", "
			});
			text = text + "\"looktarget\": GameObject.Find(\"" + this.endTarget.gameObject.name + "\").transform, ";
			if (this.isSetEndPosition)
			{
				string text2 = text;
				text = string.Concat(new object[]
				{
					text2,
					"\"endposition\", Vector3(",
					this.endPosition.x,
					", ",
					this.endPosition.y,
					", ",
					this.endPosition.z,
					"), "
				});
			}
			text += base.getEaseString(codeLanguage);
			text += "});";
		}
		return text;
	}

	public override void execute(int frameRate, float delay, string trackId)
	{
		if (!this.obj)
		{
			return;
		}
		if (this.endFrame == -1)
		{
			return;
		}
		if (this.isLookFollow())
		{
			AMTween.LookFollow(this.obj.gameObject, AMTween.Hash(new object[]
			{
				"trackid",
				trackId,
				"delay",
				base.getWaitTime(frameRate, delay),
				"time",
				this.getTime(frameRate),
				"looktarget",
				this.startTarget
			}));
		}
		else if (base.hasCustomEase())
		{
			AMTween.LookToFollow(this.obj.gameObject, AMTween.Hash(new object[]
			{
				"trackid",
				trackId,
				"delay",
				base.getWaitTime(frameRate, delay),
				"time",
				this.getTime(frameRate),
				"looktarget",
				this.endTarget,
				"endposition",
				(!this.isSetEndPosition) ? null : new Vector3?(this.endPosition),
				"easecurve",
				base.easeCurve
			}));
		}
		else
		{
			AMTween.LookToFollow(this.obj.gameObject, AMTween.Hash(new object[]
			{
				"trackid",
				trackId,
				"delay",
				base.getWaitTime(frameRate, delay),
				"time",
				this.getTime(frameRate),
				"looktarget",
				this.endTarget,
				"endposition",
				(!this.isSetEndPosition) ? null : new Vector3?(this.endPosition),
				"easetype",
				(AMTween.EaseType)this.easeType
			}));
		}
	}

	public override int getNumberOfFrames()
	{
		return this.endFrame - this.startFrame;
	}

	public float getTime(int frameRate)
	{
		return (float)this.getNumberOfFrames() / (float)frameRate;
	}

	public bool isLookFollow()
	{
		return !(this.startTarget != this.endTarget);
	}

	public Quaternion getQuaternionAtPercent(float percentage, Vector3? startVector = null, Vector3? endVector = null)
	{
		if (this.isLookFollow())
		{
			this.obj.LookAt(this.startTarget);
			return this.obj.rotation;
		}
		Vector3 position = this.obj.position;
		if (this.isSetStartPosition)
		{
			this.obj.position = this.startPosition;
		}
		this.obj.LookAt((startVector == null) ? this.startTarget.position : startVector.Value);
		Vector3 eulerAngles = this.obj.eulerAngles;
		if (this.isSetEndPosition)
		{
			this.obj.position = this.endPosition;
		}
		this.obj.LookAt((endVector == null) ? this.endTarget.position : endVector.Value);
		Vector3 eulerAngles2 = this.obj.eulerAngles;
		this.obj.position = position;
		eulerAngles2 = new Vector3(AMTween.clerp(eulerAngles.x, eulerAngles2.x, 1f), AMTween.clerp(eulerAngles.y, eulerAngles2.y, 1f), AMTween.clerp(eulerAngles.z, eulerAngles2.z, 1f));
		Vector3 euler = default(Vector3);
		AnimationCurve curve = null;
		AMTween.EasingFunction easingFunction;
		if (base.hasCustomEase())
		{
			curve = base.easeCurve;
			if (AMOrientationAction.<>f__mg$cache0 == null)
			{
				AMOrientationAction.<>f__mg$cache0 = new AMTween.EasingFunction(AMTween.customEase);
			}
			easingFunction = AMOrientationAction.<>f__mg$cache0;
		}
		else
		{
			easingFunction = AMTween.GetEasingFunction((AMTween.EaseType)this.easeType);
		}
		euler.x = easingFunction(eulerAngles.x, eulerAngles2.x, percentage, curve);
		euler.y = easingFunction(eulerAngles.y, eulerAngles2.y, percentage, curve);
		euler.z = easingFunction(eulerAngles.z, eulerAngles2.z, percentage, curve);
		return Quaternion.Euler(euler);
	}

	public override AnimatorTimeline.JSONAction getJSONAction(int frameRate)
	{
		if (!this.obj || this.endFrame == -1)
		{
			return null;
		}
		AnimatorTimeline.JSONAction jsonaction = new AnimatorTimeline.JSONAction();
		jsonaction.go = this.obj.gameObject.name;
		jsonaction.delay = base.getWaitTime(frameRate, 0f);
		jsonaction.time = this.getTime(frameRate);
		if (this.isLookFollow())
		{
			jsonaction.method = "lookfollow";
			jsonaction.strings = new string[]
			{
				this.startTarget.gameObject.name
			};
		}
		else
		{
			jsonaction.method = "looktofollow";
			jsonaction.strings = new string[]
			{
				this.endTarget.gameObject.name
			};
			if (this.isSetEndPosition)
			{
				jsonaction.setPath(new Vector3[]
				{
					this.endPosition
				});
			}
		}
		base.setupJSONActionEase(jsonaction);
		return jsonaction;
	}

	public int endFrame;

	public Transform obj;

	public Transform startTarget;

	public Transform endTarget;

	public bool isSetStartPosition;

	public bool isSetEndPosition;

	public Vector3 startPosition;

	public Vector3 endPosition;

	[CompilerGenerated]
	private static AMTween.EasingFunction <>f__mg$cache0;
}
