@@ -477,7 +477,7 @@ public GSTheme Clone()
477477 public ThemeProto ToProto ( )
478478 {
479479 if ( PlanetType != EPlanetType . Gas ) AmbientSettings . ToTheme ( this ) ;
480- return new ThemeProto
480+ var tp = new ThemeProto
481481 {
482482 name = Name ,
483483 Name = Name ,
@@ -514,15 +514,17 @@ public ThemeProto ToProto()
514514 SFXPath = SFXPath ,
515515 SFXVolume = SFXVolume ,
516516 CullingRadius = CullingRadius ,
517- terrainMat = new Material [ ] { terrainMat } ,
518- oceanMat = new Material [ ] { oceanMat } ,
519- atmosMat = new Material [ ] { atmosMat } ,
520- thumbMat = new Material [ ] { thumbMat } ,
521- minimapMat = new Material [ ] { minimapMat } ,
522- ambientDesc = new AmbientDesc [ ] { ambientDesc } ,
523- ambientSfx = new AudioClip [ ] { ambientSfx } ,
517+
524518 ID = LDBThemeId
525519 } ;
520+ if ( terrainMat != null ) tp . terrainMat = new Material [ ] { terrainMat } ;
521+ if ( oceanMat != null ) tp . oceanMat = new Material [ ] { oceanMat } ;
522+ if ( atmosMat != null ) tp . atmosMat = new Material [ ] { atmosMat } ;
523+ if ( thumbMat != null ) tp . thumbMat = new Material [ ] { thumbMat } ;
524+ if ( minimapMat != null ) tp . minimapMat = new Material [ ] { minimapMat } ;
525+ if ( ambientDesc != null ) tp . ambientDesc = new AmbientDesc [ ] { ambientDesc } ;
526+ if ( ambientSfx != null ) tp . ambientSfx = new AudioClip [ ] { ambientSfx } ;
527+ return tp ;
526528 }
527529
528530 public int AddToThemeProtoSet ( )
@@ -555,7 +557,7 @@ public int UpdateThemeProtoSet()
555557
556558 private bool CreateMaterial ( GSMaterialSettings settings , out Material material )
557559 {
558- // GS2.Log("Start|" + Name);
560+ GS2 . Log ( "Start|" + Name ) ;
559561 var materialType = "terrain" ;
560562 if ( settings == oceanMaterial ) materialType = "ocean" ;
561563
@@ -570,33 +572,56 @@ private bool CreateMaterial(GSMaterialSettings settings, out Material material)
570572 //GS2.Log("Not Copying From Another Theme");
571573 Material tempMat ;
572574 if ( settings . Path == null )
575+ {
573576 //GS2.Log("Creating Material from MaterialPath Resource @ " + MaterialPath + materialType);
574- tempMat = Resources . Load < Material > ( MaterialPath + materialType ) ;
577+ //tempMat = Resources.Load<Material>(MaterialPath + materialType);
578+ var matArray = Utils . ResourcesLoadArray < Material > ( this . MaterialPath + materialType , "{0}-{1}" , true ) ;
579+ if ( matArray != null ) tempMat = matArray [ 0 ] ;
580+ else tempMat = null ;
581+ GS2 . Log ( ( tempMat == null ) . ToString ( ) ) ;
582+ }
575583 else
584+ {
576585 //GS2.Log("Creating Material from Settings Defined Resource @ " + settings.Path);
577- tempMat = Resources . Load < Material > ( settings . Path ) ;
586+ //tempMat = Resources.Load<Material>(settings.Path);
587+ var matArray = Utils . ResourcesLoadArray < Material > ( settings . Path , "{0}-{1}" , true ) ;
588+ if ( matArray != null ) tempMat = matArray [ 0 ] ;
589+ else tempMat = null ;
590+ GS2 . Log ( ( tempMat == null ) . ToString ( ) ) ;
591+ }
578592 if ( tempMat != null )
593+ {
579594 //GS2.Log("Creating Material");
580595 material = Object . Instantiate ( tempMat ) ;
596+ }
581597 else
582- // GS2.Log("Failed to Create Material|" + Name);
583- material = Resources . Load < Material > ( MaterialPath + materialType ) ;
598+ {
599+ //GS2.Log("Failed to Create Material|" + Name);
600+ //material = Resources.Load<Material>(MaterialPath + materialType);
601+ var matArray = Utils . ResourcesLoadArray < Material > ( this . MaterialPath + materialType , "{0}-{1}" , true ) ;
602+ if ( matArray != null ) material = matArray [ 0 ] ;
603+ else material = null ;
604+ }
584605 }
585606 else
586607 {
587- // GS2.Log($"Copying {materialType} from Theme: {settings.CopyFrom}");
608+ GS2 . Log ( $ "Copying { materialType } from Theme: { settings . CopyFrom } ") ;
588609 var copyFrom = settings . CopyFrom . Split ( '.' ) ;
589610 if ( copyFrom . Length != 2 || copyFrom [ 0 ] == null || copyFrom [ 0 ] == "" || copyFrom [ 1 ] == null || copyFrom [ 1 ] == "" )
590611 {
591612 GS2 . Error ( "Copyfrom Parameter for Theme Material cannot be parsed. Please ensure it is in the format ThemeName.terrainMat etc" ) ;
592- material = Resources . Load < Material > ( MaterialPath + materialType ) ;
613+ // material = Resources.Load<Material>(MaterialPath + materialType);
614+ var matArray = Utils . ResourcesLoadArray < Material > ( this . MaterialPath + materialType , "{0}-{1}" , true ) ;
615+ if ( matArray != null ) material = matArray [ 0 ] ;
616+ else material = null ;
593617 }
594618 else
595619 {
596620 //GS2.Warn($"Copying {Name} {materialType} material from Theme {settings.CopyFrom}");
597621 var materialBaseTheme = GSSettings . ThemeLibrary . Find ( copyFrom [ 0 ] ) ;
598622 var materialName = copyFrom [ 1 ] ;
599623 material = Object . Instantiate ( ( Material ) typeof ( GSTheme ) . GetField ( materialName ) . GetValue ( materialBaseTheme ) ) ;
624+ //material = Utils.ResourcesLoadArray<Material>(this.MaterialPath + materialType, "{0}-{1}", true)[0];
600625 }
601626 }
602627
@@ -607,7 +632,7 @@ private bool CreateMaterial(GSMaterialSettings settings, out Material material)
607632 var location = value [ 0 ] ;
608633 var path = value [ 1 ] ;
609634 var name = kvp . Key ;
610- // GS2.Log("Setting Texture " + name + " from " + location + " / " + path);
635+ GS2 . Log ( "Setting Texture " + name + " from " + location + " / " + path ) ;
611636 Texture tex = null ;
612637 if ( location == "GS2" ) tex = Utils . GetTextureFromBundle ( path ) ;
613638
@@ -618,12 +643,12 @@ private bool CreateMaterial(GSMaterialSettings settings, out Material material)
618643 if ( location == "BUNDLE" ) tex = Utils . GetTextureFromExternalBundle ( path ) ;
619644
620645 if ( tex == null )
621- GS2 . Error ( "Texture not found" ) ;
646+ GS2 . Error ( "Texture not found, or method not implemented " ) ;
622647 else
623- // GS2.Log("Assigning Texture");
624- material . SetTexture ( name , tex ) ;
648+ GS2 . Log ( "Assigning Texture" ) ;
649+ material . SetTexture ( name , tex ) ;
625650 }
626-
651+ //GS2.Warn($"Material null? {material == null}");
627652 return false ;
628653 }
629654
@@ -646,14 +671,19 @@ public void InitMaterials()
646671 {
647672 if ( AmbientSettings . ResourcePath != null && AmbientSettings . ResourcePath != "" )
648673 //GS2.Log("Loading AmbientDesc from AmbientSettings.ResourcePath" + AmbientSettings.ResourcePath);
649- Resources . Load < AmbientDesc > ( AmbientSettings . ResourcePath ) ;
674+ //Resources.Load<AmbientDesc>(AmbientSettings.ResourcePath);
675+ ambientDesc = Utils . ResourcesLoadArray < AmbientDesc > ( AmbientSettings . ResourcePath , "{0}-{1}" , true ) [ 0 ] ;
650676 else if ( ambient == null )
651677 //GS2.Log("Loading AmbientDesc from MaterialPath = " + MaterialPath + "ambient");
652- ambientDesc = Resources . Load < AmbientDesc > ( MaterialPath + "ambient" ) ;
678+ //ambientDesc = Resources.Load<AmbientDesc>(MaterialPath + "ambient");
679+ ambientDesc = Utils . ResourcesLoadArray < AmbientDesc > ( this . MaterialPath + "ambient" , "{0}-{1}" , true ) [ 0 ] ;
680+
681+
653682 else
654683 //GS2.Log("Loading AmbientDesc from base theme = "+ambient);
655684 ambientDesc = GSSettings . ThemeLibrary . Find ( ambient ) . ambientDesc ;
656- ambientSfx = Resources . Load < AudioClip > ( SFXPath ) ;
685+ //ambientSfx = Resources.Load<AudioClip>(SFXPath);
686+ ambientSfx = Utils . ResourcesLoadArray < AudioClip > ( this . SFXPath , "{0}-{1}" , true ) [ 0 ] ;
657687 }
658688
659689 initialized = true ;
0 commit comments