Hi,
for my game I need a map where the player build routes via clicking on star systems. Now, those star systems need to be connected via lines. NGUI doesn't have such feature, which is why I am using Unity's LineRenderer.
My problem is that the lines in my current test case show up in the editor, but not in the game preview. See this screenshot:
In the middle column you can see many GameObject, all parented to a scroll view (which clipping does not work, btw). The three lines you can see (LineDrawer0, 1, 2) all have different Z values that I manually set for testing, with 0 (the selected line) giving me the look I want. The lines show up in the top left preview, but not in the buttom left game.
Do do I get those lines to show up in the game?
Now, you might say, well, set those lines up manully, using only NGUI. Well, I could do that. But it was already a pain setting up those buttons. Setting up the lines would be even more manual work, which I am currently doing via script:
void Start () {
foreach ( Transform nextTf in MapNeighbors ) {
createLine
( tf
.position, nextTf
.position, 0
.025f,
new Color
( 0
.5f, 0
.5f, 0
.5f, 1
.0f
) ); }
foreach ( Transform lineChild in tf ) {
Vector3 oldPos = lineChild.position;
oldPos.z = 0;
lineChild.position = oldPos;
Debug.Log( lineChild.name );
// lineChild.Translate ( new Vector3 ( 0,0, -3 / lineChild.localScale.z ) );
}
}
public void createLine (Vector3 start, Vector3 end, float lineSize, Color c) {
GameObject lineDrawer
= new GameObject
(string.Format("lineDrawer{0}", lineIndex
)); lineDrawer.layer = 9;
lineDrawer.transform.parent = tf;
LineRenderer line = (LineRenderer) lineDrawer.AddComponent<LineRenderer>();
line.material = mat; // new Material(shader);
line.material.color = c;
line.useWorldSpace = false;
line.SetWidth(lineSize, lineSize);
line.SetVertexCount(2);
line
.SetPosition(0,
new Vector3
( start
.x, start
.y,
0) ); line
.SetPosition(1,
new Vector3
( end
.x, end
.y,
0) );
lineIndex++;
}
And if I did it via NGUI ... how would I go about it? Use a NGUI Sprite for each line? Let's say a 64x64 px line graphic, turned and scaled for each line? That would take forever to setup.
Also not that my map needs some dynamic element, it is not static. To build routes, the player would click planets to build a route. On top of the current thin grey lines a thick, green line would appear. I am not sure how I would do that via NGUI, but I do know how to do it with LineRenderer.
Also note that the clipping does not work. It's a scroll panel right now. I will now go and look at the scroll camera technique.
Thx