Handle collisions with the world
Inheritance: RaycastController
    void FixtureCreateHealth() {
      Configuration.ClearInstance();
      UpdateManager.ClearInstance();
      System.GC.Collect();

      var obj = new GameObject();
      config = obj.AddComponent<Configuration>();
      Assert.NotNull(config);
      umgr = obj.AddComponent<UpdateManager>();
      Assert.NotNull(umgr);


      var objx = new GameObject();
      character = objx.AddComponent<Character>();
      Assert.NotNull(character);
      health = objx.GetComponent<CharacterHealth>();
      Assert.NotNull(health);
      col2d = objx.GetComponent<PlatformerCollider2D>();
      Assert.NotNull(col2d);

      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; };

      ResetCallbacks();
    }
Beispiel #2
0
    /// <summary>
    /// keep Character.actions in sync
    /// </summary>
    public virtual void OnEnable() {
      Assert.IsNotNull(character, "(CharacterAction) character is required: " + gameObject.GetFullName());
      Assert.IsNotNull(input, "(CharacterAction) input is required: " + gameObject.GetFullName());

      character.Awake();

      pc2d = character.gameObject.GetComponent<PlatformerCollider2D>();

      hasControl = false;

      character.actions.Add(this);
    }
    /// <summary>
    /// Listen InstancePrefab SendMessage and start logic
    /// </summary>
    public void OnInstancePrefab(InstancePrefab prefab) {
      inputMgr = prefab.instance.GetComponentInChildren<AIInput>();
      if (inputMgr == null) {
        Debug.LogWarning("AIInput is expected in the prefab");
        return;
      }
      pc2d = prefab.instance.GetComponentInChildren<PlatformerCollider2D>();


      inputMgr.SetX(1);

      pc2d.onLeftWall += OnLeftWall;
      pc2d.onRightWall += OnRightWall;
    }
    /// <summary>
    /// keep Character.actions in sync
    /// </summary>
    public virtual void OnEnable() {
      if (character == null) {
        Debug.LogError("Action character property is null", this);
      }

      if (input == null) {
        Debug.LogError("Action input property is null", this);
      }

      pc2d = character.gameObject.GetComponent<PlatformerCollider2D>();

      hasControl = false;

      character.actions.Add(this);
    }
    public void OnInstancePrefab(InstancePrefab prefab) {
      inputMgr = prefab.instance.GetComponentInChildren<AIInput>();
      if (inputMgr == null) {
        Debug.LogWarning("AIInput is expected in the prefab");
        return;
      }
      pc2d = prefab.instance.GetComponentInChildren<PlatformerCollider2D>();
      character = prefab.instance.GetComponentInChildren<Character>();


      inputMgr.SetX(1);
      character.onAreaChange += OnAreaChange;
      pc2d.onLeftWall += OnLeftWall;
      pc2d.onRightWall += OnRightWall;
    }
        // keep character.actions in sync
        public virtual void OnEnable()
        {
            if (character == null)
            {
                Debug.LogError("Action character property is null", this);
            }

            if (input == null)
            {
                Debug.LogError("Action input property is null", this);
            }

            pc2d = character.gameObject.GetComponent <PlatformerCollider2D>();

            hasControl = false;

            character.actions.Add(this);
        }
    public override void OnAwake(bool notify = true) {
      base.OnAwake(notify);


      aiInput = instance.GetComponentInChildren<AIInput>();
      if (aiInput == null) {
        Debug.LogWarning("AIInput is expected in the prefab");
        return;
      }
      pc2d = instance.GetComponentInChildren<PlatformerCollider2D>();
      character = instance.GetComponentInChildren<Character>();


      aiInput.SetX(1);
      character.onAreaChange += OnAreaChange;
      character.onStateChange += OnStateChange;
      pc2d.onLeftWall += OnLeftWall;
      pc2d.onRightWall += OnRightWall;
    }
Beispiel #8
0
        /// <summary>
        /// This method precalculate some vars, but those value could change. This need to be refactored.
        /// Maybe setters are the appropiate method to refactor this.
        /// </summary>
        virtual public void Awake()
        {
            forceAnimation = null;
            //Debug.Log("Start new Character: " + gameObject.name);
            pc2d           = GetComponent <PlatformerCollider2D> ();
            health         = GetComponent <Health>();
            health.onHurt += OnHurt;
            body           = GetComponent <BoxCollider2D>();

            if (fallingCD == null)
            {
                fallingCD = new Cooldown(fallingTime);
            }

            if (groundCD == null)
            {
                groundCD = new Cooldown(groundGraceTime);
            }
            //TODO review how hotswapping behave in this case ?!
            health.onDeath += OnDeath;
        }
 // Use this for initialization
 virtual public void Start()
 {
     pc2d = GetComponent <PlatformerCollider2D> ();
 }
 /// <summary>
 /// Get PlatformerCollider2D
 /// </summary>
 virtual public void Start() {
   pc2d = GetComponent<PlatformerCollider2D> ();
 }