Skip to content

Commit 09988c3

Browse files
committed
[修改]1. 修改加载器的URL处理
1 parent 36f9c8a commit 09988c3

File tree

2 files changed

+133
-38
lines changed

2 files changed

+133
-38
lines changed

Runtime/UI/GLoader.cs

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GLoader : GObject, IAnimationGear, IColorGear
1515
/// </summary>
1616
public bool showErrorSign;
1717

18-
string _url;
18+
protected string _url;
1919
AlignType _align;
2020
VertAlignType _verticalAlign;
2121
bool _autoSize;
@@ -44,7 +44,7 @@ public GLoader()
4444
_reloadDelegate = OnExternalReload;
4545
}
4646

47-
override protected void CreateDisplayObject()
47+
protected override void CreateDisplayObject()
4848
{
4949
displayObject = new Container("GLoader");
5050
displayObject.gOwner = this;
@@ -53,9 +53,12 @@ override protected void CreateDisplayObject()
5353
((Container)displayObject).opaque = true;
5454
}
5555

56-
override public void Dispose()
56+
public override void Dispose()
5757
{
58-
if (_disposed) return;
58+
if (_disposed)
59+
{
60+
return;
61+
}
5962

6063
if (_content.texture != null)
6164
{
@@ -74,9 +77,15 @@ override public void Dispose()
7477
}
7578

7679
if (_errorSign != null)
80+
{
7781
_errorSign.Dispose();
82+
}
83+
7884
if (_content2 != null)
85+
{
7986
_content2.Dispose();
87+
}
88+
8089
_content.Dispose();
8190

8291
base.Dispose();
@@ -101,22 +110,37 @@ public bool useResize
101110
/// <summary>
102111
///
103112
/// </summary>
104-
public string url
113+
public virtual string url
105114
{
106115
get { return _url; }
107116
set
108117
{
118+
bool isClear = false;
109119
if (_url == value)
110-
return;
120+
{
121+
if (_content2 == null && (_content.texture == null || _content.texture.nativeTexture == null) && _content.frames == null)
122+
{
123+
ClearContent();
124+
isClear = true;
125+
}
126+
else
127+
{
128+
return;
129+
}
130+
}
131+
132+
if (!isClear)
133+
{
134+
ClearContent();
135+
}
111136

112-
ClearContent();
113137
_url = value;
114138
LoadContent();
115139
UpdateGear(7);
116140
}
117141
}
118142

119-
override public string icon
143+
public override string icon
120144
{
121145
get { return _url; }
122146
set { this.url = value; }
@@ -375,13 +399,13 @@ public NTexture texture
375399
}
376400
}
377401

378-
override public IFilter filter
402+
public override IFilter filter
379403
{
380404
get { return _content.filter; }
381405
set { _content.filter = value; }
382406
}
383407

384-
override public BlendMode blendMode
408+
public override BlendMode blendMode
385409
{
386410
get { return _content.blendMode; }
387411
set { _content.blendMode = value; }
@@ -395,12 +419,18 @@ protected void LoadContent()
395419
ClearContent();
396420

397421
if (string.IsNullOrEmpty(_url))
422+
{
398423
return;
424+
}
399425

400426
if (_url.StartsWith(UIPackage.URL_PREFIX))
427+
{
401428
LoadFromPackage(_url);
429+
}
402430
else
431+
{
403432
LoadExternal();
433+
}
404434
}
405435

406436
protected void LoadFromPackage(string itemURL)
@@ -462,10 +492,12 @@ protected void LoadFromPackage(string itemURL)
462492
}
463493
}
464494
else
495+
{
465496
SetErrorState();
497+
}
466498
}
467499

468-
virtual protected void LoadExternal()
500+
protected virtual void LoadExternal()
469501
{
470502
#if FAIRYGUI_PUERTS
471503
if (__loadExternal != null)
@@ -476,12 +508,16 @@ virtual protected void LoadExternal()
476508
#endif
477509
Texture2D tex = (Texture2D)Resources.Load(_url, typeof(Texture2D));
478510
if (tex != null)
511+
{
479512
onExternalLoadSuccess(new NTexture(tex));
513+
}
480514
else
515+
{
481516
onExternalLoadFailed();
517+
}
482518
}
483519

484-
virtual protected void FreeExternal(NTexture texture)
520+
protected virtual void FreeExternal(NTexture texture)
485521
{
486522
#if FAIRYGUI_PUERTS
487523
if (__freeExternal != null)
@@ -518,14 +554,20 @@ void OnExternalReload(NTexture texture)
518554
private void SetErrorState()
519555
{
520556
if (!showErrorSign || !Application.isPlaying)
557+
{
521558
return;
559+
}
522560

523561
if (_errorSign == null)
524562
{
525563
if (UIConfig.loaderErrorSign != null)
564+
{
526565
_errorSign = UIPackage.CreateObjectFromURL(UIConfig.loaderErrorSign);
566+
}
527567
else
568+
{
528569
return;
570+
}
529571
}
530572

531573
if (_errorSign != null)
@@ -538,7 +580,9 @@ private void SetErrorState()
538580
protected void ClearErrorState()
539581
{
540582
if (_errorSign != null && _errorSign.displayObject.parent != null)
583+
{
541584
((Container)displayObject).RemoveChild(_errorSign.displayObject);
585+
}
542586
}
543587

544588
protected void UpdateLayout()
@@ -562,9 +606,15 @@ protected void UpdateLayout()
562606
{
563607
_updatingLayout = true;
564608
if (contentWidth == 0)
609+
{
565610
contentWidth = 50;
611+
}
612+
566613
if (contentHeight == 0)
614+
{
567615
contentHeight = 30;
616+
}
617+
568618
SetSize(contentWidth, contentHeight);
569619

570620
_updatingLayout = false;
@@ -640,7 +690,9 @@ protected void UpdateLayout()
640690
_content2.SetSize(contentWidth, contentHeight, true);
641691
}
642692
else
693+
{
643694
_content2.SetScale(sx, sy);
695+
}
644696
}
645697
else
646698
{
@@ -650,21 +702,39 @@ protected void UpdateLayout()
650702
float nx;
651703
float ny;
652704
if (_align == AlignType.Center)
705+
{
653706
nx = (this.width - contentWidth) / 2;
707+
}
654708
else if (_align == AlignType.Right)
709+
{
655710
nx = this.width - contentWidth;
711+
}
656712
else
713+
{
657714
nx = 0;
715+
}
716+
658717
if (_verticalAlign == VertAlignType.Middle)
718+
{
659719
ny = (this.height - contentHeight) / 2;
720+
}
660721
else if (_verticalAlign == VertAlignType.Bottom)
722+
{
661723
ny = this.height - contentHeight;
724+
}
662725
else
726+
{
663727
ny = 0;
728+
}
729+
664730
if (_content2 != null)
731+
{
665732
_content2.SetXY(nx, ny);
733+
}
666734
else
735+
{
667736
_content.SetXY(nx, ny);
737+
}
668738

669739
InvalidateBatchingState();
670740
}
@@ -695,15 +765,17 @@ private void ClearContent()
695765
_contentItem = null;
696766
}
697767

698-
override protected void HandleSizeChanged()
768+
protected override void HandleSizeChanged()
699769
{
700770
base.HandleSizeChanged();
701771

702772
if (!_updatingLayout)
773+
{
703774
UpdateLayout();
775+
}
704776
}
705777

706-
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
778+
public override void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
707779
{
708780
base.Setup_BeforeAdd(buffer, beginPos);
709781

@@ -720,7 +792,10 @@ override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
720792
_content.frame = buffer.ReadInt();
721793

722794
if (buffer.ReadBool())
795+
{
723796
_content.color = buffer.ReadColor();
797+
}
798+
724799
_content.fillMethod = (FillMethod)buffer.ReadByte();
725800
if (_content.fillMethod != FillMethod.None)
726801
{
@@ -735,7 +810,9 @@ override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
735810
}
736811

737812
if (!string.IsNullOrEmpty(_url))
813+
{
738814
LoadContent();
815+
}
739816
}
740817
}
741818
}

0 commit comments

Comments
 (0)