using System.Collections.Generic; using System.Linq; using ShiroginSDK.Runtime.Core.SDK; using UnityEditor; using UnityEngine; namespace ShiroginSDK.Editor.Core { public static class ShiroginDefinesManager { // Define Symbols private const string DEFINE_SDK = "SHIROGIN_SDK"; private const string DEFINE_IAP = "SHIROGIN_IAP"; private const string DEFINE_AD_SERVICE = "SHIROGIN_AD_SERVICE"; private const string DEFINE_ANALYTICS = "SHIROGIN_ANALYTICS"; private const string DEFINE_FIREBASE_ANALYTICS = "SHIROGIN_FIREBASE_ANALYTICS"; private const string DEFINE_FIREBASE_REMOTE_CONFIG = "SHIROGIN_FIREBASE_REMOTE_CONFIG"; private const string DEFINE_APPSFLYER = "SHIROGIN_APPSFLYER"; private const string DEFINE_FACEBOOK = "SHIROGIN_FACEBOOK"; /// /// Updates scripting define symbols based on ShiroginConfig settings. /// Call this manually from the Config Editor. /// public static void UpdateDefines() { var config = ShiroginConfig.Load(); if (config == null) { Debug.LogError("ShiroginConfig not found! Cannot update defines."); return; } var activeDefines = new List(); // --- Enable Flags --- if (config.enableSdk) activeDefines.Add(DEFINE_SDK); if (config.enableIAP) activeDefines.Add(DEFINE_IAP); if (config.enableAdService) activeDefines.Add(DEFINE_AD_SERVICE); if (config.enableAnalytics) activeDefines.Add(DEFINE_ANALYTICS); if (config.enableFirebaseAnalytics) activeDefines.Add(DEFINE_FIREBASE_ANALYTICS); if (config.enableFirebaseRemoteConfig) activeDefines.Add(DEFINE_FIREBASE_REMOTE_CONFIG); if (config.enableAppsFlyerAnalytics) activeDefines.Add(DEFINE_APPSFLYER); if (config.enableFacebook) activeDefines.Add(DEFINE_FACEBOOK); SetDefines(activeDefines); } /// /// Emergency tool to clear all SDK symbols if compilation breaks. /// Access via: Tools -> ShiroginSDK -> Force Reset Symbols /// [MenuItem("ShiroginSDK/🔧 Force Reset Symbols (Fix Errors)", false, 99)] public static void ForceReset() { SetDefines(new List()); Debug.Log("ShiroginSDK: All symbols cleared. You should be able to compile now."); } private static void SetDefines(List targetDefines) { var targetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; if (targetGroup == BuildTargetGroup.Unknown) return; string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); var allDefines = definesString.Split(';').ToList(); bool changed = false; var managedDefines = new List { DEFINE_SDK, DEFINE_IAP, DEFINE_AD_SERVICE, DEFINE_ANALYTICS, DEFINE_FIREBASE_ANALYTICS, DEFINE_FIREBASE_REMOTE_CONFIG, DEFINE_APPSFLYER, DEFINE_FACEBOOK }; // Add required foreach (var define in targetDefines) { if (!allDefines.Contains(define)) { allDefines.Add(define); changed = true; } } // Remove unused foreach (var define in managedDefines) { if (!targetDefines.Contains(define) && allDefines.Contains(define)) { allDefines.Remove(define); changed = true; } } if (changed) { PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", allDefines)); #if UNITY_2020_1_OR_NEWER UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation(); #endif Debug.Log($"[ShiroginSDK] 🔄 Defines Updated: {string.Join(", ", targetDefines)}"); } else { Debug.Log("[ShiroginSDK] No changes in defines."); } } } }