Exemple #1
0
        // ================================
        // * ACT ON LAYER PUBLIC FUNCTION *
        // ================================

        /// <summary>
        /// Interact with nearby object of given type (layer).
        /// </summary>
        /// <param name="rayFunc">The method for attempting a hit.</param>
        /// <param name="character">The character attempting the interaction.</param>
        /// <param name="layerMask">Bit mask of layers to attempt interaction with.</param>
        /// <param name="angle">Angle of cone.</param>
        /// <param name="distance">The maximum reach of the hit attempt.</param>
        /// <param name="calcScore">The function to calculate target likelihood.</param>
        /// <returns>Object interacted with, or null if none.</returns>
        static public GameObject actOnLayer(RayFunc rayFunc, GameObject character, int layerMask, float angle, float distance, ScoreFunc calcScore)
        {
            GameObject ret = null;          // game object returned by function
            float      bestScore;           // score for best candidate for target
            float      currScore;           // score for current object

            UGen.PseudoTransform charTrans; // character transform, whose position has been moved to the collider's center

            // set charTrans to character's transform information, but move position to center of character
            charTrans          = UGen.setPseudo(character.transform);
            charTrans.position = UGen.getCenter(character);

            // Get list of nearby objects in desired layers
            Collider[] objects = Physics.OverlapSphere(charTrans.position, distance, layerMask);

            // get the likeliest target object
            bestScore = float.MinValue;                       // initialize bestScore
            foreach (Collider obj in objects)                 // check each nearby object
            {
                if (rayFunc(charTrans, obj, angle, distance)) // if object was hit, check its target score
                {
                    currScore = calcScore(charTrans, obj);
                    if (currScore >= bestScore)                       // if it's likelier to be the target, set it as the target
                    {
                        bestScore = currScore;
                        ret       = obj.gameObject;
                    }
                }
            }

            return(ret);
        }
Exemple #2
0
        /// <summary>
        /// Try to hit nearby object in a wedge in front of character. Need LOS.
        /// </summary>
        /// <param name="charTrans">Transform information of the character making the hit.</param>
        /// <param name="obj">Object of the hit attempt.</param>
        /// <param name="angle">Angle of wedge.</param>
        /// <param name="distance">The maximum reach of the hit attempt.</param>
        /// <returns>True if object is hit, else false.</returns>
        static bool wedgeLOS(Transform charTrans, Collider obj, float angle, float distance)
        {
            UGen.PseudoTransform ct;

            ct = UGen.setPseudo(charTrans);

            return(wedgeLOS(ct, obj, angle, distance));
        }