Unity3d开发之十四:unity3d长string格式化,并且滑动显示,指定替换文本内容

长文本显示-----------------------------------------------------------------------------

声明一个string类型,记住格式 @“文本 ”
实例如下:

string detail = @"
1  .This activity is valid from {0} to {1}. You have to use {2} App Client (the ""App"")to join in this activity.
2  .During the activity, you may get different kinds of Puzzles and redeem them for the following rewards:
{3}
3   .During the activity, you may get the Puzzles in the following ways:
(1)  Bubble for Puzzles.You may get random Puzzles when take part in Bubble for Puzzles.There are six Bubbles at the same time displayed in applicable page as well as the kind of the Puzzle(s) you may get for each Bubble.You may choose the Bubble you want and watch a video from the beginning to the end according to the instruction to get a random number of the Puzzle(s) of such kind. Please note that if you close the App Or turn off the screen before you finish watching the video, you will get nothing; 
(2)  Luck Spin.You may get random Puzzles when you spin in the Lucky Spin.To get a chance of spin, you shall watch a video from the beginning to the end according to the instruction.
4  .The ways you get the Puzzles, the number of Puzzles you get in each way and the rewards may be changed from time to time. Please refer to the activity page in the App to check the latest activity details.
5  .When you redeem for a reward (except for the Coins), you must fill in your shipping information accurately, otherwise you are solely responsible for the failure of reward delivery.We will confirm your shipping information within 7 working days.After our confirmation, the reward will be delivered to you in several days. You need to abide by all applicable laws and take responsibility for tax declaration and payment.
6  .Please note that upon the end of the activity, any unredeemed Puzzles will be cleared up and no compensation will be made to you.
7  .We will not provide any after-sales services for the rewards you get in the App. If you have any question about the rewards, please contact the applicable manufacturer.
8  .In the event of any force majeure event or any change of circumstance that we cannot control(including but not limited to strikes, act of God, policy changes, act of governmental, cyberattack and system failure) leading to the cessation or adjustment of any activity, please understand that we are not obligated to make any compensation to you, nor shall we undertake any liability whatsoever.In the event of any failure to whatsoever.In the event of any failure to participate in any activity due to your improper operation, network failure, failure of telecom operator or any third party reasons, we are not obligated to make any compensation, nor shall we undertake any legal liability whatsoever.
9  .Please strictly abide by the activity rules.If any cheating or violation is found(including but not limited to using illegal tools to decode our services and hackings), measures will be taken including but not limited to disqualification from taking part in this activity, redeeming for any rewards, getting any redeemed reward and/or using the App, under which circumstance, no compensation in any form will be made to you and we also reserve the right to require you to return any rights, interests and rewards that you have received.
10   .To the extent permitted by the applicable law, we have the right to make adjustments to the activity rules at any time, and we will send prior notice in the App if we decide to make significant adjustment. The adjustment will take effect at the time of the release of the notice or the time specified in the notice. If you do not agree with any adjustments please do not join in this activity anymore.
11   .We reserve the right to interpret the activity rules to the extent permitted by applicable laws and regulations.
12   .Our End User License Agreement and Privacy Policy shall also be applicable to this activity.In case of any difference and inconsistency between the policies and any specific activity rules, the specific activity rules shall prevail in terms of this activity.
13   .If you have any questions or disputes arising out of or in relation to the rules this activity or the App please contact us by emailing at {4}.
14   .Apple is not involved in any way with this activity.
";

展示:

m_Email.text = m_DetailData.email;

滑动显示-----------------------------------------------------------------------------

添加滑动列表:
在这里插入图片描述
为滑动列表添加自动扩充的组件:
在这里插入图片描述
为文本框添加自动扩充组件:
在这里插入图片描述
代码里面匹配文本框高度和滑动列表高度,这里需要注意的就是需要用协程做个延时,0.1s就行,不然会有匹配不了高度的bug,这可能是unity自带的毛病:

            StartCoroutine(TimeUtlis.Delay(() =>
            {
                float height = m_Texts.GetComponent<RectTransform>().rect.height;
                m_content.GetComponent<RectTransform>().SetHeight(height);
            }));

替换指定文本-----------------------------------------------------------------------------

主要使用的是 string.Format(替换的文本,文本中的指定位置{0},文本中的指定位置{1},文本中的指定位置{2},文本中的指定位置{3},文本中的指定位置{4})
类似:
在这里插入图片描述
如果需要手动换行,在指定位置使用 \n即可!

            string detailText = "";
            for (int i = 0; i < m_DetailData.detailItemDatas.Count; i++)
            {
                detailText += "("+(i+1)+")" +"  Redeem  " + m_DetailData.detailItemDatas[i].target +"  " + m_DetailData.detailItemDatas[i].title+  "  Puzzles for a  " + m_DetailData.detailItemDatas[i].title+"; \n";
            }
            m_Texts.text = string.Format(detail, m_DetailData.startDate, m_DetailData.endDate, m_DetailData.name, detailText, m_DetailData.email);
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页