Ejemplo n.º 1
0
    void Update()
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
        {
            if (!p0 && !p1)
            {
                p0 = hit.transform;
                h0 = hit.point;
                return;
            }

            if (p0 && !p1)
            {
                p1 = hit.transform;
                h1 = hit.point;
            }

            if (p0 && p1)
            {
                LineRenderer line = new GameObject("Line " + i.ToString()).AddComponent <LineRenderer>();
                line.transform.parent = container;
                line.SetWidth(0.025F, 0.025F);
                line.SetColors(Color.red, Color.green);
                line.SetVertexCount(2);
                line.SetPosition(0, h0);
                line.SetPosition(1, h1);
                distance = Vector3.Distance(h0, h1);
                label    = "Distance between hit point 0 of " + p0.name + " and hit point 1 of " + p1.name + " = " + distance.ToString();
                p1       = null;
                p0       = null;
            }
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a selection model for a specific kerbal.
        /// </summary>
        /// <param name="eva"></param>
        private void CreateLine(EvaContainer container)
        {
            if (selectionLines.ContainsKey(container.flightID))
            {
                return;
            }

            LineRenderer lineRenderer = new GameObject().AddComponent <LineRenderer>();

            lineRenderer.useWorldSpace = false;
            lineRenderer.material      = new Material(Shader.Find("Particles/Additive"));
            lineRenderer.SetWidth(0.05f, 0.05f);
            lineRenderer.SetColors(Color.green, Color.red);

            Renderer _renderer = null;

            lineRenderer.GetComponentCached <Renderer> (ref _renderer);

            if (_renderer != null)
            {
                _renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                _renderer.receiveShadows    = false;
            }

            int segments = 32;

            lineRenderer.SetVertexCount(segments);

            CreateCircle(lineRenderer, segments, 0.25);

            //set properties
            SetSelectionLineProperties(container.EVA, lineRenderer);

            selectionLines.Add(container.flightID, lineRenderer);
        }
Ejemplo n.º 3
0
    public void SetNewConnection(GameObject neighbour)
    {
//		Debug.Log ("SetNewConnection Called! (Neighbour: " + neighbour + ")");
        if (neighbour.GetInstanceID() != this.gameObject.GetInstanceID())
        {
            if (HasConnectionsLeft())
            {
                if (neighbour.GetComponent <GridfieldController> ().HasConnectionsLeft())
                {
                    if (!connectedElements.Contains(neighbour))
                    {
                        connectedElements.Add(neighbour);
                        LineRenderer lRenderer = new GameObject("Line to " + neighbour.GetInstanceID()).AddComponent <LineRenderer> ();
                        lRenderer.transform.parent = this.transform;
                        lRenderer.SetWidth(defaultBondWidth, defaultBondWidth);
                        lRenderer.material = new Material(Shader.Find("Sprites/Default"));
                        lRenderer.SetColors(Color.black, Color.black);
                        lRenderer.SetVertexCount(2);
                        lRenderer.SetPosition(0, this.transform.position);
                        lRenderer.SetPosition(1, neighbour.transform.position);
                        lRenderer.sortingOrder = 2;
                        lineRenderers.Add(lRenderer);
                        lineDestinations.Add(lRenderer, neighbour.GetComponent <GridfieldController>().GetElement());
                        neighbour.GetComponent <GridfieldController> ().AddThisAsNeighbour(this.gameObject);
                        leftConnections--;
                    }
                    else
                    {
                        //Neighbour is at least once connected. Check for possible multiple bond.
                        AddMultipleBondNeighbour(neighbour);
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
 // Following method creates new line for MagnifyGlass's border
 private LineRenderer getLine()
 {
     LineRenderer line = new GameObject("Line").AddComponent<LineRenderer>();
     line.material = new Material(Shader.Find("Diffuse"));
     line.SetVertexCount(2);
     line.SetWidth(0.2f, 0.2f);
     line.SetColors(Color.black, Color.black);
     line.useWorldSpace = false;
     return line;
 }
Ejemplo n.º 5
0
	// Following method creates new line for MagnifyGlass's border  
	private LineRenderer getLine()  
	{  
		LineRenderer line = new GameObject("Line").AddComponent<LineRenderer>();  
		line.material = new Material(Shader.Find("Diffuse"));  
		line.SetVertexCount(2);  
		line.SetWidth(0.2f,0.2f);  
		line.SetColors(Color.black, Color.black);  
		line.useWorldSpace = false;  
		return line;  
	}  
    // Following method creates new line for MagnifyGlass's border
    private LineRenderer getLine()
    {
        LineRenderer line = new GameObject("Line").AddComponent <LineRenderer>();

        line.material = lineMaterial;
        line.SetVertexCount(2);
        line.SetWidth(0.2f, 0.2f);
        line.SetColors(Color.black, Color.black);
        line.useWorldSpace = false;
        return(line);
    }
Ejemplo n.º 7
0
 private void makeGrid(Vector3 begin, Vector3 end)
 {
     LineRenderer line = new GameObject().AddComponent<LineRenderer>();
     line.transform.parent = this.transform.parent;
     line.SetWidth(0.01F, 0.01F);
     line.SetColors(lightBlue, lightBlue);
     line.SetPosition(0, begin);
     line.SetPosition(1, end);
     line.SetVertexCount(2);
     line.material = new Material(Shader.Find("Particles/Additive"));
 }
Ejemplo n.º 8
0
    private void createLine(string name, Vector3 start, Vector3 end)
    {
        LineRenderer line = new GameObject(name).AddComponent <LineRenderer>();

        line.material = new Material(Shader.Find("Diffuse"));
        line.SetVertexCount(2);
        line.SetPosition(0, start);
        line.SetPosition(1, end);
        line.SetWidth(0.5f, 0.5f);
        line.SetColors(Color.black, Color.black);
        // line.useWorldSpace = true;
    }
Ejemplo n.º 9
0
    private void makeGrid(Vector3 begin, Vector3 end)
    {
        LineRenderer line = new GameObject().AddComponent <LineRenderer>();

        line.transform.parent = this.transform.parent;
        line.SetWidth(0.01F, 0.01F);
        line.SetColors(lightBlue, lightBlue);
        line.SetPosition(0, begin);
        line.SetPosition(1, end);
        line.SetVertexCount(2);
        line.material = new Material(Shader.Find("Particles/Additive"));
    }
Ejemplo n.º 10
0
    private void drawLine(Vector3 start, Vector3 end, Color color)
    {
        LineRenderer line = new GameObject("Line ").AddComponent <LineRenderer>();

        line.SetWidth(0.025F, 0.025F);
        line.SetColors(color, color);
        line.SetVertexCount(2);
        line.SetPosition(0, start);
        line.SetPosition(1, end);
        line.material.shader = (Shader.Find("Unlit/Color"));
        line.material.color  = color;
        lines.Add(line.gameObject);
    }
Ejemplo n.º 11
0
    private void makeLineGraph(Vector3 begin, Vector3 end)
    {
        //makePoint(begin);
        // makePoint(end);
        LineRenderer line = new GameObject().AddComponent <LineRenderer>();

        line.transform.parent = this.transform.parent;
        line.SetWidth(0.05F, 0.05F);
        line.SetColors(Color.green, Color.green);
        line.SetPosition(0, begin);
        line.SetPosition(1, end);
        line.SetVertexCount(2);
        line.material = new Material(Shader.Find("Particles/Additive"));
    }
Ejemplo n.º 12
0
    void addLineVector(Vector3 currentVector, Vector3 newVector)
    {
        // create a new line renderer
        LineRenderer lineRenderer = GetComponent <LineRenderer>();
        LineRenderer lRend        = new GameObject().AddComponent <LineRenderer>();

        lRend.SetPosition(0, transform.position);
        lRend.SetWidth(.2f, .2f);
        lRend.SetPosition(1, newVector);
        listOfVectors.Add(lRend);
        lRend.SetColors(Color.blue, Color.blue);

        //lineRenderer.SetPosition(0, transform.position);
        //lineRenderer.SetWidth(.5f, .5f);
        //lineRenderer.SetPosition(1, newVector);
    }
Ejemplo n.º 13
0
        /// <summary>
        /// Draw a new line.
        /// </summary>
        /// <param name="group">Group name to associate the line with.</param>
        /// <param name="start">Starting location.</param>
        /// <param name="end">Ending location.</param>
        /// <param name="color">Color of the line.</param>
        /// <param name="size">Width of the line.</param>
        public static void AddLine(string group, Vector3 start, Vector3 end, Color color, float size)
        {
            GameObject   groupObject = AddOrGetGroup(group);
            LineRenderer lineR       = new GameObject()
            {
                name  = "Line",
                layer = layerIgnoreRaycast
            }.AddComponent <LineRenderer>();
            var matPropBlock = new MaterialPropertyBlock();

            matPropBlock.SetColor(ShaderProperty.MainColor, color);
            lineR.SetVertexCount(2);
            lineR.SetPosition(0, start);
            lineR.SetPosition(1, end);
            lineR.SetWidth(size, size);
            lineR.material = ResourceList.getInstance().Materials.PlainColor;
            lineR.SetColors(color, color);

            lineR.transform.parent = groupObject.transform;

            SetMatPropBlock(lineR, color);
            DisableShadows(lineR);
        }
Ejemplo n.º 14
0
	public void MakeMeLaser(Color color)
	{
		/*
		foreach(GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
		{
			if(go.name == "lineUP")
			{
				GameObject.Destroy (go);
			}
		}
		// Set LineRenderer InitializationGameObject yourName = new GameObject();
		LineRenderer lineRenderer = new GameObject("lineUP").AddComponent<LineRenderer>();
		lineRenderer.sharedMaterial = new Material(Shader.Find("Particles/Additive"));
		lineRenderer.SetColors(Color.red, Color.red);
		lineRenderer.SetWidth(1f, 1f);
		lineRenderer.SetVertexCount(2);
		
		// We need no Shadows
		lineRenderer.castShadows = false;
		lineRenderer.receiveShadows = false;
		Debug.Log ("Raw posX: " + posX + "Raw posX: " + posY);

		float worldX = posX * 4;
		float worldZ = posY * 4;

		Vector3 pos = new Vector3(worldX + 2, 0, worldZ + 2);
		lineRenderer.SetPosition(0, pos);

		pos = new Vector3(worldX + 2, 800, worldZ + 2);
		lineRenderer.SetPosition(1, pos);
		*/
		// Make 
		//GameController.instance.treeGroupController.AddTreeGroup(posX, posY);

		RaycastHit hit;

		// Set LineRenderer InitializationGameObject yourName = new GameObject();
		LineRenderer lineRenderer = new GameObject("lineUP").AddComponent<LineRenderer>();
		lineRenderer.sharedMaterial = new Material(Shader.Find("Particles/Additive"));
		lineRenderer.SetColors(color, color);
		lineRenderer.SetWidth(0.2f, 0.2f);
		lineRenderer.SetVertexCount(5);
		
		// We need no Shadows
		lineRenderer.castShadows = false;
		lineRenderer.receiveShadows = false;
		
		float worldX = posX * 4;
		float worldZ = posY * 4;
		Vector3 pos;
		Ray ray = new Ray(new Vector3(worldX, 10, worldZ), Vector3.up);
		if (Physics.Raycast (ray, out hit)) 
		{
			pos = new Vector3(worldX, hit.point.y + 1, worldZ);
			lineRenderer.SetPosition(0, pos);
		}


		ray = new Ray(new Vector3(worldX + 4, 10, worldZ), Vector3.up);
		if (Physics.Raycast (ray, out hit)) 
		{
			pos = new Vector3(worldX + 4, hit.point.y + 1, worldZ);
			lineRenderer.SetPosition(1, pos);
		}

		ray = new Ray(new Vector3(worldX + 4, 10, worldZ + 4), Vector3.up);
		if (Physics.Raycast (ray, out hit)) 
		{
			pos = new Vector3(worldX + 4, hit.point.y + 1, worldZ + 4);
			lineRenderer.SetPosition(2, pos);
		}

		ray = new Ray(new Vector3(worldX, 10, worldZ + 4), Vector3.up);
		if (Physics.Raycast (ray, out hit)) 
		{
			pos = new Vector3(worldX, hit.point.y + 1, worldZ + 4);
			lineRenderer.SetPosition(3, pos);
		}

		ray = new Ray(new Vector3(worldX, 10, worldZ), Vector3.up);
		if (Physics.Raycast (ray, out hit)) 
		{
			pos = new Vector3(worldX, hit.point.y + 1, worldZ);
			lineRenderer.SetPosition(4, pos);
		}
	

		lineRenderer.gameObject.AddComponent<SelectionLine>();
	}
Ejemplo n.º 15
0
	// Draw a single line.
	void DrawLine(int lineMultiplicator, Axis axis)
	{
		// Set LineRenderer InitializationGameObject yourName = new GameObject();
		LineRenderer lineRenderer = new GameObject("line").AddComponent<LineRenderer>();
		lineRenderer.sharedMaterial = lineMaterial;
		lineRenderer.SetColors(c1, c2);
		lineRenderer.SetWidth(beginWidth, endWidth);
		lineRenderer.SetVertexCount(lengthOfLineRenderer / lineSegmentLenght + 1);
		
		// We need no Shadows
		lineRenderer.castShadows = false;
		lineRenderer.receiveShadows = false;
		
		// Create LineVertexes
		InstantiateLine(lineMultiplicator, lineRenderer, axis);
		
	}
Ejemplo n.º 16
0
    private LineRenderer createLine()
    {
        LineRenderer line;

        line = new GameObject("Line").AddComponent<LineRenderer>();

        line.SetWidth(0.06f, 0.06f);

        line.material = this.material;

        line.material.SetColor("_Color", new Color(0.8824f, 0.1843f, 0.0413f));

        line.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        line.SetColors(new Color(0.8824f, 0.1843f, 0.0413f), new Color(0.8824f, 0.1843f, 0.0413f));

        line.SetVertexCount(2);

        return line;
    }
 protected void drawLine(Vector3 start, Vector3 end, Color color)
 {
     LineRenderer line = new GameObject("Line ").AddComponent<LineRenderer>();
     line.SetWidth(0.025F, 0.025F);
     line.SetColors(color, color);
     line.SetVertexCount(2);
     line.SetPosition(0, start);
     line.SetPosition(1, end);
     line.material.shader = (Shader.Find("Unlit/Color"));
     line.material.color = color;
     lines.Add(line.gameObject);
 }
Ejemplo n.º 18
0
 private void makeLineGraph(Vector3 begin, Vector3 end)
 {
     //makePoint(begin);
    // makePoint(end);
     LineRenderer line = new GameObject().AddComponent<LineRenderer>();
     line.transform.parent = this.transform.parent;
     line.SetWidth(0.05F, 0.05F);
     line.SetColors(Color.green, Color.green);
     line.SetPosition(0, begin);
     line.SetPosition(1, end);
     line.SetVertexCount(2);
     line.material = new Material(Shader.Find("Particles/Additive"));
 }
Ejemplo n.º 19
0
    public void AddMultipleBondNeighbour(GameObject neighbour)
    {
        //Get amount of bonds with this neighbour
        int nrOfBonds = 0;

        for (int i = 0; i < connectedElements.Count; i++)
        {
            if (connectedElements [i].GetInstanceID() == neighbour.GetInstanceID())
            {
                nrOfBonds++;
            }
        }

        //Update info and renderer if additional bond is possible
        if (nrOfBonds < maxBonds)
        {
            Debug.Log("multiple Bond happening! NrOfBonds: " + nrOfBonds + ", MaxBonds: " + maxBonds);
            connectedElements.Add(neighbour);
            neighbour.GetComponent <GridfieldController> ().AddThisMultipleBondNeighbour(this.gameObject, nrOfBonds);
            leftConnections--;
            //Get the render
            bool         newRenderer = false;
            LineRenderer lRenderer   = new GameObject("Line to " + neighbour.GetInstanceID() + nrOfBonds).AddComponent <LineRenderer> ();
            for (int i = 0; i < lineRenderers.Count; i++)
            {
                if (lineRenderers[i].gameObject.name.Equals("Line to " + neighbour.GetInstanceID()))
                {
                    lRenderer.transform.parent = lineRenderers[i].transform.parent;
                    lRenderer.material         = lineRenderers[i].material;
                    lRenderer.SetVertexCount(2);
                    lRenderer.SetPosition(0, this.transform.position);
                    lRenderer.SetPosition(1, neighbour.transform.position);
                    lRenderer.sortingOrder = 2;
                    //Change the render to display the multiple bond

                    switch (nrOfBonds)
                    {
                    case 1:
                        //double bond
                        lRenderer.SetColors(new Color(174f / 255f, 174f / 255f, 174f / 255f), new Color(174f / 255f, 174f / 255f, 174f / 255f));
                        lRenderer.sortingOrder++;
                        lRenderer.SetWidth(defaultBondWidth, defaultBondWidth);
                        newRenderer = true;
                        lineRenderers[i].SetWidth(defaultBondWidth * 3, defaultBondWidth * 3);
                        break;

                    case 2:
                        //triple bond
                        lRenderer.SetColors(Color.black, Color.black);
                        lRenderer.sortingOrder += 2;
                        lRenderer.SetWidth(defaultBondWidth / 2, defaultBondWidth / 2);
                        newRenderer = true;
                        lineRenderers[i].SetWidth(defaultBondWidth * 2, defaultBondWidth * 2);
                        break;
                    }
                }
            }
            if (newRenderer)
            {
                lineRenderers.Add(lRenderer);
                lineDestinations.Add(lRenderer, neighbour.GetComponent <GridfieldController>().GetElement());
            }
        }
        else
        {
            Debug.Log(this.gameObject.name + "'s nr of bonds: " + nrOfBonds + "; Max bonds: " + maxBonds);
            //Max bonds alredy reached, reset all connections
            neighbour.GetComponent <GridfieldController> ().RemoveThisNeighbour(this.gameObject);
            RemoveThisNeighbour(neighbour);
        }
    }