コード例 #1
0
 protected void ConfigureDefaultLaunchEvent(ProjectileLaunchEvent launchEvent)
 {
     //-- Does nothing by default; meant to be overridden by subclasses
     //   if they need the launch event to diverge from default settings
     //   while still benefiting from the generation of a default launch
     //   event.
 }
コード例 #2
0
    //-- Class body

    /**
     * Instantiates and launches an instance of the projectile prefab assigned to this projectile launcher.
     */
    protected void LaunchProjectile()
    {
        //-- Make the projectile
        GameObject projectileInstance = Instantiate(m_ProjectilePrefab
                                                    , gameObject.transform.position
                                                    , Quaternion.identity) as GameObject;

        //-- Set projectile collection as parent
        projectileInstance.transform.SetParent(ProjectileCollection.instance.gameObject.transform);

        //-- Generate and send launch parameters to the new projectile
        ProjectileLaunchEvent launchEvent = GenerateLaunchEvent();

        projectileInstance.SendMessage(AbstractProjectile.MESSAGE_LAUNCH
                                       , launchEvent
                                       , SendMessageOptions.RequireReceiver);
    }
コード例 #3
0
    protected sealed override ProjectileLaunchEvent GenerateLaunchEvent()
    {
        //-- Resolve the direction of the shot relavitve to the world
        Vector3 direction = gameObject.transform.TransformVector(new Vector3(1.0f, 0.0f, 0.0f));

        float   resultantForce     = m_LaunchForce;
        Vector2 resultantDirection = direction.normalized;              //-- Normalized in case the transform scale changed the length of the vector

        //-- Add the velocity of the projectile launcher to acheive a
        //   nice smooth-looking launch
        if (null != m_Body)
        {
            //-- Get the velocities of the launcher and the launch
            Vector2 bodyVelocity   = m_Body.velocity;
            Vector2 launchVelocity = direction * m_LaunchForce;

            //-- Decompose the resultant velocity to get the new force and direction
            Vector2 resultantVelocity = bodyVelocity + launchVelocity;
            resultantForce     = resultantVelocity.magnitude;
            resultantDirection = resultantVelocity / resultantForce;
        }

        //-- Generate the launch event
        ProjectileLaunchEvent defaultEventInfo = new ProjectileLaunchEvent();

        {
            defaultEventInfo.launchForce     = resultantForce;
            defaultEventInfo.launchDirection = new Vector2(resultantDirection.x, resultantDirection.y);
            defaultEventInfo.gravityScale    = Mathf.Sign(ResolveLauncherScaleY());
        }

        //-- Give the subclass (if any) a chance to modify the default launch event
        ConfigureDefaultLaunchEvent(defaultEventInfo);

        return(defaultEventInfo);
    }