Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by INKnightStudio · Apr 21, 2017 at 08:36 PM · generationhtml

Code generation script problem

Hello! I have a code to generate html codes, and I have this problem: alt text

The Italic code are generating in wrong place, how I can fix this?

Code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class TextGenerator : MonoBehaviour
 {
 
     public InputField input;
     public InputField resultMarkupFormat;
 
     public Toggle bold;
     public Toggle italic;
 
     public Dropdown colorList;
 
     string[] boldFormat = new string[2] { "<b>", "</b>" };
     string[] italicFormat = new string[2] { "<i>", "</i>" };
 
     string[] hexadecimal = new string[31]
     {
     "No Color",
     "<color=#ff0000>Red</color> :#ff0000",
     "<color=#ffe100>Yellow</color> :#ffe100",
     "<color=#ff6600>Orange</color> :#ff6600",
     "<color=#77c2ff>OrangeRed</color> :#77c2ff",
     "<color=#ccff00>Lime</color> :#ccff00",
     "<color=#00ff00>Green</color> :#00ff00",
     "<color=#62ffab>Teal</color> :#62ffab",
     "<color=#00ffff>Cyan</color> :#00ffff",
     "<color=#1e90ff>Dodger Blue</color> :#1e90ff",
     "<color=#0000ff>Blue</color> :#0000ff",
     "<color=#5a00ff>Blue Violet</color> :#5a00ff",
     "<color=#9800ff>Violet</color> :#9800ff",
     "<color=#ff00ff>Pink</color> :#ff00ff",
     "<color=#ff0084>Deep Pink</color> :#ff0084",
     "<color=#ff7777>Light Red</color> :#ff7777",
     "<color=#ffce81>Light Orange</color> :#ff9c70",
     "<color=#ffef81>Light Yellow</color> :#fff070",
     "<color=#ffef81>Light Lime</color> :#e3ff62",
     "<color=#77ff79>Light Green</color> :#77ff79",
     "<color=#81ffb6>Light Teal</color> :#81ffb6",
     "<color=#adfcff>Light Cyan</color> :#adfcff",
     "<color=#87c8ff>Light Dodger Blue</color> :#87c8ff",
     "<color=#77c2ff>Light Blue</color> :#77c2ff",
     "<color=#a087ff>Light BlueViolet</color> :#a087ff",
     "<color=#bd87ff>Light Violet</color> :#bd87ff",
     "<color=#f287ff>Light Pink</color> :#f287ff",
     "<color=#ff78d1>Light Deep Pink</color> :#ff78d1",
     "<color=#FFFFFF>White</color> :#FFFFFF",
     "<color=#969696>Gray</color> :#969696",
     "<color=#000000>Black</color> :#000000",
     };
 
     void Start()
     {
         colorList.ClearOptions();
 
         for (int i = 0; i < hexadecimal.Length; i++)
         {
             string[] hexa = hexadecimal[i].Split(':');
             Dropdown.OptionData data = new Dropdown.OptionData();
             data.text = hexa[0];
             colorList.options.Add(data);
         }
 
     }
 
     void Update()
     {
         resultMarkupFormat.text = VerifyResult();
     }
 
     string VerifyResult()
     {
         string[] markup = new string[2] { "", "" };
 
         if (input.text.Length > 0)
         {
 
             markup[0] = bold.isOn ? boldFormat[0] : "";
             markup[0] += italic.isOn ? italicFormat[0] : "";
             if (colorList.value > 0)
             {
                 string[] hexa = hexadecimal[colorList.value].Split(':');
                 markup[0] += "<color=" + hexa[1] + ">";
             }
 
             markup[1] = bold.isOn ? boldFormat[1] : "";
             markup[1] += italic.isOn ? italicFormat[1] : "";
 
             if (colorList.value > 0)
                 markup[1] += "</color>";
 
         }
 
         return markup[0] + input.text + markup[1];
     }
 }
88xqdas.png (5.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Matthewj866 · Apr 21, 2017 at 11:03 PM

Hi there @Ghosthy

These two lines:

      markup[0] = bold.isOn ? boldFormat[0] : "";
      markup[0] += italic.isOn ? italicFormat[0] : "";

are being called too early. Instead you should call them after you have opened the color element, like this:

      if (colorList.value > 0)
      {
          string[] hexa = hexadecimal[colorList.value].Split(':');
          markup[0] = "<color=" + hexa[1] + ">";
          markup[0] += bold.isOn ? boldFormat[0] : "";
          markup[0] += italic.isOn ? italicFormat[0] : "";
      }


This should fix your issue. Hope it works out!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image INKnightStudio · Apr 28, 2017 at 02:44 AM 0
Share

Thanks a lot, :D I'll put you on the program credits :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to convert UI Document made in UI Builder to HMTL? 0 Answers

Best way to generate meshes based on algebraic functions? 0 Answers

How to add programatically animationClips to one animation from Resources folder? 0 Answers

generating hallways using prefabs based on difficulty 1 Answer

How can I create a plane at any given vertex position? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges