public void OnEncoded(System.IntPtr data, int size)
        {
            var width  = encoder.setting.width;
            var height = encoder.setting.height;

            client.Send("/uDD/ScreenSize", width, height);

            fragmenter_.Fragment(data, (uint)size);
            var n = fragmenter_.GetFragmentCount();

            for (uint i = 0; i < n; ++i)
            {
                var    fragmentData = fragmenter_.GetFragmentData(i);
                var    fragmentSize = (int)fragmenter_.GetFragmentSize(i);
                byte[] buf          = new byte[fragmentSize];
                Marshal.Copy(fragmentData, buf, 0, fragmentSize);
                client.Send("/uDD/Fragment", buf);
            }
        }
    private void ProcessDestroyable(List <DestroyableGameObject> destroyable, List <DestroyableGameObject> processing, bool isMisc)
    {
        if (Random.Range(0.0f, 1.0f) < 0.25f && destroyable.Count > 0)
        {
            int index = Random.Range(0, destroyable.Count - 1);
            DestroyableGameObject toDestroy = destroyable[index];

            if (toDestroy.state == DestroyableGameObject.StateType.decaying)
            {
                Debug.Log($"Fragmenting {toDestroy.gameObject.name}");
                Fragmenter.Stats fs = new Fragmenter.Stats();
                toDestroy.fragmenterStat = fs;
                toDestroy.state          = DestroyableGameObject.StateType.fragmenting;

                destroyable.RemoveAt(index);
                processing.Add(toDestroy);

                StartCoroutine(Fragmenter.Fragment(toDestroy.gameObject, fs, isMisc));
            }
            else if (toDestroy.state == DestroyableGameObject.StateType.fragmented)
            {
                Debug.Log($"Exploding {toDestroy.gameObject.name}");
                Fragmenter.Stats fs = new Fragmenter.Stats();
                toDestroy.fragmenterStat = fs;
                toDestroy.state          = DestroyableGameObject.StateType.exploding;

                destroyable.RemoveAt(index);
                processing.Add(toDestroy);

                StartCoroutine(Fragmenter.Explode(
                                   CalculateExplosionPoint(toDestroy.gameObject),
                                   isMisc ? Constants.MiscExplosionRadius : Constants.BuildExplosionRadius,
                                   isMisc ? Constants.MiscExplosionForce  : Constants.BuildExplosionForce,
                                   fs)
                               );
            }
            else
            {
                Debug.Log("Oops");
            }
        }
    }
Beispiel #3
0
    void Update()
    {
        // Check if user clicked on a mesh with active collider
        if (Input.GetMouseButtonDown(0) &&
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, Mathf.Infinity) &&
            !runningFragmentations.ContainsKey(hit) && !runningExplosions.ContainsKey(hit))
        {
            if (!Fragmenter.IsFragmented(hit.transform.gameObject))
            {
                Fragmenter.Stats fs = new Fragmenter.Stats();
                runningFragmentations.Add(hit, fs);
                Debug.Log($"Fragmentation Start Time: {Time.timeSinceLevelLoad}");
                StartCoroutine(Fragmenter.Fragment(hit.transform.gameObject, fs));
            }
            else
            {
                Fragmenter.Stats fs = new Fragmenter.Stats();
                runningExplosions.Add(hit, fs);
                StartCoroutine(Fragmenter.Explode(hit.point, radius, force, fs));
            }
        }

        // When fragmentation finishes, create an explosion where user clicked
        List <RaycastHit> toRemove = new List <RaycastHit>();

        foreach (KeyValuePair <RaycastHit, Fragmenter.Stats> entry in runningFragmentations)
        {
            if (entry.Value.isDone)
            {
                Debug.Log($"Fragmentation Total Time: {entry.Value.totalTime / 1000.0f}");
                toRemove.Add(entry.Key);
            }
        }
        foreach (RaycastHit rhit in toRemove)
        {
            Fragmenter.Stats fs = new Fragmenter.Stats();
            runningFragmentations.Remove(rhit);
            runningExplosions.Add(rhit, fs);
            StartCoroutine(Fragmenter.Explode(rhit.point, radius, force, fs));
        }


        toRemove.Clear();
        foreach (KeyValuePair <RaycastHit, Fragmenter.Stats> entry in runningExplosions)
        {
            if (entry.Value.isDone)
            {
                toRemove.Add(entry.Key);
            }
        }
        foreach (RaycastHit rhit in toRemove)
        {
            runningExplosions.Remove(rhit);
        }

        /*
         * for (int i = runningFragmentations.Count - 1; i >= 0; --i)
         * {
         *  (Fragmenter.Stats stats, RaycastHit rhit) = runningFragmentations[i];
         *
         *  if (stats.isDone)
         *  {
         *      StartCoroutine(Fragmenter.Explode(rhit.point, radius, force, null));
         *      runningFragmentations.RemoveAt(i);
         *  }
         * }
         */
    }