protected void Init()
        {
            if (MeshFilterComponent == null)
            {
                MeshFilterComponent = gameObject.GetOrAddComponent <MeshFilter>();
            }

            if (MeshRenderer == null)
            {
                MeshRenderer = gameObject.GetOrAddComponent <MeshRenderer>();
            }

            if (Collider == null)
            {
                Collider = gameObject.GetComponent <Collider2D>();
            }

            if (Collider == null && Application.isPlaying)
            {
                throw new NullReferenceException("No Collider2D found");
            }

            var dict = Collider2dPointsGetter.GetTypeMethodDictionary();

            if (dict.ContainsKey(Collider.GetType()))
            {
                OnRecalculate = dict[Collider.GetType()];
            }
            else
            {
                throw new Exception(Collider.GetType().ToString() + " is not supported");
            }

            Closed = !(Collider is EdgeCollider2D);
            //UseCircleProximity = !(Collider is CircleCollider2D) || !(Collider is CapsuleCollider2D);

            if (MeshInstance == null)
            {
                MeshInstance = new Mesh();
            }

            if (MeshFilterComponent != null)
            {
                MeshFilterComponent.sharedMesh = MeshInstance;
            }

            if (MeshRenderer.material == null)
            {
                MeshRenderer.material = new Material(Shader.Find("Artics/DefaultCollider2D"));
            }

            if (ShaderProperty == null)
            {
                ShaderProperty = new MaterialPropertyBlock();
            }
        }
        protected override void MultiplyMatrix()
        {
            Matrix4x4 matrix     = GetMatrix();
            Vector3   lossyScale = transform.lossyScale;

            MultipliedCenter = matrix.MultiplyPoint(Center);
            MultipliedRadius = Radius * Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.y));

            Collider2dPointsGetter.GetCircleCoordinates(MultipliedCenter, MultipliedRadius, ref MultipliedPoints, CustomProximity);
        }
示例#3
0
        /// <summary>
        /// Update bounds of collider manually.  Use it if you changed Offset, Size or Direction of the collider.
        /// </summary>
        public override void UpdateBounds()
        {
            base.UpdateBounds();

            Collider2dPointsGetter.GetCapsuleCoordinates(Collider, ref Points, CustomProximity, true);

            if (Points.Length != MultipliedPoints.Length)
            {
                MultipliedPoints = new Vector2[Points.Length];
            }
        }
示例#4
0
 protected static void DrawCircle(Vector2 center, float radius, ref Vector2[] points, Color color)
 {
     Collider2dPointsGetter.GetCircleCoordinates(center, radius, ref points);
     ShapeVisualizer.DrawPoints(points, false, color);
     Gizmos.DrawLine(points[0], points[points.Length - 1]);
 }