Skip to content

Commit

Permalink
Merge pull request #41 from VirtueSky/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VirtueSky authored Dec 11, 2024
2 parents 2cffcc0 + a77f8ec commit c3d1542
Show file tree
Hide file tree
Showing 64 changed files with 366 additions and 188 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
### 1: Download the repo and drop it into folder `Assets`
### 2: Add the line below to `Packages/manifest.json`

for version `3.2.0`
for version `3.2.1`
```csharp
"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.2.0",
"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.2.1",
```

## Includes modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void RenderAd()
{
#if VIRTUESKY_ADS && VIRTUESKY_ADS
if (_nativeOverlayAd == null) return;
_nativeOverlayAd.RenderTemplate(Style(), ConvertSize(), ConvertPosition());
_nativeOverlayAd.RenderTemplate(Style(), ConvertSize(), ConvertPosition(adsPosition));
#endif
}

Expand All @@ -141,11 +141,7 @@ public void RenderAd(RectTransform uiElement)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADS
if (_nativeOverlayAd == null) return;
var screenPosition = uiElement.ToWorldPosition();

float dpi = Screen.dpi / 160f;
var admobX = (int)(screenPosition.x / dpi);
var admobY = (int)((Screen.height - (int)screenPosition.y) / dpi);
(int admobX, int admobY) = ConvertUiElementPosToNativeAdsPos(uiElement);
_nativeOverlayAd.RenderTemplate(Style(), admobX, admobY);
#endif
}
Expand All @@ -160,11 +156,7 @@ public void RenderAd(RectTransform uiElement, int width, int height)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADS
if (_nativeOverlayAd == null) return;
var screenPosition = uiElement.ToWorldPosition();

float dpi = Screen.dpi / 160f;
var admobX = (int)(screenPosition.x / dpi);
var admobY = (int)((Screen.height - (int)screenPosition.y) / dpi);
(int admobX, int admobY) = ConvertUiElementPosToNativeAdsPos(uiElement);
_nativeOverlayAd.RenderTemplate(Style(), new AdSize(width, height), admobX, admobY);
#endif
}
Expand All @@ -174,17 +166,12 @@ public void RenderAd(RectTransform uiElement, int width, int height)
/// Can use position and size of uiElement for native overlay ads
/// </summary>
/// <param name="uiElement">RectTransform of uiElement, used to determine position for native overlay ads</param>
/// <param name="canvas">Canvas containing popups with cameras attached</param>
public void RenderAd(RectTransform uiElement, Canvas canvas, bool useSizeUiElement = true)
/// <param name="camera">Camera render uiElement</param>
public void RenderAd(RectTransform uiElement, Camera camera, bool useSizeUiElement = true)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
if (_nativeOverlayAd == null) return;
var worldPosition = uiElement.TransformPoint(uiElement.position);
Vector2 screenPosition = canvas.worldCamera.WorldToScreenPoint(worldPosition);

float dpi = Screen.dpi / 160f;
var admobX = (int)((screenPosition.x - (uiElement.rect.width / 2)) / dpi);
var admobY = (int)(((Screen.height - (int)screenPosition.y) - (uiElement.rect.height / 2)) / dpi);
(int admobX, int admobY) = ConvertUiElementPosToNativeAdsPos(uiElement, camera);
if (useSizeUiElement)
{
_nativeOverlayAd?.RenderTemplate(Style(), new AdSize((int)uiElement.rect.width, (int)uiElement.rect.height), admobX, admobY);
Expand All @@ -201,21 +188,76 @@ public void RenderAd(RectTransform uiElement, Canvas canvas, bool useSizeUiEleme
/// Can use position of uiElement and custom size for native overlay ads
/// </summary>
/// <param name="uiElement">RectTransform of uiElement, used to determine position for native overlay ads</param>
/// <param name="canvas">Canvas containing popups with cameras attached</param>
/// <param name="camera">Camera render uiElement</param>
/// <param name="width">Custom width for native overlay ads</param>
/// <param name="height">Custom height for native overlay ads</param>
public void RenderAd(RectTransform uiElement, Canvas canvas, int width, int height)
public void RenderAd(RectTransform uiElement, Camera camera, int width, int height)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
if (_nativeOverlayAd == null) return;
(int admobX, int admobY) = ConvertUiElementPosToNativeAdsPos(uiElement, camera, width, height);
_nativeOverlayAd?.RenderTemplate(Style(), new AdSize(width, height), admobX, admobY);
#endif
}

(int, int) ConvertUiElementPosToNativeAdsPos(RectTransform uiElement, Camera camera, int width, int height)
{
var worldPosition = uiElement.TransformPoint(uiElement.position);
Vector2 screenPosition = canvas.worldCamera.WorldToScreenPoint(worldPosition);
Vector2 screenPosition = camera.WorldToScreenPoint(worldPosition);

float dpi = Screen.dpi / 160f;
var admobX = (int)((screenPosition.x - width / 2) / dpi);
var admobY = (int)(((Screen.height - (int)screenPosition.y) - height / 2) / dpi);
return (admobX, admobY);
}

_nativeOverlayAd?.RenderTemplate(Style(), new AdSize(width, height), admobX, admobY);
(int, int) ConvertUiElementPosToNativeAdsPos(RectTransform uiElement, Camera camera)
{
var worldPosition = uiElement.TransformPoint(uiElement.position);
Vector2 screenPosition = camera.WorldToScreenPoint(worldPosition);

float dpi = Screen.dpi / 160f;
var admobX = (int)((screenPosition.x - (int)uiElement.rect.width / 2) / dpi);
var admobY = (int)(((Screen.height - (int)screenPosition.y) - (int)uiElement.rect.height / 2) / dpi);
return (admobX, admobY);
}

(int, int) ConvertUiElementPosToNativeAdsPos(RectTransform uiElement)
{
var screenPosition = uiElement.ToWorldPosition();
float dpi = Screen.dpi / 160f;
var admobX = (int)(screenPosition.x / dpi);
var admobY = (int)((Screen.height - (int)screenPosition.y) / dpi);
return (admobX, admobY);
}

public void SetPosition(AdsPosition adsPosition)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
_nativeOverlayAd.SetTemplatePosition(ConvertPosition(adsPosition));
#endif
}

public void SetPosition(int x, int y)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
_nativeOverlayAd.SetTemplatePosition(x, y);
#endif
}

public void SetPosition(RectTransform uiElement)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
(int x, int y) = ConvertUiElementPosToNativeAdsPos(uiElement);
_nativeOverlayAd.SetTemplatePosition(x, y);
#endif
}

public void SetPosition(RectTransform uiElement, Camera camera)
{
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
(int x, int y) = ConvertUiElementPosToNativeAdsPos(uiElement, camera);
_nativeOverlayAd.SetTemplatePosition(x, y);
#endif
}

Expand All @@ -237,9 +279,9 @@ public NativeTemplateStyle Style()
};
}

AdPosition ConvertPosition()
AdPosition ConvertPosition(AdsPosition _adsPosition)
{
return adsPosition switch
return _adsPosition switch
{
AdsPosition.Top => AdPosition.Top,
AdsPosition.Bottom => AdPosition.Bottom,
Expand Down
47 changes: 47 additions & 0 deletions VirtueSky/Component/FollowTargetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,53 @@ public class FollowTargetComponent : BaseMono
ShowIf(nameof(typeFollowTarget), TypeFollowTarget.SmoothDamp), SerializeField]
private float maxSpeed = Mathf.Infinity;

public Transform TargetTransform
{
get => targetTrans;
set => targetTrans = value;
}

public Vector3 OffsetTrans
{
get => offsetTrans;
set => offsetTrans = value;
}

public DirectionFollowTarget DirectionFollowTarget
{
get => directionFollowTarget;
set => directionFollowTarget = value;
}

public TypeFollowTarget TypeFollowTarget
{
get => typeFollowTarget;
set => typeFollowTarget = value;
}

public float InterpolateValue
{
get => interpolateValue;
set => interpolateValue = value;
}

public Vector3 CurrentVelocity
{
get => currentVelocity;
set => currentVelocity = value;
}

public float SmoothTime
{
get => smoothTime;
set => smoothTime = value;
}

public float MaxSpeed
{
get => maxSpeed;
set => maxSpeed = value;
}

private void Awake()
{
Expand Down
4 changes: 2 additions & 2 deletions VirtueSky/ControlPanel/ConstantPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class ConstantPackage
{
public const string VersionSunflower = "3.2.0";
public const string VersionSunflower = "3.2.1";
public const string PackageNameInAppPurchase = "com.unity.purchasing";
public const string MaxVersionInAppPurchase = "4.12.2";
public const string PackageNameNewtonsoftJson = "com.unity.nuget.newtonsoft-json";
Expand Down Expand Up @@ -77,7 +77,7 @@ public class ConstantPackage
#endregion

public const string PackageNameAdjust = "com.adjust.sdk";
public const string MaxVersionAdjust = "https://github.com/adjust/unity_sdk.git?path=Assets/Adjust#v5.0.5";
public const string MaxVersionAdjust = "https://github.com/adjust/unity_sdk.git?path=Assets/Adjust#v5.0.6";
public const string PackageNamePlayFab = "com.pancake.playfab";

public const string MaxVersionPlayFab =
Expand Down
7 changes: 5 additions & 2 deletions VirtueSky/Iap/Runtime/IapDataVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ public class IapDataVariable : ScriptableObject

[Space] public float price;
[SerializeField] private IapPurchaseSuccess onPurchaseSuccess;
[SerializeField] IapPurchaseFailed onPurchaseFailed;
[SerializeField] private IapPurchaseFailed onPurchaseFailed;

[ReadOnly] public Product product;
[ReadOnly] internal Product product;
[ReadOnly] internal SubscriptionInfo subscriptionInfo;
internal IapPurchaseSuccess OnPurchaseSuccess => onPurchaseSuccess;
internal IapPurchaseFailed OnPurchaseFailed => onPurchaseFailed;

[NonSerialized] public Action purchaseSuccessCallback;
[NonSerialized] public Action<string> purchaseFailedCallback;

public Product Product => product;
public SubscriptionInfo SubscriptionInfo => subscriptionInfo;

public void Purchase()
{
Expand Down
98 changes: 53 additions & 45 deletions VirtueSky/Iap/Runtime/IapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,25 @@ void InitImpl()
IsInitialized = true;
}

#region Internal Api

private bool IsPurchasedProduct(IapDataVariable product)
{
if (_controller == null) return false;
return product.productType == ProductType.NonConsumable &&
return product.productType is ProductType.NonConsumable or ProductType.Subscription &&
_controller.products.WithID(product.id).hasReceipt;
}

private string GetLocalizedPriceProduct(IapDataVariable product)
void PurchaseProduct(IapDataVariable product)
{
if (_controller == null) return "";
return _controller.products.WithID(product.id).metadata.localizedPriceString;
// call when IAPDataVariable raise event
if (changePreventDisplayAppOpenEvent != null) changePreventDisplayAppOpenEvent.Raise(true);
PurchaseProductInternal(product);
}

#endregion

#region Implement

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
{
Expand Down Expand Up @@ -143,7 +149,6 @@ public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
return PurchaseProcessingResult.Complete;
}


public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
_controller = controller;
Expand All @@ -159,11 +164,53 @@ public void OnInitialized(IStoreController controller, IExtensionProvider extens
InitProductIapDataVariable();
}

public void OnInitializeFailed(InitializationFailureReason error, string message)
{
OnInitializeFailed(error);
}

public void OnInitializeFailed(InitializationFailureReason error)
{
switch (error)
{
case InitializationFailureReason.AppNotKnown:
Debug.LogError("Is your App correctly uploaded on the relevant publisher console?");
break;
case InitializationFailureReason.PurchasingUnavailable:
Debug.LogWarning("In App Purchases disabled in device settings!");
break;
case InitializationFailureReason.NoProductsAvailable:
Debug.LogWarning("No products available for purchase!");
break;
default:
throw new ArgumentOutOfRangeException(nameof(error), error, null);
}
}

public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
InternalPurchaseFailed(product.definition.id, failureReason.ToString());
}

public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
{
InternalPurchaseFailed(product.definition.id, failureDescription.reason.ToString());
}

#endregion


private void InitProductIapDataVariable()
{
foreach (var iapDataVariable in iapSetting.Products)
{
iapDataVariable.product = _controller.products.WithID(iapDataVariable.id);
var product = _controller.products.WithID(iapDataVariable.id);
iapDataVariable.product = product;
if (iapDataVariable.productType == ProductType.Subscription)
{
var subManager = new SubscriptionManager(product, null);
iapDataVariable.subscriptionInfo = subManager.getSubscriptionInfo();
}
}
}

Expand All @@ -183,12 +230,6 @@ void PurchaseVerified(PurchaseEventArgs purchaseEvent)
InternalPurchaseSuccess(purchaseEvent.purchasedProduct.definition.id);
}

void PurchaseProduct(IapDataVariable product)
{
// call when IAPDataVariable raise event
if (changePreventDisplayAppOpenEvent != null) changePreventDisplayAppOpenEvent.Raise(true);
PurchaseProductInternal(product);
}

#region Purchase Success

Expand All @@ -207,39 +248,6 @@ void InternalPurchaseSuccess(string id)

#region Purchase Failed

public void OnInitializeFailed(InitializationFailureReason error)
{
switch (error)
{
case InitializationFailureReason.AppNotKnown:
Debug.LogError("Is your App correctly uploaded on the relevant publisher console?");
break;
case InitializationFailureReason.PurchasingUnavailable:
Debug.LogWarning("In App Purchases disabled in device settings!");
break;
case InitializationFailureReason.NoProductsAvailable:
Debug.LogWarning("No products available for purchase!");
break;
default:
throw new ArgumentOutOfRangeException(nameof(error), error, null);
}
}

public void OnInitializeFailed(InitializationFailureReason error, string message)
{
OnInitializeFailed(error);
}

public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
InternalPurchaseFailed(product.definition.id, failureReason.ToString());
}

public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
{
InternalPurchaseFailed(product.definition.id, failureDescription.reason.ToString());
}

private void InternalPurchaseFailed(string id, string reason)
{
if (changePreventDisplayAppOpenEvent != null) changePreventDisplayAppOpenEvent.Raise(false);
Expand Down
Loading

0 comments on commit c3d1542

Please sign in to comment.