238 lines
7.1 KiB
C#
238 lines
7.1 KiB
C#
using UnityEngine;
|
|
|
|
public class BatchedRewardFlyRequest
|
|
{
|
|
public BatchedRewardFlyRequestIcon Icon;
|
|
public int? Quantity;
|
|
public BatchedRewardFlyStartPoint StartPoint;
|
|
public BatchedRewardFlyEndPoint EndPoint;
|
|
// public RectTransform sourceTextRt = null;
|
|
public bool IsDestinationRewardStash;
|
|
public int AnimationParamIndex;
|
|
// TODO: redundant params
|
|
// public bool isShowCount = true;
|
|
// public bool isShowFirst = true;
|
|
public BatchedRewardFlyRequest() { }
|
|
}
|
|
|
|
public class BatchedRewardFlyRequestIcon
|
|
{
|
|
// Pick one of these three, things just work.
|
|
public int itemID; public string iconName; public Sprite icon;
|
|
}
|
|
|
|
public class BatchedRewardFlyStartPoint
|
|
{
|
|
/// <summary>
|
|
/// Global position
|
|
/// </summary>
|
|
public readonly Vector3 Pos;
|
|
/// <summary>
|
|
/// Local scale
|
|
/// </summary>
|
|
public readonly Vector3 Scale;
|
|
/// <summary>
|
|
/// RectInfo for icon, a must have
|
|
/// </summary>
|
|
public readonly BatchedRewardFlyRectInfo RectInfoIcon;
|
|
/// <summary>
|
|
/// RectInfo for text, optional, can be null
|
|
/// </summary>
|
|
public readonly BatchedRewardFlyRectInfo RectInfoText;
|
|
|
|
public BatchedRewardFlyStartPoint(Vector3 pos)
|
|
{
|
|
Pos = pos;
|
|
Scale = Vector3.one;
|
|
RectInfoIcon = null;
|
|
RectInfoText = null;
|
|
}
|
|
|
|
public BatchedRewardFlyStartPoint(Vector3 pos, float size)
|
|
{
|
|
Pos = pos;
|
|
Scale = Vector3.one;
|
|
RectInfoIcon = BatchedRewardFlyRectInfo.CreateIconRectInfoBySize(size);
|
|
RectInfoText = null;
|
|
}
|
|
|
|
public BatchedRewardFlyStartPoint(Vector3 pos, Vector3 scale, BatchedRewardFlyRectInfo rectInfoIcon, BatchedRewardFlyRectInfo rectInfoText)
|
|
{
|
|
Pos = pos;
|
|
Scale = scale;
|
|
RectInfoIcon = rectInfoIcon;
|
|
RectInfoText = rectInfoText;
|
|
}
|
|
|
|
public BatchedRewardFlyStartPoint(RewardItemNew sourceReward)
|
|
{
|
|
Pos = sourceReward.transform.position;
|
|
Scale = sourceReward.transform.localScale;
|
|
var iconRect = sourceReward.icon.rectTransform;
|
|
RectInfoIcon = new BatchedRewardFlyRectInfo(iconRect);
|
|
var textRect = sourceReward.text_num.rectTransform;
|
|
if (sourceReward.text_num.isActiveAndEnabled)
|
|
RectInfoText = new BatchedRewardFlyRectInfo(textRect);
|
|
else
|
|
RectInfoText = null;
|
|
}
|
|
public BatchedRewardFlyStartPoint(Vector3 positon,Vector3 localScale, Vector2 size,RectTransform textRect = null)
|
|
{
|
|
Pos = positon;
|
|
Scale = localScale;
|
|
RectInfoIcon = BatchedRewardFlyRectInfo.CreateCenterIconRectInfoBySize(size);
|
|
RectInfoText = BatchedRewardFlyRectInfo.CreateNew(textRect);
|
|
}
|
|
public BatchedRewardFlyStartPoint(RectTransform iconRect, RectTransform textRect = null)
|
|
{
|
|
Pos = iconRect.position;
|
|
Scale = iconRect.localScale;
|
|
RectInfoIcon = BatchedRewardFlyRectInfo.CreateCenterIconRectInfoBySize(iconRect.rect.size);
|
|
RectInfoText = BatchedRewardFlyRectInfo.CreateNew(textRect);
|
|
}
|
|
|
|
public void SetBatchedRewardFlyPositions(BatchedRewardFly brf, float showScale = 1.0f)
|
|
{
|
|
brf.transform.position = Pos;
|
|
brf.IconRoot.transform.localScale = Scale * showScale;
|
|
|
|
if (RectInfoIcon == null)
|
|
BatchedRewardFlyRectInfo.DefaultIcon.SetRectTransform(brf.icon.rectTransform);
|
|
else
|
|
RectInfoIcon.SetRectTransform(brf.icon.rectTransform);
|
|
|
|
if (RectInfoText == null)
|
|
BatchedRewardFlyRectInfo.DefaultText.SetRectTransform(brf.text_num.rectTransform);
|
|
else
|
|
RectInfoText.SetRectTransform(brf.text_num.rectTransform);
|
|
}
|
|
}
|
|
|
|
public class BatchedRewardFlyEndPoint
|
|
{
|
|
/// <summary>
|
|
/// Global position of a transform
|
|
/// </summary>
|
|
public readonly Vector3 Pos;
|
|
/// <summary>
|
|
/// Literal size of a transform
|
|
/// </summary>
|
|
public readonly float Size;
|
|
/// <summary>
|
|
/// Lossy scale of a transform
|
|
/// </summary>
|
|
public readonly float LossyScale;
|
|
|
|
public BatchedRewardFlyEndPoint(Vector3 pos, float size, float lossyScale)
|
|
{
|
|
Pos = pos;
|
|
Size = size;
|
|
LossyScale = lossyScale;
|
|
}
|
|
|
|
public BatchedRewardFlyEndPoint(Vector3 pos)
|
|
{
|
|
Pos = pos;
|
|
Size = 0f;
|
|
LossyScale = 1f;
|
|
}
|
|
|
|
public BatchedRewardFlyEndPoint(RectTransform t)
|
|
{
|
|
Pos = t.position;
|
|
Size = t.sizeDelta.x;
|
|
LossyScale = t.lossyScale.x;
|
|
}
|
|
}
|
|
|
|
public class BatchedRewardFlyRectInfo
|
|
{
|
|
public Vector2 AnchoredMin;
|
|
public Vector2 AnchoredMax;
|
|
public Vector2 AnchoredPosition;
|
|
public Vector2 SizeDelta;
|
|
public Vector2 Pivot;
|
|
public Vector3 LocalScale = Vector3.one;
|
|
|
|
public BatchedRewardFlyRectInfo() { }
|
|
|
|
public BatchedRewardFlyRectInfo(RectTransform rect)
|
|
{
|
|
if (rect == null)
|
|
return;
|
|
AnchoredMin = rect.anchorMin;
|
|
AnchoredMax = rect.anchorMax;
|
|
AnchoredPosition = rect.anchoredPosition;
|
|
SizeDelta = rect.sizeDelta;
|
|
Pivot = rect.pivot;
|
|
LocalScale = rect.localScale;
|
|
}
|
|
|
|
public BatchedRewardFlyRectInfo DeepCopy()
|
|
{
|
|
return new BatchedRewardFlyRectInfo
|
|
{
|
|
AnchoredMin = AnchoredMin,
|
|
AnchoredMax = AnchoredMax,
|
|
AnchoredPosition = AnchoredPosition,
|
|
SizeDelta = SizeDelta,
|
|
Pivot = Pivot,
|
|
LocalScale = LocalScale
|
|
};
|
|
}
|
|
|
|
public void SetRectTransform(RectTransform rect)
|
|
{
|
|
if (rect == null)
|
|
return;
|
|
rect.anchorMin = AnchoredMin;
|
|
rect.anchorMax = AnchoredMax;
|
|
rect.anchoredPosition = AnchoredPosition;
|
|
rect.sizeDelta = SizeDelta;
|
|
rect.pivot = Pivot;
|
|
rect.localScale = LocalScale;
|
|
// Debug.Log($"[RewardFLy] SetRectTransform: {AnchoredMin}, {AnchoredMax}, {AnchoredPosition}, {SizeDelta}, {Pivot}", rect.gameObject);
|
|
}
|
|
|
|
public static BatchedRewardFlyRectInfo CreateNew(RectTransform rect)
|
|
{
|
|
if (rect == null)
|
|
return null;
|
|
return new BatchedRewardFlyRectInfo(rect);
|
|
}
|
|
|
|
public static BatchedRewardFlyRectInfo CreateCenterIconRectInfoBySize(Vector2 size)
|
|
{
|
|
var res = DefaultIcon.DeepCopy();
|
|
res.SizeDelta = size;
|
|
res.AnchoredPosition = Vector2.zero;
|
|
return res;
|
|
}
|
|
|
|
public static BatchedRewardFlyRectInfo CreateIconRectInfoBySize(float size)
|
|
{
|
|
var res = DefaultIcon.DeepCopy();
|
|
res.SizeDelta = Vector2.one * size;
|
|
return res;
|
|
}
|
|
|
|
public static BatchedRewardFlyRectInfo DefaultIcon => new BatchedRewardFlyRectInfo
|
|
{
|
|
AnchoredMin = new Vector2(0.5f, 0.5f),
|
|
AnchoredMax = new Vector2(0.5f, 0.5f),
|
|
AnchoredPosition = new Vector2(0, 8),
|
|
SizeDelta = new Vector2(200, 200),
|
|
Pivot = new Vector2(0.5f, 0.5f),
|
|
LocalScale = Vector3.one
|
|
};
|
|
|
|
public static BatchedRewardFlyRectInfo DefaultText => new BatchedRewardFlyRectInfo
|
|
{
|
|
AnchoredMin = new Vector2(0.5f, 0.5f),
|
|
AnchoredMax = new Vector2(0.5f, 0.5f),
|
|
AnchoredPosition = new Vector2(0, -94),
|
|
SizeDelta = new Vector2(166, 56),
|
|
Pivot = new Vector2(0.5f, 0.5f),
|
|
LocalScale = Vector3.one
|
|
};
|
|
} |