コード例 #1
0
    private void LateUpdate()
    {
        if (myHero == null && base.photonView.isMine)
        {
            PhotonNetwork.Destroy(base.gameObject);
        }
        switch (State)
        {
        case "mounted":
            if (myHero == null)
            {
                Unmount();
                return;
            }
            myHero.transform.position = base.transform.position + Vector3.up * 1.68f;
            myHero.transform.rotation = base.transform.rotation;
            myHero.rigidbody.velocity = base.rigidbody.velocity;
            if (controller.targetDirection != -874f)
            {
                base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, controller.targetDirection, 0f), 100f * Time.deltaTime / (base.rigidbody.velocity.magnitude + 20f));
                if (controller.isWALKDown)
                {
                    base.rigidbody.AddForce(base.transform.forward * speed * 0.6f, ForceMode.Acceleration);
                    if (!(base.rigidbody.velocity.magnitude < speed * 0.6f))
                    {
                        base.rigidbody.AddForce((0f - speed) * 0.6f * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                else
                {
                    base.rigidbody.AddForce(base.transform.forward * speed, ForceMode.Acceleration);
                    if (!(base.rigidbody.velocity.magnitude < speed))
                    {
                        base.rigidbody.AddForce((0f - speed) * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                if (base.rigidbody.velocity.magnitude > 8f)
                {
                    if (!base.animation.IsPlaying("horse_Run"))
                    {
                        CrossFade("horse_Run", 0.1f);
                    }
                    if (!myHero.animation.IsPlaying("horse_Run"))
                    {
                        myHero.GetComponent <HERO>().CrossFade("horse_run", 0.1f);
                    }
                    if (!dust.GetComponent <ParticleSystem>().enableEmission)
                    {
                        dust.GetComponent <ParticleSystem>().enableEmission = true;
                        base.photonView.RPC("setDust", PhotonTargets.Others, true);
                    }
                }
                else
                {
                    if (!base.animation.IsPlaying("horse_WALK"))
                    {
                        CrossFade("horse_WALK", 0.1f);
                    }
                    if (!myHero.animation.IsPlaying("horse_idle"))
                    {
                        myHero.GetComponent <HERO>().CrossFade("horse_idle", 0.1f);
                    }
                    if (dust.GetComponent <ParticleSystem>().enableEmission)
                    {
                        dust.GetComponent <ParticleSystem>().enableEmission = false;
                        base.photonView.RPC("setDust", PhotonTargets.Others, false);
                    }
                }
            }
            else
            {
                Idle();
                if (base.rigidbody.velocity.magnitude > 15f)
                {
                    if (!myHero.animation.IsPlaying("horse_Run"))
                    {
                        myHero.GetComponent <HERO>().CrossFade("horse_run", 0.1f);
                    }
                }
                else if (!myHero.animation.IsPlaying("horse_idle"))
                {
                    myHero.GetComponent <HERO>().CrossFade("horse_idle", 0.1f);
                }
            }
            if ((controller.isAttackDown || controller.isAttackIIDown) && IsGrounded())
            {
                base.rigidbody.AddForce(Vector3.up * 25f, ForceMode.VelocityChange);
            }
            break;

        case "follow":
            if (myHero == null)
            {
                Unmount();
                return;
            }
            if (base.rigidbody.velocity.magnitude > 8f)
            {
                if (!base.animation.IsPlaying("horse_Run"))
                {
                    CrossFade("horse_Run", 0.1f);
                }
                if (!dust.GetComponent <ParticleSystem>().enableEmission)
                {
                    dust.GetComponent <ParticleSystem>().enableEmission = true;
                    base.photonView.RPC("setDust", PhotonTargets.Others, true);
                }
            }
            else
            {
                if (!base.animation.IsPlaying("horse_WALK"))
                {
                    CrossFade("horse_WALK", 0.1f);
                }
                if (dust.GetComponent <ParticleSystem>().enableEmission)
                {
                    dust.GetComponent <ParticleSystem>().enableEmission = false;
                    base.photonView.RPC("setDust", PhotonTargets.Others, false);
                }
            }
            float      horizontalAngle = FengMath.GetHorizontalAngle(base.transform.position, setPoint);
            Vector3    eulerAngles     = base.gameObject.transform.rotation.eulerAngles;
            float      num             = 0f - Mathf.DeltaAngle(horizontalAngle, eulerAngles.y - 90f);
            Transform  transform       = base.gameObject.transform;
            Quaternion rotation        = base.gameObject.transform.rotation;
            Vector3    eulerAngles2    = base.gameObject.transform.rotation.eulerAngles;
            transform.rotation = Quaternion.Lerp(rotation, Quaternion.Euler(0f, eulerAngles2.y + num, 0f), 200f * Time.deltaTime / (base.rigidbody.velocity.magnitude + 20f));
            if (Vector3.Distance(setPoint, base.transform.position) < 20f)
            {
                base.rigidbody.AddForce(base.transform.forward * speed * 0.7f, ForceMode.Acceleration);
                if (!(base.rigidbody.velocity.magnitude < speed))
                {
                    base.rigidbody.AddForce((0f - speed) * 0.7f * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                }
            }
            else
            {
                base.rigidbody.AddForce(base.transform.forward * speed, ForceMode.Acceleration);
                if (!(base.rigidbody.velocity.magnitude < speed))
                {
                    base.rigidbody.AddForce((0f - speed) * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                }
            }
            timeElapsed += Time.deltaTime;
            if (timeElapsed > 0.6f)
            {
                timeElapsed = 0f;
                if (Vector3.Distance(myHero.transform.position, setPoint) > 20f)
                {
                    Follow();
                }
            }
            if (Vector3.Distance(myHero.transform.position, base.transform.position) < 5f)
            {
                Unmount();
            }
            if (Vector3.Distance(setPoint, base.transform.position) < 5f)
            {
                Unmount();
            }
            awayTimer += Time.deltaTime;
            if (awayTimer > 6f)
            {
                awayTimer = 0f;
                LayerMask layerMask  = 1 << LayerMask.NameToLayer("Ground");
                LayerMask layerMask2 = layerMask;
                if (Physics.Linecast(base.transform.position + Vector3.up, myHero.transform.position + Vector3.up, layerMask2.value))
                {
                    Transform transform2 = base.transform;
                    Vector3   position   = myHero.transform.position;
                    float     x          = position.x;
                    float     height     = GetHeight(myHero.transform.position + Vector3.up * 5f);
                    Vector3   position2  = myHero.transform.position;
                    transform2.position = new Vector3(x, height, position2.z);
                }
            }
            break;

        case "idle":
            Idle();
            if (myHero != null && Vector3.Distance(myHero.transform.position, base.transform.position) > 20f)
            {
                Follow();
            }
            break;
        }
        base.rigidbody.AddForce(new Vector3(0f, -50f * base.rigidbody.mass, 0f));
    }
コード例 #2
0
ファイル: Horse.cs プロジェクト: kmlkmljkl2/Anarchy
    private void LateUpdate()
    {
        if (Owner == null && BasePV.IsMine)
        {
            PhotonNetwork.Destroy(gameObject);
            return;
        }

        switch (State)
        {
        case HorseState.Mounted:
        {
            if (this.Owner == null)
            {
                this.Unmounted();
                return;
            }

            Owner.baseT.position = baseT.position + heroOffsetVector;
            Owner.baseT.rotation = baseR.rotation;
            Owner.baseR.velocity = baseR.velocity;

            if (controller.targetDirection == -874f)
            {
                this.ToIdleAnimation();
                if (baseR.velocity.magnitude > 15f)
                {
                    if (!Owner.baseA.IsPlaying("horse_run"))
                    {
                        Owner.CrossFade("horse_run", 0.1f);
                    }
                }
                else if (!Owner.baseA.IsPlaying("horse_idle"))
                {
                    Owner.CrossFade("horse_idle", 0.1f);
                }
            }
            else
            {
                base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, this.controller.targetDirection, 0f), 100f * Time.deltaTime / (base.rigidbody.velocity.magnitude + 20f));
                if (this.controller.isWALKDown)
                {
                    baseR.AddForce(baseT.Forward() * this.speed * 0.6f, ForceMode.Acceleration);
                    if (baseR.velocity.magnitude >= this.speed * 0.6f)
                    {
                        baseR.AddForce(-this.speed * 0.6f * baseR.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                else
                {
                    baseR.AddForce(baseT.Forward() * this.speed, ForceMode.Acceleration);
                    if (baseR.velocity.magnitude >= this.speed)
                    {
                        baseR.AddForce(-this.speed * baseR.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                if (baseR.velocity.magnitude > 8f)
                {
                    if (!baseA.IsPlaying("horse_Run"))
                    {
                        this.CrossFade("horse_Run", 0.1f);
                    }
                    if (!this.Owner.baseA.IsPlaying("horse_run"))
                    {
                        this.Owner.CrossFade("horse_run", 0.1f);
                    }
                    if (!this.dustParticle.enableEmission)
                    {
                        this.dustParticle.enableEmission = true;
                        BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                            {
                                true
                            });
                    }
                }
                else
                {
                    if (!baseA.IsPlaying("horse_WALK"))
                    {
                        this.CrossFade("horse_WALK", 0.1f);
                    }
                    if (!this.Owner.baseA.IsPlaying("horse_idle"))
                    {
                        this.Owner.baseA.CrossFade("horse_idle", 0.1f);
                    }
                    if (this.dustParticle.enableEmission)
                    {
                        this.dustParticle.enableEmission = false;
                        BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                            {
                                false
                            });
                    }
                }
            }

            if ((this.controller.isAttackDown || this.controller.isAttackIIDown) && this.IsGrounded())
            {
                baseR.AddForce(Vectors.up * 25f, ForceMode.VelocityChange);
            }
        }
        break;

        case HorseState.Follow:
        {
            if (this.Owner == null)
            {
                this.Unmounted();
                return;
            }

            if (baseR.velocity.magnitude > 8f)
            {
                if (!baseA.IsPlaying("horse_Run"))
                {
                    this.CrossFade("horse_Run", 0.1f);
                }
                if (!this.dustParticle.enableEmission)
                {
                    this.dustParticle.enableEmission = true;
                    BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                        {
                            true
                        });
                }
            }
            else
            {
                if (!baseA.IsPlaying("horse_WALK"))
                {
                    this.CrossFade("horse_WALK", 0.1f);
                }
                if (this.dustParticle.enableEmission)
                {
                    this.dustParticle.enableEmission = false;
                    BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                        {
                            false
                        });
                }
            }

            float num = -Mathf.DeltaAngle(FengMath.GetHorizontalAngle(baseT.position, this.setPoint), base.gameObject.transform.rotation.eulerAngles.y - 90f);
            base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, base.gameObject.transform.rotation.eulerAngles.y + num, 0f), 200f * Time.deltaTime / (baseR.velocity.magnitude + 20f));
            if (Vector3.Distance(this.setPoint, baseT.position) < 20f)
            {
                baseR.AddForce(baseT.Forward() * this.speed * 0.7f, ForceMode.Acceleration);
                if (baseR.velocity.magnitude >= this.speed)
                {
                    baseR.AddForce(-this.speed * 0.7f * baseR.velocity.normalized, ForceMode.Acceleration);
                }
            }
            else
            {
                baseR.AddForce(base.transform.Forward() * this.speed, ForceMode.Acceleration);
                if (baseR.velocity.magnitude >= this.speed)
                {
                    baseR.AddForce(-this.speed * baseR.velocity.normalized, ForceMode.Acceleration);
                }
            }
            this.timeElapsed += Time.deltaTime;
            if (this.timeElapsed > 0.6f)
            {
                this.timeElapsed = 0f;
                if (Vector3.Distance(this.Owner.baseT.position, this.setPoint) > 20f)
                {
                    this.Followed();
                }
            }
            if (Vector3.Distance(this.Owner.baseT.position, baseT.position) < 5f)
            {
                this.Unmounted();
            }
            if (Vector3.Distance(this.setPoint, baseT.position) < 5f)
            {
                this.Unmounted();
            }
            this.awayTimer += Time.deltaTime;
            if (this.awayTimer > 6f)
            {
                this.awayTimer = 0f;
                if (Physics.Linecast(baseT.position + Vectors.up, this.Owner.baseT.position + Vectors.up, Layers.Ground.value))
                {
                    baseT.position = new Vector3(this.Owner.baseT.position.x, this.GetHeight(this.Owner.baseT.position + Vectors.up * 5f), this.Owner.baseT.position.z);
                }
            }
        }
        break;

        case HorseState.Idle:
        {
            this.ToIdleAnimation();
            if (this.Owner != null && Vector3.Distance(this.Owner.baseT.position, baseT.position) > 20f)
            {
                this.Followed();
            }
        }
        break;
        }
        baseR.AddForce(new Vector3(0f, -50f * baseR.mass, 0f));
    }