示例#1
0
    /*
     * -------------------------------------------- KETERANGAN -------------------------------------------------
     * NAMA : void initialitation_line_luar()
     * DESKRIPSI:
     * Fungsi yang digunakan untuk membuat garis yang menghubungkan antara nama komponen saraf dengan bagian komponen saraf luar
     * STATUS:
     * Done
     * ----------------------------------------------------------------------------------------------------------
     */
    void initialitation_line_luar()
    {
        // Add a Line Renderer to the GameObject
        cell_body_line = new GameObject().AddComponent <LineRenderer>() as LineRenderer;
        // Set the width of the Line Renderer
        cell_body_line.SetWidth(0.05F, 0.05F);
        // Set the number of vertex fo the Line Renderer
        cell_body_line.SetVertexCount(2);

        // Add a Line Renderer to the GameObject
        myelin_line = new GameObject().AddComponent <LineRenderer>() as LineRenderer;
        // Set the width of the Line Renderer
        myelin_line.SetWidth(0.05F, 0.05F);
        // Set the number of vertex fo the Line Renderer
        myelin_line.SetVertexCount(2);

        // Add a Line Renderer to the GameObject
        dendrite_line = new GameObject().AddComponent <LineRenderer>() as LineRenderer;
        // Set the width of the Line Renderer
        dendrite_line.SetWidth(0.05F, 0.05F);
        // Set the number of vertex fo the Line Renderer
        dendrite_line.SetVertexCount(2);

        // Add a Line Renderer to the GameObject
        sinapsis_line = new GameObject().AddComponent <LineRenderer>() as LineRenderer;
        // Set the width of the Line Renderer
        sinapsis_line.SetWidth(0.05F, 0.05F);
        // Set the number of vertex fo the Line Renderer
        sinapsis_line.SetVertexCount(2);
    }
示例#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);
        }
示例#3
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;
            }
        }
    }
示例#4
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);
                    }
                }
            }
        }
    }
示例#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;  
	}  
示例#6
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;
 }
示例#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"));
 }
    // 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);
    }
示例#9
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;
    }
示例#10
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"));
    }
示例#11
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);
    }
示例#12
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"));
    }
示例#13
0
        private LineRenderer initLR(Vessel v, VesselBounds vbounds)
        {
            LineRenderer Lr;

            Lr          = new GameObject().AddComponent <LineRenderer>();
            Lr.material = new Material(Shader.Find("KSP/Emissive/Diffuse"));
            Lr.material.SetColor("_EmissiveColor", Color.green);
            Lr.SetWidth(0.15f, 0.15f);
            Lr.SetVertexCount(2);
            Lr.SetPosition(0, v.CoM + vbounds.bottomPoint);
            Lr.SetPosition(1, v.CoM + vbounds.bottomPoint +
                           Vector3.ProjectOnPlane(v.CoM - FlightCamera.fetch.mainCamera.transform.position, vbounds.up).normalized);
            Lr.enabled = true;
            return(Lr);
        }
    void DrawOnMove()
    {
        //Se os valores X ou Y da variavel MouseLastPosition(Posiçao antiga do mouse) forem diferentes dos valores X ou Y da variavel MouseActualPosition(Posiçao atual do mouse), entao o mouse se moveu
        if(MouseLastPosition.x != MouseActualPosition.x || MouseLastPosition.y != MouseActualPosition.y)
        {
            LineRenderer Line = new GameObject("Line").AddComponent<LineRenderer>();
            Line.transform.parent = GameObject.Find("LineMother").transform;
            Line.material = LineColor;
            Line.SetVertexCount(2);
            Line.SetWidth(0.1f,0.1f);
            Line.SetPosition(0,Camera.main.ScreenToWorldPoint(new Vector3(MouseLastPosition.x, MouseLastPosition.y, ZPosition)));
            Line.SetPosition(1,Camera.main.ScreenToWorldPoint(new Vector3(MouseActualPosition.x, MouseActualPosition.y, ZPosition)));

            //Igualando a posiçao antiga do mouse com a atual, para caso ele se mova de novo, a comparaçao seja correta
            MouseLastPosition = Input.mousePosition;
        }
    }
示例#15
0
	public static void buildLine(Vector3 start, Vector3 end){
		LineRenderer line = new GameObject ("Line").AddComponent<LineRenderer> ();
		//apparently I should use this as a default material, but it didn't work so I used some arbitrary material
		//line.material = new Material(Shader.Find("Particles/Additive"));
		line.material = material;
		line.gameObject.layer = LayerMask.NameToLayer ("Minimap");
		line.material.SetColor ("colour", Color.black);
		line.castShadows = false;
		line.receiveShadows = false;
		line.transform.parent = GameObject.Find("lines").transform;
		line.SetWidth(1.0f, 1.0f);
		line.SetVertexCount(2);
		line.SetPosition(0, start);
		line.SetPosition (1, end);
		string positions = start.x.ToString () + "," + start.y.ToString () + "," + start.z.ToString () + "," + end.x.ToString () + "," + end.y.ToString () + "," + end.z.ToString ();
		if (Network.isServer) {
			ClientNetwork client = (ClientNetwork) GameObject.FindObjectOfType(typeof(ClientNetwork));
			client.startClientLines (positions);
		}
	}
示例#16
0
    void DrawDerivative()
    {
        for (int i = 0; i < DERIVATIVE_SEGMENT_COUNT; i++)
        {
            LineRenderer lRend = new GameObject().AddComponent <LineRenderer>() as LineRenderer;

            Vector3 vertex = GetPoint(i / (float)DERIVATIVE_SEGMENT_COUNT);

            lRend.SetVertexCount(2);
            lRend.SetPosition(0, vertex);
            lRend.SetPosition(1, vertex + GetDirection(i / (float)DERIVATIVE_SEGMENT_COUNT) * DerivativeLength);

            //lRend.material.color = Color.green;
            Material myMaterial3 = (Material)Resources.Load("ArrowAsset/MyRed", typeof(Material));
            lRend.material = myMaterial3;



            derivativeLines.Add(lRend);
            derivativeLines[i].enabled = true;
        }
    }
示例#17
0
    /*
     * -------------------------------------------- KETERANGAN -------------------------------------------------
     * NAMA : void initialitation_line_dalam()
     * DESKRIPSI:
     * Fungsi yang digunakan untuk membuat garis yang menghubungkan antara nama komponen saraf dengan bagian komponen saraf dalam
     * STATUS:
     * Done
     * ----------------------------------------------------------------------------------------------------------
     */
    void initialitation_line_dalam()
    {
        // Add a Line Renderer to the GameObject
        sell_schawann_line = new GameObject().AddComponent <LineRenderer>() as LineRenderer;
        // Set the width of the Line Renderer
        sell_schawann_line.SetWidth(0.05F, 0.05F);
        // Set the number of vertex fo the Line Renderer
        sell_schawann_line.SetVertexCount(2);

        // Add a Line Renderer to the GameObject
        akson_line = new GameObject().AddComponent <LineRenderer>() as LineRenderer;
        // Set the width of the Line Renderer
        akson_line.SetWidth(0.05F, 0.05F);
        // Set the number of vertex fo the Line Renderer
        akson_line.SetVertexCount(2);

        // Add a Line Renderer to the GameObject
        nukleus_line = new GameObject().AddComponent <LineRenderer>() as LineRenderer;
        // Set the width of the Line Renderer
        nukleus_line.SetWidth(0.05F, 0.05F);
        // Set the number of vertex fo the Line Renderer
        nukleus_line.SetVertexCount(2);
    }
示例#18
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);
        }
示例#19
0
    void DrawCurtain()
    {
        for (int i = 0; i < CURTAIN_SEGMENT_COUNT; i++)
        {
            LineRenderer lRend = new GameObject().AddComponent <LineRenderer>() as LineRenderer;

            Vector3 vertex = GetPoint(i / (float)CURTAIN_SEGMENT_COUNT);

            lRend.SetVertexCount(2);
            lRend.SetPosition(0, vertex);

            Vector3 vertex2 = new Vector3(vertex.x, 0, vertex.z);
            lRend.SetPosition(1, vertex2);

            //lRend.material.Color = Color.red;
            Material myMaterial2 = (Material)Resources.Load("ArrowAsset/MyRed", typeof(Material));
            lRend.material = myMaterial2;



            curtainLines.Add(lRend);
            curtainLines[i].enabled = true;
        }
    }
示例#20
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>();
	}
示例#21
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);
		
	}
示例#22
0
文件: DrawGraph.cs 项目: wasiher/funk
    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);
 }
示例#24
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"));
 }
示例#25
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);
        }
    }
示例#26
0
        public Part findCounterpartOnLaunch()
        {
            // Raycast upwards, return true if there's a lockable part within proper distance and aligned
            int rayCastMask = 0xFFFF;

            RaycastHit[] hits = new RaycastHit[5]; // Say, 5 colliders ought to be enough for anyone

            Transform tf = part.FindModelTransform(lockTransform);

            float upperBound = findPartUpperBound(tf);

            printDebug($"upper bound = {upperBound}");

            if (debugLevel > 1)
            {
                // Debug visual for raycast
                LineRenderer lr = new GameObject().AddComponent <LineRenderer> ();
                lr.material      = new Material(Shader.Find("KSP/Emissive/Diffuse"));
                lr.useWorldSpace = true;
                lr.material.SetColor("_EmissiveColor", Color.green);

#if (KSP_151 || KSP_161 || KSP_171)
                lr.positionCount = 2;
                lr.startWidth    = 0.05f;
                lr.endWidth      = 0.05f;
#else
                lr.SetVertexCount(2);
                lr.SetWidth(0.05f, 0.05f);
#endif

                lr.enabled = true;
                lr.SetPosition(0, tf.position);
                lr.SetPosition(1, tf.up * upperBound * 1.5f);
            }

            int nHits = Physics.RaycastNonAlloc(tf.position, tf.up, hits, upperBound * 1.5f, rayCastMask);
            printDebug($"Got {nHits} hits");
            for (int n = 0; n < nHits; n++)
            {
                printDebug($"Got raycast hit {hits[n]}, transform: {hits[n].transform}, GO: {hits[n].transform.gameObject}" +
                           $"; distance: {hits[n].distance}; collider: {hits[n].collider}");
                Part hitPart = hits[n].transform.gameObject.GetComponentInParent <Part>();
                if (hitPart == null)
                {
                    printDebug("No part");
                    continue;
                }
                printDebug($"Hit part {hitPart}; id={hitPart.flightID}");
                if (hitPart.flightID == part.flightID)
                {
                    printDebug("Got hit to ourselves");
                    continue;
                }
                // Check if it is a lockable part at all
                if (!isLockablePart(hitPart))
                {
                    printDebug("Part could not be locked to");
                    continue;
                }
                printDebug("Part could be locked to");
                // Ok, we can lock to it. Check alignment
                if (!checkRollAndDot(hitPart, upperBound))
                {
                    printDebug("Part not aligned");
                    return(null);
                }

                printDebug($"Parts aligned, returning {hitPart}");
                return(hitPart);
            }
            return(null);
        }