Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- server
- nodejs
- screencapture
- Camera Movement
- Unity Editor
- springboot
- Camera Zoom
- Packet Network
- Spring Boot
- Git
- docker
- unity
- react
- Digital Ocean
- Unity IAP
- spread 연산자
- MySQL
- express
- linux
- css framework
- --watch
- Google Developer API
- critical rendering path
- mongoDB
- SDK upgrade
- Google Refund
- draganddrop
- rpg server
- java
- OverTheWire
Archives
- Today
- Total
우당탕탕 개발일지
[Unity] Unity IAP 설정 본문
1. unity project 에서 Service > IAP를 활성화해준다.
2. 구글콘솔에 들어가서 해당프로젝트 > 수익창출 > 수익창출설정 칸에 라이선스 란이 있다. 이거를 Unity Project IAP 세팅하는곳 에 넣어주고 verify 눌러준다.
3. Unity IAP Google License Key 입력시 You are not authorized to set the license key 라는 에러 발생 시 , IAP dashBoard 에 들어가서 Project-> Project settings -> General -> In-app purchase (IAP) settings -> Google License Key에 동일한 키를 입력해준다 > 더이상 이 기능은 사용되지 않는다고 한다.Verify가 안됨.
Unity Gaming Services 로 대체되었다고하는데..
결론적으로 말하면 UnityIAP 를 초기화할때 UnityGaming Service 도 같이 초기화해주라는 것이었땅.
using System;
using System.Collections.Generic;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;
using UnityEngine.Purchasing;
using UnityEngine.Purchasing.Extension;
public class PurchaseManager : MonoBehaviour, IDetailedStoreListener
{
private IStoreController storeController;
private IExtensionProvider storeExtensionProvider;
ShopCSVContainer csvcontainer;
#region Init
public string environment = "production";
//Unity Gaming Service를 초기화 해주고 IAP를 초기화한다.
//주의할 점은, 유저데이터를 모두 로드한 다음에 초기화를 해야한다.
//구매실패가 이루어졌을 경우 init을 하면서 재구매처리를 하기때문에,
//PurchaseManager를 초기화할때는 유저 데이터가 모두 로드되어있어야한다.(재구매 및 지급가능)
async void Start()
{
try
{
var options = new InitializationOptions()
.SetEnvironmentName(environment);
await UnityServices.InitializeAsync(options);
InitIAP();
}
catch (Exception exception)
{
Debug.LogWarning("IAP init fail . " + exception.Message);
}
}
void InitIAP()
{
try
{
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct("IAPKey", ProductType.Consumable, new IDs { {"IAPName" csv.GetIAPName()"", GooglePlay.Name } });
UnityPurchasing.Initialize(this, builder);
// Debug.Log("IAP Init Complete");
}
catch (Exception exception)
{
Debug.LogWarning("Initilialize Unity Service Exception Occurred." + exception.Message);
}
}
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
storeController = controller;
storeExtensionProvider = extensions;
}
public void OnInitializeFailed(InitializationFailureReason error)
{
Debug.LogWarning("IAP Init failed." + error.ToString());
}
#endregion
void PurchaseIAP(string iapKey)
{
var product = storeController.products.WithID(iapKey);
if (product == null || !product.availableToPurchase)
{
purchaseCallback?.Invoke(StatusCode.NotExist);
return;
}
storeController.InitiatePurchase(product);
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
{
string iapName = purchaseEvent.purchasedProduct.definition.id;
bool isComplete = CheckReceiptValidation(purchaseEvent);
if (isComplete) return PurchaseProcessingResult.Complete;
else return PurchaseProcessingResult.Pending;
}
bool CheckReceiptValidation(PurchaseEventArgs purchaseEvent)
{
// 유니티 영수증검증이나 사용하는 서버에서 영수증검증을 진행하고,
//만약 실패라면 Pending를 return해야한다. 그래야 나중에 재접할때 재구매처리가능하다.
//todo;
return true;
}
public string GetIAPPrice(string iapName)
{
//todo;
//보상제공은 iap이름을 통해 제공해야한다.
// 구매처리 실패하여 재접속 시 재구매를 하게될경우 가지고있는것은 iapName뿐이기때문이다.
}
public void OnInitializeFailed(InitializationFailureReason error, string message)
{
Debug.LogWarning("IAP init failed.");
}
public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
{
Debug.LogWarning("IAP Purchased Failed.");
}
}
참고문서
https://docs.unity.com/remote-config/en/manual/RemoteSettingsMigration
'Unity' 카테고리의 다른 글
[Unity] 메일 문의하기 (1) | 2023.08.08 |
---|---|
[Unity] Android 앱 이름 Localization (0) | 2023.08.06 |
[Unity] Custom Editor - MenuItem을 만들어보자 (0) | 2023.07.27 |
[Unity ] GPGS & Firebase 총정리 (0) | 2023.07.11 |
[Unity] 빌드시 체크사항 (0) | 2023.07.04 |