Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sdas2021

Pages: [1]
1
NGUI 3 Support / Re: NGUI and Vectrosity
« on: July 16, 2017, 08:04:38 AM »
  1. using UnityEngine;
  2. using Vectrosity;
  3. using System.Collections.Generic;
  4.  
  5. public class LineDraw : MonoBehaviour
  6. {
  7.         public List<Vector3> points;
  8.         private Vector3[] curvePoints = new Vector3[4];
  9.  
  10.         public GameObject sourceGO;
  11.         public GameObject targetGO;
  12.         public Color lineColor = Color.red;
  13.         private Color _setColor = Color.white;
  14.  
  15.         public Camera unityCamera;
  16.  
  17.         //create and assign a standard material, set smoothness source to "Albedo Alpha", set smoothness to 0
  18.         public Material lineMaterial;
  19.  
  20.         private Vector3 sourcePosition;
  21.         private Vector3 targetPosition;
  22.  
  23.         private VectorLine myLine;
  24.  
  25.         private void Start()
  26.         {
  27.                 //set these items before any VectorLine is created
  28.  
  29.                 VectorLine.SetCamera3D(unityCamera);
  30.  
  31.                 //we need to set the canvas to be at the same location as the NGUI screen area
  32.                 VectorLine.canvas.renderMode = RenderMode.WorldSpace;
  33.                 //Change#1: Shifting canvas to sourceGO position
  34.                 VectorLine.canvas.transform.position = sourceGO.transform.position;
  35.                 //on UIRoot, set Constrained Scaling Style
  36.                 VectorLine.canvas.scaleFactor = NGUITools.FindInParents<UIRoot>(this.gameObject).gameObject.transform.localScale.x;
  37.  
  38.  
  39.  
  40.  
  41.  
  42.                 if(sourceGO == null | targetGO == null)
  43.                 {
  44.                         Debug.LogError("Set your source and target GOs.");
  45.                         return;
  46.                 }
  47.                 //Change#2: Changed to match sourceGO and targetGO positions
  48.                 points =new List<Vector3> { sourceGO.transform.position, targetGO.transform.position };
  49.  
  50.                 myLine = new VectorLine("myLine", points, 5f, LineType.Continuous);
  51.                 //Change#3: Changed to draw straight line
  52. //              myLine.Resize(50);
  53.  
  54.                 //setting renderqueue > 3000 will draw in front of all NGUI objects
  55.                 lineMaterial.renderQueue = 4000;
  56.                 lineMaterial.SetColor("_Color", Color.red);
  57.                 lineMaterial.SetColor("_EmissionColor", Color.red);
  58.  
  59.                 myLine.material = lineMaterial;
  60.  
  61.  
  62.                 myLine.Draw3DAuto();
  63.  
  64.         }
  65.  
  66.         private void Update()
  67.         {
  68.                 if(sourceGO == null | targetGO == null)
  69.                         return;
  70.  
  71.                 if(sourceGO.transform.localPosition != sourcePosition |
  72.                         targetGO.transform.localPosition != targetPosition)
  73.                 {
  74.                         sourcePosition = sourceGO.transform.position;
  75.                         targetPosition = targetGO.transform.position;
  76.  
  77.                         Vector3 pos1 = new Vector3(sourcePosition.x, sourcePosition.y, sourcePosition.z);
  78.                         Vector3 pos2 = new Vector3(targetPosition.x, targetPosition.y, targetPosition.z);
  79.  
  80.                         curvePoints[0] = pos1;// sourcePosition;
  81.                         curvePoints[1] = (pos1 + new Vector3(0.3f, 0f, 0f));
  82.                         curvePoints[2] = pos2;
  83.                         curvePoints[3] = (pos2 + new Vector3(0f, 0.3f, 0f));
  84.  
  85.                         myLine.MakeCurve(curvePoints);
  86.  
  87.                 }
  88.  
  89.                 if(_setColor != lineColor)
  90.                 {
  91.                         lineMaterial.renderQueue = 4000;
  92.                         lineMaterial.SetColor("_Color", lineColor);
  93.                         lineMaterial.SetColor("_EmissionColor", lineColor);
  94.  
  95.                         myLine.material = lineMaterial;
  96.                 }
  97.         }
  98. }
  99.  

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?

Pages: [1]