private void Awake() { vObject = CreateBasicUnit(transform, GetPosition(), 30f, null); unitAnimation = vObject.GetLogic <V_UnitAnimation>(); unitSkeleton = vObject.GetLogic <V_UnitSkeleton>(); objectTransform = vObject.GetLogic <V_IObjectTransform>(); UnitAnimType idleUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Idle"); UnitAnimType walkUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Walk"); UnitAnimType hitUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Hit"); UnitAnimType attackUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_PunchQuickAttack"); canShoot = true; //unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, UnitAnim.GetUnitAnim("Aim_PistolRight"), UnitAnim.GetUnitAnim("Aim_PistolLeft"), UnitAnim.GetUnitAnim("Aim_PistolShootRight"), UnitAnim.GetUnitAnim("Aim_PistolShootLeft")); unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, UnitAnim.GetUnitAnim("dMarine_AimWeaponRight"), UnitAnim.GetUnitAnim("dMarine_AimWeaponLeft"), UnitAnim.GetUnitAnim("dMarine_ShootWeaponRight"), UnitAnim.GetUnitAnim("dMarine_ShootWeaponLeft")); //unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, UnitAnim.GetUnitAnim("Aim_ShotgunRight"), UnitAnim.GetUnitAnim("Aim_ShotgunLeft"), UnitAnim.GetUnitAnim("Aim_ShotgunShootRight"), UnitAnim.GetUnitAnim("Aim_ShotgunShootLeft")); vObject.AddRelatedObject(unitSkeletonCompositeWeapon); unitSkeletonCompositeWeapon.SetActive(); unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead); unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet); }
private void Start() { /* * Transform bodyTransform = transform.Find("Body"); * unitSkeleton = new V_UnitSkeleton(1f, bodyTransform.TransformPoint, (Mesh mesh) => bodyTransform.GetComponent<MeshFilter>().mesh = mesh); * unitAnimation = new V_UnitAnimation(unitSkeleton); */ vObject = CreateBasicUnit(transform, GetPosition(), 30f, null); unitAnimation = vObject.GetLogic <V_UnitAnimation>(); unitSkeleton = vObject.GetLogic <V_UnitSkeleton>(); objectTransform = vObject.GetLogic <V_IObjectTransform>(); UnitAnimType idleUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Idle"); UnitAnimType walkUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Walk"); UnitAnimType hitUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Hit"); UnitAnimType attackUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_PunchQuickAttack"); canShoot = true; unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, UnitAnim.GetUnitAnim("Aim_PistolRight"), UnitAnim.GetUnitAnim("Aim_PistolLeft"), UnitAnim.GetUnitAnim("Aim_PistolShootRight"), UnitAnim.GetUnitAnim("Aim_PistolShootLeft")); vObject.AddRelatedObject(unitSkeletonCompositeWeapon); unitSkeletonCompositeWeapon.SetActive(); unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead); unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet); }
private void Awake() { vObject = CreateBasicUnit(transform, GetPosition(), 30f, null); unitAnimation = vObject.GetLogic <V_UnitAnimation>(); unitSkeleton = vObject.GetLogic <V_UnitSkeleton>(); objectTransform = vObject.GetLogic <V_IObjectTransform>(); UnitAnimType idleUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Idle"); UnitAnimType walkUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Walk"); UnitAnimType hitUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_Hit"); UnitAnimType attackUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_PunchQuickAttack"); unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead); unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet); }
// 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); } }); }
// 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_IObjectWalker walker = vObject.GetLogic<V_IObjectWalker>(); 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); FunctionUpdater.Create(() => { Vector3 targetPosition = UtilsClass.GetMouseWorldPosition(); Vector3 aimDir = (targetPosition - vObject.GetPosition()).normalized; 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(); objectTransform.SetPosition(objectTransform.GetPosition() + moveDir * 50f * Time.deltaTime); /* * if (isMoving) { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Walk.GetUnitAnim(moveDir), "FootL", "FootR"); * if (canShoot) { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Walk.GetUnitAnim(aimDir), "Body", "Head"); * } * } else { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Idle.GetUnitAnim(moveDir), "FootL", "FootR"); * if (canShoot) { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Idle.GetUnitAnim(aimDir), "Body", "Head"); * } * }*/ if (isMoving) { Dirt_Handler.SpawnInterval(GetPosition(), moveDir * -1f); } // Update Feet //unitSkeletonCompositeWalker_Feet.UpdateBodyParts(walker.GetLastMoveDir()); unitSkeletonCompositeWalker_Feet.UpdateBodyParts(isMoving, moveDir); if (canShoot) { // Update Head and Body parts only when Not Shooting unitSkeletonCompositeWalker_BodyHead.UpdateBodyParts(isMoving, aimDir); } }); }