コード例 #1
0
//--------------------------------------
コード例 #2
0
		/// <summary>Loads this font from the local project files. Should be a folder named after the font family and in it a series of font files.</summary>
		/// <returns>True if at least one font face was loaded.</returns>
		public bool LoadFaces(){
			
			// Load all .ttf/.otf files:
			object[] faces=Resources.LoadAll(Name,typeof(TextAsset));
			
			// For each font face..
			for(int i=0;i<faces.Length;i++){
				
				// Get the raw font face data:
				byte[] faceData=((TextAsset)faces[i]).bytes;
				
				if(faceData==null || faceData.Length==0){
					// It's a folder.
					continue;
				}
				
				// Load the font face - adds itself to the family within it if it's a valid font:
				try{
					
					FontFace loaded;
					
					if(Fonts.DeferLoad){
						loaded=FontLoader.DeferredLoad(faceData);
					}else{
						loaded=FontLoader.Load(faceData);
					}
					
					if(loaded!=null && Family==null){
						// Grab the family:
						Family=loaded.Family;
					}
					
				}catch{
					// Unity probably gave us a copyright file or something like that.
					// Generally the loader will catch this internally and return null.
				}
				
			}
			
			if(Family==null){
				return false;
			}
			
			Load();
			return true;
		}
コード例 #3
0
		/// <summary>Gets or creates a font family by name.</summary>
		public static FontFamily GetOrCreate(string name){
			
			FontFamily result=Get(name);
			
			if(result==null){
				
				if(Rasteriser==null){
					// Start now:
					Start();
				}
				
				result=new FontFamily(name);
				
				if(All==null){
					All=new Dictionary<string,FontFamily>();
				}
				
				All[name.ToLower()]=result;
				
			}
			
			return result;
		}