void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        Oni.Contact[] contacts = e.contacts.Data;
        for (int i = 0; i < e.contacts.Count; ++i)
        {
            Oni.Contact c = contacts[i];
            // make sure this is an actual contact:
            if (c.distance < 0.01f)
            {
                // get the collider:
                Collider collider = ObiCollider.idToCollider[c.other] as Collider;

                if (collider != null)
                {
                    // make it blink:
                    Blinker blinker = collider.GetComponent <Blinker>();

                    if (blinker)
                    {
                        blinker.Blink();
                    }
                }
            }
        }
    }
Beispiel #2
0
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        collisionIndices.Clear();

        for (int i = 0; i < e.points.Length; ++i)
        {
            if (e.distances[i] <= 0.1f)
            {
                collisionIndices.Add(e.indices[i * 2]);

                GameObject pSystem = null;
                Vector3    pos     = ((ObiSolver)sender).renderablePositions[e.indices[i * 2]];
                if (!objects.TryGetValue(e.indices[i * 2], out pSystem))
                {
                    objects[e.indices[i * 2]] = GameObject.Instantiate(obj, pos, Quaternion.identity) as GameObject;
                }
                else
                {
                    pSystem.transform.position = pos;
                }
            }
        }

        var itemsToRemove = objects.Where(x => !collisionIndices.Contains(x.Key)).ToArray();

        foreach (var item in itemsToRemove)
        {
            GameObject.DestroyImmediate(item.Value);
            objects.Remove(item.Key);
        }
    }
Beispiel #3
0
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        if (solver.colliderGroup == null)
        {
            return;
        }

        foreach (Oni.Contact c in e.contacts)
        {
            // make sure this is an actual contact:
            if (c.distance < 0.01f)
            {
                // get the collider:
                Collider collider = solver.colliderGroup.colliders[c.other];

                // make it blink:
                Blinker blinker = collider.GetComponent <Blinker>();

                if (blinker)
                {
                    blinker.Blink();
                }
            }
        }
    }
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        for (int i = 0; i < e.contacts.Count; ++i)
        {
            if (e.contacts[i].distance < 0.001f)
            {
                Component collider;
                if (ObiCollider.idToCollider.TryGetValue(e.contacts[i].other, out collider))
                {
                    if (collider == killer)
                    {
                        ObiSolver.ParticleInActor pa = solver.particleToActor[e.contacts[i].particle];
                        ObiEmitter emitter           = pa.actor as ObiEmitter;

                        if (emitter != null)
                        {
                            emitter.life[pa.indexInActor] = 0;
                        }
                    }
                    if (hands.Contains(collider))
                    {
                        collider.gameObject.GetComponent <Touched_Me>().touchedwater = true;
                    }
                }
            }
        }
    }
Beispiel #5
0
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        var colliderWorld = ObiColliderWorld.GetInstance();

        for (int i = 0; i < e.contacts.Count; ++i)
        {
            if (e.contacts.Data[i].distance < 0.001f)
            {
                var col = colliderWorld.colliderHandles[e.contacts.Data[i].bodyB].owner;
                if (col != null)
                {
                    int k = e.contacts.Data[i].bodyA;

                    Vector4 userData = solver.userData[k];
                    if (col == hotCollider)
                    {
                        userData[0] = Mathf.Max(0.05f, userData[0] - heat * Time.fixedDeltaTime);
                        userData[1] = Mathf.Max(0.5f, userData[1] - heat * Time.fixedDeltaTime);
                    }
                    else if (col == coldCollider)
                    {
                        userData[0] = Mathf.Min(10, userData[0] + cooling * Time.fixedDeltaTime);
                        userData[1] = Mathf.Min(2, userData[1] + cooling * Time.fixedDeltaTime);
                    }
                    solver.userData[k] = userData;
                }
            }
        }
    }
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        var colliderWorld = ObiColliderWorld.GetInstance();

        Oni.Contact[] contacts = e.contacts.Data;
        for (int i = 0; i < e.contacts.Count; ++i)
        {
            Oni.Contact c = contacts[i];
            // make sure this is an actual contact:
            if (c.distance < 0.01f)
            {
                // get the collider:
                var col = colliderWorld.colliderHandles[c.other].owner;

                if (col != null)
                {
                    // make it blink:
                    Blinker blinker = col.GetComponent <Blinker>();

                    if (blinker)
                    {
                        blinker.Blink();
                    }
                }
            }
        }
    }
Beispiel #7
0
 void SolverOnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
 {
     foreach (Oni.Contact contact in e.contacts)
     {
         // this one is an actual collision:
         if (contact.distance < 0.01)
         {
             ActiveCollider            ac = new ActiveCollider();
             ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
             ac.actor    = pa.actor;
             ac.idxInAct = pa.indexInActor;
             ac.idxInSol = contact.particle;
             Component collider;
             if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
             {
                 Vector3 SolvColPos = new Vector3(contact.point[0], contact.point[1], contact.point[2]);
                 //print("Куб: Обнаружен контакт: " + contact.particle + " " + contact.point);
                 Vector3 WorldColPos = solver.gameObject.transform.TransformPoint(SolvColPos);
                 //marker.position = WorldColPos;
                 ac.pos = WorldColPos;
                 if (collider is Collider)
                 {
                     ac.col = collider as Collider;
                 }
             }
             _actCol.Add(ac);
         }
     }
 }
Beispiel #8
0
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        for (int i = 0; i < e.contacts.Count; ++i)
        {
            if (e.contacts.Data[i].distance < 0.001f)
            {
                Component collider;
                if (ObiCollider.idToCollider.TryGetValue(e.contacts.Data[i].other, out collider))
                {
                    int k = e.contacts.Data[i].particle;

                    Vector4 userData = solver.userData[k];
                    if (collider == hotCollider)
                    {
                        userData[0] = Mathf.Max(0.05f, userData[0] - heat * Time.fixedDeltaTime);
                        userData[1] = Mathf.Max(0.5f, userData[1] - heat * Time.fixedDeltaTime);
                    }
                    else if (collider == coldCollider)
                    {
                        userData[0] = Mathf.Min(10, userData[0] + cooling * Time.fixedDeltaTime);
                        userData[1] = Mathf.Min(2, userData[1] + cooling * Time.fixedDeltaTime);
                    }
                    solver.userData[k] = userData;
                }
            }
        }
    }
        void Solver_OnCollision(object sender, ObiSolver.ObiCollisionEventArgs args)
        {
            // here we access the internal backing array (Data) directly,
            // instead of using the accessor property. This slightly improves performance.
            // note: the backing array length is the lists' capacity, so we
            // need to use args.contacts.Count to get the actual number of contacts.

            // skip all contacts above the distance threshold by moving them to the end of the array:
            int filteredCount = FilterOutDistantContacts(args.contacts.Data, args.contacts.Count);

            // sort the remaining contacts by collider, then by actor:
            Array.Sort(args.contacts.Data, 0, filteredCount, comparer);

            // remove duplicates:
            filteredCount = RemoveDuplicates(args.contacts.Data, filteredCount);

            // zip trough the current and previous contact lists once, invoking events when appropiate.
            InvokeCallbacks(args.contacts.Data, filteredCount);

            // store current contact list/count for next frame.
            // could get better performance by double buffering instead of copying:
            if (filteredCount > prevData.Length)
            {
                Array.Resize(ref prevData, filteredCount);
            }
            Array.Copy(args.contacts.Data, prevData, filteredCount);

            prevCount = filteredCount;
        }
Beispiel #10
0
    private void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        // Calculate transform matrix from grabber to world space (Note: if using local space simulation, postmultiply with solver.transform.localToWorldMatrix)
        solver2Grabber = transform.worldToLocalMatrix * solver.transform.localToWorldMatrix;

        // and its inverse:
        grabber2Solver = solver2Grabber.inverse;

        collisionEvent = e;
    }
Beispiel #11
0
 void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
 {
     for (int i = 0; i < e.points.Length; ++i)
     {
         if (e.distances[i] <= 0.001f)
         {
             //Debug.DrawRay(e.points[i],e.normals[i],Color.white);
             Debug.DrawRay(e.points[i], e.normals[i] * e.normalImpulses[i] * 10, Color.red);
             Debug.DrawRay(e.points[i], e.normals[i] * e.tangentImpulses[i] * 10, Color.blue);
             //Debug.DrawRay(e.points[i],e.stickImpulses[i],Color.green);
         }
     }
 }
Beispiel #12
0
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                Component collider;
                if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
                {
                    if (collider.gameObject.GetComponent <CanBoil>())
                    {
                        canBoilScript = collider.gameObject.GetComponent <CanBoil>();
                        int index = Int32.Parse(contact.particle.ToString());
                        if (!collidedParticles.Contains(index))
                        {
                            collidedParticles.Add(index);
                        }
                    }

                    else if (collider.gameObject.GetComponentInParent <CanFry>())
                    {
                        canFryScript = collider.gameObject.GetComponentInParent <CanFry>();
                        int index = Int32.Parse(contact.particle.ToString());
                        if (!collidedParticles.Contains(index))
                        {
                            collidedParticles.Add(index);
                        }
                    }

                    if (!collidedWithBowl && collider.transform.parent)
                    {
                        if (!collidedWithBowl && collider.transform.parent.transform.parent)
                        {
                            if (!collidedWithBowl && collider.transform.parent.transform.parent.gameObject.GetComponent <CanMixedIn>() != null)
                            {
                                collidedWithBowl = true;
                                List <Obi.ObiEmitter> emitters = collider.transform.parent.transform.parent.gameObject.GetComponent <CanMixedIn>().emitters;
                                emitters.Add(gameObject.GetComponent <ObiEmitter>());
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #13
0
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        foreach (Oni.Contact c in e.contacts)
        {
            // make sure this is an actual contact:
            if (c.distance < 0.01f)
            {
                // get the collider:
                Collider collider = ObiCollider.idToCollider[c.other] as Collider;

                // make it blink:
                Blinker blinker = collider.GetComponent <Blinker>();

                if (blinker)
                {
                    blinker.Blink();
                }
            }
        }
    }
    public void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();

        foreach (Oni.Contact contact in e.contacts)
        {
            ObiColliderBase collider = world.colliderHandles[contact.other].owner;
            if (collider != null)
            {
                if (collider.tag != "Ground" || collider.tag != "Walls")
                {
                    if (contact.distance < 0.01)
                    {
                        ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
                        Slime s = pa.actor.gameObject.GetComponent <Slime> ();
                        switch (collider.tag)
                        {
                        case "Food":
                            for (var f = 0; f < s.food.Count; f++)
                            {
                                if (s.food[f] == collider.transform)
                                {
                                    if (s.testingFood[f])
                                    {
                                        s.testingFood[f] = false;
                                        s.AddReward(1f);
                                        break;
                                    }
                                }
                            }
                            break;

                        case "Enemy":
                            s.Death();
                            break;
                        }
                    }
                }
            }
        }
    }
Beispiel #15
0
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        HashSet <int> currentParticles = new HashSet <int>();

        for (int i = 0; i < e.contacts.Count; ++i)
        {
            if (e.contacts.Data[i].distance < 0.001f)
            {
                /*Component collider;
                 * if (ObiCollider2D.idToCollider.TryGetValue(e.contacts.Data[i].other,out collider)){
                 *
                 *  if (collider == targetCollider)
                 *      currentParticles.Add(e.contacts.Data[i].particle);
                 *
                 * }*/
            }
        }

        particles.ExceptWith(currentParticles);
        counter  += particles.Count;
        particles = currentParticles; Debug.Log(counter);
    }
    private void HandleSolverCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        if (e == null || e.contacts == null || !rightControllerInfo.grabbingEnabled && !leftControllerInfo.grabbingEnabled)
        {
            return;
        }

        // Reset every frame
        leftControllerInfo.Clear();
        rightControllerInfo.Clear();

        for (int i = 0; i < e.contacts.Length; ++i)
        {
            var contact       = e.contacts[i];
            var pia           = solver.particleToActor[e.contacts[i].particle];
            var actor         = pia.actor;
            var particleIndex = pia.indexInActor;

            // make sure this is an actual contact
            if (contact.distance < 0.01f)
            {
                Collider collider = ObiColliderBase.idToCollider[contact.other] as Collider;

                if (ReferenceEquals(collider, leftControllerInfo.collider))
                {
                    leftControllerInfo.isTouchingParticle = true;
                    leftControllerInfo.touchingParticle   = particleIndex;
                    leftControllerInfo.currentInteraction = actor.gameObject.GetComponent <VRTK_ObiRopeInteraction>();
                }
                else if (ReferenceEquals(collider, rightControllerInfo.collider))
                {
                    rightControllerInfo.isTouchingParticle = true;
                    rightControllerInfo.touchingParticle   = particleIndex;
                    rightControllerInfo.currentInteraction = actor.gameObject.GetComponent <VRTK_ObiRopeInteraction>();
                }
            }
        }
    }
Beispiel #17
0
    void Detector(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        foreach (Oni.Contact contact in e.contacts)
        {
            if (contact.distance < 0.01)
            {
                Component collider;
                if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
                {
                    if (collider.tag == killerTag)
                    {
                        ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
                        ObiEmitter emitter           = pa.actor as ObiEmitter;

                        // destory particle
                        emitter.life[pa.indexInActor] = 0;

                        if (emitter != null)
                        {
                            Transform sirupObject = collider.transform.parent.Find(sirupObjectName);
                            if (sirupObject != null)
                            {
                                if (!emitter.transform.parent.Equals(sirupObject.parent))
                                {
                                    // update cup
                                    TheSirup cupScript = sirupObject.GetComponent <TheSirup>();
                                    Color    color     = emitter.transform.GetComponent <ObiParticleRenderer>().particleColor;
                                    cupScript.addParticle(color);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        frame = e;
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                Component collider;
                if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
                {
                    // do something with the collider.

                    // call collision report function
                    PatternPuzzlePointChecker checker = collider.GetComponent <PatternPuzzlePointChecker>();

                    if (checker)
                    {
                        checker.Collide();
                    }
                }
            }
        }
    }
    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                Component component;
                if (ObiCollider.idToCollider.TryGetValue(contact.other, out component))
                {
                    ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
                    ObiEmitter emitter           = pa.actor as ObiEmitter;

                    if (emitter != null && emitter.life[pa.indexInActor] > 0f)
                    {
                        WithLiquid wl = component.gameObject.GetComponent <WithLiquid>();
                        if (wl)
                        {
                            if (wl.Fill(WithLiquid.volumePerParticle))
                            {
                                emitter.life[pa.indexInActor] = 0;
                            }
                        }
                        else
                        {
                            Effect effect = pa.actor.GetComponent <Effect>();
                            if (effect && effect.AddEffectTo(component.gameObject))
                            {
                                emitter.life[pa.indexInActor] = 0;
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #20
0
 private void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
 {
     collisionEvents[(ObiSolver)sender] = e;
 }
Beispiel #21
0
 void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
 {
     frame = e;
 }