modify scripts
This commit is contained in:
@ -15,8 +15,9 @@ using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
using WordsToolkit.Scripts.Settings;
|
||||
|
||||
namespace WordsToolkit.Scripts.Settings.Editor
|
||||
namespace WordConnectGameToolkit.Scripts.Settings.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(AdElement))]
|
||||
public class AdElementDrawer : PropertyDrawer
|
||||
@ -45,7 +46,24 @@ namespace WordsToolkit.Scripts.Settings.Editor
|
||||
var adTypeScriptableObject = (AdReference)adTypeScriptableProperty.objectReferenceValue;
|
||||
if (adTypeScriptableObject != null && adTypeScriptableObject.adType == EAdType.Interstitial)
|
||||
{
|
||||
popupField.visible = true;
|
||||
// Add button to open InterstitialSettings for interstitial ads
|
||||
var interstitialButton = new Button(() => {
|
||||
OpenInterstitialSettings();
|
||||
})
|
||||
{
|
||||
text = "Open Interstitial Settings"
|
||||
};
|
||||
interstitialButton.style.marginTop = 5;
|
||||
|
||||
// Show/hide button and popup field based on ad type
|
||||
adTypeScriptableField.RegisterValueChangeCallback(evt =>
|
||||
{
|
||||
UpdateFieldVisibility(adTypeScriptableProperty, popupField, interstitialButton, root);
|
||||
});
|
||||
|
||||
// Initial visibility setup
|
||||
UpdateFieldVisibility(adTypeScriptableProperty, popupField, interstitialButton, root);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -69,6 +87,46 @@ namespace WordsToolkit.Scripts.Settings.Editor
|
||||
// Return the root VisualElement
|
||||
return root;
|
||||
}
|
||||
|
||||
private void UpdateFieldVisibility(SerializedProperty adTypeScriptableProperty, VisualElement popupField, Button interstitialButton, VisualElement root)
|
||||
{
|
||||
var adTypeScriptableObject = (AdReference)adTypeScriptableProperty.objectReferenceValue;
|
||||
|
||||
if (adTypeScriptableObject != null && adTypeScriptableObject.adType == EAdType.Interstitial)
|
||||
{
|
||||
popupField.style.display = DisplayStyle.None; // Hide popup field for interstitials
|
||||
if (!root.Contains(interstitialButton))
|
||||
{
|
||||
root.Add(interstitialButton);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
popupField.style.display = DisplayStyle.Flex; // Show popup field for other ad types
|
||||
if (root.Contains(interstitialButton))
|
||||
{
|
||||
root.Remove(interstitialButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenInterstitialSettings()
|
||||
{
|
||||
// Find InterstitialSettings asset
|
||||
string[] guids = AssetDatabase.FindAssets("t:InterstitialSettings");
|
||||
if (guids.Length > 0)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
var interstitialSettings = AssetDatabase.LoadAssetAtPath<InterstitialSettings>(path);
|
||||
Selection.activeObject = interstitialSettings;
|
||||
EditorGUIUtility.PingObject(interstitialSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("InterstitialSettings Not Found",
|
||||
"Could not find InterstitialSettings ScriptableObject in the project.", "OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user