@@ -15,7 +15,7 @@ public class GLoader : GObject, IAnimationGear, IColorGear
15
15
/// </summary>
16
16
public bool showErrorSign ;
17
17
18
- string _url ;
18
+ protected string _url ;
19
19
AlignType _align ;
20
20
VertAlignType _verticalAlign ;
21
21
bool _autoSize ;
@@ -44,7 +44,7 @@ public GLoader()
44
44
_reloadDelegate = OnExternalReload ;
45
45
}
46
46
47
- override protected void CreateDisplayObject ( )
47
+ protected override void CreateDisplayObject ( )
48
48
{
49
49
displayObject = new Container ( "GLoader" ) ;
50
50
displayObject . gOwner = this ;
@@ -53,9 +53,12 @@ override protected void CreateDisplayObject()
53
53
( ( Container ) displayObject ) . opaque = true ;
54
54
}
55
55
56
- override public void Dispose ( )
56
+ public override void Dispose ( )
57
57
{
58
- if ( _disposed ) return ;
58
+ if ( _disposed )
59
+ {
60
+ return ;
61
+ }
59
62
60
63
if ( _content . texture != null )
61
64
{
@@ -74,9 +77,15 @@ override public void Dispose()
74
77
}
75
78
76
79
if ( _errorSign != null )
80
+ {
77
81
_errorSign . Dispose ( ) ;
82
+ }
83
+
78
84
if ( _content2 != null )
85
+ {
79
86
_content2 . Dispose ( ) ;
87
+ }
88
+
80
89
_content . Dispose ( ) ;
81
90
82
91
base . Dispose ( ) ;
@@ -101,22 +110,37 @@ public bool useResize
101
110
/// <summary>
102
111
///
103
112
/// </summary>
104
- public string url
113
+ public virtual string url
105
114
{
106
115
get { return _url ; }
107
116
set
108
117
{
118
+ bool isClear = false ;
109
119
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
+ }
111
136
112
- ClearContent ( ) ;
113
137
_url = value ;
114
138
LoadContent ( ) ;
115
139
UpdateGear ( 7 ) ;
116
140
}
117
141
}
118
142
119
- override public string icon
143
+ public override string icon
120
144
{
121
145
get { return _url ; }
122
146
set { this . url = value ; }
@@ -375,13 +399,13 @@ public NTexture texture
375
399
}
376
400
}
377
401
378
- override public IFilter filter
402
+ public override IFilter filter
379
403
{
380
404
get { return _content . filter ; }
381
405
set { _content . filter = value ; }
382
406
}
383
407
384
- override public BlendMode blendMode
408
+ public override BlendMode blendMode
385
409
{
386
410
get { return _content . blendMode ; }
387
411
set { _content . blendMode = value ; }
@@ -395,12 +419,18 @@ protected void LoadContent()
395
419
ClearContent ( ) ;
396
420
397
421
if ( string . IsNullOrEmpty ( _url ) )
422
+ {
398
423
return ;
424
+ }
399
425
400
426
if ( _url . StartsWith ( UIPackage . URL_PREFIX ) )
427
+ {
401
428
LoadFromPackage ( _url ) ;
429
+ }
402
430
else
431
+ {
403
432
LoadExternal ( ) ;
433
+ }
404
434
}
405
435
406
436
protected void LoadFromPackage ( string itemURL )
@@ -462,10 +492,12 @@ protected void LoadFromPackage(string itemURL)
462
492
}
463
493
}
464
494
else
495
+ {
465
496
SetErrorState ( ) ;
497
+ }
466
498
}
467
499
468
- virtual protected void LoadExternal ( )
500
+ protected virtual void LoadExternal ( )
469
501
{
470
502
#if FAIRYGUI_PUERTS
471
503
if ( __loadExternal != null )
@@ -476,12 +508,16 @@ virtual protected void LoadExternal()
476
508
#endif
477
509
Texture2D tex = ( Texture2D ) Resources . Load ( _url , typeof ( Texture2D ) ) ;
478
510
if ( tex != null )
511
+ {
479
512
onExternalLoadSuccess ( new NTexture ( tex ) ) ;
513
+ }
480
514
else
515
+ {
481
516
onExternalLoadFailed ( ) ;
517
+ }
482
518
}
483
519
484
- virtual protected void FreeExternal ( NTexture texture )
520
+ protected virtual void FreeExternal ( NTexture texture )
485
521
{
486
522
#if FAIRYGUI_PUERTS
487
523
if ( __freeExternal != null )
@@ -518,14 +554,20 @@ void OnExternalReload(NTexture texture)
518
554
private void SetErrorState ( )
519
555
{
520
556
if ( ! showErrorSign || ! Application . isPlaying )
557
+ {
521
558
return ;
559
+ }
522
560
523
561
if ( _errorSign == null )
524
562
{
525
563
if ( UIConfig . loaderErrorSign != null )
564
+ {
526
565
_errorSign = UIPackage . CreateObjectFromURL ( UIConfig . loaderErrorSign ) ;
566
+ }
527
567
else
568
+ {
528
569
return ;
570
+ }
529
571
}
530
572
531
573
if ( _errorSign != null )
@@ -538,7 +580,9 @@ private void SetErrorState()
538
580
protected void ClearErrorState ( )
539
581
{
540
582
if ( _errorSign != null && _errorSign . displayObject . parent != null )
583
+ {
541
584
( ( Container ) displayObject ) . RemoveChild ( _errorSign . displayObject ) ;
585
+ }
542
586
}
543
587
544
588
protected void UpdateLayout ( )
@@ -562,9 +606,15 @@ protected void UpdateLayout()
562
606
{
563
607
_updatingLayout = true ;
564
608
if ( contentWidth == 0 )
609
+ {
565
610
contentWidth = 50 ;
611
+ }
612
+
566
613
if ( contentHeight == 0 )
614
+ {
567
615
contentHeight = 30 ;
616
+ }
617
+
568
618
SetSize ( contentWidth , contentHeight ) ;
569
619
570
620
_updatingLayout = false ;
@@ -640,7 +690,9 @@ protected void UpdateLayout()
640
690
_content2 . SetSize ( contentWidth , contentHeight , true ) ;
641
691
}
642
692
else
693
+ {
643
694
_content2 . SetScale ( sx , sy ) ;
695
+ }
644
696
}
645
697
else
646
698
{
@@ -650,21 +702,39 @@ protected void UpdateLayout()
650
702
float nx ;
651
703
float ny ;
652
704
if ( _align == AlignType . Center )
705
+ {
653
706
nx = ( this . width - contentWidth ) / 2 ;
707
+ }
654
708
else if ( _align == AlignType . Right )
709
+ {
655
710
nx = this . width - contentWidth ;
711
+ }
656
712
else
713
+ {
657
714
nx = 0 ;
715
+ }
716
+
658
717
if ( _verticalAlign == VertAlignType . Middle )
718
+ {
659
719
ny = ( this . height - contentHeight ) / 2 ;
720
+ }
660
721
else if ( _verticalAlign == VertAlignType . Bottom )
722
+ {
661
723
ny = this . height - contentHeight ;
724
+ }
662
725
else
726
+ {
663
727
ny = 0 ;
728
+ }
729
+
664
730
if ( _content2 != null )
731
+ {
665
732
_content2 . SetXY ( nx , ny ) ;
733
+ }
666
734
else
735
+ {
667
736
_content . SetXY ( nx , ny ) ;
737
+ }
668
738
669
739
InvalidateBatchingState ( ) ;
670
740
}
@@ -695,15 +765,17 @@ private void ClearContent()
695
765
_contentItem = null ;
696
766
}
697
767
698
- override protected void HandleSizeChanged ( )
768
+ protected override void HandleSizeChanged ( )
699
769
{
700
770
base . HandleSizeChanged ( ) ;
701
771
702
772
if ( ! _updatingLayout )
773
+ {
703
774
UpdateLayout ( ) ;
775
+ }
704
776
}
705
777
706
- override public void Setup_BeforeAdd ( ByteBuffer buffer , int beginPos )
778
+ public override void Setup_BeforeAdd ( ByteBuffer buffer , int beginPos )
707
779
{
708
780
base . Setup_BeforeAdd ( buffer , beginPos ) ;
709
781
@@ -720,7 +792,10 @@ override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
720
792
_content . frame = buffer . ReadInt ( ) ;
721
793
722
794
if ( buffer . ReadBool ( ) )
795
+ {
723
796
_content . color = buffer . ReadColor ( ) ;
797
+ }
798
+
724
799
_content . fillMethod = ( FillMethod ) buffer . ReadByte ( ) ;
725
800
if ( _content . fillMethod != FillMethod . None )
726
801
{
@@ -735,7 +810,9 @@ override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
735
810
}
736
811
737
812
if ( ! string . IsNullOrEmpty ( _url ) )
813
+ {
738
814
LoadContent ( ) ;
815
+ }
739
816
}
740
817
}
741
818
}
0 commit comments