Example #1
0
    void OnFreeChunkCollision(FracturedChunk.CollisionInfo info)
    {
        // We can cancel the collision processing here
        info.bCancelCollisionEvent = false;

        // Simply increase a counter for each collision
        nChunkCollisions++;
    }
Example #2
0
    void OnChunkDetach(FracturedChunk.CollisionInfo info)
    {
        // We can cancel the collision processing here
        info.bCancelCollisionEvent = false;

        // Simply increase a counter for each chunk detached
        nChunksDetached++;
    }
    public void NotifyDetachChunkCollision(FracturedChunk.CollisionInfo collisionInfo)
    {
        // This one will be called internally from FracturedChunk from within a collision

        if (EventDetachCollisionCallGameObject != null && EventDetachCollisionCallMethod.Length > 0)
        {
            EventDetachCollisionCallGameObject.SendMessage(EventDetachCollisionCallMethod, collisionInfo);
        }

        if (collisionInfo.bCancelCollisionEvent == false)
        {
            NotifyDetachChunkCollision(collisionInfo.collisionPoint, collisionInfo.bIsMain);
        }
    }
    public void NotifyFreeChunkCollision(FracturedChunk.CollisionInfo collisionInfo)
    {
        if (EventDetachedCollisionCallGameObject != null && EventDetachedCollisionCallMethod.Length > 0)
        {
            EventDetachedCollisionCallGameObject.SendMessage(EventDetachedCollisionCallMethod, collisionInfo);
        }

        if (collisionInfo.bCancelCollisionEvent == false)
        {
            if (EventDetachedSoundArray.Length > 0)
            {
                int nFreeSound = -1;

                for (int nSound = 0; nSound < m_afFreeChunkSoundTimers.Length; nSound++)
                {
                    if (m_afFreeChunkSoundTimers[nSound] <= 0.0f)
                    {
                        nFreeSound = nSound;
                        break;
                    }
                }

                if (nFreeSound != -1)
                {
                    AudioClip clip = EventDetachedSoundArray[UnityEngine.Random.Range(0, EventDetachedSoundArray.Length)];

                    if (clip != null)
                    {
                        AudioSource.PlayClipAtPoint(clip, collisionInfo.collisionPoint);
                    }

                    m_afFreeChunkSoundTimers[nFreeSound] = clip.length;
                }
            }

            if (EventDetachedPrefabsArray.Length > 0)
            {
                FracturedObject.PrefabInfo prefab = EventDetachedPrefabsArray[UnityEngine.Random.Range(0, EventDetachedPrefabsArray.Length)];

                if (prefab != null)
                {
                    int nFreePrefab = -1;

                    for (int nPrefab = 0; nPrefab < m_afFreeChunkPrefabTimers.Length; nPrefab++)
                    {
                        if (m_afFreeChunkPrefabTimers[nPrefab] <= 0.0f)
                        {
                            nFreePrefab = nPrefab;
                            break;
                        }
                    }

                    if (nFreePrefab != -1)
                    {
                        GameObject newGameObject = Instantiate(prefab.GameObject, collisionInfo.collisionPoint, prefab.GameObject.transform.rotation) as GameObject;

                        if (Mathf.Approximately(prefab.MinLifeTime, 0.0f) == false || Mathf.Approximately(prefab.MaxLifeTime, 0.0f) == false)
                        {
                            DieTimer timer = newGameObject.AddComponent <DieTimer>();
                            timer.SecondsToDie = UnityEngine.Random.Range(prefab.MinLifeTime, prefab.MaxLifeTime);

                            m_afFreeChunkPrefabTimers[nFreePrefab] = timer.SecondsToDie;
                        }
                        else
                        {
                            m_afFreeChunkPrefabTimers[nFreePrefab] = float.MaxValue;
                        }
                    }
                }
            }
        }
    }