// #if UNITY_EDITOR // using UnityEditor; // using UnityEngine; // using UnityEngine.UIElements; // using ShiroginSDK.Runtime.IAP.SO; // using ShiroginSDK.Runtime.IAP.Enums; // using System.IO; // using System.Collections.Generic; // // namespace ShiroginSDK.Editor.IAP // { // [CustomEditor(typeof(StoreItem))] // public class StoreItemEditor : UnityEditor.Editor // { // private const string SaveFolder = "Assets/ShiroginSDK/Generated/StoreItemIcons"; // private const string JsonPath = "Assets/ShiroginSDK/Generated/storeitemeditor.json"; // // [System.Serializable] // private class IconData { public string itemPath; public string iconPath; } // // [System.Serializable] // private class IconDataList { public List list = new(); } // // public override VisualElement CreateInspectorGUI() // { // var root = new VisualElement { style = { paddingTop = 6, paddingBottom = 8 } }; // var item = (StoreItem)target; // // // Default inspector (IMGUIContainer ile izole) // var defaultInspector = new IMGUIContainer(() => DrawDefaultInspector()); // root.Add(defaultInspector); // // // Separator // var line = new VisualElement(); // line.style.height = 1; // line.style.marginTop = 8; // line.style.marginBottom = 8; // line.style.backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.6f); // root.Add(line); // // // Box container // var box = new VisualElement(); // box.style.borderTopLeftRadius = 6; // box.style.borderTopRightRadius = 6; // box.style.borderBottomLeftRadius = 6; // box.style.borderBottomRightRadius = 6; // box.style.paddingTop = 8; // box.style.paddingBottom = 8; // box.style.paddingLeft = 10; // box.style.paddingRight = 10; // box.style.backgroundColor = new Color(0.12f, 0.12f, 0.12f, 0.6f); // root.Add(box); // // var header = new Label("🧩 Shirogin IAP Tools"); // header.style.unityFontStyleAndWeight = FontStyle.Bold; // header.style.marginBottom = 6; // box.Add(header); // // if (item.icon == null) // { // var help = new HelpBox("Please assign an icon sprite before applying.", HelpBoxMessageType.Warning); // box.Add(help); // } // // var button = new Button(() => GenerateAndSave(item)) // { // text = "🖼 Generate & Save Icon", // style = // { // height = 28, // unityTextAlign = TextAnchor.MiddleCenter, // marginTop = 4 // } // }; // box.Add(button); // // return root; // } // // private void GenerateAndSave(StoreItem item) // { // Directory.CreateDirectory(SaveFolder); // // Texture2D baseTex = AssetPreview.GetAssetPreview(item.icon); // if (baseTex == null) // { // Debug.LogWarning("[ShiroginSDK] Couldn't create preview texture."); // return; // } // // string category = item.category.ToString(); // Texture2D label = Resources.Load($"Shirogin/IAP_Labels/{category}") ?? // Resources.Load("Shirogin/IAP_Labels/Unknown"); // // Texture2D final = new Texture2D(baseTex.width, baseTex.height, TextureFormat.RGBA32, false); // Graphics.CopyTexture(baseTex, final); // if (label != null) Overlay(final, label); // final.Apply(); // // string savePath = $"{SaveFolder}/{item.name}_Icon.png"; // File.WriteAllBytes(savePath, final.EncodeToPNG()); // AssetDatabase.ImportAsset(savePath); // AssetDatabase.Refresh(); // // Texture2D savedTex = AssetDatabase.LoadAssetAtPath(savePath); // if (savedTex != null) // EditorGUIUtility.SetIconForObject(item, savedTex); // // EditorUtility.SetDirty(item); // AssetDatabase.SaveAssets(); // SaveJson(AssetDatabase.GetAssetPath(item), savePath); // Debug.Log($"[ShiroginSDK] Icon saved → {savePath}"); // } // // private void Overlay(Texture2D baseTex, Texture2D labelTex) // { // int w = baseTex.width; // int h = baseTex.height; // int lh = Mathf.RoundToInt(h * 0.2f); // Texture2D scaled = Scale(labelTex, w, lh); // // for (int y = 0; y < lh; y++) // { // for (int x = 0; x < w; x++) // { // Color a = baseTex.GetPixel(x, h - lh + y); // Color b = scaled.GetPixel(x, y); // baseTex.SetPixel(x, h - lh + y, Color.Lerp(a, b, b.a)); // } // } // } // // private Texture2D Scale(Texture2D src, int w, int h) // { // RenderTexture rt = RenderTexture.GetTemporary(w, h); // Graphics.Blit(src, rt); // RenderTexture.active = rt; // Texture2D result = new Texture2D(w, h, TextureFormat.RGBA32, false); // result.ReadPixels(new Rect(0, 0, w, h), 0, 0); // result.Apply(); // RenderTexture.ReleaseTemporary(rt); // RenderTexture.active = null; // return result; // } // // private void SaveJson(string itemPath, string iconPath) // { // IconDataList data = File.Exists(JsonPath) // ? JsonUtility.FromJson(File.ReadAllText(JsonPath)) // : new IconDataList(); // // data.list.RemoveAll(x => x.itemPath == itemPath); // data.list.Add(new IconData { itemPath = itemPath, iconPath = iconPath }); // // File.WriteAllText(JsonPath, JsonUtility.ToJson(data, true)); // AssetDatabase.Refresh(); // } // // [InitializeOnLoadMethod] // private static void RestoreIconsOnLoad() // { // EditorApplication.delayCall += () => // { // if (!File.Exists(JsonPath)) return; // var data = JsonUtility.FromJson(File.ReadAllText(JsonPath)); // if (data == null || data.list.Count == 0) return; // // foreach (var entry in data.list) // { // var item = AssetDatabase.LoadAssetAtPath(entry.itemPath); // var icon = AssetDatabase.LoadAssetAtPath(entry.iconPath); // if (item != null && icon != null) // EditorGUIUtility.SetIconForObject(item, icon); // } // // Debug.Log($"[ShiroginSDK] Restored {data.list.Count} StoreItem icons (Unity 6 compatible)."); // }; // } // } // } // #endif