Inheritance: UnityEngine.MonoBehaviour
コード例 #1
0
    public TestCharacter(string name) {
      charObj = new GameObject();
      charObj.name = name;
      character = charObj.AddComponent<Character>();
      Assert.NotNull(character);
      health = charObj.GetComponent<CharacterHealth>();
      Assert.NotNull(health);
      health.Start();

      enterHitBox = charObj.CreateChild("entreAreas").AddComponent<HitBox>();
      enterHitBox.type = HitBoxType.EnterAreas;
      enterHitBox.gameObject.layer = 1;

      enterBox2D = enterHitBox.gameObject.AddComponent<BoxCollider2D>();
      enterBox2D.size = new Vector2(1, 1);
      enterHitBox.owner = health;
      enterHitBox.Start();

      dealHitBox = charObj.CreateChild("dealHitBox").AddComponent<HitBox>();
      Assert.NotNull(dealHitBox);

      dealHitBox.type = HitBoxType.DealDamage;
      dealHitBox.collideWith = (1 << 2); // | (1 << ?)
      dealHitBox.gameObject.layer = 2;
      damage = dealHitBox.gameObject.AddComponent<Damage>();
      damage.causer = health;
      damage.Start();
      dealHitBox.owner = health;

      dealBox2D = dealHitBox.gameObject.AddComponent<BoxCollider2D>();
      dealBox2D.size = new Vector2(1, 1);
      dealHitBox.Start();

      recieveHitBox = charObj.CreateChild("recieveHitBox").AddComponent<HitBox>();
      Assert.NotNull(recieveHitBox);

      recieveHitBox.type = HitBoxType.RecieveDamage;
      recieveHitBox.collideWith = (1 << 2);
      recieveHitBox.gameObject.layer = 2;
      recieveHitBox.owner = health;

      recieveBox2D = recieveHitBox.gameObject.AddComponent<BoxCollider2D>();
      recieveBox2D.size = new Vector2(1, 1);
      recieveHitBox.Start();

      // init health callbacks
      health.onHeal += () => { onHealCalled = true; };
      health.onDamage += () => { onDamageCalled = true; };
      health.onImmunity += () => { onImmunityCalled = true; };
      health.onMaxHealth += () => { onMaxHealthCalled = true; };
      health.onInjured += (Damage dt, CharacterHealth to) => { onInjuredCalled = true; };
      health.onHurt += (Damage dt, CharacterHealth to) => { onHurtCalled = true; };
      health.onDeath += () => { onDeathCalled = true; };
      health.onGameOver += () => { onGameOverCalled = true; };
      health.onInvulnerabilityStart += () => { onInvulnerabilityStartCalled = true; };
      health.onInvulnerabilityEnd += () => { onInvulnerabilityEndCalled = true; };
      health.onRespawn += () => { onRespawnCalled = true; };

    }
コード例 #2
0
ファイル: Damage.cs プロジェクト: wolfreak99/unity-platformer
        /// <summary>
        /// check missconfiguration
        /// </summary>
        public void Start()
        {
            Assert.IsNotNull(causer, "(Damage) causer cannot be null at " + gameObject.GetFullName());

            // REVIEW this may not be necessary...
            HitBox hitbox = GetComponent <HitBox> ();

            Assert.IsNotNull(hitbox, "(Damage) Missing MonoBehaviour HitBox at " + gameObject.GetFullName());
            if (hitbox.type != HitBoxType.DealDamage)
            {
                Assert.IsNotNull(null, "(Damage) Damage found but hitbox type is not DealDamage at " + gameObject.GetFullName());
            }
        }
コード例 #3
0
ファイル: Liquid.cs プロジェクト: yhnu/unity-platformer
        /// <summary>
        /// if a Hitbox(EnterAreas) enter -> exitArea
        /// </summary>
        public virtual void OnTriggerExit2D(Collider2D o)
        {
            HitBox h = o.GetComponent <HitBox>();

            if (h && h.type == HitBoxType.EnterAreas)
            {
                Character p = h.owner.GetComponent <Character>();
                if (p.liquid == this) // REVIEW with this liquid should overlap
                {
                    p.liquid = null;
                    p.ExitArea(Areas.Liquid);
                }
            }
        }
コード例 #4
0
ファイル: Utils.cs プロジェクト: yhnu/unity-platformer
        static public Character SmartGetCharacter(GameObject obj)
        {
            Character p = obj.GetComponent <Character>();

            if (p != null)
            {
                return(p);
            }

            HitBox hb = obj.GetComponent <HitBox>();

            if (hb != null)
            {
                return(hb.owner.character);
            }

            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Create and configure RopeSection
        /// </summary>
        GameObject CreateSection(int i, Rigidbody2D connectedBody)
        {
            GameObject section;
            float      currentLocalYPos = -segmentLength / 2.0f - segmentLength * i;

            if (sectionPrefab != null)
            {
                section = (GameObject)GameObject.Instantiate(sectionPrefab);
            }
            else
            {
                section = new GameObject();
            }
            section.name  = "RopeSection_" + i;
            section.layer = gameObject.layer;

            // Set length and position
            section.transform.parent        = transform;
            section.transform.localPosition = new Vector3(0, currentLocalYPos, 0);

            Rigidbody2D rb = section.GetOrAddComponent <Rigidbody2D>();

            rb.mass = ropeMass;
            // NOTE this is mandatory atm.
            // the rope movement it's a bit basic, because i cannot have a more stable
            // version
            rb.isKinematic = true;

            BoxCollider2D bc2d = section.GetOrAddComponent <BoxCollider2D>();

            // Default to a 0.5f wide box collider
            bc2d.size      = new Vector2(0.5f, segmentLength);
            bc2d.isTrigger = true;

            // Check Hinge Joint
            HingeJoint2D hingeJoint = section.GetOrAddComponent <HingeJoint2D>();

            hingeJoint.anchor          = new Vector2(0, 0.5f);
            hingeJoint.connectedAnchor = new Vector2(0, i == 0 ? 0.0f : -0.5f);
            hingeJoint.connectedBody   = connectedBody;
            if (angleLimits > 0)
            {
                hingeJoint.useLimits = true;
                JointAngleLimits2D limits = new JointAngleLimits2D();
                limits.min        = angleLimits;
                limits.max        = -angleLimits;
                hingeJoint.limits = limits;
            }

            // this will handle the player entering the rope
            RopeSection rs = section.AddComponent <RopeSection>();

            rs.rope  = this;
            rs.index = i;

            if (health != null)
            {
                // NOTE add/get the HitBox so it can be destroyed
                // if we add a hitbox, it's just useless we need a proper collideWith
                // configured
                HitBox hitbox = section.GetOrAddComponent <HitBox>();
                hitbox.owner = health;
                //hitbox.type = HitBoxType.RecieveDamage;
                //hitbox.collideWith = recieveDamage;
            }

            // Special case, for last section
            if (i == segments - 1)
            {
                rb.mass = ropeMass * 5;
            }

            sections[i] = section;
            return(section);
        }