コード例 #1
0
 /// <summary>
 /// add an aglomera to the list (called on the OnEnable of the aglomera)
 /// </summary>
 /// <param name="aglomera"></param>
 public void AddAglomera(Aglomera aglomera)
 {
     Debug.Log("called both time ?");
     if (!AllAglomera.Contains(aglomera))
     {
         AllAglomera.AddIfNotContain(aglomera);
     }
 }
コード例 #2
0
ファイル: Aglomera.cs プロジェクト: jamsforfun/DribbleMaster
 /// <summary>
 /// combine this aglomera with us !
 /// </summary>
 /// <param name="other"></param>
 private void CombineThisAglomeraWithUs(Aglomera other)
 {
     Debug.Log("contact between 2 aglomera !");
     for (int i = 0; i < other._allBoxManager.Count; i++)
     {
         AddThisBoxToOurAglomera(other._allBoxManager[i].GetThisCollisionObject());
     }
     other.Kill();
 }
コード例 #3
0
    /// <summary>
    /// called when a box is colliding with another box,
    /// and no one is pressing A
    /// </summary>
    /// <returns></returns>
    public Aglomera CreateAglomera(List <OnCollisionObject> allbox)
    {
        GameObject newAglomeraObject = Instantiate(_aglomeraPrefabs, transform);
        Aglomera   newAglomera       = newAglomeraObject.GetComponent <Aglomera>();

        newAglomera.Init(this, _countPlayerPushingBox);
        newAglomera.AddBoxToOurAglomera(allbox);

        AddAglomera(newAglomera);

        return(newAglomera);
    }
コード例 #4
0
ファイル: Aglomera.cs プロジェクト: jamsforfun/DribbleMaster
    /// <summary>
    /// try to have 2 aglomera stick with each other
    /// </summary>
    private void CollideWithOtherBox()
    {
        if (_onCollisionObject.ListRigidBodyBox.Count == 0)
        {
            return;
        }
        Aglomera other = IsOtherInAglomera();

        if (other == null)
        {
            return;
        }
        CombineThisAglomeraWithUs(other);
    }
コード例 #5
0
    public int GetNumberPlayerPushingMyAglomera(OnCollisionObject aglomera)
    {
        Aglomera aglo = aglomera.Aglomera;

        aglo.AllPlayerColliding.Clear();

        for (int i = 0; i < aglomera.ListRigidBodyPlayer.Count; i++)
        {
            aglo.AllPlayerColliding.AddIfNotContain(aglomera.ListRigidBodyPlayer[i]);
        }

        TryToAddOtherToAglomera(aglo);

        return(aglo.AllPlayerColliding.Count);
    }
コード例 #6
0
 /// <summary>
 /// Try to add the one pushing to other player...
 /// </summary>
 private void TryToAddOtherToAglomera(Aglomera aglo)
 {
     //here do another pass...
     for (int i = 0; i < aglo.AllPlayerColliding.Count; i++)
     {
         for (int j = 0; j < aglo.AllPlayerColliding[i].ListRigidBody.Count; j++)
         {
             if (aglo.AllPlayerColliding[i].ListRigidBody[j].TypeRigidBodyMe == OnCollisionObject.TypeObject.PLAYER &&
                 !aglo.AllPlayerColliding.Contains(aglo.AllPlayerColliding[i].ListRigidBody[j]))
             {
                 aglo.AllPlayerColliding.AddIfNotContain(aglo.AllPlayerColliding[i].ListRigidBody[j]);
                 TryToAddOtherToAglomera(aglo);
             }
         }
     }
 }
コード例 #7
0
    /// <summary>
    /// call here when another Box is collider with us
    /// </summary>
    /// <param name="other"></param>
    public void CollideWithOtherBox()
    {
        //no collision with box
        if (_onCollisionObject.ListRigidBodyBox.Count == 0)
        {
            return;
        }
        ExtLog.LogList(_onCollisionObject.ListRigidBodyBox);

        Aglomera other = IsOtherInAglomera();

        //collision with box
        if (AglomeraRef == null && other == null)
        {
            if (IsPressingA || IsOtherBoxIsPressingA())
            {
                //here do nothing ! ye pressing action !
                return;
            }

            Debug.Log("create an aglometa !");
            AglomeraRef = _aglomeraManager.CreateAglomera(_onCollisionObject.ListRigidBodyBox);
        }
        else
        {
            if (AglomeraRef == null)
            {
                //here we are NOT in an aglorema, but other does

                if (IsPressingA)
                {
                    //here do nothing ! ye pressing action !
                    return;
                }

                AglomeraRef = other;
                AglomeraRef.AddThisBoxToOurAglomera(_onCollisionObject);
            }
            else
            {
                //here we are inside the aglomera, try to add all other box in collision

                ExtLog.LogList(_onCollisionObject.ListRigidBodyBox);
                AglomeraRef.AddBoxToOurAglomera(_onCollisionObject.ListRigidBodyBox);
            }
        }
    }
コード例 #8
0
    /// <summary>
    /// unplug from aglomera
    /// </summary>
    public void UnplugFromAglomera(Rigidbody2D settingsRb)
    {
        Debug.Log("unplug from aglomera");
        _onCollisionObject.enabled = true;
        AglomeraRef = null;
        _onCollisionObject.ListRigidBody.Clear();
        _onCollisionObject.ListRigidBodyBox.Clear();
        _onCollisionObject.ListRigidBodyPlayer.Clear();

        RbBox                        = gameObject.GetOrAddComponent <Rigidbody2D>();
        RbBox.mass                   = 1f;
        RbBox.bodyType               = RigidbodyType2D.Dynamic;
        RbBox.simulated              = true;
        RbBox.drag                   = 10f;
        RbBox.angularDrag            = 1f;
        RbBox.gravityScale           = 0f;
        RbBox.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
        RbBox.sleepMode              = RigidbodySleepMode2D.StartAwake;
        RbBox.interpolation          = RigidbodyInterpolation2D.None;
        RbBox.constraints            = RigidbodyConstraints2D.FreezeRotation;
    }