顯示具有 C# 標籤的文章。 顯示所有文章
顯示具有 C# 標籤的文章。 顯示所有文章

2025年7月17日 星期四

Unity串廣告 - Unity實作篇

 一段時間沒在Unity串廣告, Unity又升級做法了

寫這篇時是2025年7月,這時新版的做法是用LevelPlay與Ads Mediation

新版可以選擇的廣告商變得更多了, 但是設定也更複雜了


在開始之前提一下,以前的Unity Ads還是可以使用,不過官方不再更新支援,想用可以參考:https://www.goostudio.tw/post/介接unity-ads


接下來就是在Unity專案裡實做廣告串接:

連接Unity Cloud

Unity專案需要連接Unity Cloud才能運行Ads Mediation,連接設定可以參考:https://goocoding.blogspot.com/2025/07/unity-cloud.html

安裝Ads Mediation

在PackageManager中的Unity Registry可以找到Ads Mediation安裝

本篇的版本用的是8.10.0

實作初始化LevelPlay

創建一個腳本運行LevelPlay的初始化,程式碼範例如下圖:

要注意的是,UnityServices初始化完成後才能進行LevelPlay的初始化

還有LevelPlay.Init需要的appKey可以從LevelPlay的後台->Apps( https://platform.ironsrc.com/partners/home )找到

如果後台沒有的話,可以參考此篇設定:https://goocoding.blogspot.com/2025/07/unity-levelplay.html

實作廣告呼叫

接著實作廣告的讀取與呼叫

本範例的腳本是綁在(UGUI的)Button物件上,點擊時呼叫ShowAd()

如果你沒有Button物件的話,我建議你有

程式碼範例如下圖:

其中new LevelPlayRewardedAd時要用到的adUnitId可以從LevelPlay的後台->Setup->Ad units

( https://platform.ironsrc.com/partners/next/adUnits/ )找到

後台的ad unit設定可以參考此篇: https://goocoding.blogspot.com/2025/07/unity-levelplay.html

在這個範例中,你可以利用AdsCompleteEvent來呼叫廣告播放完成後的遊戲邏輯(ex: 復活、給次數、etc...)

2017年4月27日 星期四

[Unity]AssetBundleManager & AssetBundleGraphTool 之整合使用

AssetBundle Manager是官方提供的bundle管理器, 能夠方便的讀取, 以及模擬測試bundle, 可從Asset Store免費下載(https://www.assetstore.unity3d.com/en/#!/content/45836)


AssetBundleGraphTool 則是Unity日本開發的圖形化打包工具, 能夠很輕鬆的設計自動化打包流程, 也是開源免費(https://bitbucket.org/Unity-Technologies/assetbundlegraphtool)


AssetBundle Manager有附帶快速打包的工具, 但我們必須為要打包的物件設定包名(甚至variants)

2014年8月28日 星期四

[Unity][C#]2 simple ways of load the data form XML // 兩種簡便讀取XML資料的方法

假如今天要讀取路徑為Resources/test.xml 的XML, 內容如下:
For example, the XML data we want read as below, the path is "Resources/test.xml":

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ROOT>
<table wave="1" level="1" name="aaa"/>
<table wave="2" level="1" name="bbb"/>
</ROOT>

我們有兩種簡便讀取的方法:
We have 2 simple ways can use:

2013年10月20日 星期日

[C#]About the way of trace the value of Rectangle.Fill //關於追蹤Rectangle.Fill值的方法

      我最近在研究用C#跟XAML開發 Windows phone APP, 不過遇到了些困難, 其中一個就是我找不到可以直接追蹤Rectangle.Fill值的方法

      I study of Windows phone APP development with C# and XAML nearly, but I experience some troubles, one of them is we have no way to trace to the value of Rectangle.Fill immediately.

      我能理解設計者必須站在高處為開發者考慮通用的功能;矩形不只能填充單一色彩, 也能填充漸層甚至更複雜的圖案, 所以要設計一個參數或者方法去得顏色的值是很困難的

      I can understand that designer need concern the general function for developers; the rectangle not only could be filled with one color,  but also could be filled with linear gradient or even more complicated picture, so it's hard to design a property or a method for show the value of color.

      不過我的要求其實很單純, 我只是要取得Rectangle.Fill的值, 我們只能給Rectangle.Fill設一種顏色對吧?不需要複雜的方法去比較每一個像素, 只需要一個參數去儲存色碼, 為什麼我們沒有方法去追蹤Fill的值呢?