private SetPath ( int index, Vector2 points ) : void | ||
index | int | |
points | Vector2 | |
return | void |
static public int SetPath(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.PolygonCollider2D self = (UnityEngine.PolygonCollider2D)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); UnityEngine.Vector2[] a2; checkArray(l, 3, out a2); self.SetPath(a1, a2); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
void Start() { Debug.Log("Started"); gameObject.AddComponent<LineRenderer>(); classpc = gameObject.AddComponent<PolygonCollider2D>(); classpc.SetPath(0, new Vector2[] { }); //classpc.SetPath(1, new Vector2[] { }); }
public void addPolygonCollider(PolygonCollider2D polyCollider) { if (type < 1) return; if (type > 14) return; Vector2[] points = null; Vector2 nodeOffset = new Vector2(nodePosition.x - polyCollider.transform.localPosition.x, nodePosition.y - polyCollider.transform.localPosition.y); if ((type >=1) && (type <=12)) { points = new Vector2[vertices.Length]; for (int i=0; i<vertices.Length; i++) { points[i] = new Vector2(vertices[i].x, vertices[i].y) + nodeOffset; } polyCollider.SetPath(polyCollider.pathCount-1, points); polyCollider.pathCount = polyCollider.pathCount+1; } if ((type == 13) || (type == 14)) { points = new Vector2[3]; for (int i=0; i<3; i++) { points[i] = new Vector2(vertices[i].x, vertices[i].y) + nodeOffset; } polyCollider.SetPath(polyCollider.pathCount-1, points); polyCollider.pathCount = polyCollider.pathCount+1; points = new Vector2[3]; for (int i=3; i<6; i++) { points[i-3] = new Vector2(vertices[i].x, vertices[i].y) + nodeOffset; } polyCollider.SetPath(polyCollider.pathCount-1, points); polyCollider.pathCount = polyCollider.pathCount+1; } }
static public int SetPath(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); if (matchType(l, argc, 2, typeof(int), typeof(UnityEngine.Vector2[]))) { UnityEngine.PolygonCollider2D self = (UnityEngine.PolygonCollider2D)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); UnityEngine.Vector2[] a2; checkArray(l, 3, out a2); self.SetPath(a1, a2); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(int), typeof(List <UnityEngine.Vector2>))) { UnityEngine.PolygonCollider2D self = (UnityEngine.PolygonCollider2D)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); System.Collections.Generic.List <UnityEngine.Vector2> a2; checkType(l, 3, out a2); self.SetPath(a1, a2); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function SetPath to call"); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
public void PasteTo( PolygonCollider2D polygonCollider ) { polygonCollider.pathCount = paths.Count; for ( int i = 0; i < paths.Count; i++ ) { polygonCollider.SetPath( i, paths[ i ] ); } polygonCollider.isTrigger = isTrigger; polygonCollider.offset = offset; polygonCollider.sharedMaterial = sharedMaterial; polygonCollider.usedByEffector = usedByEffector; polygonCollider.enabled = enabled; }
static public int SetPath(IntPtr l) { try { UnityEngine.PolygonCollider2D self = (UnityEngine.PolygonCollider2D)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); UnityEngine.Vector2[] a2; checkType(l, 3, out a2); self.SetPath(a1, a2); return(0); } catch (Exception e) { return(error(l, e)); } }
static int QPYX_SetPath_YXQP(IntPtr L_YXQP) { try { ToLua.CheckArgsCount(L_YXQP, 3); UnityEngine.PolygonCollider2D QPYX_obj_YXQP = (UnityEngine.PolygonCollider2D)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.PolygonCollider2D)); int QPYX_arg0_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 2); UnityEngine.Vector2[] QPYX_arg1_YXQP = ToLua.CheckStructArray <UnityEngine.Vector2>(L_YXQP, 3); QPYX_obj_YXQP.SetPath(QPYX_arg0_YXQP, QPYX_arg1_YXQP); return(0); } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static int SetPath(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); UnityEngine.PolygonCollider2D obj = (UnityEngine.PolygonCollider2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.PolygonCollider2D)); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); UnityEngine.Vector2[] arg1 = ToLua.CheckStructArray <UnityEngine.Vector2>(L, 3); obj.SetPath(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
internal void ResetCell(Site site) { this.site = site; // add polygon polygon = gameObject.GetComponent<PolygonCollider2D>(); polygon.SetPath (0, site.Vertices.ToArray ()); // TODO: Use a MeshCollider instead // MeshCollider myMC = GetComponent<MeshCollider>(); // Mesh newMesh = new Mesh(); // newMesh.vertices = newverts; // newMesh.triangles = newtris; // newMesh.RecalculateBounds(); // myMC.sharedMesh = newMesh; gameObject.name = ToString (); }
public void CopyVertices(PolygonCollider2D a_rPolygonCollider2DTo) { // Clear a_rPolygonCollider2DTo.points = new Vector2[0]; if(shapes == null) { return; } a_rPolygonCollider2DTo.pathCount = shapes.Count; int iShapeIndex = 0; foreach(Uni2DMeshShape2D rShape in shapes) { a_rPolygonCollider2DTo.SetPath(iShapeIndex, rShape.vertices); ++iShapeIndex; } }
void OptimizePolygonCollider2D(GameObject gameobject, PolygonCollider2D polygonCollider2D) { int origVertCount = 0; int cleanVertCount = 0; float angleThreshold = 90.0f; List<Vector2> newVerts = new List<Vector2>(); for (int i = 0; i < polygonCollider2D.pathCount; i++) { newVerts.Clear(); Vector2[] path = polygonCollider2D.GetPath(i); if (path.Length < 4) { continue; } origVertCount += path.Length; float angle1 = 0; float angle2 = 0; newVerts.Clear(); int mx = path.Length; Vector2 currentDir = (path[0] - path[1]).normalized; angle1 = Vector2.Angle(path[0] - path[1], currentDir); for (int j = 0; j < mx; j++) { int sPrev = (((j - 1) % mx) + mx) % mx; int sNext = (((j + 1) % mx) + mx) % mx; angle1 = Vector2.Angle(path[sPrev] - path[j], currentDir); angle2 = Vector2.Angle(path[j] - path[sNext], currentDir); if (angle1 > angleThreshold || angle2 > angleThreshold) { currentDir = (path[j] - path[sNext]).normalized; newVerts.Add(path[j]); } } polygonCollider2D.SetPath(i, newVerts.ToArray()); cleanVertCount += newVerts.Count; } }
//************ // // Private Unity Methods // //************ private void Awake() { //create an object and mesh for the trail GameObject trail = new GameObject("Trail", new[] { typeof(MeshRenderer), typeof(MeshFilter), typeof(PolygonCollider2D) }); mesh = trail.GetComponent<MeshFilter>().mesh = new Mesh(); trail.GetComponent<Renderer>().material = trailMaterial; //get and set the polygon collider on this trail. collider = trail.GetComponent<PolygonCollider2D>(); collider.isTrigger = colliderIsTrigger; collider.SetPath(0, null); //get the transform of the object this script is attatched to trans = base.transform; //set the first center position as the current position centerPositions = new LinkedList<Vector3>(); centerPositions.AddFirst(trans.position); leftVertices = new LinkedList<Vertex>(); rightVertices = new LinkedList<Vertex>(); }
public static void SetColliderPointsLocal (PolygonCollider2D collider, Slot slot, BoundingBoxAttachment box) { if (box == null) return; if (box.IsWeighted()) Debug.LogWarning("UnityEngine.PolygonCollider2D does not support weighted or animated points. Collider points will not be animated and may have incorrect orientation. If you want to use it as a collider, please remove weights and animations from the bounding box in Spine editor."); var verts = box.GetLocalVertices(slot, null); collider.SetPath(0, verts); }
private void AddCharHoles(PolygonCollider2D navPoly, AC.Char charToExclude, CharacterEvasion characterEvasion) { ResetHoles (KickStarter.sceneSettings.navMesh, false); Vector2 navPosition = navPoly.transform.position; AC.Char[] characters = GameObject.FindObjectsOfType (typeof (AC.Char)) as AC.Char[]; foreach (AC.Char character in characters) { CircleCollider2D circleCollider2D = character.GetComponent <CircleCollider2D>(); if (circleCollider2D != null && (character.charState == CharState.Idle || characterEvasion == CharacterEvasion.AllCharacters) && (charToExclude == null || character != charToExclude) && Physics2D.OverlapPointNonAlloc (character.transform.position, NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0) { circleCollider2D.isTrigger = true; List<Vector2> newPoints3D = new List<Vector2>(); #if UNITY_5 Vector2 centrePoint = character.transform.TransformPoint (circleCollider2D.offset); #else Vector2 centrePoint = character.transform.TransformPoint (circleCollider2D.center); #endif float radius = circleCollider2D.radius * character.transform.localScale.x; newPoints3D.Add (centrePoint + Vector2.up * radius); newPoints3D.Add (centrePoint + Vector2.right * radius); newPoints3D.Add (centrePoint - Vector2.up * radius); newPoints3D.Add (centrePoint - Vector2.right * radius); navPoly.pathCount ++; List<Vector2> newPoints = new List<Vector2>(); for (int i=0; i<newPoints3D.Count; i++) { // Only add a point if it is on the NavMesh if (Physics2D.OverlapPointNonAlloc (newPoints3D[i], NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0) { newPoints.Add (newPoints3D[i] - navPosition); } else { Vector2 altPoint = GetLineIntersect (newPoints3D[i], centrePoint); if (altPoint != Vector2.zero) { newPoints.Add (altPoint - navPosition); } } } if (newPoints.Count > 1) { navPoly.SetPath (navPoly.pathCount-1, newPoints.ToArray ()); } } } RebuildVertexArray (navPoly.transform, navPoly); }
public void StopDraw() { StartDraw = false; previousObj = null; startPoint = null; if(linePoints.Count<2){ linePoints.Clear(); return;} #region getting circle shape Hashtable table = new Hashtable(); foreach (Vector3 item in linePoints) { float radius = (float) System.Math.Round( Vector2.Distance( item, compute2DPolygonCentroid(linePoints.ToArray(), linePoints.Count)), 2); if(!table.ContainsKey( radius)) table.Add(radius, 0); table[radius] = (int) table[radius] + 1; } GameObject parentObj = new GameObject("lineObject"); parentObj.transform.parent = transform; foreach (DictionaryEntry item in table) { if((int)item.Value >= 10 && table.Count > 6) { CreateCircle(compute2DPolygonCentroid(linePoints.ToArray(), linePoints.Count), ""+item.Key, parentObj); linePoints.Clear(); return; } } #endregion int ii = 0; GameObject gm = null; GameObject polyObj = new GameObject("polyObj"); polyObj.transform.parent = parentObj.transform; PlaneFromPoly scr = polyObj.AddComponent<PlaneFromPoly>(); foreach (Vector3 item in linePoints) { //create points gm = Instantiate(point, item, transform.rotation) as GameObject; if(startPoint == null) startPoint = gm; gm.transform.parent = polyObj.transform; gm.GetComponent<LineObject>().firstObject = item; gm.GetComponent<LineObject>().nextObject = gm; if(previousObj != null){ gm.GetComponent<LineObject>().nextObject = previousObj; } previousObj = gm; ii++; } scr.mat = mat; scr.poly = linePoints.ToArray(); scr.keyPoints = linePoints; int scoreMinus = -80; if(Vector3.Distance( startPos, Input.mousePosition) < 10f){ // if shape is rounded scoreMinus = -50; scr.BuildMesh(linePoints); gm.GetComponent<LineObject>().nextObject = startPoint; polyCollider = polyObj.AddComponent<PolygonCollider2D>(); polyCollider.sharedMaterial = bounce; polyCollider.CreatePrimitive(linePoints.Count); polyCollider.SetPath(0, linePoints.ToArray() ); } else{ edgeCollider = polyObj.AddComponent<EdgeCollider2D>(); edgeCollider.sharedMaterial = bounce; // polyCollider = polyObj.AddComponent<PolygonCollider2D>(); // polyCollider.sharedMaterial = bounce; // polyCollider.CreatePrimitive( linePoints.Count * 2 ); Vector2[] listV2 = new Vector2[linePoints.Count*2]; for (int i = 0; i < linePoints.Count; i++) { listV2[i] = linePoints[i]; } int j =0; for (int i = linePoints.Count - 1; i >= 0; i--) { listV2[j+linePoints.Count] = linePoints[i]+Vector2.up*0.05f; j++; } edgeCollider.points = linePoints.ToArray(); //listV2; // polyCollider.SetPath(0, listV2); } previousObj = null; startPoint = null; Rigidbody2D r = polyObj.AddComponent<Rigidbody2D>(); r.mass = 0.2f * linePoints.Count; // r.collisionDetectionMode = CollisionDetectionMode2D.Continuous; linePoints.Clear(); }
private static void CompileTracedEdges(PolygonCollider2D polygonCollider, int pathCount) { generatedPoints.Clear(); foreach (var point in tracedEdges) { generatedPoints.Add(point.Position); } if (polygonCollider.pathCount <= pathCount) { polygonCollider.pathCount += 1; } polygonCollider.SetPath(pathCount, generatedPoints.ToArray()); }
public static void CopyVertices(List<Vector2[]> a_rShapeVerticesFrom, PolygonCollider2D a_rPolygonCollider2DTo) { // Clear a_rPolygonCollider2DTo.points = new Vector2[0]; a_rPolygonCollider2DTo.pathCount = a_rShapeVerticesFrom.Count; int iShapeIndex = 0; foreach(Vector2[] rVertices in a_rShapeVerticesFrom) { a_rPolygonCollider2DTo.SetPath(iShapeIndex, rVertices); ++iShapeIndex; } }
void Update() { //if(Input.GetKey(KeyCode.Alpha0) && index == 1) { // index = 0; // classpc = gameObject.AddComponent<PolygonCollider2D>(); // classpc.SetPath(0, new Vector2[] { }); //} //if (Input.GetKey(KeyCode.Alpha1) && index == 0) { // index = 1; // classpc = gameObject.AddComponent<PolygonCollider2D>(); // classpc.SetPath(0, new Vector2[] { }); //} Touch t; if (Input.touches.Length > 0) { t = Input.GetTouch(0); if (t.phase == TouchPhase.Ended) { Debug.Log("Finished touching!!"); classpc = gameObject.AddComponent<PolygonCollider2D>(); classpc.SetPath(0, new Vector2[] { }); } } var str = ""; var oldpath = classpc.GetPath(0); for (int i = 0; i < oldpath.Length; i++) { str += i + ": x=" + oldpath[i].x + " y=" + oldpath[i].y + " | "; } //if (Input.touchCount > 0) { // var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); // sphere.transform.position = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); // sphere.transform.position = new Vector3(sphere.transform.position.x, sphere.transform.position.y, 0); // Debug.Log(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position)); //} var currInput = Input.touchCount > 0; //if (currInput && !lastInput) { // var pc = gameObject.AddComponent<PolygonCollider2D>(); // pc.SetPath(0, new Vec) //} if (currInput) { var point = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); var newPath = new Vector2[oldpath.Length + 2]; for (int i = 0; i < oldpath.Length / 2; i++) { newPath[i] = oldpath[i]; } newPath[oldpath.Length / 2] = point; newPath[oldpath.Length / 2 + 1] = new Vector2(point.x, point.y - 0.2f); for (int i = oldpath.Length / 2; i < oldpath.Length; i++) { newPath[i + 2] = oldpath[i]; } classpc.SetPath(0, newPath); oldpath = newPath; // } lastInput = currInput; var lr = GetComponent<LineRenderer>(); lr.SetVertexCount(oldpath.Length / 2); for (int i = 0; i < oldpath.Length / 2; i++) { lr.SetColors(new Color(123, 244, 80), new Color(244, 80, 123)); lr.SetWidth(0.1F, 0.1F); lr.SetPosition(i, oldpath[i]); } // Debug.Log(str); }