public void Start() { /*Plane groundPlane = (Plane) GameObject.FindObjectOfType(typeof(Plane)); * if (groundPlane == null) Debug.LogError("Plane not found. Please add a plane mesh to your stage prefab!");*/ groundLayer = LayerMask.NameToLayer("Ground"); groundMask = 1 << groundLayer; myControlsScript = GetComponent <ControlsScript>(); character = myControlsScript.character; myHitBoxesScript = character.GetComponent <HitBoxesScript>(); myMoveSetScript = character.GetComponent <MoveSetScript>(); appliedGravity = myControlsScript.myInfo.physics.weight * UFE.config.gravity; walkSpeed = myControlsScript.myInfo.physics.walkSpeed; runSpeed = myControlsScript.myInfo.physics.runSpeed; }
void FixedUpdate() { if (opHitBoxesScript == null) { if (opControlsScript == null) { opControlsScript = opponent.GetComponent <ControlsScript>(); } opPhysicsScript = opponent.GetComponent <PhysicsScript>(); opHitBoxesScript = opponent.GetComponentInChildren <HitBoxesScript>(); opInfo = opControlsScript.myInfo; if (gameObject.name == "Player2" && character.name == opControlsScript.character.name) { // Alternative Costume //Renderer charRender = character.GetComponentInChildren<Renderer>(); //charRender.material.color = myInfo.alternativeColor; Renderer[] charRenders = character.GetComponentsInChildren <Renderer>(); foreach (Renderer charRender in charRenders) { //charRender.material.shader = Shader.Find("VertexLit"); charRender.material.color = myInfo.alternativeColor; //charRender.material.SetColor("_Emission", myInfo.alternativeColor); } } Renderer[] charRenderers = character.GetComponentsInChildren <Renderer>(); List <Shader> shaderList = new List <Shader>(); List <Color> colorList = new List <Color>(); foreach (Renderer char_rend in charRenderers) { shaderList.Add(char_rend.material.shader); colorList.Add(char_rend.material.color); } normalShaders = shaderList.ToArray(); normalColors = colorList.ToArray(); } // 两个hitbox碰撞的越多,退的越远(攻击碰撞?)身体碰撞体 if (Vector3.Distance(transform.position, opponent.transform.position) < 10) { float totalHits = myHitBoxesScript.testCollision(opHitBoxesScript.hitBoxes); if (totalHits > 0) { if (transform.position.x < opponent.transform.position.x) { transform.Translate(new Vector3(-.05f * totalHits, 0, 0)); } else { transform.Translate(new Vector3(.05f * totalHits, 0, 0)); } } } if (currentMove != null) { /*debugger.text = ""; * if (storedMove != null) debugger.text += storedMove.name + "\n"; * debugger.text += currentMove.name +": "+ character.animation.IsPlaying(currentMove.name) + "\n"; * debugger.text += "frames:"+ currentMove.currentFrame + "/" + currentMove.totalFrames + "\n"; * debugger.text += "animationPaused:"+ animationPaused + "\n"; * if (character.animation.IsPlaying(currentMove.name)){ * debugger.text += "normalizedTime: "+ character.animation[currentMove.name].normalizedTime + "\n"; * debugger.text += "time: "+ character.animation[currentMove.name].time + "\n"; * }*/ // 动作还没开始执行时,赋值动画参数 if (currentMove.currentFrame == 0) { if (character.GetComponent <Animation>()[currentMove.name] == null) { Debug.LogError("Animation for move '" + currentMove.moveName + "' not found!"); } character.GetComponent <Animation>()[currentMove.name].time = 0; character.GetComponent <Animation>().CrossFade(currentMove.name, currentMove.interpolationSpeed); character.GetComponent <Animation>()[currentMove.name].speed = currentMove.animationSpeed; } // ANIMATION FRAME DATA if (!animationPaused) { currentMove.currentFrame++; } //if (currentMove.currentFrame == 1) AddGauge(currentMove.gaugeGainOnMiss); // 根据配置的动画类型 设置当前动画的时间点 //if (UFE.config.animationFlow == AnimationFlow.MorePrecision) //{ // character.GetComponent<Animation>()[currentMove.name].speed = 0; // AnimationState animState = character.GetComponent<Animation>()[currentMove.name]; // animState.time = GetAnimationTime(currentMove.currentFrame); // //animState.time = ((float)currentMove.currentFrame / (float)GlobalScript.prefs.framesPerSeconds) / (1/currentMove.animationSpeed); //} // 生成该动作的发射物 foreach (Projectile projectile in currentMove.projectiles) { if (!projectile.casted && currentMove.currentFrame >= projectile.castingFrame) { if (projectile.projectilePrefab == null) { continue; } projectile.casted = true; if (projectile.projectilePrefab == null) { Debug.LogError("Projectile prefab for move " + currentMove.moveName + " not found. Make sure you have set the prefab correctly in the Move Editor"); } GameObject pTemp = (GameObject)Instantiate(projectile.projectilePrefab, projectile.position.position, Quaternion.Euler(0, 0, projectile.directionAngle)); pTemp.AddComponent <ProjectileMoveScript>(); ProjectileMoveScript pTempScript = pTemp.GetComponent <ProjectileMoveScript>(); pTempScript.data = projectile; pTempScript.opHitBoxesScript = opHitBoxesScript; pTempScript.opControlsScript = opControlsScript; //pTempScript.mirror = mirror; } } // 播放动作的特效 //foreach (MoveParticleEffect particleEffect in currentMove.particleEffects) //{ // if (!particleEffect.casted && currentMove.currentFrame >= particleEffect.castingFrame) // { // if (particleEffect.particleEffect.prefab == null) // Debug.LogError("Particle effect for move " + currentMove.moveName + " not found. Make sure you have set the prefab for this particle correctly in the Move Editor"); // particleEffect.casted = true; // GameObject pTemp = (GameObject)Instantiate(particleEffect.particleEffect.prefab); // pTemp.transform.parent = transform; // pTemp.transform.localPosition = particleEffect.particleEffect.position; // Destroy(pTemp, particleEffect.particleEffect.duration); // } //} // 应用动作施加的力 foreach (AppliedForce addedForce in currentMove.appliedForces) { if (!addedForce.casted && currentMove.currentFrame >= addedForce.castingFrame) { myPhysicsScript.resetForces(addedForce.resetPreviousHorizontal, addedForce.resetPreviousVertical, true); myPhysicsScript.addForce(addedForce.force, 1); addedForce.casted = true; } } // 播放动作的音效 //foreach (SoundEffect soundEffect in currentMove.soundEffects) //{ // if (!soundEffect.casted && currentMove.currentFrame >= soundEffect.castingFrame) // { // if (UFE.config.soundfx) Camera.main.GetComponent<AudioSource>().PlayOneShot(soundEffect.sound); // soundEffect.casted = true; // } //} // 播放摄像机的移动 //foreach (CameraMovement cameraMovement in currentMove.cameraMovements) //{ // if (currentMove.currentFrame >= cameraMovement.castingFrame) // { // cameraMovement.time += Time.deltaTime; // if (!cameraMovement.casted) // { // myPhysicsScript.freeze = cameraMovement.freezeGame; // opPhysicsScript.freeze = cameraMovement.freezeGame; // LockCam(cameraMovement.freezeAnimation); // cameraMovement.casted = true; // Vector3 targetPosition = character.transform.TransformPoint(cameraMovement.position); // Vector3 targetRotation = cameraMovement.rotation; // targetRotation.y *= mirror; // targetRotation.z *= mirror; // cameraScript.moveCameraToLocation(targetPosition, // targetRotation, // cameraMovement.fieldOfView, // cameraMovement.camSpeed); // } // } // if (cameraMovement.casted && UFE.freeCamera && cameraMovement.time >= cameraMovement.duration) // { // ReleaseCam(); // } //} // 隐藏动作无敌部分的hitbox if (currentMove.invincibleBodyParts.Length > 0) { foreach (InvincibleBodyParts invBodyPart in currentMove.invincibleBodyParts) { if (currentMove.currentFrame >= invBodyPart.activeFramesBegin && currentMove.currentFrame < invBodyPart.activeFramesEnds) { if (invBodyPart.completelyInvincible) { myHitBoxesScript.hideHitBoxes(); } else { myHitBoxesScript.hideHitBoxes(invBodyPart.hitBoxes); } } if (currentMove.currentFrame >= invBodyPart.activeFramesEnds) { if (invBodyPart.completelyInvincible) { myHitBoxesScript.showHitBoxes(); } else { myHitBoxesScript.showHitBoxes(invBodyPart.hitBoxes); } } } } // 防御区域判断 //if (currentMove.blockableArea.bodyPart != BodyPart.none) //{ // if (currentMove.currentFrame >= currentMove.blockableArea.activeFramesBegin && // currentMove.currentFrame < currentMove.blockableArea.activeFramesEnds) // { // myHitBoxesScript.blockableArea = currentMove.blockableArea; // Vector3 collisionVector_block = opHitBoxesScript.testCollision(myHitBoxesScript.blockableArea); // if (collisionVector_block != Vector3.zero) opControlsScript.CheckBlocking(true); // } // else if (currentMove.currentFrame >= currentMove.blockableArea.activeFramesEnds) // { // opControlsScript.CheckBlocking(false); // } //} // 动作的多段攻击?在动作文件中activeframe 中可以设置 hit数组 foreach (Hit hit in currentMove.hits) { //if (comboHits >= UFE.config.comboOptions.maxCombo) continue; // 取消技,当播放到可以取消的帧的时候执行下个动作 if ((hit.hasHit && currentMove.frameLink.onlyOnHit) || !currentMove.frameLink.onlyOnHit) { if (currentMove.currentFrame >= currentMove.frameLink.activeFramesBegins) { currentMove.cancelable = true; } if (currentMove.currentFrame >= currentMove.frameLink.activeFramesEnds) { currentMove.cancelable = false; } } if (hit.hasHit) { continue; } if (currentMove.currentFrame >= hit.activeFramesBegin && currentMove.currentFrame < hit.activeFramesEnds) { if (hit.hurtBoxes.Length > 0) { myHitBoxesScript.activeHurtBoxes = hit.hurtBoxes; // hurtbox判断,攻击中敌方 Vector3 collisionVector_hit = opHitBoxesScript.testCollision(myHitBoxesScript.activeHurtBoxes); if (collisionVector_hit != Vector3.zero) { // HURTBOX TEST // 对手成功防御 //if (!opControlsScript.stunned && opControlsScript.currentMove == null && opControlsScript.isBlocking && opControlsScript.TestBlockStances(hit.hitType)) //{ // opControlsScript.GetHitBlocking(hit, currentMove.totalFrames - currentMove.currentFrame, collisionVector_hit); // AddGauge(currentMove.gaugeGainOnBlock); // opControlsScript.AddGauge(currentMove.opGaugeGainOnBlock); // // 对手成功避开 //} //else if (opControlsScript.potentialParry > 0 && opControlsScript.currentMove == null && opControlsScript.TestParryStances(hit.hitType)) //{ // opControlsScript.GetHitParry(hit, collisionVector_hit); // opControlsScript.AddGauge(currentMove.opGaugeGainOnParry); //} //else //{ // 成功攻击到对手 opControlsScript.GetHit(hit, currentMove.totalFrames - currentMove.currentFrame, collisionVector_hit); //AddGauge(currentMove.gaugeGainOnHit); // 攻击拉近? //if (hit.pullSelfIn.enemyBodyPart != BodyPart.none && hit.pullSelfIn.characterBodyPart != BodyPart.none) //{ // Vector3 newPos = opHitBoxesScript.getPosition(hit.pullSelfIn.enemyBodyPart); // if (newPos != Vector3.zero) // { // pullInLocation = transform.position + (newPos - hit.pullSelfIn.position.position); // pullInSpeed = hit.pullSelfIn.speed; // } //} //} // 施加力 myPhysicsScript.resetForces(hit.resetPreviousHorizontal, hit.resetPreviousVertical, true); myPhysicsScript.addForce(hit.appliedForce, 1); // 碰到屏幕两边施加力 //if ((opponent.transform.position.x >= UFE.config.selectedStage.rightBoundary - 2 || // opponent.transform.position.x <= UFE.config.selectedStage.leftBoundary + 2) && // myPhysicsScript.isGrounded()) //{ // myPhysicsScript.addForce( // new Vector2(hit.pushForce.x + (opPhysicsScript.airTime * opInfo.physics.friction), 0), // mirror * -1); //} // 场景抖动效果 //HitPause(); //Invoke("HitUnpause", GetFreezingTime(hit.hitStrengh)); if (!hit.continuousHit) { hit.hasHit = true; } } ; } } } // 当前动作的帧播完 if (currentMove.currentFrame >= currentMove.totalFrames) { //if (currentMove == myMoveSetScript.getIntro()) introPlayed = true; KillCurrentMove(); } } // 击晕判断 if ((stunned || blockStunned) && stunTime > 0 && !myPhysicsScript.freeze) { // 动画减速 character.GetComponent <Animation>()[currentHitAnimation].speed -= hitStunDeceleration * Time.deltaTime; // 空中覆盖时空中连击不减少眩晕时间 if (UFE.config.comboOptions.neverAirRecover && !myPhysicsScript.isGrounded()) { stunTime = 1; } else { stunTime -= Time.deltaTime; } /*if (myPhysicsScript.debugger != null){ * myPhysicsScript.debugger.text = ""; * myPhysicsScript.debugger.text += "<color=#003300>animation speed: "+ character.animation[currentHitAnimation].speed +"</color>\n"; * myPhysicsScript.debugger.text += "<color=#003300>stunTime: "+ stunTime +"</color>\n"; * }*/ // 倒地爬起判断 if (!isDead && stunTime <= UFE.config.knockDownOptions.getUpTime) { if (currentState == PossibleStates.FallDown && myPhysicsScript.isGrounded()) { currentState = PossibleStates.Stand; character.GetComponent <Animation>().Play("getUp"); } } // 眩晕时间结束 if (stunTime <= 0) { ReleaseStun(); } } myPhysicsScript.applyForces(currentMove); myPhysicsScript.resetForces(true, false, true); }
void Start() { controlsScript = transform.parent.gameObject.GetComponent <ControlsScript>(); myMoveSetScript = GetComponent <MoveSetScript>(); detect3dHits = UFE.config.detect3D_Hits; foreach (HitBox hitBox in hitBoxes) { hitBox.storedRadius = hitBox.radius; } foreach (MoveInfo move in myMoveSetScript.moves) { foreach (InvincibleBodyParts invBodyPart in move.invincibleBodyParts) { List <HitBox> invHitBoxes = new List <HitBox>(); foreach (BodyPart bodyPart in invBodyPart.bodyParts) { foreach (HitBox hitBox in hitBoxes) { if (bodyPart == hitBox.bodyPart) { invHitBoxes.Add(hitBox); break; } } } invBodyPart.hitBoxes = invHitBoxes.ToArray(); } foreach (HitBox hitBox in hitBoxes) { if (move.blockableArea.bodyPart == hitBox.bodyPart) { move.blockableArea.position = hitBox.position; break; } } foreach (Hit hit in move.hits) { foreach (HitBox hitBox in hitBoxes) { if (hit.pullEnemyIn.characterBodyPart == hitBox.bodyPart) { hit.pullEnemyIn.position = hitBox.position; break; } } foreach (HurtBox hurtBox in hit.hurtBoxes) { foreach (HitBox hitBox in hitBoxes) { if (hurtBox.bodyPart == hitBox.bodyPart) { hurtBox.position = hitBox.position; break; } } } } foreach (Projectile projectile in move.projectiles) { foreach (HitBox hitBox in hitBoxes) { if (projectile.bodyPart == hitBox.bodyPart) { projectile.position = hitBox.position; } } } } }
void Awake() { controlsScript = transform.parent.GetComponent <ControlsScript>(); controlsScript.myInfo.currentCombatStance = CombatStances.Stance10; changeMoveStances(CombatStances.Stance1); }