Author Topic: Creating a simple newsfeed  (Read 8350 times)

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #15 on: March 16, 2015, 08:51:40 PM »
Here is a few while running with it selected, hopefully what you are looking for. And yes its Pos X is 0 before I run it.

What are the settings on the parent image object?

Can you create a package of the scene with just the text objects? That might make it easier to figure out what is different.

P.S. The skip you are getting is pretty big so if you watch it in gameview, you will see when it resets back to the start. Does it seems to reset when the RectTransform gets to 0 (the start position)? All of the text should also be contained in the RectTransform as well.
« Last Edit: March 16, 2015, 09:20:57 PM by Stephan B. »

rxmarcus

  • Newbie
  • *
  • Posts: 25
Re: Creating a simple newsfeed
« Reply #16 on: March 17, 2015, 02:13:00 PM »
Finally put together a package you can import into a new project. Just open up the scene in the scenes folder. I copied the setup I had in my original scene and when I pasted it into this new scene, the line drop on the duplicated text object is no longer happening, but the skip still is.

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #17 on: March 17, 2015, 03:09:43 PM »
Finally put together a package you can import into a new project. Just open up the scene in the scenes folder. I copied the setup I had in my original scene and when I pasted it into this new scene, the line drop on the duplicated text object is no longer happening, but the skip still is.

Thank you for forwarding this package to me. It made very simple to find out where the issue was :)

Since the parent image is scaled, the width of the text doesn't match the actual width which is affected by the parent's scale.

Code: C#
  1. float width = TextMeshProComponent.preferredWidth * m_textRectTransform.lossyScale.x;

This will adjust the width to factor in the scale of the parent / hierarchy.

rxmarcus

  • Newbie
  • *
  • Posts: 25
Re: Creating a simple newsfeed
« Reply #18 on: March 17, 2015, 04:55:56 PM »
That seems to work great, no more jumping. I'm still having the second line dropping down like in that video but I think thats something wacky on my side, going to just delete everything and try again.

I wanted to ask your opinion on what might be the best way to handle shorter statements in this newsfeed. All I can think is to use a bunch of spaces after the end of the short statement to pad it so its long enough to make the wrap work well even with a short statement. thoughts?

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #19 on: March 17, 2015, 05:41:57 PM »
That seems to work great, no more jumping. I'm still having the second line dropping down like in that video but I think thats something wacky on my side, going to just delete everything and try again.

I wanted to ask your opinion on what might be the best way to handle shorter statements in this newsfeed. All I can think is to use a bunch of spaces after the end of the short statement to pad it so its long enough to make the wrap work well even with a short statement. thoughts?

In terms of short statements, I think extra padding makes sense.  I would use the "\t" for tab instead of spaces.  Alternatively, you could use additional clone object to avoid the long gap between statements but then you get into managing those. Whatever works best for you i guess :)



rxmarcus

  • Newbie
  • *
  • Posts: 25
Re: Creating a simple newsfeed
« Reply #20 on: March 17, 2015, 09:19:59 PM »
Yea padding sounds good to me =P
Thanks for taking the time to help me with this, much appreciated.

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #21 on: March 17, 2015, 09:33:58 PM »
Yea padding sounds good to me =P
Thanks for taking the time to help me with this, much appreciated.

You are most welcome :)

rxmarcus

  • Newbie
  • *
  • Posts: 25
Re: Creating a simple newsfeed
« Reply #22 on: March 22, 2015, 03:41:05 PM »
I'm sorry to bring this thread back up again, but I'm now trying to use this in a World Space UI setup and am having strange issues. Have you tried it using World Space?
My copy text is way out of position and such.

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #23 on: March 22, 2015, 03:52:24 PM »
I'm sorry to bring this thread back up again, but I'm now trying to use this in a World Space UI setup and am having strange issues. Have you tried it using World Space?
My copy text is way out of position and such.

Let me take a look.

doktor3d

  • Beta User
  • Jr. Member
  • *
  • Posts: 54
Re: Creating a simple newsfeed
« Reply #24 on: March 23, 2015, 09:40:33 AM »
Stephan, would this solution also work for soft masking with the TMP UGUI component, or does the stencil mask still prevent that from working?

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #25 on: March 23, 2015, 12:26:16 PM »
Stephan, would this solution also work for soft masking with the TMP UGUI component, or does the stencil mask still prevent that from working?

When you are using the UI Mask Component, you can't really use the hard or soft masking since those two things are kind of redundant.

In order to do this with the soft masking, you would need to use the modified shader that I created for NGUI which works in World Space as opposed to object space. This is only because the text may be shorter than the RectTransform and if you want a continuous scroll where the text can repeat within the same space, two or more objects need to be able to share the same masking coordinates.


Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #26 on: March 24, 2015, 01:23:12 AM »
I'm sorry to bring this thread back up again, but I'm now trying to use this in a World Space UI setup and am having strange issues. Have you tried it using World Space?
My copy text is way out of position and such.

Since the RectTransform position and anchors is affected by the Canvas RenderModes, you need to revise these code examples to account for some of that.

Code: C#
  1. cloneRectTransform.anchorMin = new Vector2(1, 0.5f);
  2. cloneRectTransform.anchorMax = new Vector2(1, 0.5f);
  3. cloneRectTransform.localPosition = Vector2.zero;
  4. cloneRectTransform.localScale = new Vector3(1, 1, 1);

This should make it work fine in Canvas RenderMode World Space Camera and Screen Space Overlay but would not work for Screen Space - Camera since Unity moves the objects relative to the position of the camera and thus the positioning of the objects would then have to take into account the position of the camera. Again these are examples of potential ways to create an horizontal news feed.

BTW: For World Space, I am not certain I would use a Canvas and would likely switch to the normal TextMesh Pro Component which uses the Mesh Renderer since it doesn't inherit from the Canvas system performance overhead. The positioning of the objects would have to be handled differently but the same results could be achieved.

rxmarcus

  • Newbie
  • *
  • Posts: 25
Re: Creating a simple newsfeed
« Reply #27 on: March 24, 2015, 04:00:26 PM »
Awesome thats helpful I'll give it a try.

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Creating a simple newsfeed
« Reply #28 on: January 20, 2016, 01:52:39 PM »
Here is a revised package which contains an updated scene and script.