Example #1
0
    public void SetBaseOffset(TextAnchor anchor, TextDisplayAxis display_axis, TextAlignment alignment, List <TextSizeData> text_datas)
    {
        TextSizeData text_data = text_datas[m_progression_variables.m_line_value];

        m_base_offsets_setup = true;
        if (display_axis == TextDisplayAxis.HORIZONTAL)
        {
            m_base_offset += new Vector3(m_x_offset, -text_data.m_line_height_offset, 0);
        }
        else
        {
            m_base_offset += new Vector3(text_data.m_line_height_offset, 0, 0);
        }

        // Handle text y offset
        if (anchor == TextAnchor.MiddleLeft || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.MiddleRight)
        {
            m_text_anchoring_y_offset = (text_data.m_total_text_height / 2) - m_effect_manager_handle.FontBaseLine;
        }
        else if (anchor == TextAnchor.LowerLeft || anchor == TextAnchor.LowerCenter || anchor == TextAnchor.LowerRight)
        {
            m_text_anchoring_y_offset = text_data.m_total_text_height - text_data.m_text_line_height;
        }
        else
        {
            m_text_anchoring_y_offset = -m_effect_manager_handle.FontBaseLine;
        }


        float alignment_offset = 0;

        if (display_axis == TextDisplayAxis.HORIZONTAL)
        {
            if (alignment == TextAlignment.Center)
            {
                alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width) / 2;
            }
            else if (alignment == TextAlignment.Right)
            {
                alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width);
            }
        }
        else
        {
            if (alignment == TextAlignment.Center)
            {
                m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height) / 2;
            }
            else if (alignment == TextAlignment.Right)
            {
                m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height);
            }
        }

        // Handle text x offset
        if (anchor == TextAnchor.LowerRight || anchor == TextAnchor.MiddleRight || anchor == TextAnchor.UpperRight)
        {
            m_base_offset.x -= text_data.m_total_text_width - alignment_offset;
        }
        else if (anchor == TextAnchor.LowerCenter || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.UpperCenter)
        {
            m_base_offset.x -= (text_data.m_total_text_width / 2) - alignment_offset;
        }
        else
        {
            m_base_offset.x += alignment_offset;
        }
    }
Example #2
0
    public override void OnInspectorGUI()
    {
//		DrawDefaultInspector();

        font_manager = (EffectManager)target;

        m_old_text           = font_manager.m_text;
        m_old_display_axis   = font_manager.m_display_axis;
        m_old_text_anchor    = font_manager.m_text_anchor;
        m_old_text_alignment = font_manager.m_text_alignment;
        m_old_char_size      = font_manager.m_character_size;
        m_old_line_height    = font_manager.m_line_height;
        m_old_px_offset      = font_manager.m_px_offset;
        m_old_max_width      = font_manager.m_max_width;

        if (GUI.changed)
        {
            return;
        }

        EditorGUILayout.LabelField("Font Setup Data", EditorStyles.boldLabel);

#if !UNITY_3_5
        font_manager.m_font = EditorGUILayout.ObjectField(new GUIContent("Font (.ttf, .dfont, .otf)", "Your font file to use for this text."), font_manager.m_font, typeof(Font), true) as Font;
        if (GUI.changed && font_manager.m_font != null)
        {
            font_manager.gameObject.GetComponent <Renderer>().material = font_manager.m_font.material;
            font_manager.m_font_material = font_manager.m_font.material;
            font_manager.SetText(font_manager.m_text, true);
        }
#endif

        font_manager.m_font_data_file = EditorGUILayout.ObjectField(new GUIContent("Font Data File", "Your Bitmap font text data file."), font_manager.m_font_data_file, typeof(TextAsset), true) as TextAsset;
        if (GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
        {
            // Wipe the old character data hashtable
            font_manager.ClearFontCharacterData();
            font_manager.SetText(font_manager.m_text, true);
            return;
        }
        font_manager.m_font_material = EditorGUILayout.ObjectField(new GUIContent("Font Material", "Your Bitmap font material"), font_manager.m_font_material, typeof(Material), true) as Material;
        if (GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
        {
            // Reset the text with the new material assigned.
            font_manager.gameObject.GetComponent <Renderer>().material = font_manager.m_font_material;
            font_manager.SetText(font_manager.m_text, true);
            return;
        }
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField(new GUIContent("Text", "The text to display."), EditorStyles.boldLabel);
        font_manager.m_text = EditorGUILayout.TextArea(font_manager.m_text, GUILayout.Width(Screen.width - 25));
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Text Settings", EditorStyles.boldLabel);
        font_manager.m_display_axis   = (TextDisplayAxis)EditorGUILayout.EnumPopup(new GUIContent("Display Axis", "Denotes whether to render the text horizontally or vertically."), font_manager.m_display_axis);
        font_manager.m_text_anchor    = (TextAnchor)EditorGUILayout.EnumPopup(new GUIContent("Text Anchor", "Defines the anchor point about which the text is rendered"), font_manager.m_text_anchor);
        font_manager.m_text_alignment = (TextAlignment)EditorGUILayout.EnumPopup(new GUIContent("Text Alignment", "Defines the alignment of the text, just like your favourite word processor."), font_manager.m_text_alignment);
        font_manager.m_character_size = EditorGUILayout.FloatField(new GUIContent("Character Size", "Specifies the size of the text."), font_manager.m_character_size);
        font_manager.m_line_height    = EditorGUILayout.FloatField(new GUIContent("Line Height", "Defines the height of the text lines, based on the tallest line. If value is 2, the lines will be spaced at double the height of the tallest line."), font_manager.m_line_height);
        font_manager.m_px_offset      = EditorGUILayout.Vector2Field("Letter Spacing Offset", font_manager.m_px_offset);
        font_manager.m_max_width      = EditorGUILayout.FloatField(new GUIContent("Max Width", "Defines the maximum width of the text, and breaks the text onto new lines to keep it within this maximum."), font_manager.m_max_width);
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Effect Settings", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        font_manager.m_begin_on_start = EditorGUILayout.Toggle(new GUIContent("Play On Start", "Should this effect be automatically triggered when it's first started in the scene?"), font_manager.m_begin_on_start);
        if (font_manager.m_begin_on_start)
        {
            font_manager.m_begin_delay = EditorGUILayout.FloatField(new GUIContent("Delay", "How much the effect is delayed after first being started."), font_manager.m_begin_delay);
            if (font_manager.m_begin_delay < 0)
            {
                font_manager.m_begin_delay = 0;
            }
        }
        EditorGUILayout.EndHorizontal();
        font_manager.m_on_finish_action = (ON_FINISH_ACTION)EditorGUILayout.EnumPopup(new GUIContent("On Finish Action", "What should happen when the effect finishes?"), font_manager.m_on_finish_action);

        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button(!m_previewing_anim || m_paused ? "Play" : "Pause"))
        {
            if (m_previewing_anim)
            {
                m_paused = !m_paused;
            }
            else
            {
                m_previewing_anim = true;

                font_manager.PlayAnimation();
                m_paused = false;
            }

            m_old_time = Time.realtimeSinceStartup;
        }
        if (GUILayout.Button("Reset"))
        {
            m_paused          = true;
            m_previewing_anim = false;
            font_manager.ResetAnimation();
        }
        EditorGUILayout.EndHorizontal();

        // Render continue animation buttons
        if (font_manager.Playing)
        {
            EditorGUILayout.BeginHorizontal();

            if (font_manager.m_master_animations.Count > 1)
            {
                int continue_count = 0;
                foreach (LetterAnimation animation in font_manager.m_master_animations)
                {
                    if (animation.CurrentAnimationState == LETTER_ANIMATION_STATE.WAITING)
                    {
                        if (GUILayout.Button("Continue[" + (continue_count + 1) + "]"))
                        {
                            font_manager.ContinueAnimation(continue_count);
                        }
                    }
                    continue_count++;
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(font_manager);
        }

        if (m_old_char_size != font_manager.m_character_size ||
            m_old_display_axis != font_manager.m_display_axis ||
            m_old_line_height != font_manager.m_line_height ||
            m_old_max_width != font_manager.m_max_width ||
            !m_old_text.Equals(font_manager.m_text) ||
            m_old_text_alignment != font_manager.m_text_alignment ||
            m_old_text_anchor != font_manager.m_text_anchor ||
            m_old_px_offset != font_manager.m_px_offset)
        {
            font_manager.SetText(font_manager.m_text);
        }


        if (GUILayout.Button("Open Animation Editor"))
        {
            EditorWindow.GetWindow(typeof(TextEffectsManager));
        }
    }
		public override void OnInspectorGUI ()
		{
	//		DrawDefaultInspector();
			
			font_manager = (EffectManager)target;
			
			m_old_text = font_manager.m_text;
			m_old_display_axis = font_manager.m_display_axis;
			m_old_text_anchor = font_manager.m_text_anchor;
			m_old_text_alignment = font_manager.m_text_alignment;
			m_old_char_size = font_manager.m_character_size;
			m_old_line_height = font_manager.m_line_height_factor;
			m_old_px_offset = font_manager.m_px_offset;
			m_old_baseline_override = font_manager.m_override_font_baseline;
			m_old_font_baseline = font_manager.m_font_baseline_override;
			m_old_max_width = font_manager.m_max_width;
			
			if(GUI.changed)
			{
				return;
			}

			GUILayout.Space(10);

			EditorGUILayout.LabelField("Import Preset Effect", EditorStyles.boldLabel);

			EditorGUILayout.BeginHorizontal();
			m_selected_animation_idx = EditorGUILayout.Popup(m_selected_animation_idx, TextFxAnimationConfigs.m_config_list.GetArrayOfFirstEntries());

			if(GUI.changed)
			{
				EditorPrefs.SetInt("SelectedTextFxAnim", m_selected_animation_idx);
			}

			if(GUILayout.Button("Apply"))// && EditorUtility.DisplayDialog("Import TextFx Animation", "Are you sure you want to import this \"" + 
			                              //                               TextFxAnimationConfigs.m_config_list.GetArrayOfFirstEntries()[m_selected_animation_idx] +
			                              //                               "\" effect?", "Import", "Cancel"))
			{
				if(!TextFxAnimationConfigs.m_config_list[m_selected_animation_idx,1].Equals(""))
				{
					font_manager.ImportData(TextFxAnimationConfigs.m_config_list[m_selected_animation_idx,1]);
					Debug.Log("TextFx animation '" + TextFxAnimationConfigs.m_config_list[m_selected_animation_idx,0] + "' imported");
				}
			}
			EditorGUILayout.EndHorizontal();

			GUILayout.Space(10);


			
			EditorGUILayout.LabelField("Font Setup Data", EditorStyles.boldLabel);
			
	#if !UNITY_3_5
			font_manager.m_font = EditorGUILayout.ObjectField(new GUIContent("Font (.ttf, .dfont, .otf)", "Your font file to use for this text."), font_manager.m_font, typeof(Font), true) as Font;
			if(GUI.changed && font_manager.m_font != null)
			{
				font_manager.gameObject.GetComponent<Renderer>().material = font_manager.m_font.material;
				font_manager.m_font_material = font_manager.m_font.material;
				font_manager.SetText(font_manager.m_text, true);
			}
	#endif
			
			font_manager.m_font_data_file = EditorGUILayout.ObjectField(new GUIContent("Font Data File", "Your Bitmap font text data file."), font_manager.m_font_data_file, typeof(TextAsset), true) as TextAsset;
			if(GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
			{
				// Wipe the old character data hashtable
				font_manager.ClearFontCharacterData();
				font_manager.SetText(font_manager.m_text, true);
				return;
			}
			font_manager.m_font_material = EditorGUILayout.ObjectField(new GUIContent("Font Material", "Your Bitmap font material"), font_manager.m_font_material, typeof(Material), true) as Material;
			if(GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
			{
				// Reset the text with the new material assigned.
				font_manager.gameObject.GetComponent<Renderer>().material = font_manager.m_font_material;
				font_manager.SetText(font_manager.m_text, true);
				return;
			}
			EditorGUILayout.Separator();
			
			EditorGUILayout.LabelField(new GUIContent("Text", "The text to display."), EditorStyles.boldLabel);
			font_manager.m_text = EditorGUILayout.TextArea(font_manager.m_text, GUILayout.Width(Screen.width - 25));
			EditorGUILayout.Separator();
			
			EditorGUILayout.LabelField("Text Settings", EditorStyles.boldLabel);
			font_manager.m_display_axis = (TextDisplayAxis) EditorGUILayout.EnumPopup(new GUIContent("Display Axis", "Denotes whether to render the text horizontally or vertically."), font_manager.m_display_axis);
			font_manager.m_text_anchor = (TextAnchor) EditorGUILayout.EnumPopup(new GUIContent("Text Anchor", "Defines the anchor point about which the text is rendered"), font_manager.m_text_anchor);
			font_manager.m_text_alignment = (TextAlignment) EditorGUILayout.EnumPopup(new GUIContent("Text Alignment", "Defines the alignment of the text, just like your favourite word processor."), font_manager.m_text_alignment);
			font_manager.m_character_size = EditorGUILayout.FloatField(new GUIContent("Character Size", "Specifies the size of the text."), font_manager.m_character_size);
			font_manager.m_line_height_factor = EditorGUILayout.FloatField(new GUIContent("Line Height", "Defines the height of the text lines, based on the tallest line. If value is 2, the lines will be spaced at double the height of the tallest line."), font_manager.m_line_height_factor);
			EditorGUILayout.BeginHorizontal();
			font_manager.m_override_font_baseline = EditorGUILayout.Toggle(new GUIContent("Override Font Baseline?", "Allows you to manually set a baseline y-offset for the font to be rendered to."), font_manager.m_override_font_baseline);
			if(font_manager.m_override_font_baseline)
			{
				font_manager.m_font_baseline_override = EditorGUILayout.FloatField(new GUIContent("Font Baseline Offset", ""), font_manager.m_font_baseline_override);
			}
			EditorGUILayout.EndHorizontal();
			font_manager.m_px_offset = EditorGUILayout.Vector2Field("Letter Spacing Offset", font_manager.m_px_offset);
			font_manager.m_max_width = EditorGUILayout.FloatField(new GUIContent("Max Width", "Defines the maximum width of the text, and breaks the text onto new lines to keep it within this maximum."), font_manager.m_max_width);
			EditorGUILayout.Separator();
			
			EditorGUILayout.LabelField("Effect Settings", EditorStyles.boldLabel);
			EditorGUILayout.BeginHorizontal();
			font_manager.m_begin_on_start = EditorGUILayout.Toggle(new GUIContent("Play On Start", "Should this effect be automatically triggered when it's first started in the scene?"), font_manager.m_begin_on_start);
			if(font_manager.m_begin_on_start)
			{
				font_manager.m_begin_delay = EditorGUILayout.FloatField(new GUIContent("Delay", "How much the effect is delayed after first being started."), font_manager.m_begin_delay);
				if(font_manager.m_begin_delay < 0)
				{
					font_manager.m_begin_delay = 0;
				}
			}
			EditorGUILayout.EndHorizontal();
			font_manager.m_animation_speed_factor = EditorGUILayout.FloatField("Animation Speed Factor", font_manager.m_animation_speed_factor);
			font_manager.m_on_finish_action = (ON_FINISH_ACTION) EditorGUILayout.EnumPopup(new GUIContent("On Finish Action", "What should happen when the effect finishes?"), font_manager.m_on_finish_action);
			
			EditorGUILayout.Separator();
			EditorGUILayout.Separator();
			
			EditorGUILayout.BeginHorizontal();
			if(GUILayout.Button(!m_previewing_anim || m_paused ? "Play" : "Pause"))
			{
				if(m_previewing_anim)
				{
					m_paused = !m_paused;
					font_manager.Paused = m_paused;
				}
				else
				{
					m_previewing_anim = true;
					
					font_manager.PlayAnimation();
					m_paused = false;
					font_manager.Paused = false;
				}
			
				m_old_time = Time.realtimeSinceStartup;
			}
			if(GUILayout.Button("Reset"))
			{
				m_paused = false;
				m_previewing_anim = false;
				font_manager.ResetAnimation();
				
				SceneView.RepaintAll();
			}
			EditorGUILayout.EndHorizontal();
			
			// Render continue animation buttons
			if(font_manager.Playing)
			{
				EditorGUILayout.BeginHorizontal();
				
				if(font_manager.NumAnimations > 1)
				{
					int continue_count = 0;
					LetterAnimation animation;
					for(int anim_idx=0; anim_idx < font_manager.NumAnimations; anim_idx++)
					{
						animation = font_manager.GetAnimation(anim_idx);
						if(animation.CurrentAnimationState == LETTER_ANIMATION_STATE.WAITING)
						{
							if(GUILayout.Button("Continue[" + (continue_count+1) + "]"))
							{
								font_manager.ContinueAnimation(continue_count);
							}
						}
						continue_count ++;
					}
				}
				
				EditorGUILayout.EndHorizontal();
			}
			
			if (GUI.changed)
			{
				EditorUtility.SetDirty(font_manager);
			}
			
			if(m_old_char_size != font_manager.m_character_size ||
				m_old_display_axis != font_manager.m_display_axis ||
			   	m_old_line_height != font_manager.m_line_height_factor ||
				m_old_max_width != font_manager.m_max_width ||
				!m_old_text.Equals(font_manager.m_text)	||
				m_old_text_alignment != font_manager.m_text_alignment ||
				m_old_text_anchor != font_manager.m_text_anchor ||
				m_old_px_offset != font_manager.m_px_offset ||
				m_old_baseline_override != font_manager.m_override_font_baseline || 
				(font_manager.m_override_font_baseline && m_old_font_baseline != font_manager.m_font_baseline_override))
			{
				font_manager.SetText(font_manager.m_text);
			}

			GUILayout.Space(3);

			GUILayout.BeginHorizontal();
			GUIStyle style = new GUIStyle(EditorStyles.miniButton);

			if(GUILayout.Button(new GUIContent("Copy [S]", "Soft Copy this TextEffect animation configuration, not including any Text settings."), style))
			{
				string json_data = font_manager.ExportData();
				EditorGUIUtility.systemCopyBuffer = json_data;
				EditorPrefs.SetString("EffectExport", json_data);
				Debug.Log("Soft Copied " + font_manager.name);
			}
			if(GUILayout.Button(new GUIContent("Copy [H]", "Hard Copy this TextEffect animation configuration, including all Text settings."), style))
			{
				string json_data = font_manager.ExportData(hard_copy: true);
				EditorGUIUtility.systemCopyBuffer = json_data;
				EditorPrefs.SetString("EffectExport", json_data);
				Debug.Log("Hard Copied " + font_manager.name);
			}
			if(GUILayout.Button(new GUIContent("Paste", "Paste a copied TextEffect animation configuration onto this effect."), style))
			{
				if(EditorPrefs.HasKey("EffectExport"))
				{
					font_manager.ImportData(EditorPrefs.GetString("EffectExport"), true);
					Debug.Log("Pasted onto " + font_manager.name);
				}
			}
			GUILayout.EndHorizontal();

			GUILayout.Space(3);
			
			if (GUILayout.Button("Open Animation Editor"))
			{
				EditorWindow.GetWindow(typeof(TextEffectsManager));
			}
			
			if(font_manager.HasAudioParticleChildInstances)
			{
				GUILayout.Space(15);
				
				if (GUILayout.Button("Clear Audio/Particle Instances"))
				{
					font_manager.ClearCachedAudioParticleInstances();
				}
			}
		}
	public void ImportData(string data, bool force_clear_old_audio_particles = false)
	{
		if (force_clear_old_audio_particles)
			ClearCachedAudioParticleInstances(true);

		var json_data = JSONObject.Parse(data, true);

		if (json_data != null)
		{
			m_animate_per = (AnimatePerOptions)(int)json_data["m_animate_per"].Number;
			m_display_axis = (TextDisplayAxis)(int)json_data["m_display_axis"].Number;

			if (json_data.ContainsKey("m_begin_delay"))
				m_begin_delay = (float)json_data["m_begin_delay"].Number;
			if (json_data.ContainsKey("m_begin_on_start"))
				m_begin_on_start = json_data["m_begin_on_start"].Boolean;
			if (json_data.ContainsKey("m_character_size"))
				m_character_size = (float)json_data["m_character_size"].Number;
			if (json_data.ContainsKey("m_line_height"))
				m_line_height_factor = (float)json_data["m_line_height"].Number;
			if (json_data.ContainsKey("m_max_width"))
				m_max_width = (float)json_data["m_max_width"].Number;
			if (json_data.ContainsKey("m_on_finish_action"))
				m_on_finish_action = (ON_FINISH_ACTION)(int)json_data["m_on_finish_action"].Number;
			if (json_data.ContainsKey("m_px_offset"))
				m_px_offset = json_data["m_px_offset"].Obj.JSONtoVector2();
//			if(json_data.ContainsKey("m_text")) m_text = json_data["m_text"].Str;
			if (json_data.ContainsKey("m_text_alignment"))
				m_text_alignment = (TextAlignment)(int)json_data["m_text_alignment"].Number;
			if (json_data.ContainsKey("m_text_anchor"))
				m_text_anchor = (TextAnchor)(int)json_data["m_text_anchor"].Number;
			if (json_data.ContainsKey("m_time_type"))
				m_time_type = (AnimationTime)(int)json_data["m_time_type"].Number;

			m_master_animations = new List<LetterAnimation>();
			LetterAnimation letter_anim;
			foreach (var animation_data in json_data["LETTER_ANIMATIONS_DATA"].Array)
			{
				letter_anim = new LetterAnimation();
				letter_anim.ImportData(animation_data.Obj);
				m_master_animations.Add(letter_anim);
			}
		}
		else
		// Import string is not valid JSON, therefore assuming it is in the legacy data import format.
			this.ImportLegacyData(data);

		if (!Application.isPlaying && m_text.Equals(""))
			m_text = "TextFx";

		if (!m_text.Equals(""))
			SetText(m_text);

		ResetAnimation();
	}
        public override void OnInspectorGUI()
        {
            // Draw TextFx inspector section
            TextFxBaseInspector.DrawTextFxInspectorSection(this, animationManager);

//			DrawDefaultInspector();

            textfx_instance = (TextFxNative)target;

            m_old_text              = textfx_instance.m_text;
            m_old_display_axis      = textfx_instance.m_display_axis;
            m_old_text_anchor       = textfx_instance.m_text_anchor;
            m_old_text_alignment    = textfx_instance.m_text_alignment;
            m_old_char_size         = textfx_instance.m_character_size;
            m_old_textColour        = textfx_instance.m_textColour;
            m_old_vertexColour      = textfx_instance.m_textColourGradient.Clone();
            m_old_use_gradients     = textfx_instance.m_use_colour_gradient;
            m_old_textColour        = textfx_instance.m_textColour;
            m_old_line_height       = textfx_instance.m_line_height_factor;
            m_old_px_offset         = textfx_instance.m_px_offset;
            m_old_baseline_override = textfx_instance.m_override_font_baseline;
            m_old_font_baseline     = textfx_instance.m_font_baseline_override;
            m_old_max_width         = textfx_instance.m_max_width;

            if (GUI.changed)
            {
                return;
            }


            EditorGUILayout.LabelField("Font Setup Data", EditorStyles.boldLabel);

        #if !UNITY_3_5
            textfx_instance.m_font = EditorGUILayout.ObjectField(new GUIContent("Font (.ttf, .dfont, .otf)", "Your font file to use for this text."), textfx_instance.m_font, typeof(Font), true) as Font;
            if (GUI.changed && textfx_instance.m_font != null)
            {
                textfx_instance.gameObject.GetComponent <Renderer>().material = textfx_instance.m_font.material;
                textfx_instance.m_font_material = textfx_instance.m_font.material;
                textfx_instance.SetText(textfx_instance.m_text);
            }
        #endif

            textfx_instance.m_font_data_file = EditorGUILayout.ObjectField(new GUIContent("Font Data File", "Your Bitmap font text data file."), textfx_instance.m_font_data_file, typeof(TextAsset), true) as TextAsset;
            if (GUI.changed && textfx_instance.m_font_data_file != null && textfx_instance.m_font_material != null)
            {
                // Wipe the old character data hashtable
                textfx_instance.ClearFontCharacterData();
                textfx_instance.SetText(textfx_instance.m_text);
                return;
            }
            textfx_instance.m_font_material = EditorGUILayout.ObjectField(new GUIContent("Font Material", "Your Bitmap font material"), textfx_instance.m_font_material, typeof(Material), true) as Material;
            if (GUI.changed && textfx_instance.m_font_data_file != null && textfx_instance.m_font_material != null)
            {
                // Reset the text with the new material assigned.
                textfx_instance.gameObject.GetComponent <Renderer>().material = textfx_instance.m_font_material;
                textfx_instance.SetText(textfx_instance.m_text);
                return;
            }
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField(new GUIContent("Text", "The text to display."), EditorStyles.boldLabel);
            textfx_instance.m_text = EditorGUILayout.TextArea(textfx_instance.m_text, GUILayout.Width(Screen.width - 25));
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Text Settings", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();

            if (textfx_instance.m_use_colour_gradient)
            {
                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal();
                textfx_instance.m_textColourGradient.top_left  = EditorGUILayout.ColorField("Colour", textfx_instance.m_textColourGradient.top_left);
                textfx_instance.m_textColourGradient.top_right = EditorGUILayout.ColorField(textfx_instance.m_textColourGradient.top_right, GUILayout.Width(53));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                textfx_instance.m_textColourGradient.bottom_left  = EditorGUILayout.ColorField(" ", textfx_instance.m_textColourGradient.bottom_left);
                textfx_instance.m_textColourGradient.bottom_right = EditorGUILayout.ColorField(textfx_instance.m_textColourGradient.bottom_right, GUILayout.Width(53));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            else
            {
                textfx_instance.m_textColour = EditorGUILayout.ColorField("Colour", textfx_instance.m_textColour);                //, GUILayout.Width(260));
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.LabelField("Use Gradient?", GUILayout.Width(100));
            textfx_instance.m_use_colour_gradient = EditorGUILayout.Toggle(textfx_instance.m_use_colour_gradient, GUILayout.Width(20));
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            textfx_instance.m_display_axis       = (TextDisplayAxis)EditorGUILayout.EnumPopup(new GUIContent("Display Axis", "Denotes whether to render the text horizontally or vertically."), textfx_instance.m_display_axis);
            textfx_instance.m_text_anchor        = (TextAnchor)EditorGUILayout.EnumPopup(new GUIContent("Text Anchor", "Defines the anchor point about which the text is rendered"), textfx_instance.m_text_anchor);
            textfx_instance.m_text_alignment     = (TextAlignment)EditorGUILayout.EnumPopup(new GUIContent("Text Alignment", "Defines the alignment of the text, just like your favourite word processor."), textfx_instance.m_text_alignment);
            textfx_instance.m_character_size     = EditorGUILayout.FloatField(new GUIContent("Character Size", "Specifies the size of the text."), textfx_instance.m_character_size);
            textfx_instance.m_line_height_factor = EditorGUILayout.FloatField(new GUIContent("Line Height", "Defines the height of the text lines, based on the tallest line. If value is 2, the lines will be spaced at double the height of the tallest line."), textfx_instance.m_line_height_factor);

            EditorGUILayout.BeginHorizontal();
            textfx_instance.m_override_font_baseline = EditorGUILayout.Toggle(new GUIContent("Override Font Baseline?", "Allows you to manually set a baseline y-offset for the font to be rendered to."), textfx_instance.m_override_font_baseline);
            if (textfx_instance.m_override_font_baseline)
            {
                textfx_instance.m_font_baseline_override = EditorGUILayout.FloatField(new GUIContent("Font Baseline Offset", ""), textfx_instance.m_font_baseline_override);
            }
            EditorGUILayout.EndHorizontal();

            textfx_instance.m_px_offset = EditorGUILayout.Vector2Field("Letter Spacing Offset", textfx_instance.m_px_offset);
            textfx_instance.m_max_width = EditorGUILayout.FloatField(new GUIContent("Max Width", "Defines the maximum width of the text, and breaks the text onto new lines to keep it within this maximum."), textfx_instance.m_max_width);

            if (GUI.changed)
            {
                EditorUtility.SetDirty(textfx_instance);
            }

            if (m_old_char_size != textfx_instance.m_character_size ||
                m_old_textColour != textfx_instance.m_textColour ||
                !m_old_vertexColour.Equals(textfx_instance.m_textColourGradient) ||
                m_old_use_gradients != textfx_instance.m_use_colour_gradient ||
                m_old_display_axis != textfx_instance.m_display_axis ||
                m_old_line_height != textfx_instance.m_line_height_factor ||
                m_old_max_width != textfx_instance.m_max_width ||
                !m_old_text.Equals(textfx_instance.m_text) ||
                m_old_text_alignment != textfx_instance.m_text_alignment ||
                m_old_text_anchor != textfx_instance.m_text_anchor ||
                m_old_px_offset != textfx_instance.m_px_offset ||
                m_old_baseline_override != textfx_instance.m_override_font_baseline ||
                (textfx_instance.m_override_font_baseline && m_old_font_baseline != textfx_instance.m_font_baseline_override))
            {
                textfx_instance.SetText(textfx_instance.m_text);
            }
        }
Example #6
0
    public void SetBaseOffset(TextAnchor anchor, TextDisplayAxis display_axis, TextAlignment alignment, List <TextSizeData> text_datas)
    {
        SetupBaseOffsets(anchor, display_axis, alignment, text_datas[m_progression_variables.m_line_value]);

        m_base_offsets_setup = true;
    }
Example #7
0
    void SetupBaseOffsets(TextAnchor anchor, TextDisplayAxis display_axis, TextAlignment alignment, TextSizeData text_data)
    {
        if (display_axis == TextDisplayAxis.HORIZONTAL)
        {
            m_base_offset += new Vector3(m_x_offset, m_y_offset - text_data.m_line_height_offset, 0);
        }
        else
        {
            m_base_offset += new Vector3(text_data.m_line_height_offset, 0, 0);
        }

        m_base_offset.y -= text_data.m_y_max;

        // Handle text y offset
        if (anchor == TextAnchor.MiddleLeft || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.MiddleRight)
        {
            m_base_offset.y += text_data.m_total_text_height / 2;
        }
        else if (anchor == TextAnchor.LowerLeft || anchor == TextAnchor.LowerCenter || anchor == TextAnchor.LowerRight)
        {
            m_base_offset.y += text_data.m_total_text_height;
        }

        float alignment_offset = 0;

        if (display_axis == TextDisplayAxis.HORIZONTAL)
        {
            if (alignment == TextAlignment.Center)
            {
                alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width) / 2;
            }
            else if (alignment == TextAlignment.Right)
            {
                alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width);
            }
        }
        else
        {
            if (alignment == TextAlignment.Center)
            {
                m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height) / 2;
            }
            else if (alignment == TextAlignment.Right)
            {
                m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height);
            }
        }

        // Handle text x offset
        if (anchor == TextAnchor.LowerRight || anchor == TextAnchor.MiddleRight || anchor == TextAnchor.UpperRight)
        {
            m_base_offset.x -= text_data.m_total_text_width - alignment_offset;
        }
        else if (anchor == TextAnchor.LowerCenter || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.UpperCenter)
        {
            m_base_offset.x -= (text_data.m_total_text_width / 2) - alignment_offset;
        }
        else
        {
            m_base_offset.x += alignment_offset;
        }
    }
Example #8
0
    public void SetBaseOffset(TextAnchor anchor, TextDisplayAxis display_axis, TextAlignment alignment, List<TextSizeData> text_datas)
    {
        SetupBaseOffsets(anchor, display_axis, alignment, text_datas[m_progression_variables.m_line_value]);

        m_base_offsets_setup = true;
    }
Example #9
0
    void SetupBaseOffsets(TextAnchor anchor, TextDisplayAxis display_axis, TextAlignment alignment, TextSizeData text_data)
    {
        if(display_axis == TextDisplayAxis.HORIZONTAL)
        {
            m_base_offset += new Vector3(m_x_offset, m_y_offset - text_data.m_line_height_offset, 0);
        }
        else
        {
            m_base_offset += new Vector3(text_data.m_line_height_offset, 0, 0);
        }

        m_base_offset.y -= text_data.m_y_max;

        // Handle text y offset
        if(anchor == TextAnchor.MiddleLeft || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.MiddleRight)
        {
            m_base_offset.y += text_data.m_total_text_height / 2;
        }
        else if(anchor == TextAnchor.LowerLeft || anchor == TextAnchor.LowerCenter || anchor == TextAnchor.LowerRight)
        {
            m_base_offset.y += text_data.m_total_text_height;
        }

        float alignment_offset = 0;
        if(display_axis == TextDisplayAxis.HORIZONTAL)
        {
            if(alignment == TextAlignment.Center)
            {
                alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width) / 2;
            }
            else if(alignment == TextAlignment.Right)
            {
                alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width);
            }
        }
        else
        {
            if(alignment == TextAlignment.Center)
            {
                m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height) / 2;
            }
            else if(alignment == TextAlignment.Right)
            {
                m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height);
            }
        }

        // Handle text x offset
        if(anchor == TextAnchor.LowerRight || anchor == TextAnchor.MiddleRight || anchor == TextAnchor.UpperRight)
        {
            m_base_offset.x -= text_data.m_total_text_width - alignment_offset;
        }
        else if(anchor == TextAnchor.LowerCenter || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.UpperCenter)
        {
            m_base_offset.x -= (text_data.m_total_text_width/2) - alignment_offset;
        }
        else
        {
            m_base_offset.x += alignment_offset;
        }
    }
        public override void OnInspectorGUI()
        {
            //		DrawDefaultInspector();

            font_manager = (EffectManager)target;

            m_old_text              = font_manager.m_text;
            m_old_display_axis      = font_manager.m_display_axis;
            m_old_text_anchor       = font_manager.m_text_anchor;
            m_old_text_alignment    = font_manager.m_text_alignment;
            m_old_char_size         = font_manager.m_character_size;
            m_old_line_height       = font_manager.m_line_height_factor;
            m_old_px_offset         = font_manager.m_px_offset;
            m_old_baseline_override = font_manager.m_override_font_baseline;
            m_old_font_baseline     = font_manager.m_font_baseline_override;
            m_old_max_width         = font_manager.m_max_width;

            if (GUI.changed)
            {
                return;
            }

            GUILayout.Space(10);

            EditorGUILayout.LabelField("Import Preset Effect", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            m_selected_animation_idx = EditorGUILayout.Popup(m_selected_animation_idx, TextFxAnimationConfigs.m_config_list.GetArrayOfFirstEntries());

            if (GUI.changed)
            {
                EditorPrefs.SetInt("SelectedTextFxAnim", m_selected_animation_idx);
            }

            if (GUILayout.Button("Apply"))           // && EditorUtility.DisplayDialog("Import TextFx Animation", "Are you sure you want to import this \"" +
                                                     //                               TextFxAnimationConfigs.m_config_list.GetArrayOfFirstEntries()[m_selected_animation_idx] +
                                                     //                               "\" effect?", "Import", "Cancel"))
            {
                if (!TextFxAnimationConfigs.m_config_list[m_selected_animation_idx, 1].Equals(""))
                {
                    font_manager.ImportData(TextFxAnimationConfigs.m_config_list[m_selected_animation_idx, 1]);
                    Debug.Log("TextFx animation '" + TextFxAnimationConfigs.m_config_list[m_selected_animation_idx, 0] + "' imported");
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);



            EditorGUILayout.LabelField("Font Setup Data", EditorStyles.boldLabel);

        #if !UNITY_3_5
            font_manager.m_font = EditorGUILayout.ObjectField(new GUIContent("Font (.ttf, .dfont, .otf)", "Your font file to use for this text."), font_manager.m_font, typeof(Font), true) as Font;
            if (GUI.changed && font_manager.m_font != null)
            {
                font_manager.gameObject.GetComponent <Renderer>().material = font_manager.m_font.material;
                font_manager.m_font_material = font_manager.m_font.material;
                font_manager.SetText(font_manager.m_text, true);
            }
        #endif

            font_manager.m_font_data_file = EditorGUILayout.ObjectField(new GUIContent("Font Data File", "Your Bitmap font text data file."), font_manager.m_font_data_file, typeof(TextAsset), true) as TextAsset;
            if (GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
            {
                // Wipe the old character data hashtable
                font_manager.ClearFontCharacterData();
                font_manager.SetText(font_manager.m_text, true);
                return;
            }
            font_manager.m_font_material = EditorGUILayout.ObjectField(new GUIContent("Font Material", "Your Bitmap font material"), font_manager.m_font_material, typeof(Material), true) as Material;
            if (GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
            {
                // Reset the text with the new material assigned.
                font_manager.gameObject.GetComponent <Renderer>().material = font_manager.m_font_material;
                font_manager.SetText(font_manager.m_text, true);
                return;
            }
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField(new GUIContent("Text", "The text to display."), EditorStyles.boldLabel);
            font_manager.m_text = EditorGUILayout.TextArea(font_manager.m_text, GUILayout.Width(Screen.width - 25));
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Text Settings", EditorStyles.boldLabel);
            font_manager.m_display_axis       = (TextDisplayAxis)EditorGUILayout.EnumPopup(new GUIContent("Display Axis", "Denotes whether to render the text horizontally or vertically."), font_manager.m_display_axis);
            font_manager.m_text_anchor        = (TextAnchor)EditorGUILayout.EnumPopup(new GUIContent("Text Anchor", "Defines the anchor point about which the text is rendered"), font_manager.m_text_anchor);
            font_manager.m_text_alignment     = (TextAlignment)EditorGUILayout.EnumPopup(new GUIContent("Text Alignment", "Defines the alignment of the text, just like your favourite word processor."), font_manager.m_text_alignment);
            font_manager.m_character_size     = EditorGUILayout.FloatField(new GUIContent("Character Size", "Specifies the size of the text."), font_manager.m_character_size);
            font_manager.m_line_height_factor = EditorGUILayout.FloatField(new GUIContent("Line Height", "Defines the height of the text lines, based on the tallest line. If value is 2, the lines will be spaced at double the height of the tallest line."), font_manager.m_line_height_factor);
            EditorGUILayout.BeginHorizontal();
            font_manager.m_override_font_baseline = EditorGUILayout.Toggle(new GUIContent("Override Font Baseline?", "Allows you to manually set a baseline y-offset for the font to be rendered to."), font_manager.m_override_font_baseline);
            if (font_manager.m_override_font_baseline)
            {
                font_manager.m_font_baseline_override = EditorGUILayout.FloatField(new GUIContent("Font Baseline Offset", ""), font_manager.m_font_baseline_override);
            }
            EditorGUILayout.EndHorizontal();
            font_manager.m_px_offset = EditorGUILayout.Vector2Field("Letter Spacing Offset", font_manager.m_px_offset);
            font_manager.m_max_width = EditorGUILayout.FloatField(new GUIContent("Max Width", "Defines the maximum width of the text, and breaks the text onto new lines to keep it within this maximum."), font_manager.m_max_width);
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Effect Settings", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();
            font_manager.m_begin_on_start = EditorGUILayout.Toggle(new GUIContent("Play On Start", "Should this effect be automatically triggered when it's first started in the scene?"), font_manager.m_begin_on_start);
            if (font_manager.m_begin_on_start)
            {
                font_manager.m_begin_delay = EditorGUILayout.FloatField(new GUIContent("Delay", "How much the effect is delayed after first being started."), font_manager.m_begin_delay);
                if (font_manager.m_begin_delay < 0)
                {
                    font_manager.m_begin_delay = 0;
                }
            }
            EditorGUILayout.EndHorizontal();
            font_manager.m_animation_speed_factor = EditorGUILayout.FloatField("Animation Speed Factor", font_manager.m_animation_speed_factor);
            font_manager.m_on_finish_action       = (ON_FINISH_ACTION)EditorGUILayout.EnumPopup(new GUIContent("On Finish Action", "What should happen when the effect finishes?"), font_manager.m_on_finish_action);

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(!m_previewing_anim || m_paused ? "Play" : "Pause"))
            {
                if (m_previewing_anim)
                {
                    m_paused            = !m_paused;
                    font_manager.Paused = m_paused;
                }
                else
                {
                    m_previewing_anim = true;

                    font_manager.PlayAnimation();
                    m_paused            = false;
                    font_manager.Paused = false;
                }

                m_old_time = Time.realtimeSinceStartup;
            }
            if (GUILayout.Button("Reset"))
            {
                m_paused          = false;
                m_previewing_anim = false;
                font_manager.ResetAnimation();

                SceneView.RepaintAll();
            }
            EditorGUILayout.EndHorizontal();

            // Render continue animation buttons
            if (font_manager.Playing)
            {
                EditorGUILayout.BeginHorizontal();

                if (font_manager.NumAnimations > 1)
                {
                    int             continue_count = 0;
                    LetterAnimation animation;
                    for (int anim_idx = 0; anim_idx < font_manager.NumAnimations; anim_idx++)
                    {
                        animation = font_manager.GetAnimation(anim_idx);
                        if (animation.CurrentAnimationState == LETTER_ANIMATION_STATE.WAITING)
                        {
                            if (GUILayout.Button("Continue[" + (continue_count + 1) + "]"))
                            {
                                font_manager.ContinueAnimation(continue_count);
                            }
                        }
                        continue_count++;
                    }
                }

                EditorGUILayout.EndHorizontal();
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(font_manager);
            }

            if (m_old_char_size != font_manager.m_character_size ||
                m_old_display_axis != font_manager.m_display_axis ||
                m_old_line_height != font_manager.m_line_height_factor ||
                m_old_max_width != font_manager.m_max_width ||
                !m_old_text.Equals(font_manager.m_text) ||
                m_old_text_alignment != font_manager.m_text_alignment ||
                m_old_text_anchor != font_manager.m_text_anchor ||
                m_old_px_offset != font_manager.m_px_offset ||
                m_old_baseline_override != font_manager.m_override_font_baseline ||
                (font_manager.m_override_font_baseline && m_old_font_baseline != font_manager.m_font_baseline_override))
            {
                font_manager.SetText(font_manager.m_text);
            }

            GUILayout.Space(3);

            GUILayout.BeginHorizontal();
            GUIStyle style = new GUIStyle(EditorStyles.miniButton);

            if (GUILayout.Button(new GUIContent("Copy [S]", "Soft Copy this TextEffect animation configuration, not including any Text settings."), style))
            {
                string json_data = font_manager.ExportData();
                EditorGUIUtility.systemCopyBuffer = json_data;
                EditorPrefs.SetString("EffectExport", json_data);
                Debug.Log("Soft Copied " + font_manager.name);
            }
            if (GUILayout.Button(new GUIContent("Copy [H]", "Hard Copy this TextEffect animation configuration, including all Text settings."), style))
            {
                string json_data = font_manager.ExportData(hard_copy: true);
                EditorGUIUtility.systemCopyBuffer = json_data;
                EditorPrefs.SetString("EffectExport", json_data);
                Debug.Log("Hard Copied " + font_manager.name);
            }
            if (GUILayout.Button(new GUIContent("Paste", "Paste a copied TextEffect animation configuration onto this effect."), style))
            {
                if (EditorPrefs.HasKey("EffectExport"))
                {
                    font_manager.ImportData(EditorPrefs.GetString("EffectExport"), true);
                    Debug.Log("Pasted onto " + font_manager.name);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(3);

            if (GUILayout.Button("Open Animation Editor"))
            {
                EditorWindow.GetWindow(typeof(TextEffectsManager));
            }

            if (font_manager.HasAudioParticleChildInstances)
            {
                GUILayout.Space(15);

                if (GUILayout.Button("Clear Audio/Particle Instances"))
                {
                    font_manager.ClearCachedAudioParticleInstances();
                }
            }
        }
Example #11
0
		// Calculates the amount that the whole text block needs to be offset in order to adhere to the anchor and text-alignment settings
		Vector3 CalculateTextPositionalOffset(TextAnchor anchor, TextDisplayAxis display_axis, TextAlignment alignment, float line_width)
		{
			Vector3 text_positional_offset = Vector3.zero;
			
			// Handle text y offset
			if(anchor == TextAnchor.MiddleLeft || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.MiddleRight)
			{
				text_positional_offset += new Vector3(0, (m_total_text_height / 2) - FontBaseLine, 0);
			}
			else if(anchor == TextAnchor.LowerLeft || anchor == TextAnchor.LowerCenter || anchor == TextAnchor.LowerRight)
			{
				text_positional_offset += new Vector3(0, m_total_text_height - m_line_height, 0);
			}
			else
			{
				text_positional_offset += new Vector3(0, -FontBaseLine, 0);
			}
			
			
			float alignment_offset = 0;
			if(display_axis == TextDisplayAxis.HORIZONTAL)
			{
				if(alignment == TextAlignment.Center)
				{
					alignment_offset = (m_total_text_width - line_width) / 2;
				}
				else if(alignment == TextAlignment.Right)
				{
					alignment_offset = (m_total_text_width - line_width);
				}
			}
			else
			{
				if(alignment == TextAlignment.Center)
				{
					text_positional_offset -= new Vector3(0, (m_total_text_height - m_line_height) / 2, 0);
					
				}
				else if(alignment == TextAlignment.Right)
				{
					text_positional_offset -= new Vector3(0, (m_total_text_height - m_line_height), 0);
				}
			}
			
			// Handle text x offset
			if(anchor == TextAnchor.LowerRight || anchor == TextAnchor.MiddleRight || anchor == TextAnchor.UpperRight)
			{
				text_positional_offset -= new Vector3(m_total_text_width - alignment_offset, 0, 0);
			}
			else if(anchor == TextAnchor.LowerCenter || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.UpperCenter)
			{
				text_positional_offset -= new Vector3((m_total_text_width/2) - alignment_offset, 0, 0);
			}
			else
			{
				text_positional_offset += new Vector3(alignment_offset, 0, 0);
			}
			
			return text_positional_offset;
		}
    public override void OnInspectorGUI()
    {
        //		DrawDefaultInspector();

        font_manager = (EffectManager)target;

        m_old_text = font_manager.m_text;
        m_old_display_axis = font_manager.m_display_axis;
        m_old_text_anchor = font_manager.m_text_anchor;
        m_old_text_alignment = font_manager.m_text_alignment;
        m_old_char_size = font_manager.m_character_size;
        m_old_line_height = font_manager.m_line_height;
        m_old_px_offset = font_manager.m_px_offset;
        m_old_max_width = font_manager.m_max_width;

        if(GUI.changed)
        {
            return;
        }

        EditorGUILayout.LabelField("Font Setup Data", EditorStyles.boldLabel);

        #if !UNITY_3_5
        font_manager.m_font = EditorGUILayout.ObjectField(new GUIContent("Font (.ttf, .dfont, .otf)", "Your font file to use for this text."), font_manager.m_font, typeof(Font), true) as Font;
        if(GUI.changed && font_manager.m_font != null)
        {
            font_manager.gameObject.GetComponent<Renderer>().material = font_manager.m_font.material;
            font_manager.m_font_material = font_manager.m_font.material;
            font_manager.SetText(font_manager.m_text, true);
        }
        #endif

        font_manager.m_font_data_file = EditorGUILayout.ObjectField(new GUIContent("Font Data File", "Your Bitmap font text data file."), font_manager.m_font_data_file, typeof(TextAsset), true) as TextAsset;
        if(GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
        {
            // Wipe the old character data hashtable
            font_manager.ClearFontCharacterData();
            font_manager.SetText(font_manager.m_text, true);
            return;
        }
        font_manager.m_font_material = EditorGUILayout.ObjectField(new GUIContent("Font Material", "Your Bitmap font material"), font_manager.m_font_material, typeof(Material), true) as Material;
        if(GUI.changed && font_manager.m_font_data_file != null && font_manager.m_font_material != null)
        {
            // Reset the text with the new material assigned.
            font_manager.gameObject.GetComponent<Renderer>().material = font_manager.m_font_material;
            font_manager.SetText(font_manager.m_text, true);
            return;
        }
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField(new GUIContent("Text", "The text to display."), EditorStyles.boldLabel);
        font_manager.m_text = EditorGUILayout.TextArea(font_manager.m_text, GUILayout.Width(Screen.width - 25));
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Text Settings", EditorStyles.boldLabel);
        font_manager.m_display_axis = (TextDisplayAxis) EditorGUILayout.EnumPopup(new GUIContent("Display Axis", "Denotes whether to render the text horizontally or vertically."), font_manager.m_display_axis);
        font_manager.m_text_anchor = (TextAnchor) EditorGUILayout.EnumPopup(new GUIContent("Text Anchor", "Defines the anchor point about which the text is rendered"), font_manager.m_text_anchor);
        font_manager.m_text_alignment = (TextAlignment) EditorGUILayout.EnumPopup(new GUIContent("Text Alignment", "Defines the alignment of the text, just like your favourite word processor."), font_manager.m_text_alignment);
        font_manager.m_character_size = EditorGUILayout.FloatField(new GUIContent("Character Size", "Specifies the size of the text."), font_manager.m_character_size);
        font_manager.m_line_height = EditorGUILayout.FloatField(new GUIContent("Line Height", "Defines the height of the text lines, based on the tallest line. If value is 2, the lines will be spaced at double the height of the tallest line."), font_manager.m_line_height);
        font_manager.m_px_offset = EditorGUILayout.Vector2Field("Letter Spacing Offset", font_manager.m_px_offset);
        font_manager.m_max_width = EditorGUILayout.FloatField(new GUIContent("Max Width", "Defines the maximum width of the text, and breaks the text onto new lines to keep it within this maximum."), font_manager.m_max_width);
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Effect Settings", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        font_manager.m_begin_on_start = EditorGUILayout.Toggle(new GUIContent("Play On Start", "Should this effect be automatically triggered when it's first started in the scene?"), font_manager.m_begin_on_start);
        if(font_manager.m_begin_on_start)
        {
            font_manager.m_begin_delay = EditorGUILayout.FloatField(new GUIContent("Delay", "How much the effect is delayed after first being started."), font_manager.m_begin_delay);
            if(font_manager.m_begin_delay < 0)
            {
                font_manager.m_begin_delay = 0;
            }
        }
        EditorGUILayout.EndHorizontal();
        font_manager.m_on_finish_action = (ON_FINISH_ACTION) EditorGUILayout.EnumPopup(new GUIContent("On Finish Action", "What should happen when the effect finishes?"), font_manager.m_on_finish_action);

        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        if(GUILayout.Button(!m_previewing_anim || m_paused ? "Play" : "Pause"))
        {
            if(m_previewing_anim)
            {
                m_paused = !m_paused;
            }
            else
            {
                m_previewing_anim = true;

                font_manager.PlayAnimation();
                m_paused = false;
            }

            m_old_time = Time.realtimeSinceStartup;
        }
        if(GUILayout.Button("Reset"))
        {
            m_paused = true;
            m_previewing_anim = false;
            font_manager.ResetAnimation();
        }
        EditorGUILayout.EndHorizontal();

        // Render continue animation buttons
        if(font_manager.Playing)
        {
            EditorGUILayout.BeginHorizontal();

            if(font_manager.m_master_animations.Count > 1)
            {
                int continue_count = 0;
                foreach(LetterAnimation animation in font_manager.m_master_animations)
                {
                    if(animation.CurrentAnimationState == LETTER_ANIMATION_STATE.WAITING)
                    {
                        if(GUILayout.Button("Continue[" + (continue_count+1) + "]"))
                        {
                            font_manager.ContinueAnimation(continue_count);
                        }
                    }
                    continue_count ++;
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(font_manager);
        }

        if(m_old_char_size != font_manager.m_character_size ||
            m_old_display_axis != font_manager.m_display_axis ||
            m_old_line_height != font_manager.m_line_height ||
            m_old_max_width != font_manager.m_max_width ||
            !m_old_text.Equals(font_manager.m_text)	||
            m_old_text_alignment != font_manager.m_text_alignment ||
            m_old_text_anchor != font_manager.m_text_anchor ||
            m_old_px_offset != font_manager.m_px_offset)
        {
            font_manager.SetText(font_manager.m_text);
        }

        if (GUILayout.Button("Open Animation Editor"))
        {
            EditorWindow.GetWindow(typeof(TextEffectsManager));
        }
    }
Example #13
0
		public void SetBaseOffset(TextAnchor anchor, TextDisplayAxis display_axis, TextAlignment alignment, List<TextSizeData> text_datas)
		{
			TextSizeData text_data = text_datas[m_progression_variables.m_line_value];
				
			m_base_offsets_setup = true;
			if(display_axis == TextDisplayAxis.HORIZONTAL)
			{
				m_base_offset += new Vector3(m_x_offset, -m_progression_variables.m_line_value * m_effect_manager_handle.LineHeight, 0);
			}
			else
			{
				m_base_offset += new Vector3(m_progression_variables.m_line_value * m_effect_manager_handle.LineHeight, 0, 0);
			}
			
			// Handle text y offset
			if(anchor == TextAnchor.MiddleLeft || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.MiddleRight)
			{
				m_text_anchoring_y_offset = (text_data.m_total_text_height / 2) - m_effect_manager_handle.FontBaseLine;
			}
			else if(anchor == TextAnchor.LowerLeft || anchor == TextAnchor.LowerCenter || anchor == TextAnchor.LowerRight)
			{
				m_text_anchoring_y_offset = text_data.m_total_text_height - text_data.m_text_line_height;
			}
			else
			{
				m_text_anchoring_y_offset = -m_effect_manager_handle.FontBaseLine;
			}
			
			
			float alignment_offset = 0;
			if(display_axis == TextDisplayAxis.HORIZONTAL)
			{
				if(alignment == TextAlignment.Center)
				{
					alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width) / 2;
				}
				else if(alignment == TextAlignment.Right)
				{
					alignment_offset = (text_data.m_total_text_width - text_data.m_text_line_width);
				}
			}
			else
			{
				if(alignment == TextAlignment.Center)
				{
					m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height) / 2;
				}
				else if(alignment == TextAlignment.Right)
				{
					m_base_offset.y -= (text_data.m_total_text_height - text_data.m_text_line_height);
				}
			}
			
			// Handle text x offset
			if(anchor == TextAnchor.LowerRight || anchor == TextAnchor.MiddleRight || anchor == TextAnchor.UpperRight)
			{
				m_base_offset.x -= text_data.m_total_text_width - alignment_offset;
			}
			else if(anchor == TextAnchor.LowerCenter || anchor == TextAnchor.MiddleCenter || anchor == TextAnchor.UpperCenter)
			{
				m_base_offset.x -= (text_data.m_total_text_width/2) - alignment_offset;
			}
			else
			{
				m_base_offset.x += alignment_offset;
			}
		}
		public override void OnInspectorGUI ()
		{
//			DrawDefaultInspector();
			
			textfx_instance = (TextFxNative)target;
			
			m_old_text = textfx_instance.m_text;
			m_old_display_axis = textfx_instance.m_display_axis;
			m_old_text_anchor = textfx_instance.m_text_anchor;
			m_old_text_alignment = textfx_instance.m_text_alignment;
			m_old_char_size = textfx_instance.m_character_size;
			m_old_textColour = textfx_instance.m_textColour;
			m_old_vertexColour = textfx_instance.m_textColourGradient.Clone();
			m_old_use_gradients = textfx_instance.m_use_colour_gradient;
			m_old_textColour = textfx_instance.m_textColour;
			m_old_line_height = textfx_instance.m_line_height_factor;
			m_old_px_offset = textfx_instance.m_px_offset;
			m_old_baseline_override = textfx_instance.m_override_font_baseline;
			m_old_font_baseline = textfx_instance.m_font_baseline_override;
			m_old_max_width = textfx_instance.m_max_width;
			
			if(GUI.changed)
			{
				return;
			}

			
			EditorGUILayout.LabelField("Font Setup Data", EditorStyles.boldLabel);
			
	#if !UNITY_3_5
			textfx_instance.m_font = EditorGUILayout.ObjectField(new GUIContent("Font (.ttf, .dfont, .otf)", "Your font file to use for this text."), textfx_instance.m_font, typeof(Font), true) as Font;
			if(GUI.changed && textfx_instance.m_font != null)
			{
				textfx_instance.gameObject.GetComponent<Renderer>().material = textfx_instance.m_font.material;
				textfx_instance.m_font_material = textfx_instance.m_font.material;
				textfx_instance.SetText(textfx_instance.m_text);
			}
	#endif
			
			textfx_instance.m_font_data_file = EditorGUILayout.ObjectField(new GUIContent("Font Data File", "Your Bitmap font text data file."), textfx_instance.m_font_data_file, typeof(TextAsset), true) as TextAsset;
			if(GUI.changed && textfx_instance.m_font_data_file != null && textfx_instance.m_font_material != null)
			{
				// Wipe the old character data hashtable
				textfx_instance.ClearFontCharacterData();
				textfx_instance.SetText(textfx_instance.m_text);
				return;
			}
			textfx_instance.m_font_material = EditorGUILayout.ObjectField(new GUIContent("Font Material", "Your Bitmap font material"), textfx_instance.m_font_material, typeof(Material), true) as Material;
			if(GUI.changed && textfx_instance.m_font_data_file != null && textfx_instance.m_font_material != null)
			{
				// Reset the text with the new material assigned.
				textfx_instance.gameObject.GetComponent<Renderer>().material = textfx_instance.m_font_material;
				textfx_instance.SetText(textfx_instance.m_text);
				return;
			}
			EditorGUILayout.Separator();
			
			EditorGUILayout.LabelField(new GUIContent("Text", "The text to display."), EditorStyles.boldLabel);
			textfx_instance.m_text = EditorGUILayout.TextArea(textfx_instance.m_text, GUILayout.Width(Screen.width - 25));
			EditorGUILayout.Separator();
			
			EditorGUILayout.LabelField("Text Settings", EditorStyles.boldLabel);
			EditorGUILayout.BeginHorizontal ();

			if(textfx_instance.m_use_colour_gradient)
			{
				EditorGUILayout.BeginVertical ();
				EditorGUILayout.BeginHorizontal ();
				textfx_instance.m_textColourGradient.top_left = EditorGUILayout.ColorField("Colour", textfx_instance.m_textColourGradient.top_left);
				textfx_instance.m_textColourGradient.top_right = EditorGUILayout.ColorField(textfx_instance.m_textColourGradient.top_right, GUILayout.Width(53));
				EditorGUILayout.EndHorizontal ();
				EditorGUILayout.BeginHorizontal ();
				textfx_instance.m_textColourGradient.bottom_left = EditorGUILayout.ColorField(" ", textfx_instance.m_textColourGradient.bottom_left);
				textfx_instance.m_textColourGradient.bottom_right = EditorGUILayout.ColorField(textfx_instance.m_textColourGradient.bottom_right, GUILayout.Width(53));
				EditorGUILayout.EndHorizontal ();
				EditorGUILayout.EndVertical ();
			}
			else
			{
				textfx_instance.m_textColour = EditorGUILayout.ColorField("Colour", textfx_instance.m_textColour);//, GUILayout.Width(260));
			}
			GUILayout.FlexibleSpace ();
			EditorGUILayout.LabelField ("Use Gradient?", GUILayout.Width(100));
			textfx_instance.m_use_colour_gradient = EditorGUILayout.Toggle (textfx_instance.m_use_colour_gradient, GUILayout.Width(20));
			GUILayout.FlexibleSpace ();
			EditorGUILayout.EndHorizontal ();

			textfx_instance.m_display_axis = (TextDisplayAxis) EditorGUILayout.EnumPopup(new GUIContent("Display Axis", "Denotes whether to render the text horizontally or vertically."), textfx_instance.m_display_axis);
			textfx_instance.m_text_anchor = (TextAnchor) EditorGUILayout.EnumPopup(new GUIContent("Text Anchor", "Defines the anchor point about which the text is rendered"), textfx_instance.m_text_anchor);
			textfx_instance.m_text_alignment = (TextAlignment) EditorGUILayout.EnumPopup(new GUIContent("Text Alignment", "Defines the alignment of the text, just like your favourite word processor."), textfx_instance.m_text_alignment);
			textfx_instance.m_character_size = EditorGUILayout.FloatField(new GUIContent("Character Size", "Specifies the size of the text."), textfx_instance.m_character_size);
			textfx_instance.m_line_height_factor = EditorGUILayout.FloatField(new GUIContent("Line Height", "Defines the height of the text lines, based on the tallest line. If value is 2, the lines will be spaced at double the height of the tallest line."), textfx_instance.m_line_height_factor);
			EditorGUILayout.BeginHorizontal();
			textfx_instance.m_override_font_baseline = EditorGUILayout.Toggle(new GUIContent("Override Font Baseline?", "Allows you to manually set a baseline y-offset for the font to be rendered to."), textfx_instance.m_override_font_baseline);
			if(textfx_instance.m_override_font_baseline)
			{
				textfx_instance.m_font_baseline_override = EditorGUILayout.FloatField(new GUIContent("Font Baseline Offset", ""), textfx_instance.m_font_baseline_override);
			}
			EditorGUILayout.EndHorizontal();
			textfx_instance.m_px_offset = EditorGUILayout.Vector2Field("Letter Spacing Offset", textfx_instance.m_px_offset);
			textfx_instance.m_max_width = EditorGUILayout.FloatField(new GUIContent("Max Width", "Defines the maximum width of the text, and breaks the text onto new lines to keep it within this maximum."), textfx_instance.m_max_width);
			EditorGUILayout.Separator();
			
			EditorGUILayout.Separator();
			EditorGUILayout.Separator();

			if (GUI.changed)
			{
				EditorUtility.SetDirty(textfx_instance);
			}
			
			if(m_old_char_size != textfx_instance.m_character_size ||
			   m_old_textColour != textfx_instance.m_textColour ||
			   !m_old_vertexColour.Equals(textfx_instance.m_textColourGradient) ||
			   m_old_use_gradients != textfx_instance.m_use_colour_gradient ||
				m_old_display_axis != textfx_instance.m_display_axis ||
			   	m_old_line_height != textfx_instance.m_line_height_factor ||
				m_old_max_width != textfx_instance.m_max_width ||
				!m_old_text.Equals(textfx_instance.m_text)	||
				m_old_text_alignment != textfx_instance.m_text_alignment ||
				m_old_text_anchor != textfx_instance.m_text_anchor ||
				m_old_px_offset != textfx_instance.m_px_offset ||
				m_old_baseline_override != textfx_instance.m_override_font_baseline || 
				(textfx_instance.m_override_font_baseline && m_old_font_baseline != textfx_instance.m_font_baseline_override))
			{
				textfx_instance.SetText(textfx_instance.m_text);
			}

			GUILayout.Space(10);
			
			GUILayout.Label ("TextFx", EditorStyles.boldLabel);
			
			if (GUILayout.Button("Open Animation Editor", GUILayout.Width(150)))
			{
				EditorWindow.GetWindow(typeof(TextEffectsManager));
			}
		}