private void CheckExecution(GameObjectCallback e)
 {
     if (e == executeOn)
     {
         Execute();
     }
 }
Esempio n. 2
0
 public static void OnCallBack(GameObjectCallback callBack, UnityEngine.GameObject go, IsObjectOldFunc func)
 {
     if (callBack != null)
     {
         bool isOld = func != null && func();
         callBack(go, isOld);
     }
 }
Esempio n. 3
0
    public static GameObject GetOrCreate(string goName, GameObjectCallback callback = null)
    {
        var go = GameObject.Find(goName);

        if (!go)
        {
            go = new GameObject(goName);
            if (callback != null)
            {
                callback(go);
            }
        }
        return(go);
    }
Esempio n. 4
0
 public static void Blowback(Vector2 center, float radius,
                             float blowback_strength, bool blowback_is_velocity = false,
                             int layerMask = Physics2D.DefaultRaycastLayers,
                             GameObjectCallback onCollided = null,
                             HashSet <GameObject> excludes = null)
 {
     // Usage
     //
     // When `blowback_is_velocity` is false, the `blowback` parameter
     // will be added as a force. When it's true, the force required to reach
     // a velocity given by `blowback` based on collided objects mass will be
     // used.
     //
     // onCollided will be called on each collided object.
     if (onCollided == null)
     {
         onCollided = delegate { };
     }
     if (excludes == null)
     {
         excludes = new HashSet <GameObject>();
     }
     Collider2D[] collided = Physics2D.OverlapCircleAll(center, radius, layerMask);
     foreach (Collider2D collider in collided)
     {
         GameObject thing = collider.gameObject;
         if (excludes.Contains(thing))
         {
             continue;
         }
         Rigidbody2D rigidbody = thing.GetComponent <Rigidbody2D>();
         if (rigidbody != null)
         {
             onCollided(thing);
             Vector2 direction = (Vector2)rigidbody.transform.position - center;
             Vector2 knockback = direction * blowback_strength;
             if (blowback_is_velocity)
             {
                 knockback = knockback * rigidbody.mass;
             }
             rigidbody.AddForce(knockback, ForceMode2D.Impulse);
         }
     }
 }
Esempio n. 5
0
    public static void BlowbackPlayers(Vector2 center, float radius,
                                       float blowback_strength,
                                       bool blowback_is_velocity     = false,
                                       HashSet <GameObject> excludes = null,
                                       float?stunTime = null)
    {
        GameObjectCallback stunPlayer = (GameObject thing) =>
        {
            PlayerStateManager player = thing.GetComponent <PlayerStateManager>();
            PlayerStun         stun   = thing.GetComponent <PlayerStun>();
            if (player != null && stun != null)
            {
                player.AttemptStun(
                    () => stun.StartStun(null, stunTime), stun.StopStunned);
            }
        };

        Blowback(center, radius, blowback_strength, blowback_is_velocity,
                 LayerMask.GetMask("Player"), stunPlayer, excludes);
    }
 public void Reset()
 {
     executeOn = GameObjectCallback.None;
 }
Esempio n. 7
0
 public static void OnCallBack(GameObjectCallback callBack, UnityEngine.GameObject go, bool isOld)
 {
     callBack?.Invoke(go, isOld);
 }