PersistentTrails.Track.setupRenderer C# (CSharp) Method

setupRenderer() public method

public setupRenderer ( ) : void
return void
        public void setupRenderer()
        {
            if (Visible)
            {
                if (drawnPathObj == null) {
                    drawnPathObj = new GameObject("PersistentTrails Track");

                    lineRenderer = drawnPathObj.AddComponent<LineRenderer>();

                    lineRenderer.material = new Material(Shader.Find("KSP/Emissive/Diffuse"));
                    lineRenderer.renderer.castShadows = false;
                    lineRenderer.renderer.receiveShadows = false;

                    //Map mode
                    //mapModeObj = new GameObject();
                    //mapModeObj.layer = 10;
                    //mapModeObj.transform.parent = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == this.referenceBody.name);

                    //mapLineRenderer = mapModeObj.AddComponent<LineRenderer>();

                    //mapLineRenderer.material = new Material(Shader.Find("KSP/Emissive/Diffuse"));
                    //mapLineRenderer.renderer.castShadows = false;
                    //mapLineRenderer.renderer.receiveShadows = false;
                }

                //lineMaterial.SetColor("_EmissiveColor", LineColor);
                lineRenderer.material.color = LineColor;
                lineRenderer.material.SetColor("_EmissiveColor", LineColor);

                //lineRenderer.SetColors(LineColor, LineColor);
                lineRenderer.SetWidth(LineWidth, LineWidth);

                //mapLineRenderer.material.color = LineColor;
                //mapLineRenderer.material.SetColor("_EmissiveColor", LineColor);
                //mapLineRenderer.SetWidth(LineWidth / 6000, LineWidth / 6000);

                calculateLineVertices();

                foreach (LogEntry logEntry in logEntries)
                {
                    setupLogEntryLabel(logEntry);

                }

                updateDirectionMarkers();

            }
            else
            {
                //renderCoords.Clear();

                if (drawnPathObj != null)
                {
                    Debug.Log("Removing Renderer for Path " + TrackName);
                    lineRenderer.SetVertexCount(0);
                    lineRenderer.enabled = false;
                    GameObject.Destroy(drawnPathObj);
                    GameObject.Destroy(lineRenderer);
                    drawnPathObj = null;
                    lineRenderer = null;

                    //GameObject.Destroy(mapModeObj);
                    //GameObject.Destroy(mapLineRenderer);

                    foreach (LogEntry entry in logEntries) {
                        if (entry.gameObject != null)
                            GameObject.Destroy(entry.gameObject);
                    }

                    foreach (GameObject obj in directionMarkers)
                        obj.renderer.enabled = false;
                }
            }
        }

Usage Example

Esempio n. 1
0
        protected override void DrawWindowContents(int windowID)
        {
            GUILayout.BeginVertical(); // BEGIN outer container

            GUILayout.BeginHorizontal();
            GUILayout.Label("Track Name:");
            newName = GUILayout.TextField(newName);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Description:");
            newDescription = GUILayout.TextField(newDescription);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Color");

            GUILayout.BeginVertical();
            float h, s, v;

            Utilities.ColorToHSV(newColor, out h, out s, out v);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Hue");
            h = GUILayout.HorizontalSlider(h, 0, 360);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Sat.");
            s = GUILayout.HorizontalSlider(s, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Val.");
            v        = GUILayout.HorizontalSlider(v, 0, 1);
            newColor = Utilities.ColorFromHSV(h, s, v);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            Utilities.SetTextureColor(colorTex, 32, 32, this.newColor);
            //this.colorStyle = new GUIStyle();
            //colorStyle.normal.textColor = this.newColor;
            //GUIStyle generic_style = new GUIStyle();
            //GUI.skin.box = generic_style;
            //GUI.Box(new Rect(x, y, w, h), rgb_texture);

            if (GUILayout.Button(colorTex))
            {
                // Show the color dialog.
                ExplorerTrackBehaviour.Instance.colorDlg = new ColorPicker(this);
                ExplorerTrackBehaviour.Instance.colorDlg.Awake();
                ExplorerTrackBehaviour.Instance.colorDlg.SetVisible(true);
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Draw Sampling:");
            sampling = GUILayout.HorizontalSlider(sampling, 1, 10);
            GUILayout.Label("" + (int)sampling + "x");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Line Width (m):");
            float sliderPos = lineWidthToSliderPos(lineWidth);

            sliderPos = GUILayout.HorizontalSlider(sliderPos, 1, 12);
            lineWidth = sliderPosToLineWidth(sliderPos);
            GUILayout.Label("" + lineWidth + "m");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Direction marker radius:");
            markerRadiusFactor = GUILayout.HorizontalSlider(markerRadiusFactor, 2, 50);
            GUILayout.Label("" + lineWidth * markerRadiusFactor + "m");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Number of direction markers:");
            numMarkers = GUILayout.HorizontalSlider(numMarkers, 0, 20);
            GUILayout.Label("" + (int)numMarkers);
            GUILayout.EndHorizontal();

            colliders = GUILayout.Toggle(colliders, "Activate Replay Colliders");

            GUILayout.BeginHorizontal();
            GUILayout.Label("Replay End Action:");
            selectedActionIndex = GUILayout.SelectionGrid(selectedActionIndex, new string[] { "Stop", "Loop", "OffRails", "Delete" }, 4);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Loop closure time:");
            loopTime = GUILayout.HorizontalSlider(loopTime, 0, 100);
            GUILayout.Label("" + (int)loopTime + "s");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("OK"))
            {
                string newUniqueName = Utilities.makeUniqueTrackName(newName, ref trackList, true);
                if (File.Exists(Utilities.TrackPath + track.TrackName + ".trk"))
                {
                    File.Move(Utilities.TrackPath + track.TrackName + ".trk", Utilities.TrackPath + newUniqueName + ".trk");
                }

                track.TrackName      = newUniqueName;
                track.Description    = newDescription;
                track.LineColor      = newColor;
                track.SamplingFactor = (int)sampling;
                track.LineWidth      = lineWidth;
                track.ConeRadiusToLineWidthFactor = markerRadiusFactor;
                track.NumDirectionMarkers         = (int)numMarkers;
                track.LoopClosureTime             = (int)loopTime;
                track.ReplayColliders             = colliders;
                track.EndAction = (Track.EndActions)selectedActionIndex;

                track.Modified = true;

                track.setupRenderer();
                mainWindow.updateColorTextures();
                SetVisible(false);
                Save(new ConfigNode(GetConfigNodeName()));//Does nothing...
            }

            if (GUILayout.Button("Cancel"))
            {
                SetVisible(false);
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }