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 | 29 | 30 | 31 |
Tags
- C#
- python
- 백준
- Unity
- W3Schools
- dynamic
- Material
- Programming
- 재귀
- Basic
- Tutorial
- Unreal Engine 5
- dfs
- Algorithm
- 프로그래밍
- 오류
- w3school
- 문제풀이
- loop
- github
- DP
- parameter
- 기초
- 시작해요 언리얼 2022
- c++
- guide
- Class
- UE5
- String
- 파이썬
Archives
- Today
- Total
행복한 개구리
OceanCleaner 21.08.07 개발일지 본문
스크립트 구조와 씬, 오브젝트 구조 전반적으로 파악중
일단 해당 팝업창의 앵커위치들이 제대로 잡혀있지 않았고 오브젝트 레벨구조가 Flat하기에 손을 좀 보았다.
상단, 중단, 하단(광고버튼)으로 나누었으며 각 부분은 이름에 맞게 앵커를 설정해주었다.
- TopBar(Top Section)
- Middle_Info (Middle Section)
- AdButtons (Bottom Section)
- 이런식으로 구조를 바꿨고 각 버튼에 붙어있던 AD매니저들을 Ad Buttons 즉, 부모오브젝트에서 버튼을 관리하도록 유도했다.
- 덕분에 어떠한 버튼을 누르면 바로 광고를 재생시킬 수 있었으며 분기를 하나의 스크립트 내에서 나눠줄 수 있었다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GoogleMobileAds.Api;
public class GoogleAdManager : MonoBehaviour
{
public bool isTestMode;
public Button RewardAdsBtn;
public Button FrontAdsBtn;
public GarbageInfo garbageInfo;
public System.Action onRewardCompelte;
public System.Action onFrontComplete;
public void Awake()
{
List<string> deviceIds = new List<string>();
deviceIds.Add("4DEC3DE9C913C80CAFA67E73B68FD3E5");
RequestConfiguration requestConfiguration = new RequestConfiguration
.Builder()
.SetTestDeviceIds(deviceIds)
.build();
MobileAds.SetRequestConfiguration(requestConfiguration);
MobileAds.SetApplicationVolume(0.5f);
}
void PlayAds()
{
this.RewardAdsBtn.onClick.AddListener(() =>
{
ShowRewardAd();
});
this.FrontAdsBtn.onClick.AddListener(() =>
{
ShowFrontAd();
});
}
private void Update()
{
FrontAdsBtn.interactable = frontAd.IsLoaded();
RewardAdsBtn.interactable = rewardedAd.IsLoaded();
}
private void Start()
{
// LoadBannerAd();
LoadFrontAd();
LoadRewardAds();
PlayAds();
}
const string bannerTestId = "ca-app-pub-3940256099942544/6300978111";
const string bannerId = "";
BannerView bannerAd;
void LoadBannerAd()
{
bannerAd = new BannerView(isTestMode ? bannerTestId : bannerId, AdSize.SmartBanner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
bannerAd.LoadAd(request);
ToggleBannerAd(false);
}
public void ToggleBannerAd(bool b)
{
if (b) bannerAd.Show();
else bannerAd.Hide();
}
const string frontTestId = "ca-app-pub-3940256099942544/1033173712";
const string frontId = "";
InterstitialAd frontAd;
void LoadFrontAd()
{
frontAd = new InterstitialAd(isTestMode ? frontTestId : frontId);
AdRequest request = new AdRequest.Builder().Build();
frontAd.LoadAd(request);
frontAd.OnAdClosed += (sender, e) =>
{
Debug.Log("전면광고 성공");
UserInfo.Instance.SetAds();
garbageInfo.NoSkipTrashProcess_Front();
onFrontComplete();
};
}
public void ShowFrontAd()
{
frontAd.Show();
LoadFrontAd();
}
const string RewardTestId = "ca-app-pub-3940256099942544/5224354917";
const string RewardID = "ca-app-pub-1927818007016210/3851928870";
RewardedAd rewardedAd;
void LoadRewardAds()
{
rewardedAd = new RewardedAd(isTestMode ? RewardTestId : RewardID);
AdRequest request = new AdRequest.Builder().Build();
rewardedAd.LoadAd(request);
rewardedAd.OnUserEarnedReward += (sender, e) =>
{
Debug.Log("리워드 광고 성공");
UserInfo.Instance.SetAds();
garbageInfo.NoSkipTrashProcess_Reward();
onRewardCompelte();
};
}
public void ShowRewardAd()
{
rewardedAd.Show();
LoadRewardAds();
}
}
- 기존에 존재하던 광고를 불러오는 코드들을 연동시켜서 보상광고/전면광고로 분기를 나누어 주었다.
- Front(Intistitial Ad/전면광고)버튼을 누르면 전면광고를 Load하고 Show해주는 경로를 지정해주고 Rewarded(Rewarded Ad/보상광고) 버튼을 누르면 보상광고를 Load하고 Show해주는 경로로 지정해주었다.
- 또한 해당 각 광고들의 onComplete대리자의 분기도 나누어주었다.
googleAd.onFrontComplete = () =>
{
fristMachinePopup.SetActive(false);
StartCoroutine(machine.ProcessMachine(() => {
secondMachinePopup.SetActive(true);
machine.isProcessing = false;
}));
};
googleAd.onRewardCompelte = () =>
{
fristMachinePopup.SetActive(false);
StartCoroutine(machine.ProcessMachine(() => {
secondMachinePopup.SetActive(true);
machine.isProcessing = false;
}));
};
다만 위 스크립트에서 눈에 밟히는 점은 둘 모두 같은 기능인데 굳이 분기를 나눴어야 했나... 라는 점이다.
시간이 날 때 분기를 합쳐 테스트 해보는 것이 좋겠다.
'Unity > Project : Ocean Cleaner' 카테고리의 다른 글
OceanCleaner 21.08.19. 개발일지 - 어셋찾기 (0) | 2021.08.20 |
---|---|
Ocean Cleaner 21.08.18. 개발일지 - 최적화 (0) | 2021.08.18 |
Ocean Cleaner 21.08.17. 개발일지 - 최적화 (0) | 2021.08.17 |
OceanCleaner 21.08.16. 개발일지 - 미리보기 이미지 키우기 (0) | 2021.08.17 |
OceanCleaner 21.08.08~21.08.09 개발일지 (0) | 2021.08.10 |