コード例 #1
0
    //When a line finishes movement, we'll automatically complete the transformation of all off screen characters that were started.
    private void TransformationLine_LineFinished(TransformationLine i_TransformationLine)
    {
        CharacterForm affectedForm = r_FormLineDict[i_TransformationLine];

        i_TransformationLine.OnLineFinished -= TransformationLine_LineFinished;

        affectedForm.TransformRate = 1;
    }
コード例 #2
0
    //Creates a new transformation sequence on this character and maps it to the invoking transformation line.
    private CharacterForm createNewTransformation(TransformationLine i_TransformationLine)
    {
        if (r_FormLineDict[i_TransformationLine])
        {
            throw new ArgumentException("A form already exists for given transformation line on this character");
        }

        CharacterForm newForm = m_NextForm;

        i_TransformationLine.OnLineFinished += TransformationLine_LineFinished;
        newForm.OnTransformationComplete    += CharacterForm_TransformationComplete;

        r_FormLineDict.Add(newForm, i_TransformationLine);

        return(newForm);
    }
コード例 #3
0
    /// <summary>
    /// Transforms a character in its current transformation sequence up to the x point of the given point.
    /// </summary>
    /// <param name="i_TransformationLine">The transformation line that invoked this transformation. Each unique line that affects this character will be linked to a unique specific form object.</param>
    /// <param name="i_WorldPointHit">The world point where the transformation line hit. We'll transform the character with this point's x as the seperator.</param>
    public void TransformByPoint(TransformationLine i_TransformationLine, Vector2 i_WorldPointHit)
    {
        CharacterForm affectedForm = r_FormLineDict[i_TransformationLine];

        if (affectedForm == null)
        {
            affectedForm = createNewTransformation(i_TransformationLine);
        }

        //First we'll get the x point of the hit in local spaces (-sprite width / 2 <= Pixel in sprite <= sprite width / 2).
        float centerRelativeHitX = transform.InverseTransformPoint(i_WorldPointHit).x;
        //Then we offset it to sprite size (0 <= pixel in sprite <= sprite width), since sprite local spaces in unity can be negative.
        float pixelHitX = centerRelativeHitX + affectedForm.Sprite.rectTransform.rect.width / 2;
        //And finally we got the normal of the hit (What % of the transformation is complete).
        float hitFillNormal = pixelHitX / affectedForm.Sprite.rectTransform.rect.width;

        affectedForm.TransformRate = hitFillNormal;
    }