예제 #1
0
    private void Start()
    {
        if (waitTimeList.Length != 0)
        {
            waitTimer = waitTimeList[0];
        }

        lastMoveDir = aimDirection;

        fieldOfView = Instantiate(pfFieldofView, null).GetComponent <FOV>();
        fieldOfView.SetFoV(fov);
        fieldOfView.SetViewDistance(viewDistance);
    }
예제 #2
0
    // Use this for initialization
    private void Start()
    {
        V_Object           vObject         = CreateBasicUnit(transform, new Vector3(500, 680), 30f, GameAssets.i.m_MarineSpriteSheet);
        V_UnitAnimation    unitAnimation   = vObject.GetLogic <V_UnitAnimation>();
        V_UnitSkeleton     unitSkeleton    = vObject.GetLogic <V_UnitSkeleton>();
        V_IObjectTransform objectTransform = vObject.GetLogic <V_IObjectTransform>();

        bool canShoot = true;

        V_UnitSkeleton_Composite_Weapon unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, GameAssets.UnitAnimEnum.dMarine_AimWeaponRight, GameAssets.UnitAnimEnum.dMarine_AimWeaponRightInvertV, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRight, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRightInvertV);

        vObject.AddRelatedObject(unitSkeletonCompositeWeapon);
        unitSkeletonCompositeWeapon.SetActive();

        V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" });

        vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead);

        V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" });

        vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet);

        // Update Code
        bool isAimDownSights = false;

        FunctionUpdater.Create(() => {
            Vector3 targetPosition   = UtilsClass.GetMouseWorldPosition();
            Vector3 aimDir           = (targetPosition - vObject.GetPosition()).normalized;
            fieldOfView.transform.up = (aimDir);

            // Check for hits
            Vector3 gunEndPointPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash");
            RaycastHit2D raycastHit     = Physics2D.Raycast(gunEndPointPosition, (targetPosition - gunEndPointPosition).normalized, Vector3.Distance(gunEndPointPosition, targetPosition));
            if (raycastHit.collider != null)
            {
                // Hit something
                targetPosition = raycastHit.point;
            }

            unitSkeletonCompositeWeapon.SetAimTarget(targetPosition);

            if (canShoot && Input.GetMouseButton(0))
            {
                // Shoot
                canShoot = false;
                // Replace Body and Head with Attack
                unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dMarine_Attack.GetUnitAnim(aimDir), "Body", "Head");
                // Shoot Composite Skeleton
                unitSkeletonCompositeWeapon.Shoot(targetPosition, () => {
                    canShoot = true;
                });

                // Add Effects
                Vector3 shootFlashPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash");
                if (OnShoot != null)
                {
                    OnShoot(this, new OnShootEventArgs {
                        gunEndPointPosition = shootFlashPosition, shootPosition = targetPosition
                    });
                }

                //Shoot_Flash.AddFlash(shootFlashPosition);
                //WeaponTracer.Create(shootFlashPosition, targetPosition);
            }


            // Manual Movement
            bool isMoving   = false;
            Vector3 moveDir = new Vector3(0, 0);
            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
            {
                moveDir.y = +1; isMoving = true;
            }
            if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
            {
                moveDir.y = -1; isMoving = true;
            }
            if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
            {
                moveDir.x = -1; isMoving = true;
            }
            if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
            {
                moveDir.x = +1; isMoving = true;
            }
            moveDir.Normalize();

            float moveSpeed = 50f;
            Vector3 targetMoveToPosition = objectTransform.GetPosition() + moveDir * moveSpeed * Time.deltaTime;
            // Test if can move there
            raycastHit = Physics2D.Raycast(GetPosition() + moveDir * .1f, moveDir, Vector3.Distance(GetPosition(), targetMoveToPosition));
            if (raycastHit.collider != null)
            {
                // Hit something
            }
            else
            {
                // Can move, no wall
                objectTransform.SetPosition(targetMoveToPosition);
            }

            if (isMoving)
            {
                Dirt_Handler.SpawnInterval(GetPosition(), moveDir * -1f);
            }


            // Update Feet
            unitSkeletonCompositeWalker_Feet.UpdateBodyParts(isMoving, moveDir);

            if (canShoot)
            {
                // Update Head and Body parts only when Not Shooting
                unitSkeletonCompositeWalker_BodyHead.UpdateBodyParts(isMoving, aimDir);
            }

            if (Input.GetMouseButtonDown(1))
            {
                isAimDownSights = !isAimDownSights;
                if (isAimDownSights)
                {
                    // Aiming down sights
                    fieldOfView.SetFoV(40f);
                    fieldOfView.SetViewDistance(100f);
                }
                else
                {
                    // Normal
                    fieldOfView.SetFoV(90f);
                    fieldOfView.SetViewDistance(50f);
                }
            }
        });
    }