SpriteText.Init C# (CSharp) Method

Init() protected method

protected Init ( ) : void
return void
	protected virtual void Init()
	{
		// Get our screen placer, if any:
		screenPlacer = (EZScreenPlacement)GetComponent(typeof(EZScreenPlacement));

		if (!Application.isPlaying)
		{
			if (screenPlacer != null)
				screenPlacer.SetCamera(renderCamera);
		}

		// Get a default font:
		if(font == null && UIManager.Exists())
			font = UIManager.instance.defaultFont;

		if (meshRenderer.sharedMaterial == null && UIManager.Exists())
		{
			meshRenderer.sharedMaterial = UIManager.instance.defaultFontMaterial;
			if (meshRenderer.sharedMaterial != null)
				texture = meshRenderer.sharedMaterial.mainTexture;
		}
		else
		{
			if (meshRenderer.sharedMaterial != null)
				texture = meshRenderer.sharedMaterial.mainTexture;
		}

#if WARN_ON_NO_MATERIAL
		if (texture == null && Application.isPlaying)
			Debug.LogWarning("Text on GameObject \"" + name + "\" has not been assigned either a texture or a material.");
#endif


		// Get the font:
		if (font != null)
		{
			spriteFont = FontStore.GetFont(font);

			if (spriteFont == null)
				Debug.LogWarning("Warning: " + name + " was unable to load font \"" + font.name + "\"!");
		}
		else if(Application.isPlaying)
			Debug.LogWarning("Warning: " + name + " currently has no font assigned.");

		if (mesh == null)
		{
			CreateMesh();
		}

		// If this mesh is to persist, prevent it from being
		// destroyed on load:
		if (persistent)
		{
			Persistent = true;
		}

		if (texture != null)
			SetPixelToUV(texture);

		// Build our tab expansion string:
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < tabSize; ++i)
		{
			sb.Append(' ');
		}
		tabSpaces = sb.ToString();
	}