Exemple #1
0
    public void AddDrawingPoint(Vector3 position)
    {
        if (RendereredLine.positionCount == 0)
        {
            RendereredLine.positionCount++;
            RendereredLine.SetPosition(0, position);
        }
        else
        {
            if ((RendereredLine.GetPosition(RendereredLine.positionCount - 1) - position).sqrMagnitude >= distanceBetweenLinePosition * distanceBetweenLinePosition)
            {
                //Add new line point
                if (maxLinePointCount < 2 || RendereredLine.positionCount < maxLinePointCount)
                {
                    RendereredLine.positionCount++;
                    RendereredLine.SetPosition(RendereredLine.positionCount - 1, position);
                    m_colliderPoints.Add(position);
                    //CreateColliderBetweenPoints(RendereredLine.GetPosition(RendereredLine.positionCount - 2), position, null);
                }
                else //modify line point
                {
                    RendereredLine.SetPosition(RendereredLine.positionCount - 1, position);
                    m_colliderPoints[m_colliderPoints.Count - 1] = position;
                    //CreateColliderBetweenPoints(RendereredLine.GetPosition(RendereredLine.positionCount - 2), position, m_ColliderSegments[m_ColliderSegments.Count - 1]);
                }

                SetupCollider();
            }
        }
    }
Exemple #2
0
    ///// <summary>
    ///// if modifiedCapsule is set, it will be modified rather than creating new collider
    ///// </summary>
    ///// <param name="startPosition"></param>
    ///// <param name="endPosition"></param>
    ///// <param name=""></param>
    ///// <returns></returns>
    //private CapsuleCollider2D CreateColliderBetweenPoints(Vector3 startPosition, Vector3 endPosition, CapsuleCollider2D modifiedCapsule)
    //{

    //    CapsuleCollider2D capsuleCollider2D = modifiedCapsule;

    //    if (modifiedCapsule == null)
    //    {
    //        ////Create collider segment
    //        //GameObject gameObject = new GameObject("Collider");
    //        //capsuleCollider2D = gameObject.AddComponent<CapsuleCollider2D>();
    //        //capsuleCollider2D.transform.parent = transform;

    //        DefaultPoolObject colliderObject = m_ColliderPool.Pop((startPosition + endPosition) / 2);
    //        capsuleCollider2D = colliderObject.transform.GetComponent<CapsuleCollider2D>();
    //        capsuleCollider2D.transform.parent = transform;

    //        m_ColliderSegments.Add(capsuleCollider2D);
    //        m_ColliderObjects.Add(colliderObject);

    //    }

    //    Vector3 direction = startPosition - endPosition;
    //    capsuleCollider2D.transform.position = (startPosition + endPosition) / 2;
    //    capsuleCollider2D.transform.RotateToDirection(direction, 90);
    //    capsuleCollider2D.size = new Vector2(colliderThickness, direction.magnitude);

    //    return capsuleCollider2D;
    //}

    /// <summary>
    /// Get righestpoint in world space
    /// </summary>
    /// <returns></returns>
    public Vector3 CalculateRightestPoint()
    {
        if (RendereredLine.positionCount == 0)
        {
            Debug.LogError("There is no point");
        }

        Vector3 rightestPosition = transform.TransformPoint(RendereredLine.GetPosition(0));

        for (int i = 1; i < RendereredLine.positionCount; i++)
        {
            Vector3 position = transform.TransformPoint(RendereredLine.GetPosition(i));

            if (rightestPosition.x < position.x)
            {
                rightestPosition = position;
            }
        }

        return(rightestPosition);
    }