Esempio n. 1
0
        public void ShowMessage(string message, Vector3 invokePos, float lifeTime = -1)
        {
            this.Activate();

            if (invokePos != Vector3.zero)
            {
                this.transform.position = invokePos;
            }

            this.transform.GetTextComponent().text = message;

            if (lifeTime > 0)
            {
                this.StopAllCoroutines();
                UEx.DelayedAction(lifeTime, this.Deactivate,
                                  () => this.gameObject.activeSelf);
            }
        }
Esempio n. 2
0
    public static float SqrLineDistance(Vector3 lineP1, Vector3 lineP2, Vector3 point, out int closestPoint)
    {
        Vector3 vector = lineP2 - lineP1;
        Vector3 lhs    = point - lineP1;
        float   num    = Vector3.Dot(lhs, vector);

        if (num <= 0f)
        {
            closestPoint = 1;
            return(UEx.SqrDistance(point, lineP1));
        }
        float num2 = Vector3.Dot(vector, vector);

        if (num2 <= num)
        {
            closestPoint = 2;
            return(UEx.SqrDistance(point, lineP2));
        }
        float   d      = num / num2;
        Vector3 second = lineP1 + d * vector;

        closestPoint = 4;
        return(UEx.SqrDistance(point, second));
    }
    private void OnCollisionStay(Collision collInfo)
    {
        if (!this.coll)
        {
            this.coll = base.GetComponent <Collider>();
            this.GetCollType();
        }
        this.collFlags = CollisionFlags.None;
        Vector3 center = this.coll.bounds.center;

        switch (this.collType)
        {
        case 1:
        {
            Vector3 vector = this._trans.up * ((this.cColl.height - this.cColl.radius * 2f) * 0.5f);
            vector = Vector3.Scale(vector, this._trans.localScale);
            Vector3 vector2 = center - vector;
            Vector3 vector3 = center + vector;
            Debug.DrawLine(this.coll.bounds.center, vector2, Color.green);
            Debug.DrawLine(this.coll.bounds.center, vector3, Color.blue);
            ContactPoint[] contacts = collInfo.contacts;
            for (int i = 0; i < contacts.Length; i++)
            {
                ContactPoint contactPoint = contacts[i];
                int          num          = 0;
                float        num2         = UEx.SqrLineDistance(vector2, vector3, contactPoint.point, out num);
                if (contactPoint.otherCollider.GetType() == typeof(MeshCollider))
                {
                    if ((double)contactPoint.point.y < (double)vector2.y + 0.25)
                    {
                        Vector3 vector4 = contactPoint.point;
                        Vector3 normal  = contactPoint.normal;
                        vector4 += normal;
                        RaycastHit raycastHit;
                        if (contactPoint.otherCollider.Raycast(new Ray(vector4, -normal), out raycastHit, 2f))
                        {
                            this.groundAngleVal = Mathf.Abs(Vector3.Angle(raycastHit.normal, Vector3.up));
                        }
                        else
                        {
                            this.groundAngleVal = 0f;
                        }
                        this.collFlags |= CollisionFlags.Below;
                    }
                }
                else if (num == 1)
                {
                    this.collFlags     |= CollisionFlags.Below;
                    this.groundAngleVal = 0f;
                }
                else if (num == 2)
                {
                    this.collFlags     |= CollisionFlags.Above;
                    this.groundAngleVal = 0f;
                }
                else
                {
                    this.collFlags     |= CollisionFlags.Sides;
                    this.groundAngleVal = 0f;
                }
            }
            break;
        }

        case 2:
        {
            ContactPoint[] contacts2 = collInfo.contacts;
            for (int j = 0; j < contacts2.Length; j++)
            {
                ContactPoint contactPoint2 = contacts2[j];
                Vector3      rhs           = contactPoint2.point - center;
                rhs.Normalize();
                float num3 = Vector3.Dot(this._trans.up, rhs);
                if (num3 < 0.333f)
                {
                    this.collFlags |= CollisionFlags.Below;
                }
                else if (num3 > 0.333f)
                {
                    this.collFlags |= CollisionFlags.Above;
                }
                else
                {
                    this.collFlags |= CollisionFlags.Sides;
                }
            }
            break;
        }

        case 3:
        {
            ContactPoint[] contacts3 = collInfo.contacts;
            for (int k = 0; k < contacts3.Length; k++)
            {
                ContactPoint contactPoint3 = contacts3[k];
                Vector3      rhs2          = contactPoint3.point - center;
                rhs2.Normalize();
                float num4 = Vector3.Dot(this._trans.up, rhs2);
                if (num4 < 0.5f)
                {
                    this.collFlags |= CollisionFlags.Below;
                }
                else if (num4 > 0.5f)
                {
                    this.collFlags |= CollisionFlags.Above;
                }
                else
                {
                    this.collFlags |= CollisionFlags.Sides;
                }
            }
            break;
        }
        }
    }
    public void OnCollisionStayProxied(Collision collInfo)
    {
        if (!this.coll)
        {
            this.coll = base.GetComponent <Collider>();
            this.GetCollType();
        }
        this.collFlags = CollisionFlags.None;
        Vector3 center = this.coll.bounds.center;

        switch (this.collType)
        {
        case 1:
        {
            Vector3 vector = this._trans.up * ((this.cColl.height - this.cColl.radius * 2f) * 0.5f);
            vector = Vector3.Scale(vector, this._trans.localScale);
            Vector3 lineP  = center - vector;
            Vector3 lineP2 = center + vector;
            for (int i = 0; i < collInfo.contacts.Length; i++)
            {
                int   num  = 0;
                float num2 = UEx.SqrLineDistance(lineP, lineP2, collInfo.contacts[i].point, out num);
                if (collInfo.contacts[i].point.y < lineP.y + this.heightOffset)
                {
                    Vector3 vector2 = collInfo.contacts[i].point;
                    Vector3 normal  = collInfo.contacts[i].normal;
                    vector2 += normal;
                    base.transform.position.y = lineP.y + this.heightOffset;
                    RaycastHit raycastHit;
                    if (collInfo.contacts[i].otherCollider.Raycast(new Ray(vector2, -normal), out raycastHit, 2f))
                    {
                        this.groundAngleVal = Mathf.Abs(Vector3.Angle(raycastHit.normal, Vector3.up));
                    }
                    else
                    {
                        this.groundAngleVal = 0f;
                    }
                    this.slopeNormal = raycastHit.normal;
                    this.collFlags  |= CollisionFlags.Below;
                    this.testBelow   = true;
                }
                if (collInfo.contacts[i].point.y < lineP.y + 0.8f)
                {
                    this.stuckPointCount++;
                    if (this.stuckPointCount > 2)
                    {
                        this.testBelow = true;
                    }
                }
                else if (num == 2)
                {
                    this.collFlags     |= CollisionFlags.Above;
                    this.groundAngleVal = 0f;
                }
                else
                {
                    this.collFlags     |= CollisionFlags.Sides;
                    this.groundAngleVal = 0f;
                }
            }
            this.stuckPointCount = 0;
            break;
        }

        case 2:
            foreach (ContactPoint contactPoint in collInfo.contacts)
            {
                Vector3 rhs = contactPoint.point - center;
                rhs.Normalize();
                float num3 = Vector3.Dot(this._trans.up, rhs);
                if (num3 < 0.333f)
                {
                    this.collFlags |= CollisionFlags.Below;
                }
                else if (num3 > 0.333f)
                {
                    this.collFlags |= CollisionFlags.Above;
                }
                else
                {
                    this.collFlags |= CollisionFlags.Sides;
                }
            }
            break;

        case 3:
            foreach (ContactPoint contactPoint2 in collInfo.contacts)
            {
                Vector3 rhs2 = contactPoint2.point - center;
                rhs2.Normalize();
                float num4 = Vector3.Dot(this._trans.up, rhs2);
                if (num4 < 0.5f)
                {
                    this.collFlags |= CollisionFlags.Below;
                }
                else if (num4 > 0.5f)
                {
                    this.collFlags |= CollisionFlags.Above;
                }
                else
                {
                    this.collFlags |= CollisionFlags.Sides;
                }
            }
            break;
        }
    }