示例#1
0
    private StickmanPart CreatePart(string partName, StickmanPart parent, float length, float thickness, float mass, int limits, bool twoSides = true, int angle = 0)
    {
        StickmanPart part = StickmanPart.Create(partName, length, thickness, mass, twoSides);

        if (parent == null)
        {
            part.transform.parent        = base.transform;
            part.transform.localPosition = Vector3.zero;
        }
        else
        {
            part.transform.parent        = parent.transform;
            part.transform.localPosition = new Vector3(0f, -parent.Length);
            HingeJoint joint = part.gameObject.AddComponent <HingeJoint>();
            joint.connectedBody = parent.rigidbody;
            joint.axis          = Vector3.forward;
            joint.useLimits     = true;
            JointLimits limits2 = new JointLimits {
                max       = limits,
                min       = -limits,
                maxBounce = 0.5f,
                minBounce = 0.5f
            };
            joint.limits    = limits2;
            joint.useSpring = true;
        }
        part.transform.localEulerAngles = new Vector3(0f, 0f, (float)angle);
        return(part);
    }
示例#2
0
    private void OnCollisionEnter(Collision collision)
    {
        StickmanPart component = collision.gameObject.GetComponent <StickmanPart>();

        if ((component != null) && (component.Stickman.CurrentHealth > 0))
        {
            Vector3 point = collision.contacts[0].point;
            if (this._blowMultiplier > 0f)
            {
                Vector3 vector2 = component.rigidbody.position - point;
                component.StartForce((Vector2)((vector2.normalized * this._game.BlowForce) * this._blowMultiplier), point, this._game.BlowTime);
            }
            this._game.CreateHitParticles(collision.contacts[0].point, false);
            component.Stickman.Hit(this._damage);
            component.Blink();
            if (component.Stickman.CurrentHealth <= 0)
            {
                this._game.PlayDeathSound();
            }
            this._game.PlaySwordSound();
            if (component.name.Contains("Head"))
            {
                component.Stickman.ReleaseWeapons();
            }
            if (!this._game.IsOver)
            {
                this._game.SlowMo(component.Stickman.CurrentHealth <= 0);
            }
        }
    }
示例#3
0
    public static StickmanPart Create(string name = "Part", float mass = 1, string partName = "")
    {
        GameObject obj = new GameObject(name);

        obj.SetActive(false);
        obj.tag = "Player";
        StickmanPart part = obj.AddComponent <StickmanPart>();

        part._partName               = partName;
        part._rigidbody              = part.gameObject.AddComponent <Rigidbody2D>();
        part._rigidbody.mass         = mass;
        part._baseMass               = mass;
        part._rigidbody.angularDrag  = 1f;
        part._rigidbody.drag         = 0.0f;
        part._rigidbody.gravityScale = GameOptions.gravityScale;
        PhysicsMaterial2D phyMat2D = new PhysicsMaterial2D("physicMat");

        phyMat2D.bounciness            = GameOptions.bounciness;
        part._rigidbody.sharedMaterial = phyMat2D;
        part._rigidbody.interpolation  = RigidbodyInterpolation2D.Interpolate;
        part._body = new GameObject("body");
        part._body.AddComponent <SphereCollider>().enabled = false;//±ê¼ÇλÖÃÓÃ
        part._body.transform.parent = part.transform;
        part.UpdatePart();
        obj.SetActive(true);
        return(part);
    }
示例#4
0
 public override void SetToStickman(Stickman stickman, StickmanPart part)
 {
     base.SetToStickman(stickman, part);
     if (base.Stickman != null)
     {
         this._time = Time.time + UnityEngine.Random.Range(0f, this._rechargeTime);
     }
 }
示例#5
0
 public void PrepareToReplay()
 {
     for (int i = 0; i < base.transform.childCount; i++)
     {
         StickmanPart component = base.transform.GetChild(i).GetComponent <StickmanPart>();
         if (component != null)
         {
             UnityEngine.Object.Destroy(component.hingeJoint);
             UnityEngine.Object.Destroy(component.rigidbody);
             UnityEngine.Object.Destroy(component.collider);
         }
     }
 }
示例#6
0
 public override void SetToStickman(Stickman stickman, StickmanPart part)
 {
     base.SetToStickman(stickman, part);
     if (((base.Stickman != null) && (base.Stickman.CurrentHealth > 0)) && (this._collider != null))
     {
         Collider[] componentsInChildren = base.Stickman.GetComponentsInChildren <Collider>();
         for (int i = 0; i < componentsInChildren.Length; i++)
         {
             if (componentsInChildren[i] != this._collider)
             {
                 Physics.IgnoreCollision(componentsInChildren[i], this._collider, true);
             }
         }
     }
 }
示例#7
0
    private StickmanPart CreatePart(string partName, StickmanPart parent, float mass, int limits, int angle = 0)
    {
        StickmanPart part = StickmanPart.Create(partName, mass, partName);

        if (parent == null) //spine
        {
            part.transform.parent        = base.transform;
            part.transform.localPosition = Vector3.zero;
        }
        else
        {
            part.transform.parent        = parent.transform;
            part.transform.localPosition = new Vector3(0f, -parent.Length);
            HingeJoint2D joint = part.gameObject.AddComponent <HingeJoint2D>();

            joint.connectedBody = parent.GetComponent <Rigidbody2D>();
            joint.useLimits     = true;

            JointAngleLimits2D limits2 = new JointAngleLimits2D
            {
                min = -limits / 2f,
                max = limits / 2f
            };

            joint.limits = limits2;

            RelativeJoint2D springJoint = part.gameObject.AddComponent <RelativeJoint2D>();
            springJoint.connectedBody = parent.GetComponent <Rigidbody2D>();
            springJoint.maxForce      = 0f;
            springJoint.maxTorque     = GameOptions.maxRelativeTorque;
            //springJoint.frequency = this._spring;
            //springJoint.autoConfigureConnectedAnchor = true;
            //springJoint.dampingRatio = this.Damper;
        }
        part.transform.localEulerAngles = new Vector3(0f, 0f, (float)angle);
        return(part);
    }
示例#8
0
    private void Awake()
    {
        this._spine3   = base.transform.FindChild("Spine3").GetComponent <StickmanPart>();
        this._spine2   = base.transform.FindChild("Spine2").GetComponent <StickmanPart>();
        this._spine1   = base.transform.FindChild("Spine1").GetComponent <StickmanPart>();
        this._head     = base.transform.FindChild("Head").GetComponent <StickmanPart>();
        this._upArmL   = base.transform.FindChild("UpArmL").GetComponent <StickmanPart>();
        this._upArmR   = base.transform.FindChild("UpArmR").GetComponent <StickmanPart>();
        this._downArmL = base.transform.FindChild("DownArmL").GetComponent <StickmanPart>();
        this._downArmR = base.transform.FindChild("DownArmR").GetComponent <StickmanPart>();
        this._upLegL   = base.transform.FindChild("UpLegL").GetComponent <StickmanPart>();
        this._upLegR   = base.transform.FindChild("UpLegR").GetComponent <StickmanPart>();
        this._downLegL = base.transform.FindChild("DownLegL").GetComponent <StickmanPart>();
        this._downLegR = base.transform.FindChild("DownLegR").GetComponent <StickmanPart>();
        Physics.IgnoreCollision(this._upLegL.collider, this._upLegR.collider);
        Physics.IgnoreCollision(this._upArmL.collider, this._head.collider);
        Physics.IgnoreCollision(this._upArmR.collider, this._head.collider);
        Physics.IgnoreCollision(this._upArmL.collider, this._spine2.collider);
        Physics.IgnoreCollision(this._upArmR.collider, this._spine2.collider);
        Physics.IgnoreCollision(this._downArmL.collider, this._head.collider);
        Physics.IgnoreCollision(this._downArmR.collider, this._head.collider);
        Physics.IgnoreCollision(this._upArmL.collider, this._upArmR.collider);
        this.CurrentHealth = this.Health;
        if (Application.isPlaying)
        {
            this._leftLife = GameObject.CreatePrimitive(PrimitiveType.Quad);
            UnityEngine.Object.DestroyImmediate(this._leftLife.collider);
            this._leftLife.name = "leftLife";
            this._leftLife.transform.localScale    = (Vector3)(base.transform.lossyScale * this._thickness);
            this._leftLife.transform.parent        = this._downArmL.transform;
            this._leftLife.transform.localPosition = new Vector3(0f, -this._downArmL.Length * 0.7f, -0.01f);
            this._leftLife.renderer.material       = this._spine3.QuadMaterial;
            this._leftLifeMesh        = this._leftLife.GetComponent <MeshFilter>().mesh;
            this._leftLifeMesh.colors = new UnityEngine.Color[] { this.Color, this.Color, this.Color, this.Color };

            this._rightLife = GameObject.CreatePrimitive(PrimitiveType.Quad);
            UnityEngine.Object.DestroyImmediate(this._rightLife.collider);
            this._rightLife.name = "rightLife";
            this._rightLife.transform.localScale    = (Vector3)(base.transform.lossyScale * this._thickness);
            this._rightLife.transform.parent        = this._downArmR.transform;
            this._rightLife.transform.localPosition = new Vector3(0f, -this._downArmR.Length * 0.7f, -0.01f);
            this._rightLife.renderer.material       = this._spine3.QuadMaterial;
            this._rightLifeMesh        = this._rightLife.GetComponent <MeshFilter>().mesh;
            this._rightLifeMesh.colors = new UnityEngine.Color[] { this.Color, this.Color, this.Color, this.Color };

            this.WeaponLTransform                  = new GameObject("weaponL").transform;
            this.WeaponLTransform.parent           = this._downArmL.transform;
            this.WeaponLTransform.localPosition    = new Vector3(0f, -this._downArmL.Length * 0.85f, 0.01f);
            this.WeaponLTransform.localEulerAngles = new Vector3(0f, 180f, -90f);

            this.WeaponRTransform               = new GameObject("weaponR").transform;
            this.WeaponRTransform.parent        = this._downArmR.transform;
            this.WeaponRTransform.localPosition = new Vector3(0f, -this._downArmR.Length * 0.85f, 0.01f);

            float num = ((float)PlayerSettings.Flexibility.Value) * 0.1f;
            this._spring *= num;
            this._damp   *= num * 0.5f;
            this.UpdateJoints();
            this.Id = base.GetInstanceID();
        }
    }
示例#9
0
    private void OnCollisionEnter2D_Legacy(Collision2D collision)
    {
        foreach (ContactPoint2D hit in collision.contacts)
        {
            Vector2 hitPoint = hit.point;
        }

        StickmanPart component = collision.gameObject.GetComponent <StickmanPart>();

        if (((((component != null) && (component.Stickman != this.Stickman)) && ((this.Stickman.Hp > 0) && (component.Stickman.Hp > 0))) && (this.Stickman.IsPlayer != component.Stickman.IsPlayer)) && (this._rigidbody.velocity.sqrMagnitude >= component._rigidbody.velocity.sqrMagnitude))
        {
            Vector3 point = collision.contacts[0].point;
            if (this.CanHit || component.CanHit)
            {
                //Vector3 vector4 = this._rigidbody.position - point;
                //this.StartForce((Vector2)(vector4.normalized * this._game.BlowForce), point, this._game.BlowTime);
                //Vector3 vector5 = component._rigidbody.position - point;
                //component.StartForce((Vector2)(vector5.normalized * this._game.BlowForce), point, this._game.BlowTime);
            }
            bool twice = false;
            if (this.CanHit && component.CanGetHit)
            {
                //this._game.CreateHitParticles(point, true);
                //component.Stickman.Hit(this.Stickman.Damage);
                component.Blink();
                if (component.Stickman.Hp <= 0)
                {
                    //this._game.PlayDeathSound();
                    twice = true;
                }
                else
                {
                    //this._game.PlayHitSound(false);
                }
                string str = string.Empty;
                if (base.name.Contains("Head"))
                {
                    str = "Butt";
                }
                else if (base.name.Contains("Arm"))
                {
                    str = "Punch";
                }
                else if (base.name.Contains("Leg"))
                {
                    str = "Kick";
                }
                string str2 = string.Empty;
                if (component.name.Contains("Head"))
                {
                    str2 = "Head";
                }
                else if (component.name.Contains("Arm"))
                {
                    str2 = "Arm";
                }
                else if (component.name.Contains("Leg"))
                {
                    str2 = "Leg";
                }
                else if (component.name.Contains("Spine"))
                {
                    str2 = "Body";
                }
                if (base.name.Contains("Head") && component.name.Contains("Head"))
                {
                    str2 = "Head";
                    str  = "Bounce";
                }
                //this._game.CreateText(str2 + " " + str, UnityEngine.Color.red, point, 0, 0f, -1f, 0f, 0f);
                if (str2 == "Head")
                {
                    //component.Stickman.ReleaseWeapons();
                }
            }
            if (this.CanGetHit && component.CanHit)
            {
                //this._game.CreateHitParticles(point, true);
                //this.Stickman.Hit(component.Stickman.Damage);
                this.Blink();
                if (this.Stickman.Hp <= 0)
                {
                    //this._game.PlayDeathSound();
                    twice = true;
                }
                else
                {
                    //this._game.PlayHitSound(false);
                }
                string str3 = string.Empty;
                if (component.name.Contains("Head"))
                {
                    str3 = "Butt";
                }
                else if (component.name.Contains("Arm"))
                {
                    str3 = "Punch";
                }
                else if (component.name.Contains("Leg"))
                {
                    str3 = "Kick";
                }
                string str4 = string.Empty;
                if (base.name.Contains("Head"))
                {
                    str4 = "Head";
                }
                else if (base.name.Contains("Arm"))
                {
                    str4 = "Arm";
                }
                else if (base.name.Contains("Leg"))
                {
                    str4 = "Leg";
                }
                else if (base.name.Contains("Spine"))
                {
                    str4 = "Body";
                }
                if (base.name.Contains("Head") && component.name.Contains("Head"))
                {
                    str4 = "Head";
                    str3 = "Bounce";
                }
                //this._game.CreateText(str4 + " " + str3, UnityEngine.Color.red, point, 0, 0f, -1f, 0f, 0f);
                if (str4 == "Head")
                {
                    //this.Stickman.ReleaseWeapons();
                }
            }
            if ((this.CanHit && !this.CanGetHit) && (component.CanHit && !component.CanGetHit))
            {
                //this._game.CreateBlockParticles(point);
                //this._game.PlayBlockSound();
            }
            if (this.CanHit || component.CanHit)
            {
                //this._game.SlowMo(twice);
                //this._game.AddStickmanKey(this.Stickman);
                //this._game.AddStickmanKey(component.Stickman);
            }
        }
    }
示例#10
0
    private void Start()
    {
        this._spine    = base.transform.FindChild("Spine").GetComponent <StickmanPart>();
        this._head     = base.transform.FindChild("Head").GetComponent <StickmanPart>();
        this._upArmL   = base.transform.FindChild("UpArmL").GetComponent <StickmanPart>();
        this._upArmR   = base.transform.FindChild("UpArmR").GetComponent <StickmanPart>();
        this._downArmL = base.transform.FindChild("DownArmL").GetComponent <StickmanPart>();
        this._downArmR = base.transform.FindChild("DownArmR").GetComponent <StickmanPart>();
        this._upLegL   = base.transform.FindChild("UpLegL").GetComponent <StickmanPart>();
        this._upLegR   = base.transform.FindChild("UpLegR").GetComponent <StickmanPart>();
        this._downLegL = base.transform.FindChild("DownLegL").GetComponent <StickmanPart>();
        this._downLegR = base.transform.FindChild("DownLegR").GetComponent <StickmanPart>();


        Physics2D.IgnoreCollision(this._downLegL.gameObject.GetComponent <Collider2D>(), this._downLegR.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._upLegL.gameObject.GetComponent <Collider2D>(), this._upLegR.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downLegL.gameObject.GetComponent <Collider2D>(), this._upLegR.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._upLegL.gameObject.GetComponent <Collider2D>(), this._downLegR.gameObject.GetComponent <Collider2D>());

        Physics2D.IgnoreCollision(this._upArmL.gameObject.GetComponent <Collider2D>(), this._head.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._upArmR.gameObject.GetComponent <Collider2D>(), this._head.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downArmL.gameObject.GetComponent <Collider2D>(), this._head.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downArmR.gameObject.GetComponent <Collider2D>(), this._head.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._upArmL.gameObject.GetComponent <Collider2D>(), this._upArmR.gameObject.GetComponent <Collider2D>());

        Physics2D.IgnoreCollision(this._head.gameObject.GetComponent <Collider2D>(), this._spine.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._upArmL.gameObject.GetComponent <Collider2D>(), this._spine.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._upArmR.gameObject.GetComponent <Collider2D>(), this._spine.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downArmL.gameObject.GetComponent <Collider2D>(), this._spine.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downArmR.gameObject.GetComponent <Collider2D>(), this._spine.gameObject.GetComponent <Collider2D>());


        Physics2D.IgnoreCollision(this._downArmL.gameObject.GetComponent <Collider2D>(), this._upLegR.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downArmL.gameObject.GetComponent <Collider2D>(), this._upLegL.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downArmR.gameObject.GetComponent <Collider2D>(), this._upLegR.gameObject.GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(this._downArmR.gameObject.GetComponent <Collider2D>(), this._upLegL.gameObject.GetComponent <Collider2D>());

        if (Application.isPlaying)
        {
            //this._leftLife = GameObject.CreatePrimitive(PrimitiveType.Quad);
            //UnityEngine.Object.DestroyImmediate(this._leftLife.GetComponent<Collider>());
            //this._leftLife.name = "leftLife";
            //this._leftLife.transform.localScale = (Vector3)(base.transform.lossyScale * this._thickness);
            //this._leftLife.transform.parent = this._downArmL.transform;
            //this._leftLife.transform.localPosition = new Vector3(0f, -this._downArmL.Length * 0.7f, -0.01f);
            //this._leftLifeMesh = this._leftLife.GetComponent<MeshFilter>().mesh;

            //this._rightLife = GameObject.CreatePrimitive(PrimitiveType.Quad);
            //UnityEngine.Object.DestroyImmediate(this._rightLife.GetComponent<Collider>());
            //this._rightLife.name = "rightLife";
            //this._rightLife.transform.localScale = (Vector3)(base.transform.lossyScale * this._thickness);
            //this._rightLife.transform.parent = this._downArmR.transform;
            //this._rightLife.transform.localPosition = new Vector3(0f, -this._downArmR.Length * 0.7f, -0.01f);
            //this._rightLifeMesh = this._rightLife.GetComponent<MeshFilter>().mesh;

            float num = 1f;
            this._spring *= num;
            this._damp   *= num * 0.9f;
            this.UpdateJoints();
            this.Id = base.GetInstanceID();
        }
    }