1
NGUI 3 Support / Re: NGUI and Vectrosity
« on: July 16, 2017, 08:04:38 AM »- using UnityEngine;
- using Vectrosity;
- using System.Collections.Generic;
- public class LineDraw : MonoBehaviour
- {
- public List<Vector3> points;
- public GameObject sourceGO;
- public GameObject targetGO;
- public Color lineColor = Color.red;
- private Color _setColor = Color.white;
- public Camera unityCamera;
- //create and assign a standard material, set smoothness source to "Albedo Alpha", set smoothness to 0
- public Material lineMaterial;
- private Vector3 sourcePosition;
- private Vector3 targetPosition;
- private VectorLine myLine;
- private void Start()
- {
- //set these items before any VectorLine is created
- VectorLine.SetCamera3D(unityCamera);
- //we need to set the canvas to be at the same location as the NGUI screen area
- VectorLine.canvas.renderMode = RenderMode.WorldSpace;
- //Change#1: Shifting canvas to sourceGO position
- VectorLine.canvas.transform.position = sourceGO.transform.position;
- //on UIRoot, set Constrained Scaling Style
- VectorLine.canvas.scaleFactor = NGUITools.FindInParents<UIRoot>(this.gameObject).gameObject.transform.localScale.x;
- if(sourceGO == null | targetGO == null)
- {
- Debug.LogError("Set your source and target GOs.");
- return;
- }
- //Change#2: Changed to match sourceGO and targetGO positions
- //Change#3: Changed to draw straight line
- // myLine.Resize(50);
- //setting renderqueue > 3000 will draw in front of all NGUI objects
- lineMaterial.renderQueue = 4000;
- lineMaterial.SetColor("_Color", Color.red);
- lineMaterial.SetColor("_EmissionColor", Color.red);
- myLine.material = lineMaterial;
- myLine.Draw3DAuto();
- }
- private void Update()
- {
- if(sourceGO == null | targetGO == null)
- return;
- if(sourceGO.transform.localPosition != sourcePosition |
- targetGO.transform.localPosition != targetPosition)
- {
- sourcePosition = sourceGO.transform.position;
- targetPosition = targetGO.transform.position;
- curvePoints[0] = pos1;// sourcePosition;
- curvePoints[2] = pos2;
- myLine.MakeCurve(curvePoints);
- }
- if(_setColor != lineColor)
- {
- lineMaterial.renderQueue = 4000;
- lineMaterial.SetColor("_Color", lineColor);
- lineMaterial.SetColor("_EmissionColor", lineColor);
- myLine.material = lineMaterial;
- }
- }
- }
I am using the code given by Zyxil at http://www.tasharen.com/forum/index.php?topic=14921.msg65089#msg65089
Have changed the code to put start and end position at sourceGO and targetGO, and draw a straight line.
Issue: As you can see in the attachment that in the scene view, line is drawn correctly. But in Game view the scale of the line is off. How can I correct it?
