// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved.
// This code can only be used under the standard Unity Asset Store End User License Agreement
// A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms
using System;
using UnityEngine;
using static UnityEngine.Mathf;
// ReSharper disable UnusedMember.Global
// ReSharper disable MemberCanBePrivate.Global
namespace Doozy.Runtime.Reactor
{
public static class ReactorUtils
{
public static MoveDirection Reverse(this MoveDirection target)
{
switch (target)
{
case MoveDirection.Left: return MoveDirection.Right;
case MoveDirection.Top: return MoveDirection.Bottom;
case MoveDirection.Right: return MoveDirection.Left;
case MoveDirection.Bottom: return MoveDirection.Top;
case MoveDirection.TopLeft: return MoveDirection.BottomRight;
case MoveDirection.TopCenter: return MoveDirection.BottomCenter;
case MoveDirection.TopRight: return MoveDirection.BottomLeft;
case MoveDirection.MiddleLeft: return MoveDirection.MiddleRight;
case MoveDirection.MiddleCenter: return MoveDirection.MiddleCenter;
case MoveDirection.MiddleRight: return MoveDirection.MiddleLeft;
case MoveDirection.BottomLeft: return MoveDirection.TopRight;
case MoveDirection.BottomCenter: return MoveDirection.TopCenter;
case MoveDirection.BottomRight: return MoveDirection.TopLeft;
case MoveDirection.CustomPosition: return MoveDirection.CustomPosition;
default: throw new ArgumentOutOfRangeException(nameof(target), target, null);
}
}
/// Get the 'to' (end) position por a move out (hide) animation
/// Target RectTransform
/// Direction to where the animation goes to
/// From (start) position for the move out (hide) animation
public static Vector3 GetMoveOutPosition(RectTransform target, MoveDirection moveToDirection, Vector3 fromPosition) =>
GetTargetPosition(target, moveToDirection, fromPosition, target.localScale, target.localEulerAngles);
/// Get the 'to' (end) position por a move out (hide) animation
/// Target RectTransform
/// Direction to where the animation goes to
/// From (start) position for the move out (hide) animation
/// If there is a to local scale (whe UIAnimation modifies the target's scale) the 'to' scale value needs to be passed
/// If there is a 'to' local rotation (when UIAnimation modifies the target's rotation) the 'to' rotation value needs to be passed
public static Vector3 GetMoveOutPosition(RectTransform target, MoveDirection moveToDirection, Vector3 fromPosition, Vector3 toLocalScale, Vector3 toLocalEulerAngles) =>
GetTargetPosition(target, moveToDirection, fromPosition, toLocalScale, toLocalEulerAngles);
/// Get the 'from' (start) position for a move in (show) animation
/// Target RectTransform
/// Direction from where the animation comes from
/// To (end) position for a move in (show) animation
public static Vector3 GetMoveInPosition(RectTransform target, MoveDirection moveFromDirection, Vector3 toValue) =>
GetTargetPosition(target, moveFromDirection, toValue, target.localScale, target.localEulerAngles);
/// Get the 'from' (start) position for a move in (show) animation
/// Target RectTransform
/// Direction from where the animation comes from
/// To (end) position for a move in (show) animation
/// If there is a 'from' local scale (when UIAnimation modifies the target's scale) the 'from' scale value needs to be passed
/// If there is a 'from' local rotation (when UIAnimation modifies the target's rotation) the 'from' rotation value needs to be passed
public static Vector3 GetMoveInPosition(RectTransform target, MoveDirection moveFromDirection, Vector3 toValue, Vector3 fromLocalScale, Vector3 fromLocalEulerAngles) =>
GetTargetPosition(target, moveFromDirection, toValue, fromLocalScale, fromLocalEulerAngles);
public static Vector3 GetTargetPosition(RectTransform target, MoveDirection moveDirection, Vector3 startPosition, Vector3 targetLocalScale, Vector3 targetLocalEulerAngles)
{
if (target == null) return Vector3.zero; //null target
// Canvas canvas = target.GetComponent