void Start() { MeshFilter meshFilter = GetComponent <MeshFilter>(); currentCurve = gameObject.GetComponent <CurveLineRenderer>(); mesh = meshFilter.mesh; if (mesh == null) { mesh = new Mesh(); mesh.name = "Curve Line Mesh"; meshFilter.mesh = mesh; } Material[] materials = GetComponent <MeshRenderer>().materials; for (int i = 0; i < materials.Length; ++i) { if (materials[i].mainTexture != null && materials[i].mainTexture.wrapMode != TextureWrapMode.Repeat) { Debug.LogWarning("Main texture of " + materials[i].name + " should have 'Repeat' wrap mode"); } } ; meshCollider = GetComponent <MeshCollider>(); Invalidate(); }
public void updateComponents() { MeshRenderer meshRenderer = GetComponent <MeshRenderer>(); currentCurve = gameObject.GetComponent <CurveLineRenderer>(); Material defaultMaterial = Resources.Load <Material>("CurveLineMaterial") as Material; meshRenderer.material = defaultMaterial; }
void OnEnable() { curveLineRenderer = (CurveLineRenderer)target; handleTransform = curveLineRenderer.transform; handleRotation = Tools.pivotRotation == PivotRotation.Local ? handleTransform.rotation : Quaternion.identity; handleMeshFilter = curveLineRenderer.GetComponent <MeshFilter>(); handleMeshCollider = curveLineRenderer.GetComponent <MeshCollider>(); SceneView.onSceneGUIDelegate = OnSceneDraw; RebuildMesh(); }
private void RenderCurve() { CurveLineRenderer.SetCurvePositions(_curve, control); //set arrow position arrowSprite.position = _curve.GetPosition(_curve.positionCount - 1); //set arrow rotation Vector2 v = (_curve.GetPosition(_curve.positionCount - 1) - _curve.GetPosition(_curve.positionCount - 3)).normalized; float degree = Mathf.Rad2Deg * Mathf.Atan(v.y / v.x); degree = v.x < 0 ? degree + 180 : degree; // Debug.Log(v.x + " " + v.y + " " + degree); arrowSprite.transform.rotation = Quaternion.Euler(0, 0, degree); }
void OnDisable() { curveLineRenderer = null; SceneView.onSceneGUIDelegate -= OnSceneDraw; }
void Start() { splineRenderer = GetComponent <CurveLineRenderer> (); rates = new int[6]; rates [0] = -1; rates [1] = 1; rates [2] = 2; rates [3] = 3; rates [4] = 1; rates [5] = 1; tiles = new List <GameObject> (); path = new List <Vector3> (); tileList = new List <Tile>(width * height); edgeMatrix = new int[width * height][]; Tile[] tileArray = FindObjectsOfType <Tile> (); tileList.AddRange(tileArray); tileList.Sort(new Tile.PositionComparer()); colors = new Color32[6]; colors[0] = tileList[0].gameObject.GetComponent <Renderer>().material.color; int nextTileId = 0; for (int iii = 0; iii < tileList.Count; ++iii) { Tile t = tileList[iii]; t.id = nextTileId++; tiles.Add(t.gameObject); edgeMatrix[t.id] = new int[8]; t.gameObject.GetComponent <Renderer>().material.color = t.gameObject.GetComponent <Renderer>().material.color; int i = t.id % width; int j = t.id / height; int k = 0; int y = t.y; for (int jj = j - 1; jj < j + 2; ++jj) { for (int ii = i - 1; ii < i + 2; ++ii) { if (ii == i && jj == j) { continue; } if (ii > -1 && ii < width && jj > -1 && jj < height) { int yy = (tileList[jj * width + ii]).y; if (Mathf.Abs(yy - y) < 1.5f) { edgeMatrix[t.id][k] = jj * width + ii; } else { edgeMatrix[t.id][k] = -1; } } else { edgeMatrix[t.id][k] = -1; } k++; } } } for (int i = 0; i < tileList.Count; ++i) { Tile t = tileList[i]; int y = t.y; if (y == 1) { int y1 = tileList[edgeMatrix[t.id][1]].y; int y2 = tileList[edgeMatrix[t.id][6]].y; int v1 = 0; int v2 = 0; if (y1 == y2) { v1 = edgeMatrix[t.id][1]; v2 = edgeMatrix[t.id][6]; edgeMatrix[v1][6] = -1; edgeMatrix[v2][1] = -1; edgeMatrix[t.id][1] = -1; edgeMatrix[t.id][6] = -1; } else { v1 = edgeMatrix[t.id][3]; v2 = edgeMatrix[t.id][4]; edgeMatrix[v1][4] = -1; edgeMatrix[v2][3] = -1; edgeMatrix[t.id][3] = -1; edgeMatrix[t.id][4] = -1; } } } UpdateTilesInRange(); }