예제 #1
0
        public static string GetDescription(this LedgeDetectionType me)
        {
            switch (me)
            {
            case LedgeDetectionType.NONE: return("The ledge will be detected by a tag/layer and the position of the transform will be the ledge position.");

            case LedgeDetectionType.BOX: return("The edge of the BoxCollider2D (plus the ledge offset) will be considered the ledge position.");

            case LedgeDetectionType.CIRCLE_CAST: return("A circle will be cast from above the character and the first point hit on the ledge collider will be considered the ledge position.");
            }
            return("No information available.");
        }
        /// <summary>
        /// Initialise the movement with the given movement data.
        /// </summary>
        /// <param name="character">Character.</param>
        /// <param name="movementData">Movement data.</param>
        override public Movement Init(Character character, MovementVariable[] movementData)
        {
            this.character = character;

            if (movementData != null && movementData.Length >= MovementVariableCount)
            {
                RequiredColliders   = movementData[RequiredCollidersIndex].IntValue;
                ledgeDetectionType  = (LedgeDetectionType)movementData[LedgeDetectionTypeIndex].IntValue;
                gapDetectionType    = (GapDetectionType)movementData[GapDetectionTypeIndex].IntValue;
                animationTargetting = (LedgeClimbAnimationTargetting)movementData[AnimationTargettingIndex].IntValue;
                ledgeOffset         = movementData[LedgeOffsetIndex].Vector2Value;
                standOffset         = movementData[StandOffsetIndex].Vector2Value;
                dismountOffset      = movementData[DismountOffsetIndex].Vector2Value;
                graspingBone        = (HumanBodyBones)movementData[GraspingBoneIndex].IntValue;
                minGraspLeeway      = movementData[MinGraspLeewayIndex].FloatValue;
                maxGraspLeeway      = movementData[MaxGraspLeewayIndex].FloatValue;
                minReachTime        = movementData[MinReachTimeIndex].FloatValue;
            }
            else
            {
                Debug.LogError("Invalid movement data, not enough values.");
            }

            // TODO Only get this if required
            myAnimator = character.gameObject.GetComponentInChildren <Animator> ();
            if (animationTargetting == LedgeClimbAnimationTargetting.SPRITE_PIVOT)
            {
                myRenderer = character.gameObject.GetComponentInChildren <SpriteRenderer> ();
                if (myRenderer == null)
                {
                    // TODO Throw error?
                }
                else
                {
                    initialSpritePivot = myRenderer.sprite.bounds.center;
                }
            }
            return(this);
        }