com.typhoon.unitysdk 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/Editor/EditorIcons.cs +27 -45
  2. package/Editor/Interactive/test_banner.png +0 -0
  3. package/Editor/Interactive/{sdk_banner.png.meta → test_banner.png.meta} +6 -6
  4. package/Editor/Interactive/test_banner_2.png +0 -0
  5. package/Editor/Interactive/{sdk_close.png.meta → test_banner_2.png.meta} +25 -1
  6. package/Editor/Interactive/test_float_icon_1.png +0 -0
  7. package/Editor/Interactive/{sdk_/345/244/261/350/264/245/350/277/224/345/233/236.png.meta → test_float_icon_1.png.meta} +25 -1
  8. package/Editor/Interactive/test_float_icon_2.png +0 -0
  9. package/Editor/Interactive/{sdk_white_4x4.png.meta → test_float_icon_2.png.meta} +25 -1
  10. package/Editor/Interactive/test_float_icon_3.png +0 -0
  11. package/Editor/Interactive/test_float_icon_3.png.meta +144 -0
  12. package/Editor/Interactive/test_float_icon_4.png +0 -0
  13. package/Editor/Interactive/test_float_icon_4.png.meta +144 -0
  14. package/Editor/Interactive/test_inters.png +0 -0
  15. package/Editor/Interactive/test_inters.png.meta +144 -0
  16. package/Editor/Interactive/test_native.png +0 -0
  17. package/Editor/Interactive/test_native.png.meta +144 -0
  18. package/Editor/InteractiveSources.asset +23 -0
  19. package/Editor/{Interactive/SDKInteractiveUI.prefab.meta → InteractiveSources.asset.meta} +3 -2
  20. package/Editor/PreferencesWindow.cs +8 -9
  21. package/Editor/PublishSettingGUIDrawer.cs +4 -1
  22. package/Editor/PublishVivoBatSettingWindow.cs +3 -4
  23. package/Editor/PublishWindow.cs +39 -29
  24. package/Editor/Skin.guiskin +119 -864
  25. package/Editor/SkinLight.guiskin +1994 -0
  26. package/Editor/SkinLight.guiskin.meta +8 -0
  27. package/Editor/Skins.cs +20 -1
  28. package/Editor/SkinsTexture.asset +133 -0
  29. package/Editor/SkinsTexture.asset.meta +8 -0
  30. package/Editor/Styles.cs +3 -14
  31. package/Editor/StylesExtension.cs +7 -5
  32. package/Editor/Texture/{btn_active.png.meta → dark_active.png.meta} +120 -120
  33. package/Editor/Texture/{btn_hover.png.meta → dark_hover.png.meta} +120 -120
  34. package/Editor/Texture/{btn_normal.png.meta → dark_normal.png.meta} +120 -120
  35. package/Editor/Texture/icon_android.png.meta +120 -120
  36. package/Editor/Texture/icon_douyin.png.meta +120 -120
  37. package/Editor/Texture/icon_download.png +0 -0
  38. package/Editor/Texture/icon_download.png.meta +120 -120
  39. package/Editor/Texture/icon_extension.png +0 -0
  40. package/Editor/Texture/icon_extension.png.meta +120 -120
  41. package/Editor/Texture/icon_googleplay.png.meta +120 -120
  42. package/Editor/Texture/icon_html5.png.meta +120 -120
  43. package/Editor/Texture/icon_import.png +0 -0
  44. package/Editor/Texture/icon_ios.png.meta +120 -120
  45. package/Editor/Texture/icon_oppo.png.meta +120 -120
  46. package/Editor/Texture/icon_refresh.png +0 -0
  47. package/Editor/Texture/icon_refresh.png.meta +120 -120
  48. package/Editor/Texture/icon_save.png +0 -0
  49. package/Editor/Texture/icon_save.png.meta +120 -120
  50. package/Editor/Texture/icon_search.png +0 -0
  51. package/Editor/Texture/{btn_blue_active.png.meta → icon_search.png.meta} +25 -1
  52. package/Editor/Texture/icon_vivo.png.meta +120 -120
  53. package/Editor/Texture/icon_wechat.png.meta +120 -120
  54. package/Editor/Texture/light_active.png +0 -0
  55. package/Editor/Texture/{btn_blue_hover.png.meta → light_active.png.meta} +25 -1
  56. package/Editor/Texture/light_hover.png +0 -0
  57. package/Editor/Texture/light_hover.png.meta +144 -0
  58. package/Editor/Texture/light_normal.png +0 -0
  59. package/Editor/Texture/light_normal.png.meta +144 -0
  60. package/Editor/Texture/tex_select.png.meta +120 -120
  61. package/Runtime/InteractiveSources.cs +34 -0
  62. package/{Editor/OriginalStyles.cs.meta → Runtime/InteractiveSources.cs.meta} +1 -1
  63. package/Runtime/SDKInteractiveUI.cs +432 -117
  64. package/Runtime/SdkTestInUnity.cs +2 -0
  65. package/Runtime/TyphoonSdk.cs +75 -97
  66. package/Sources~/ChinaAndroid/Assets/Typhoon_Gen/TyphoonSDK/Runtime/ChinaAndroid/Editor/PublishChinaAndroidAAR.cs +2 -2
  67. package/package.json +1 -1
  68. package/Editor/Interactive/SDKInteractiveUI.prefab +0 -3026
  69. package/Editor/Interactive/sdk_banner.png +0 -0
  70. package/Editor/Interactive/sdk_close.png +0 -0
  71. package/Editor/Interactive/sdk_inters.png +0 -0
  72. package/Editor/Interactive/sdk_inters.png.meta +0 -120
  73. package/Editor/Interactive/sdk_white_4x4.png +0 -0
  74. package/Editor/Interactive/sdk_/345/244/261/350/264/245/350/277/224/345/233/236.png +0 -0
  75. package/Editor/Interactive/sdk_/346/202/254/346/265/256/345/271/277/345/221/212.png +0 -0
  76. package/Editor/Interactive/sdk_/346/202/254/346/265/256/345/271/277/345/221/212.png.meta +0 -120
  77. package/Editor/Interactive/sdk_/346/210/220/345/212/237/350/277/224/345/233/236.png +0 -0
  78. package/Editor/Interactive/sdk_/346/210/220/345/212/237/350/277/224/345/233/236.png.meta +0 -120
  79. package/Editor/Interactive/sdk_/350/277/231/346/230/257/344/270/200/344/270/252/345/216/237/347/224/237/346/250/241/346/235/277.png +0 -0
  80. package/Editor/Interactive/sdk_/350/277/231/346/230/257/344/270/200/344/270/252/345/216/237/347/224/237/346/250/241/346/235/277.png.meta +0 -120
  81. package/Editor/Interactive/sdk_/350/277/231/346/230/257/344/270/200/344/270/252/346/217/222/351/241/265/345/271/277/345/221/212.png +0 -0
  82. package/Editor/Interactive/sdk_/350/277/231/346/230/257/344/270/200/344/270/252/346/217/222/351/241/265/345/271/277/345/221/212.png.meta +0 -120
  83. package/Editor/Interactive/sdk_/350/277/231/346/230/257/344/270/200/344/270/252/350/247/206/351/242/221/345/271/277/345/221/212.png +0 -0
  84. package/Editor/Interactive/sdk_/350/277/231/346/230/257/344/270/200/344/270/252/350/247/206/351/242/221/345/271/277/345/221/212.png.meta +0 -120
  85. package/Editor/OriginalStyles.cs +0 -708
  86. package/Editor/StyleEditorWindow.cs +0 -23
  87. package/Editor/StyleEditorWindow.cs.meta +0 -11
  88. package/Editor/Texture/btn_blue_active.png +0 -0
  89. package/Editor/Texture/btn_blue_hover.png +0 -0
  90. package/Editor/Texture/btn_blue_normal.png +0 -0
  91. package/Editor/Texture/btn_blue_normal.png.meta +0 -120
  92. package/Editor/Texture/btn_green_active.png +0 -0
  93. package/Editor/Texture/btn_green_active.png.meta +0 -120
  94. package/Editor/Texture/btn_green_hover.png +0 -0
  95. package/Editor/Texture/btn_green_hover.png.meta +0 -120
  96. package/Editor/Texture/btn_green_normal.png +0 -0
  97. package/Editor/Texture/btn_green_normal.png.meta +0 -120
  98. package/Editor/Texture/btn_yellow_active.png +0 -0
  99. package/Editor/Texture/btn_yellow_active.png.meta +0 -120
  100. package/Editor/Texture/btn_yellow_hover.png +0 -0
  101. package/Editor/Texture/btn_yellow_hover.png.meta +0 -120
  102. package/Editor/Texture/btn_yellow_normal.png +0 -0
  103. package/Editor/Texture/btn_yellow_normal.png.meta +0 -120
  104. /package/Editor/Texture/{btn_active.png → dark_active.png} +0 -0
  105. /package/Editor/Texture/{btn_hover.png → dark_hover.png} +0 -0
  106. /package/Editor/Texture/{btn_normal.png → dark_normal.png} +0 -0
@@ -2,7 +2,6 @@ using System;
2
2
  using System.Collections.Generic;
3
3
  using System.IO;
4
4
  using UnityEngine;
5
- using UnityEngine.UI;
6
5
  #if UNITY_EDITOR
7
6
  using UnityEditor;
8
7
  #endif
@@ -14,6 +13,9 @@ namespace TyphoonUnitySDK
14
13
  /// </summary>
15
14
  public class SDKInteractiveUI : MonoSingleton<SDKInteractiveUI>
16
15
  {
16
+ #if UNITY_EDITOR
17
+ public static float HOLD_TIME = SdkTestInUnity.Instance.InteractiveHoldCloseTime;
18
+
17
19
  public static string PathRoot
18
20
  {
19
21
  get
@@ -36,51 +38,86 @@ namespace TyphoonUnitySDK
36
38
  Portrait,
37
39
  }
38
40
 
39
- public ScreenMode Mode;
40
-
41
41
  public BannerView Banner = new BannerView();
42
42
  public IntersView Inters = new IntersView();
43
43
  public VideoView Video = new VideoView();
44
44
  public NativeView Native = new NativeView();
45
45
  public FloatIconView FloatIcon = new FloatIconView();
46
+ public InteractiveSources Sources;
47
+ public GUISkin Skin;
46
48
 
47
-
48
- protected override void Init()
49
+ public class UIStyles
49
50
  {
50
- base.Init();
51
- DontDestroyOnLoad(gameObject);
52
- Mode = Screen.width - Screen.height > 0 ? ScreenMode.Landscape : ScreenMode.Portrait;
53
- Debug.Log($" {Screen.width},{Screen.height}");
51
+ private static GUIStyle _bottomImageStyle = null;
52
+ private static GUIStyle _topmageStyle = null;
53
+ private static GUIStyle _boldLabel = null;
54
54
 
55
- //加载资源
56
- #if UNITY_EDITOR
57
- var path = $"{PathRoot}/Editor/Interactive/SDKInteractiveUI.prefab";
58
- var source =
59
- AssetDatabase.LoadAssetAtPath<GameObject>(path);
60
- var clone = Instantiate(source);
61
- Initialize(clone, Mode);
62
- #endif
63
- }
55
+ public static GUIStyle BoldLabel
56
+ {
57
+ get
58
+ {
59
+ if (_boldLabel == null)
60
+ {
61
+ _boldLabel = new GUIStyle(GUI.skin.label);
62
+ _boldLabel.alignment = TextAnchor.MiddleCenter;
63
+ _boldLabel.fixedWidth = 0;
64
+ _boldLabel.fixedHeight = 0;
65
+ _boldLabel.fontSize = 30;
66
+ _boldLabel.fontStyle = FontStyle.Bold;
67
+ _boldLabel.normal.textColor = Color.white;
68
+ }
69
+
70
+ return _boldLabel;
71
+ }
72
+ }
64
73
 
65
- public void Initialize(GameObject source, ScreenMode mode)
66
- {
67
- DontDestroyOnLoad(source);
68
- var root = source.transform;
69
- var canvasScaler = root.GetComponent<CanvasScaler>();
70
- canvasScaler.referenceResolution =
71
- mode == ScreenMode.Landscape ? new Vector2(1920, 1080) : new Vector2(1080, 1920);
72
- canvasScaler.matchWidthOrHeight = mode == ScreenMode.Landscape ? 1 : 0;
73
- Banner.Initialize(root);
74
- Video.Initialize(root);
75
- Inters.Initialize(root);
76
- Native.Initialize(root);
77
- FloatIcon.Initialize(root);
74
+ public static GUIStyle BottomImageStyle
75
+ {
76
+ get
77
+ {
78
+ if (_bottomImageStyle == null)
79
+ {
80
+ _bottomImageStyle = new GUIStyle(GUI.skin.box);
81
+ _bottomImageStyle.alignment = TextAnchor.LowerCenter;
82
+ _bottomImageStyle.fixedWidth = 0;
83
+ _bottomImageStyle.fixedHeight = 0;
84
+ }
85
+
86
+ return _bottomImageStyle;
87
+ }
88
+ }
89
+
90
+ public static GUIStyle TopImageStyle
91
+ {
92
+ get
93
+ {
94
+ if (_topmageStyle == null)
95
+ {
96
+ _topmageStyle = new GUIStyle(GUI.skin.box);
97
+ _topmageStyle.alignment = TextAnchor.UpperCenter;
98
+ _topmageStyle.fixedWidth = 0;
99
+ _topmageStyle.fixedHeight = 0;
100
+ }
101
+
102
+ return _topmageStyle;
103
+ }
104
+ }
78
105
  }
79
106
 
80
- public static void SetViewValid(CanvasGroup canvasGroup, bool isOn)
107
+ protected override void Init()
81
108
  {
82
- canvasGroup.alpha = isOn ? 1 : 0;
83
- canvasGroup.blocksRaycasts = isOn;
109
+ base.Init();
110
+ DontDestroyOnLoad(gameObject);
111
+ Skin =
112
+ AssetDatabase.LoadAssetAtPath<GUISkin>($"{PathRoot}/Editor/Skin.guiskin");
113
+ var path = $"{PathRoot}/Editor/InteractiveSources.asset";
114
+ Sources =
115
+ AssetDatabase.LoadAssetAtPath<InteractiveSources>(path);
116
+ Banner.Initialize(Sources);
117
+ Video.Initialize(Sources);
118
+ Inters.Initialize(Sources);
119
+ Native.Initialize(Sources);
120
+ FloatIcon.Initialize(Sources);
84
121
  }
85
122
 
86
123
  public void ShowBanner(BannerPosition position)
@@ -129,34 +166,86 @@ namespace TyphoonUnitySDK
129
166
 
130
167
  public class BannerView
131
168
  {
132
- public CanvasGroup View;
133
- public CanvasGroup Bottom;
134
- public CanvasGroup Top;
135
- public Button BtnCloseBottom;
136
- public Button BtnCloseTop;
137
-
138
- public void Initialize(Transform root)
139
- {
140
- View = root.Find("Banner").GetComponent<CanvasGroup>();
141
- Bottom = root.Find("Banner/BannerBottom").GetComponent<CanvasGroup>();
142
- Top = root.Find("Banner/BannerTop").GetComponent<CanvasGroup>();
143
- BtnCloseBottom = root.Find("Banner/BannerBottom/BtnClose").GetComponent<Button>();
144
- BtnCloseTop = root.Find("Banner/BannerTop/BtnClose").GetComponent<Button>();
145
- BtnCloseBottom.onClick.AddListener(Hide);
146
- BtnCloseTop.onClick.AddListener(Hide);
147
- Hide();
169
+ public bool IsShow = false;
170
+ public BannerPosition BannerPosition;
171
+ public InteractiveSources Sources;
172
+ public GUIStyle TopStyle => UIStyles.TopImageStyle;
173
+ public GUIStyle BottomStyle => UIStyles.BottomImageStyle;
174
+
175
+ public Texture2D Image
176
+ {
177
+ get
178
+ {
179
+ switch (BannerPosition)
180
+ {
181
+ case BannerPosition.Top:
182
+ return Sources.Get("test_banner_2");
183
+ }
184
+
185
+ return Sources.Get("test_banner");
186
+ }
187
+ }
188
+
189
+ public float HoldTime = 0;
190
+
191
+ public void Initialize(InteractiveSources sources)
192
+ {
193
+ Sources = sources;
148
194
  }
149
195
 
150
196
  public void Show(BannerPosition position)
151
197
  {
152
- SetViewValid(View, true);
153
- SetViewValid(Bottom, position == BannerPosition.Bottom);
154
- SetViewValid(Top, position == BannerPosition.Top);
198
+ IsShow = true;
199
+ BannerPosition = position;
200
+ HoldTime = 0;
155
201
  }
156
202
 
157
203
  public void Hide()
158
204
  {
159
- SetViewValid(View, false);
205
+ IsShow = false;
206
+ }
207
+
208
+
209
+ public void OnGUI(Rect rect, ScreenMode mode)
210
+ {
211
+ if (IsShow)
212
+ {
213
+ var heightScale = mode == ScreenMode.Portrait ? 0.1f : 0.07f;
214
+ var height = heightScale * rect.height;
215
+ var view = rect;
216
+ view.height = height;
217
+ var size = CalculateImageMatchSize(Image, view);
218
+ view.width = size.x;
219
+ view.height = size.y;
220
+ view.y = 0;
221
+ if (BannerPosition == BannerPosition.Bottom)
222
+ {
223
+ view.y = rect.yMax - view.height;
224
+ }
225
+
226
+ view.x = rect.center.x - view.width * 0.5f;
227
+ GUI.DrawTexture(view, Image, ScaleMode.StretchToFill);
228
+ //绘制关闭按钮
229
+ var rectClose = view;
230
+ rectClose.width = 146;
231
+ rectClose.height = 60;
232
+ rectClose.x = view.xMax - rectClose.width - 6;
233
+ rectClose.y = 6;
234
+ if (BannerPosition == BannerPosition.Bottom)
235
+ {
236
+ rectClose.y = view.y + 10;
237
+ }
238
+
239
+ DrawViewTxtLabel(rectClose, "关闭");
240
+ //悬停/关闭
241
+ HoldHide(rectClose, ref HoldTime, Hide);
242
+
243
+ var rectTitle = view;
244
+ rectTitle.width = 300;
245
+ rectTitle.height = 66;
246
+ rectTitle.center = view.center;
247
+ DrawViewTxtLabel(rectTitle, "这是一个测试Banner");
248
+ }
160
249
  }
161
250
  }
162
251
 
@@ -166,25 +255,54 @@ namespace TyphoonUnitySDK
166
255
 
167
256
  public class IntersView
168
257
  {
169
- public CanvasGroup View;
170
- public Button BtnClose;
258
+ public InteractiveSources Sources;
171
259
 
172
- public void Initialize(Transform root)
260
+ public bool IsShow = false;
261
+ public Texture2D Image => Sources.Get("test_inters");
262
+ public float HoldTime = 0;
263
+
264
+ public void Initialize(InteractiveSources sources)
173
265
  {
174
- View = root.Find("Inters").GetComponent<CanvasGroup>();
175
- BtnClose = root.Find("Inters/Layout/BtnClose").GetComponent<Button>();
176
- BtnClose.onClick.AddListener(Hide);
177
- Hide();
266
+ Sources = sources;
178
267
  }
179
268
 
180
269
  public void Show()
181
270
  {
182
- SetViewValid(View, true);
271
+ IsShow = true;
183
272
  }
184
273
 
185
274
  public void Hide()
186
275
  {
187
- SetViewValid(View, false);
276
+ IsShow = false;
277
+ }
278
+
279
+ public void OnGUI(Rect rect, ScreenMode mode)
280
+ {
281
+ if (IsShow)
282
+ {
283
+ EditorGUI.DrawRect(rect, Color.black);
284
+ var size = CalculateImageMatchSize(Image, rect);
285
+ var imageRect = rect;
286
+ imageRect.width = size.x;
287
+ imageRect.height = size.y;
288
+ imageRect.center = rect.center;
289
+ GUI.DrawTexture(imageRect, Image);
290
+
291
+ var rectClose = imageRect;
292
+ rectClose.width = 246;
293
+ rectClose.height = 66;
294
+ rectClose.x = imageRect.xMax - rectClose.width - 10;
295
+ rectClose.y += 10;
296
+ DrawViewTxtLabel(rectClose, "关闭");
297
+ //悬停/关闭
298
+ HoldHide(rectClose, ref HoldTime, Hide);
299
+
300
+ var titleRect = imageRect;
301
+ titleRect.width = 400;
302
+ titleRect.height = 128;
303
+ titleRect.center = imageRect.center;
304
+ DrawViewTxtLabel(titleRect, "这是一个测试插页广告");
305
+ }
188
306
  }
189
307
  }
190
308
 
@@ -194,20 +312,18 @@ namespace TyphoonUnitySDK
194
312
 
195
313
  public class VideoView
196
314
  {
197
- public CanvasGroup View;
198
- public Button BtnSuccess;
199
- public Button BtnFail;
315
+ public InteractiveSources Sources;
316
+ public bool IsShow = false;
200
317
  public Action OnSuccess;
201
318
  public Action OnFail;
319
+ public Texture2D Image => Sources.Get("test_inters");
320
+ public float HoldTime = 0;
321
+ public float BtnYesHoldTime = 0;
322
+ public float BtnNoHoldTime = 0;
202
323
 
203
- public void Initialize(Transform root)
324
+ public void Initialize(InteractiveSources sources)
204
325
  {
205
- View = root.Find("Video").GetComponent<CanvasGroup>();
206
- BtnSuccess = root.Find("Video/BtnSuccess").GetComponent<Button>();
207
- BtnFail = root.Find("Video/BtnFail").GetComponent<Button>();
208
- BtnSuccess.onClick.AddListener(OnClickSuccess);
209
- BtnFail.onClick.AddListener(OnClickFail);
210
- Hide();
326
+ Sources = sources;
211
327
  }
212
328
 
213
329
  public void OnClickSuccess()
@@ -226,13 +342,55 @@ namespace TyphoonUnitySDK
226
342
  {
227
343
  OnSuccess = success;
228
344
  OnFail = fail;
229
- SetViewValid(View, true);
345
+ IsShow = true;
230
346
  }
231
347
 
232
348
 
233
349
  public void Hide()
234
350
  {
235
- SetViewValid(View, false);
351
+ IsShow = false;
352
+ }
353
+
354
+ public void OnGUI(Rect rect, ScreenMode mode)
355
+ {
356
+ if (IsShow)
357
+ {
358
+ EditorGUI.DrawRect(rect, Color.black);
359
+ var size = CalculateImageMatchSize(Image, rect);
360
+ var adRect = rect;
361
+ adRect.width = size.x;
362
+ adRect.height = size.y;
363
+ adRect.center = rect.center;
364
+ GUI.DrawTexture(adRect, Image);
365
+
366
+ var rectClose = adRect;
367
+ rectClose.width = 246;
368
+ rectClose.height = 66;
369
+ rectClose.x = adRect.xMax - rectClose.width - 10;
370
+ rectClose.y += 10;
371
+ DrawViewTxtLabel(rectClose, "关闭");
372
+
373
+ //成功返回
374
+ var rectYes = adRect;
375
+ rectYes.width = 346;
376
+ rectYes.height = 128;
377
+ rectYes.center = new Vector2(adRect.center.x, adRect.center.y + 80);
378
+ //失败返回
379
+ var rectNo = rectYes;
380
+ rectNo.center = new Vector2(adRect.center.x, adRect.center.y - 80);
381
+ DrawViewTxtLabel(rectYes, "成功返回");
382
+ DrawViewTxtLabel(rectNo, "失败返回");
383
+ HoldHide(rectYes, ref BtnYesHoldTime, OnClickSuccess);
384
+ HoldHide(rectNo, ref BtnNoHoldTime, OnClickFail);
385
+ HoldHide(rectClose, ref HoldTime, OnClickFail);
386
+
387
+ var rectTitle = adRect;
388
+ rectTitle.width = 400;
389
+ rectTitle.height = 128;
390
+ rectTitle.center = adRect.center;
391
+ rectTitle.y -= 300;
392
+ DrawViewTxtLabel(rectTitle, "这是一个测试视频");
393
+ }
236
394
  }
237
395
  }
238
396
 
@@ -242,37 +400,42 @@ namespace TyphoonUnitySDK
242
400
 
243
401
  public class FloatIconView
244
402
  {
245
- public Transform View;
246
403
  public Dictionary<string, FloatIconItem> Items = new Dictionary<string, FloatIconItem>();
247
- public GameObject Prefab;
248
- public Transform RangeMin;
249
- public Transform RangeMax;
404
+ public InteractiveSources Sources;
405
+
406
+ public static string[] ImageNames = new[]
407
+ {
408
+ "test_float_icon_1",
409
+ "test_float_icon_2",
410
+ "test_float_icon_4",
411
+ "test_float_icon_5",
412
+ };
413
+
414
+ public Texture2D Image
415
+ {
416
+ get
417
+ {
418
+ var index = (Items.Count + 1) % ImageNames.Length;
419
+ return Sources.Get(ImageNames[index]);
420
+ }
421
+ }
250
422
 
251
- public void Initialize(Transform root)
423
+ public void Initialize(InteractiveSources sources)
252
424
  {
253
- View = root;
254
- Prefab = root.Find("FloatIcon").gameObject;
255
- RangeMin = root.Find("RangeMin");
256
- RangeMax = root.Find("RangeMax");
257
- var prefabView = Prefab.GetComponent<CanvasGroup>();
258
- SetViewValid(prefabView, false);
425
+ Sources = sources;
259
426
  }
260
427
 
261
428
  public void Show(string scene, float spx, float spy)
262
429
  {
263
- var x = Mathf.Lerp(RangeMin.position.x, RangeMax.position.x, spx);
264
- var y = Mathf.Lerp(RangeMin.position.y, RangeMax.position.y, spy);
265
- var pos = new Vector3(x, y, View.transform.position.z);
266
430
  if (Items.TryGetValue(scene, out var match))
267
431
  {
268
- match.Show(pos);
432
+ match.Show(new Vector2(spx, spy));
269
433
  }
270
434
  else
271
435
  {
272
- var clone = Instantiate(Prefab, View);
273
- var item = FloatIconItem.Create(scene, clone);
436
+ var item = FloatIconItem.Create(scene, Image);
274
437
  Items.Add(scene, item);
275
- item.Show(pos);
438
+ item.Show(new Vector2(spx, spy));
276
439
  }
277
440
  }
278
441
 
@@ -283,40 +446,59 @@ namespace TyphoonUnitySDK
283
446
  match.Hide();
284
447
  }
285
448
  }
449
+
450
+ public void OnGUI(Rect rect, ScreenMode mode)
451
+ {
452
+ foreach (var item in Items.Values)
453
+ {
454
+ item.OnGUI(rect);
455
+ }
456
+ }
286
457
  }
287
458
 
288
459
  public class FloatIconItem
289
460
  {
461
+ public bool IsShow = false;
462
+ public Vector2 Sp;
463
+ public Texture2D Image;
290
464
  public string SceneName;
291
- public CanvasGroup View;
292
- public Button BtnClose;
465
+ public float HoldTime;
293
466
 
294
- public static FloatIconItem Create(string scene, GameObject prefab)
467
+ public static FloatIconItem Create(string scene, Texture2D image)
295
468
  {
296
469
  var result = new FloatIconItem();
470
+ result.Image = image;
297
471
  result.SceneName = scene;
298
- result.View = prefab.GetComponent<CanvasGroup>();
299
- result.Initialize();
300
472
  return result;
301
473
  }
302
474
 
303
- public void Initialize()
475
+ public void Hide()
304
476
  {
305
- BtnClose = View.gameObject.GetComponentInChildren<Button>();
306
- BtnClose.onClick.AddListener(Hide);
477
+ IsShow = false;
307
478
  }
308
479
 
309
-
310
- public void Hide()
480
+ public void Show(Vector2 sp)
311
481
  {
312
- SetViewValid(View, false);
482
+ IsShow = true;
483
+ Sp = sp;
313
484
  }
314
485
 
315
-
316
- public void Show(Vector3 pos)
486
+ public void OnGUI(Rect rect)
317
487
  {
318
- View.transform.position = pos;
319
- SetViewValid(View, true);
488
+ if (IsShow)
489
+ {
490
+ var min = Mathf.Min(rect.height, rect.width);
491
+ var size = (int)(min * 0.1f);
492
+ var view = rect;
493
+ view.height = size;
494
+ view.width = size;
495
+ view.x = Mathf.Lerp(0, rect.width, Sp.x);
496
+ view.y = Mathf.Lerp(0, rect.width, Sp.y);
497
+ GUI.DrawTexture(view, Image);
498
+ var rectClose = view;
499
+ DrawViewTxtLabel(rectClose, "关闭", TextAnchor.UpperRight,0.3f);
500
+ HoldHide(rectClose, ref HoldTime, Hide);
501
+ }
320
502
  }
321
503
  }
322
504
 
@@ -326,28 +508,161 @@ namespace TyphoonUnitySDK
326
508
 
327
509
  public class NativeView
328
510
  {
329
- public CanvasGroup View;
330
- public Button BtnClose;
511
+ public InteractiveSources Sources;
512
+ public bool IsShow = false;
513
+ public Texture2D Image => Sources.Get("test_native");
331
514
 
332
- public void Initialize(Transform root)
515
+ public float HoldTime = 0;
516
+
517
+ public void Initialize(InteractiveSources sources)
333
518
  {
334
- View = root.Find("Native").GetComponent<CanvasGroup>();
335
- BtnClose = root.Find("Native/Mask/BtnClose").GetComponent<Button>();
336
- BtnClose.onClick.AddListener(Hide);
337
- Hide();
519
+ Sources = sources;
338
520
  }
339
521
 
340
522
  public void Show()
341
523
  {
342
- SetViewValid(View, true);
524
+ IsShow = true;
343
525
  }
344
526
 
345
527
  public void Hide()
346
528
  {
347
- SetViewValid(View, false);
529
+ IsShow = false;
530
+ }
531
+
532
+ public void OnGUI(Rect rect, ScreenMode mode)
533
+ {
534
+ if (IsShow)
535
+ {
536
+ var heightScale = mode == ScreenMode.Portrait ? 0.4f : 0.8f;
537
+ var widthScale = mode == ScreenMode.Portrait ? 0.8f : 0.6f;
538
+ var height = heightScale * rect.height;
539
+ var width = widthScale * rect.width;
540
+ var view = rect;
541
+ view.height = height;
542
+ view.width = width;
543
+ var size = CalculateImageMatchSize(Image, view);
544
+ var imageRect = view;
545
+ imageRect.width = size.x;
546
+ imageRect.height = size.y;
547
+ imageRect.center = rect.center;
548
+ GUI.DrawTexture(imageRect, Image);
549
+ var rectClose = imageRect;
550
+ rectClose.width = 246;
551
+ rectClose.height = 66;
552
+ rectClose.x = imageRect.xMax - rectClose.width - 10;
553
+ rectClose.y += 10;
554
+ DrawViewTxtLabel(rectClose, "关闭");
555
+ HoldHide(rectClose, ref HoldTime, Hide);
556
+
557
+ var rectTitle = imageRect;
558
+ rectTitle.width = 400;
559
+ rectTitle.height = 128;
560
+ rectTitle.center = imageRect.center;
561
+ DrawViewTxtLabel(rectTitle, "这是一个测试原生广告");
562
+ }
348
563
  }
349
564
  }
350
565
 
351
566
  #endregion
567
+
568
+ private ScreenMode GetMode()
569
+ {
570
+ return Screen.width - Screen.height > 0 ? ScreenMode.Landscape : ScreenMode.Portrait;
571
+ }
572
+
573
+ private void OnGUI()
574
+ {
575
+ #if UNITY_EDITOR
576
+
577
+ var skin = GUI.skin;
578
+ GUI.skin = Skin;
579
+ var mode = GetMode();
580
+ var rect = new Rect(0, 0, Screen.width, Screen.height);
581
+ Banner.OnGUI(rect, mode);
582
+ FloatIcon.OnGUI(rect, mode);
583
+ Native.OnGUI(rect, mode);
584
+ Inters.OnGUI(rect, mode);
585
+ Video.OnGUI(rect, mode);
586
+ GUI.skin = skin;
587
+ #endif
588
+ }
589
+
590
+ /// <summary>
591
+ /// 计算图片适配大小
592
+ /// </summary>
593
+ private static Vector2 CalculateImageMatchSize(Texture2D tex, Rect view)
594
+ {
595
+ var checkHeight = (view.width / tex.width) * tex.height;
596
+ if (checkHeight < view.height)
597
+ {
598
+ //以高为准,宽还有余量
599
+ return new Vector2(view.width, checkHeight);
600
+ }
601
+
602
+ //以宽为准,高有余量
603
+ return new Vector2(view.height * tex.width / tex.height, view.height);
604
+ }
605
+
606
+ /*绘制文本*/
607
+ private static void DrawViewTxtLabel(Rect rect, string label, TextAnchor alignment = TextAnchor.MiddleCenter,
608
+ float dark = 0.75f)
609
+ {
610
+ EditorGUI.DrawRect(rect, Color.black * dark);
611
+ var rectLab = rect;
612
+ rectLab.width -= 10;
613
+ rectLab.height -= 10;
614
+ rectLab.center = rect.center;
615
+ UIStyles.BoldLabel.alignment = alignment;
616
+ GUI.Label(rectLab, label, UIStyles.BoldLabel);
617
+ }
618
+
619
+ /*长按隐藏*/
620
+ private static void HoldHide(Rect rectClose, ref float holdTime, Action hideHandler)
621
+ {
622
+ var inside = rectClose.Contains(Event.current.mousePosition);
623
+ if (inside && Event.current.delta == Vector2.zero)
624
+ {
625
+ holdTime += Time.unscaledDeltaTime;
626
+ var process = Mathf.Clamp01(holdTime / HOLD_TIME);
627
+ var rectProcess = rectClose;
628
+ rectProcess.width *= process;
629
+ EditorGUI.DrawRect(rectProcess, Color.green * 0.5f);
630
+ if (process >= 1)
631
+ {
632
+ hideHandler?.Invoke();
633
+ }
634
+ }
635
+ else
636
+ {
637
+ holdTime = 0;
638
+ }
639
+
640
+ if (inside && Event.current.type == EventType.MouseDown)
641
+ {
642
+ hideHandler?.Invoke();
643
+ Event.current.Use();
644
+ }
645
+ }
646
+
647
+
648
+ public static Type GetType(string typeName)
649
+ {
650
+ var assemblies = AppDomain.CurrentDomain.GetAssemblies();
651
+ foreach (var element in assemblies)
652
+ {
653
+ var types = element.GetTypes();
654
+ foreach (var type in types)
655
+ {
656
+ if (type.FullName == typeName)
657
+ {
658
+ return type;
659
+ }
660
+ }
661
+ }
662
+
663
+ return null;
664
+ }
665
+
666
+ #endif
352
667
  }
353
668
  }