//------------------------------------------------------------------------- void Awake() { if (mSyncToParentSpriteRenderer) { mSpriteRenderer = this.transform.parent.GetComponentInParent <SpriteRenderer>(); } else { mSpriteRenderer = this.GetComponent <SpriteRenderer>(); } SetupRemovedFrameReferences(); EnableActiveFrameCollider(); if (mColliderMode == ColliderMode.NONE) { if (mPolygonCollidersToSwitch != null && mPolygonCollidersToSwitch.Length > 0) { mColliderMode = ColliderMode.POLYGON_COLLIDER_2D; } #if UNITY_SUPPORTS_EDGECOLLIDER2D else if (mEdgeCollidersToSwitch != null && mEdgeCollidersToSwitch.Length > 0) { mColliderMode = ColliderMode.EDGE_COLLIDER_2D; } #endif else if (mMeshCollidersToSwitch != null && mMeshCollidersToSwitch.Length > 0) { mColliderMode = ColliderMode.MESH_COLLIDER; } } }
//------------------------------------------------------------------------- void Awake() { mSpriteRenderer = this.GetComponent <SpriteRenderer>(); if (mPolygonCollidersToSwitch != null) { for (int index = 0; index < mPolygonCollidersToSwitch.Length; ++index) { if (index != mActiveColliderIndex) { mPolygonCollidersToSwitch[index].enabled = false; } else { mPolygonCollidersToSwitch[index].enabled = true; } } } if (mMeshCollidersToSwitch != null) { for (int index = 0; index < mMeshCollidersToSwitch.Length; ++index) { if (index != mActiveColliderIndex) { mMeshCollidersToSwitch[index].enabled = false; } else { mMeshCollidersToSwitch[index].enabled = true; } } } if (mColliderMode == ColliderMode.NONE) { if (mPolygonCollidersToSwitch != null && mPolygonCollidersToSwitch.Length > 0) { mColliderMode = ColliderMode.POLYGON_COLLIDER_2D; } else if (mMeshCollidersToSwitch != null && mMeshCollidersToSwitch.Length > 0) { mColliderMode = ColliderMode.MESH_COLLIDER; } } }
private IEnumerator AutoTest() { CastMode[] castModes = new CastMode[]{ CastMode.Line, CastMode.Sphere }; ColliderMode[] colModes = new ColliderMode[] { ColliderMode.Box, ColliderMode.Sphere }; int[] colNums = new int[]{ 0, 1, 10, 50, 100, 500, 1000 }; string markdownTable = "|Cast mode|Col mode|Box nums|Sphere nums|IsHit|Total col|Total mesh|Hit mesh|Time|\n" + "|:-:|:-:|--:|--:|:-:|--:|--:|--:|--:|\n"; foreach (CastMode castMode in castModes) { foreach (ColliderMode colMode in colModes) { foreach (int boxNums in colNums) { foreach (int sphereNums in colNums) { cur.colMode = ColliderMode.Box; ClearCols (); yield return null; Enumerable.Range (0, boxNums).ToList ().ForEach (i => AddCol ()); cur.colMode = ColliderMode.Sphere; ClearCols (); yield return null; Enumerable.Range (0, sphereNums).ToList ().ForEach (i => AddCol ()); cur.colMode = colMode; cur.castMode = castMode; yield return null; TestCast (); Debug.Log (castMode + "," + colMode + "," + boxNums + "," + sphereNums); markdownTable += cur.toMarkdown() + "\n"; yield return null; } } } } Debug.Log (markdownTable); }
//------------------------------------------------------------------------- void Awake() { mSpriteRenderer = this.GetComponent<SpriteRenderer>(); if (mPolygonCollidersToSwitch != null) { for (int index = 0; index < mPolygonCollidersToSwitch.Length; ++index) { if (index != mActiveColliderIndex) { mPolygonCollidersToSwitch[index].enabled = false; } else { mPolygonCollidersToSwitch[index].enabled = true; } } } if (mMeshCollidersToSwitch != null) { for (int index = 0; index < mMeshCollidersToSwitch.Length; ++index) { if (index != mActiveColliderIndex) { mMeshCollidersToSwitch[index].enabled = false; } else { mMeshCollidersToSwitch[index].enabled = true; } } } if (mColliderMode == ColliderMode.NONE) { if (mPolygonCollidersToSwitch != null && mPolygonCollidersToSwitch.Length > 0) mColliderMode = ColliderMode.POLYGON_COLLIDER_2D; else if (mMeshCollidersToSwitch != null && mMeshCollidersToSwitch.Length > 0) mColliderMode = ColliderMode.MESH_COLLIDER; } }
// Update is called once per frame void Update() { var rotation = To180Angle(transform.rotation.eulerAngles.z); if ((rotation > -toleranceDegrees && rotation < toleranceDegrees)|| (rotation > 180 - toleranceDegrees || rotation < -180 + toleranceDegrees)) { Mode = ColliderMode.Sides; } else if ((rotation > 90 - toleranceDegrees && rotation < 90 + toleranceDegrees) || (rotation > -90 - toleranceDegrees && rotation < -90 + toleranceDegrees)) { Mode = ColliderMode.TopAndBottom; } else { Mode = ColliderMode.All; } }
// Use this for initialization void Start() { _colliderMode = ColliderMode.All; Mode = ColliderMode.Sides; }