Exemplo n.º 1
0
        public int Hash(Vector3 p)
        {
            for (int i = 0; i < count; i++)
            {
                var item = buckets[i];

                float diffX  = p.x - item.x;
                float diffY  = p.y - item.y;
                float diffZ  = p.z - item.z;
                float sqrMag = diffX * diffX + diffY * diffY + diffZ * diffZ;

                if (sqrMag < bucketSize2)
                {
                    return(i);
                }
            }

            if (count >= buckets.Length)
            {
                ExploderUtils.Log("Hash out of range: " + count + " " + buckets.Length);
                return(count - 1);
            }

            buckets[count++] = p;
            return(count - 1);
        }
Exemplo n.º 2
0
 private void ExplodeObject(GameObject gameObject)
 {
     ExploderUtils.SetActive(Exploder.gameObject, true);
     Exploder.transform.position = ExploderUtils.GetCentroid(gameObject);
     Exploder.Radius             = 1.0f;
     Exploder.ExplodeRadius();
 }
 private void ExplodeObject(GameObject gameObject)
 {
     ExploderUtils.SetActive(((Component)this.Exploder).get_gameObject(), true);
     ((Component)this.Exploder).get_transform().set_position(ExploderUtils.GetCentroid(gameObject));
     this.Exploder.Radius = 1f;
     this.Exploder.ExplodeRadius();
 }
Exemplo n.º 4
0
    private void OnExplode(float timeMS, ExploderObject.ExplosionState state)
    {
        if (state == ExploderObject.ExplosionState.ExplosionStarted)
        {
            // deactivate the grenade game object
            ExploderUtils.SetVisible(gameObject, false);

            // play explosion sound
            SourceExplosion.PlayOneShot(ExplosionSound);

            Flash.gameObject.transform.position  = gameObject.transform.position;
            Flash.gameObject.transform.position += Vector3.up;

            // turn on flash light for 5 frames
            flashing = 10;

            ExplosionEffect.gameObject.transform.position = gameObject.transform.position;
            // ExplosionEffect.Emit(1);

            ExploderUtils.Log("OnExplode started");
        }

        if (state == ExploderObject.ExplosionState.ExplosionFinished)
        {
            ExplodeFinished     = true;
            explosionInProgress = false;

            ExploderUtils.Log("OnExplode finished");
        }
    }
 private void Update()
 {
     if (Input.GetKeyDown((KeyCode)103) && !this.exploding)
     {
         this.throwTimer = 0.4f;
         this.Source.PlayOneShot(this.Throw);
         this.explodeTimer = 2f;
         this.exploding    = true;
         this.Grenade.Throw();
         ExploderUtils.SetVisible(((Component)this).get_gameObject(), false);
     }
     this.throwTimer -= Time.get_deltaTime();
     if ((double)this.throwTimer < 0.0)
     {
         this.throwTimer = float.MaxValue;
         ExploderUtils.SetVisible(((Component)this.Grenade).get_gameObject(), true);
         ExploderUtils.SetActive(((Component)this.Grenade).get_gameObject(), true);
         ((Component)this.Grenade).get_transform().set_position(((Component)this).get_gameObject().get_transform().get_position());
         ((Rigidbody)((Component)this.Grenade).GetComponent <Rigidbody>()).set_velocity(Vector3.op_Multiply(((Component)this.MainCamera).get_transform().get_forward(), 20f));
     }
     this.explodeTimer -= Time.get_deltaTime();
     if ((double)this.explodeTimer < 0.0)
     {
         this.Grenade.Explode();
         this.explodeTimer = float.MaxValue;
     }
     if (!this.Grenade.ExplodeFinished)
     {
         return;
     }
     this.exploding = false;
     ExploderUtils.SetVisible(((Component)this).get_gameObject(), true);
 }
Exemplo n.º 6
0
        private void OnGUI()
        {
            if (GUI.Button(new Rect(10, 10, 100, 30), "Explode!"))
            {
                if (Exploder)
                {
                    Exploder.Explode();
                }
            }

            if (GUI.Button(new Rect(130, 10, 100, 30), "Reset"))
            {
                // activate exploder
                ExploderUtils.SetActive(Exploder.gameObject, true);

                if (!Exploder.DestroyOriginalObject)
                {
                    foreach (var destroyableObject in DestroyableObjects)
                    {
                        ExploderUtils.SetActiveRecursively(destroyableObject, true);
                    }
                    ExploderUtils.SetActive(Exploder.gameObject, true);
                }
            }
        }
Exemplo n.º 7
0
 void Start()
 {
     camera = Camera.main;
     ExploderUtils.SetActive(CrosshairGun.gameObject, true);
     ExploderUtils.SetActive(CrosshairHand.gameObject, true);
     ExploderUtils.SetActive(PanelText.gameObject, true);
 }
Exemplo n.º 8
0
        public void Remove(int key)
        {
            ExploderUtils.Assert(key < Size, "Key index out of range! " + key + " maxSize: " + Size);
            ExploderUtils.Assert(dictionary[key].valid == true, "Key does not exist!");
            dictionary[key].valid = false;

            Count--;
        }
Exemplo n.º 9
0
    private int GetLevel(float distance, float radius)
    {
        ExploderUtils.Assert(distance >= 0.0f, "");
        ExploderUtils.Assert(radius >= 0.0f, "");
//        ExploderUtils.Assert(distance <= radius*radius, "distance: " + distance + " radius: " + radius);

        return((int)distance / 2 + 1);
    }
Exemplo n.º 10
0
 public T this[int key]
 {
     get
     {
         ExploderUtils.Assert(key < size, "Key index out of range! " + key + " maxSize: " + size);
         return(array[key]);
     }
 }
Exemplo n.º 11
0
    void Update()
    {
        if (launchTimeout < 0.0f)
        {
            if (!launch)
            {
                launch           = true;
                transform.parent = null;

                SmokeTrail.emit = true;

                RocketLight.intensity = 2;

                RaycastHit hit;
                direction.origin = direction.origin + direction.direction * 2.0f;
                if (Physics.Raycast(direction, out hit, Mathf.Infinity))
                {
                    shotPos        = gameObject.transform.position;
                    targetDistance = (gameObject.transform.position - hit.point).sqrMagnitude;
                }
                else
                {
                    targetDistance = 100 * 100;
                }
            }

            gameObject.transform.position += direction.direction * RocketVelocity * Time.timeScale;

            RocketLight.transform.position = gameObject.transform.position;

            if ((shotPos - gameObject.transform.position).sqrMagnitude > targetDistance)
            {
                Source.PlayOneShot(Explosion);

                HitCallback(gameObject.transform.position);

                launchTimeout = float.MaxValue;
                launch        = false;

                SmokeTrail.emit = false;
                ExplosionEffect.gameObject.transform.position = gameObject.transform.position;
                ExplosionSmoke.gameObject.transform.position  = gameObject.transform.position;
                ExplosionEffect.Emit(1);
                ExplosionSmoke.Emit(1);

                ExploderUtils.SetVisible(gameObject, false);

                RocketLight.intensity = 0;
            }
        }

        launchTimeout -= Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.H))
        {
            HitCallback(gameObject.transform.position);
        }
    }
Exemplo n.º 12
0
    /// <summary>
    /// on activate this game object
    /// </summary>
    public void OnActivate()
    {
        ExploderUtils.SetActive(RocketStatic.gameObject, true);

        if (parent)
        {
            ExploderUtils.SetVisible(gameObject, false);
        }
    }
Exemplo n.º 13
0
 public void OnActivate()
 {
     ExploderUtils.SetActive(this.RocketStatic.get_gameObject(), true);
     if (!Object.op_Implicit((Object)this.parent))
     {
         return;
     }
     ExploderUtils.SetVisible(((Component)this).get_gameObject(), false);
 }
Exemplo n.º 14
0
        /// <summary>
        /// c-tor
        /// </summary>
        /// <param name="pnts">points of the polygon</param>
        public Polygon(Vector2[] pnts)
        {
            ExploderUtils.Assert(pnts.Length >= 3, "Invalid polygon!");

            Points = pnts;
            Area   = GetArea();

            holes = new List <Polygon>();
        }
Exemplo n.º 15
0
    /// <summary>
    /// explode cracked objects
    /// Use this method in combination with Crack()
    /// Purpose of this method is to get higher performance of explosion, Crack() will
    /// calculate the explosion and prepare all fragments. Calling ExplodeCracked() will
    /// then start the explosion (flying fragments...) immediately
    /// </summary>
    public void ExplodeCracked(OnExplosion callback)
    {
        ExploderUtils.Assert(crack, "You must call Crack() first!");

        if (cracked)
        {
            PostCrackExplode(callback);
            crack = false;
        }
    }
Exemplo n.º 16
0
        public void Add(int key, T data)
        {
            ExploderUtils.Assert(key < Size, "Key index out of range! " + key + " maxSize: " + Size);
            ExploderUtils.Assert(dictionary[key].valid == false, "Key already exists!");

            dictionary[key].valid = true;
            dictionary[key].data  = data;

            Count++;
        }
Exemplo n.º 17
0
        public void Initialize(int newSize)
        {
            if (newSize > size)
            {
                ExploderUtils.Log("Initialize, resising: " + size + " => " + newSize);
                array = new T[newSize];
                size  = newSize;
            }

            Clear();
        }
Exemplo n.º 18
0
        public override void Use()
        {
            base.Use();

            ExploderUtils.ClearLog();

            foreach (var o in objectList)
            {
                ExploderUtils.SetActiveRecursively(o, true);
                ExploderUtils.SetVisible(o, true);
            }
        }
Exemplo n.º 19
0
    /// <summary>
    /// crack will calculate fragments and prepare object for explosion
    /// Use this method in combination with ExplodeCracked()
    /// Purpose of this method is to get higher performance of explosion, Crack() will
    /// calculate the explosion and prepare all fragments. Calling ExplodeCracked() will
    /// then start the explosion (flying fragments...) immediately
    /// </summary>
    public void Crack(OnCracked callback)
    {
        ExploderUtils.Assert(!crack, "Another crack in progress!");

        if (!crack)
        {
            CrackedCallback = callback;
            crack           = true;
            cracked         = false;
            Explode(null);
        }
    }
Exemplo n.º 20
0
 public void Launch(Ray ray)
 {
     this.direction = ray;
     this.Source.PlayOneShot(this.GunShot);
     this.launchTimeout = 0.3f;
     this.launch        = false;
     ExploderUtils.SetActive(this.RocketStatic.get_gameObject(), false);
     ExploderUtils.SetVisible(((Component)this).get_gameObject(), true);
     ((Component)this).get_gameObject().get_transform().set_parent(this.parent);
     ((Component)this).get_gameObject().get_transform().set_localPosition(this.RocketStatic.get_gameObject().get_transform().get_localPosition());
     ((Component)this).get_gameObject().get_transform().set_localRotation(this.RocketStatic.get_gameObject().get_transform().get_localRotation());
     ((Component)this).get_gameObject().get_transform().set_localScale(this.RocketStatic.get_gameObject().get_transform().get_localScale());
 }
Exemplo n.º 21
0
 public override void Use()
 {
     base.Use();
     ExploderUtils.ClearLog();
     using (List <GameObject> .Enumerator enumerator = this.objectList.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             GameObject current = enumerator.Current;
             ExploderUtils.SetActiveRecursively(current, true);
             ExploderUtils.SetVisible(current, true);
         }
     }
 }
Exemplo n.º 22
0
    void Update()
    {
                #if UNITY_EDITOR
        if (Input.GetMouseButtonDown(2) && !exploding)
                #else
        if (Input.touchCount == 1 && Input.touches[0].phase == TouchPhase.Moved && !exploding)
                #endif

        {
            throwTimer = 0.4f;

            Source.PlayOneShot(Throw);

            explodeTimer = 2.0f;

            exploding = true;

            Grenade.Throw();

            ExploderUtils.SetVisible(gameObject, false);
        }

        throwTimer -= Time.deltaTime;

        if (throwTimer < 0.0f)
        {
            throwTimer = float.MaxValue;

            ExploderUtils.SetVisible(Grenade.gameObject, true);
            ExploderUtils.SetActive(Grenade.gameObject, true);

            Grenade.transform.position = gameObject.transform.position;

            Grenade.GetComponent <Rigidbody>().velocity = MainCamera.transform.forward * 10;
        }

        explodeTimer -= Time.deltaTime;

        if (explodeTimer < 0.0f)
        {
            Grenade.Explode();
            explodeTimer = float.MaxValue;
        }

        if (Grenade.ExplodeFinished)
        {
            exploding = false;
            ExploderUtils.SetVisible(gameObject, true);
        }
    }
Exemplo n.º 23
0
    public void Launch(Ray ray)
    {
        direction = ray;
        Source.PlayOneShot(GunShot);
        launchTimeout = 0.3f;
        launch        = false;

        ExploderUtils.SetActive(RocketStatic.gameObject, false);
        ExploderUtils.SetVisible(gameObject, true);
        gameObject.transform.parent        = parent;
        gameObject.transform.localPosition = RocketStatic.gameObject.transform.localPosition;
        gameObject.transform.localRotation = RocketStatic.gameObject.transform.localRotation;
        gameObject.transform.localScale    = RocketStatic.gameObject.transform.localScale;
    }
Exemplo n.º 24
0
        public T this[int key]
        {
            get
            {
                ExploderUtils.Assert(key < Size, "Key index out of range! " + key + " maxSize: " + Size);
                ExploderUtils.Assert(dictionary[key].valid == true, "Key does not exist!");
                return(dictionary[key].data);
            }

            set
            {
                ExploderUtils.Assert(dictionary[key].valid == true, "Key does not exist!");
                dictionary[key].data = value;
            }
        }
Exemplo n.º 25
0
        public T GetFirstValue()
        {
            for (int i = 0; i < Size; i++)
            {
                var item = dictionary[i];

                if (item.valid)
                {
                    return(item.data);
                }
            }

            ExploderUtils.Assert(false, "No valid key!");
            return(default(T));
        }
Exemplo n.º 26
0
        public bool TryGetValue(int key, out T value)
        {
            ExploderUtils.Assert(key < Size, "Key index out of range! " + key + " maxSize: " + Size);

            var item = dictionary[key];

            if (item.valid)
            {
                value = item.data;
                return(true);
            }

            value = default(T);
            return(false);
        }
Exemplo n.º 27
0
    void Start()
    {
        parent = transform.parent;

        launchTimeout = float.MaxValue;

        SmokeTrail.emit      = false;
        ExplosionEffect.emit = false;
        ExplosionSmoke.emit  = false;

        ExploderUtils.SetActive(SmokeTrail.gameObject, true);
        ExploderUtils.SetActive(ExplosionEffect.gameObject, true);
        ExploderUtils.SetActive(ExplosionSmoke.gameObject, true);
        ExploderUtils.SetActive(RocketStatic.gameObject, false);
    }
Exemplo n.º 28
0
 private void OnGUI()
 {
     if (GUI.Button(new Rect(10f, 10f, 100f, 30f), "Reset") && !this.Exploder.DestroyOriginalObject)
     {
         foreach (GameObject destroyableObject in this.DestroyableObjects)
         {
             ExploderUtils.SetActiveRecursively(destroyableObject, true);
         }
         ExploderUtils.SetActive(((Component)this.Exploder).get_gameObject(), true);
     }
     if (!GUI.Button(new Rect(10f, 50f, 100f, 30f), "NextScene"))
     {
         return;
     }
     SceneManager.LoadScene(0);
 }
Exemplo n.º 29
0
 private void Update()
 {
     if (Input.GetKeyDown((KeyCode)49))
     {
         ExploderUtils.SetActiveRecursively(this.RPG, false);
         ExploderUtils.SetActiveRecursively(this.Shotgun, true);
         ((ShotgunController)this.Shotgun.GetComponent <ShotgunController>()).OnActivate();
     }
     if (!Input.GetKeyDown((KeyCode)50))
     {
         return;
     }
     ExploderUtils.SetActiveRecursively(this.RPG, true);
     ExploderUtils.SetActiveRecursively(this.Shotgun, false);
     ((RPGController)this.RPG.GetComponent <RPGController>()).OnActivate();
 }
Exemplo n.º 30
0
    /// <summary>
    /// callback from queue, do not call this unles you know what you are doing!
    /// </summary>
    public void StartExplosionFromQueue(Vector3 pos, int id, OnExplosion callback)
    {
        ExploderUtils.Assert(state == State.None, "Wrong state: " + state);

        mainCentroid      = pos;
        explosionID       = id;
        state             = State.Preprocess;
        ExplosionCallback = callback;

#if DBG
        processingTime        = 0.0f;
        preProcessingTime     = 0.0f;
        postProcessingTime    = 0.0f;
        postProcessingTimeEnd = 0.0f;
        isolatingIslandsTime  = 0.0f;
#endif
    }