Exemple #1
0
        private void OsciDecay_ValueChanged(object sender, EventArgs e)
        {
            switch (OsciDecay.Value)
            {
            case 0: decay = DecayMode.off; break;

            case 1: decay = DecayMode.Decay1; break;

            case 2: decay = DecayMode.Decay2; break;

            case 3: decay = DecayMode.Decay3; break;

            case 4: decay = DecayMode.Decay4; break;

            case 5: decay = DecayMode.Decay5; break;

            case 6: decay = DecayMode.Decay6; break;

            case 7: decay = DecayMode.Decay7; break;
            }
        }
Exemple #2
0
    public virtual void Decay()
    {
        DecayMode   mode   = AtomChart.elements[this.p - 1].nuclides[this.n].decayMode;
        GameObject  p0     = null;
        GameObject  insO   = null;
        InsetCamera ins    = null;
        float       i      = 0f;
        int         eOut   = 0;
        int         toal   = 0;
        GameObject  objOut = null;

        Vector3[] dirs = new Vector3[8];
        i = 0;
        while (i < 4)
        {
            Vector3 derp = Quaternion.AngleAxis(Mathf.Lerp(130f, 215f, i / 4f), Vector3.forward) * Vector3.right;
            dirs[Mathf.RoundToInt(i)]     = derp;
            dirs[Mathf.RoundToInt(i) + 4] = -derp;
            i++;
        }
        float   ri   = Mathf.Round(Random.Range(0, 4));
        Vector3 rDir = dirs[Mathf.RoundToInt(ri)] * (Random.value > 0.5f ? 1 : -1);
        float   gi   = ri;

        while ((gi == ri) || (gi == (ri + 4)))
        {
            gi = Mathf.Round(Random.Range(0, 8));
        }
        bool onlyGamma = AtomChart.elements[this.p - 1].nuclides[this.n].onlyGamma;

        if (AtomChart.elements[this.p - 1].nuclides[this.n].gamma)
        {
            p0 = UnityEngine.Object.Instantiate(this.pGamma, this.transform.position, this.transform.rotation);
            ((Debris)p0.GetComponent(typeof(Debris))).velocity = dirs[Mathf.RoundToInt(gi)] * 12;
            insO             = UnityEngine.Object.Instantiate(this.insetCamera);
            ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
            ins.targetObject = p0.transform;
            ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
            ins.pCharge      = 0;
            ins.pSpeed       = 7;
            ins.p            = 0;
            ins.n            = 0;
        }
        //DecayMode.ECPE, DecayMode.Beta, DecayMode.Alpha, DecayMode.Proton, DecayMode.Neutron, DecayMode.Fission
        if (mode == DecayMode.ECPE)
        {
            this.p--;
            this.n++;
            p0 = UnityEngine.Object.Instantiate(this.pPositron, this.transform.position, this.transform.rotation);
            ((Debris)p0.GetComponent(typeof(Debris))).velocity = rDir * 7;
            insO             = UnityEngine.Object.Instantiate(this.insetCamera);
            ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
            ins.targetObject = p0.transform;
            ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
            ins.pCharge      = 1;
            ins.pSpeed       = 1.5f;
            ins.p            = 0;
            ins.n            = 0;
            ins.e            = -1;
            if (this.e > 0)
            {
                this.RipElectron(rDir);
            }
            if ((this.e > 0) && (Random.value > 0.5f))
            {
                this.RipElectron(rDir);
            }
        }
        else
        {
            if (mode == DecayMode.Beta)
            {
                this.p++;
                this.n--;
                p0 = UnityEngine.Object.Instantiate(this.pElectron, this.transform.position, this.transform.rotation);
                ((Debris)p0.GetComponent(typeof(Debris))).velocity = rDir * (onlyGamma ? 3.5f : 7f);
                if (!onlyGamma)
                {
                    insO             = UnityEngine.Object.Instantiate(this.insetCamera);
                    ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
                    ins.targetObject = p0.transform;
                    ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
                    ins.pCharge      = -1;
                    ins.pSpeed       = 1.5f;
                    ins.p            = 0;
                    ins.n            = 0;
                    ins.e            = 1;
                }
                if (this.e > 0)
                {
                    this.RipElectron(rDir);
                }
                if ((this.e > 0) && (Random.value > 0.5f))
                {
                    this.RipElectron(rDir);
                }
            }
            else
            {
                if (mode == DecayMode.Alpha)
                {
                    this.p = this.p - 2;
                    this.n = this.n - 2;
                    p0     = UnityEngine.Object.Instantiate(this.pNucleus, this.transform.position, this.transform.rotation);
                    ((Debris)p0.GetComponent(typeof(Debris))).velocity = rDir * 4;
                    insO             = UnityEngine.Object.Instantiate(this.insetCamera);
                    ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
                    ins.targetObject = p0.transform;
                    ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
                    ins.pCharge      = 2;
                    ins.pSpeed       = 0.5f;
                    ins.p            = 2;
                    ins.n            = 2;
                    toal             = (int)(eOut = (int)Mathf.Min(Mathf.Max(1, Mathf.Ceil(this.e * 0.07f)), this.e));
                    if ((this.p == 4) && (this.n == 4))
                    {
                        toal = eOut = 2;
                    }
                    while (eOut > 0)
                    {
                        objOut = this.RipElectron(rDir);
                        foreach (Transform t in objOut.transform)
                        {
                            t.GetComponent <Renderer>().material.color = Color.Lerp(Color.clear, t.GetComponent <Renderer>().material.color, 8f / toal);
                        }
                        eOut--;
                    }
                }
                else
                {
                    if (mode == DecayMode.Proton)
                    {
                        this.p = this.p - 1;
                        p0     = UnityEngine.Object.Instantiate(this.pNucleus, this.transform.position, this.transform.rotation);
                        ((Debris)p0.GetComponent(typeof(Debris))).velocity = rDir * 6;
                        insO             = UnityEngine.Object.Instantiate(this.insetCamera);
                        ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
                        ins.targetObject = p0.transform;
                        ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
                        ins.pCharge      = 1;
                        ins.pSpeed       = 0.8f;
                        ins.p            = 1;
                        ins.n            = 0;
                        toal             = (int)(eOut = (int)Mathf.Min(Mathf.Max(1, Mathf.Round(this.e * 0.1f)), this.e));
                        while (eOut > 0)
                        {
                            objOut = this.RipElectron(rDir);
                            foreach (Transform t in objOut.transform)
                            {
                                t.GetComponent <Renderer>().material.color = Color.Lerp(Color.clear, t.GetComponent <Renderer>().material.color, 4f / toal);
                            }
                            eOut--;
                        }
                    }
                    else
                    {
                        if (mode == DecayMode.Neutron)
                        {
                            this.n = this.n - 1;
                            p0     = UnityEngine.Object.Instantiate(this.pNeutron, this.transform.position, this.transform.rotation);
                            ((Debris)p0.GetComponent(typeof(Debris))).velocity = rDir * 6;
                            insO             = UnityEngine.Object.Instantiate(this.insetCamera);
                            ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
                            ins.targetObject = p0.transform;
                            ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
                            ins.pCharge      = 0;
                            ins.pSpeed       = 0.8f;
                            ins.p            = 0;
                            ins.n            = 1;
                        }
                        else
                        {
                            if (mode == DecayMode.Fission) //  || mode == DecayMode.Unknown
                            {
                                float eAmt  = Mathf.Round(this.e * 0.1f) * 2;
                                float prod0 = 0.5f + (Random.Range(0.1f, 0.2f) * (Random.value > 0.5f ? 1 : -1));
                                int   pool  = 3;
                                this.n = this.n - pool;
                                float p0p = this.p * prod0;
                                this.p = (int)(this.p - p0p);
                                float p0n = this.n * prod0;
                                this.n = (int)(this.n - p0n);
                                DecayMode p0dm = AtomChart.elements[Mathf.RoundToInt(p0p) - 1].nuclides[Mathf.RoundToInt(p0n)].decayMode;
                                DecayMode p1dm = AtomChart.elements[this.p - 1].nuclides[this.n].decayMode;
                                int       itr  = 0;
                                while ((itr < 100) && ((p0dm == DecayMode.ECPE) || (p1dm == DecayMode.ECPE)))
                                {
                                    itr++;
                                    if (p0dm == DecayMode.ECPE)
                                    {
                                        if (AtomChart.elements[this.p - 1].nuclides[this.n - 1].decayMode != DecayMode.ECPE)
                                        {
                                            this.n--;
                                            p0n++;
                                        }
                                        else
                                        {
                                            pool--;
                                            p0n++;
                                        }
                                    }
                                    if (p0dm == DecayMode.ECPE)
                                    {
                                        if (AtomChart.elements[Mathf.RoundToInt(p0p) - 1].nuclides[Mathf.RoundToInt(p0n) - 1].decayMode != DecayMode.ECPE)
                                        {
                                            p0n--;
                                            this.n++;
                                        }
                                        else
                                        {
                                            pool--;
                                            this.n++;
                                        }
                                    }
                                    p0dm = AtomChart.elements[Mathf.RoundToInt(p0p) - 1].nuclides[Mathf.RoundToInt(p0p)].decayMode;
                                    p1dm = AtomChart.elements[this.p - 1].nuclides[this.n].decayMode;
                                }
                                Debug.Log((((("pool:" + pool) + " p0dm: ") + p0dm) + "  p1dm: ") + p1dm);
                                if (pool < 1)
                                {
                                    pool = 1;
                                    Debug.Log("Something wrong with fission neutron exchange loop: negative pool result!!!!");
                                }
                                if (itr > 50)
                                {
                                    Debug.Log("Something wrong with fission neutron exchange loop: insane amount of iterations!!");
                                }
                                p0 = UnityEngine.Object.Instantiate(this.pNucleus, this.transform.position, this.transform.rotation);
                                ((Debris)p0.GetComponent(typeof(Debris))).velocity          = dirs[Mathf.RoundToInt(ri)] * 4;
                                ((Debris)p0.GetComponent(typeof(Debris))).eRenderer.enabled = true;
                                insO             = UnityEngine.Object.Instantiate(this.insetCamera);
                                ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
                                ins.targetObject = p0.transform;
                                ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
                                ins.pCharge      = 1;
                                ins.pSpeed       = 0.3f;
                                ins.p            = (int)p0p;
                                ins.n            = (int)p0n;
                                ins.e            = (int)(eAmt * prod0);
                                p0 = UnityEngine.Object.Instantiate(this.pNucleus, this.transform.position, this.transform.rotation);
                                ((Debris)p0.GetComponent(typeof(Debris))).velocity          = dirs[Mathf.RoundToInt(ri) + 4] * 4;
                                ((Debris)p0.GetComponent(typeof(Debris))).eRenderer.enabled = true;
                                insO             = UnityEngine.Object.Instantiate(this.insetCamera);
                                ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
                                ins.targetObject = p0.transform;
                                ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
                                ins.pCharge      = 1;
                                ins.pSpeed       = 0.3f;
                                ins.p            = this.p;
                                ins.n            = this.n;
                                ins.e            = (int)(eAmt * (1 - prod0));
                                int[] nis   = new int[pool];
                                int   added = 0;
                                i = 0;
                                while (i < 8)
                                {
                                    if (((i != ri) && (i != (ri + 4))) && (i != gi))
                                    {
                                        if (added < pool)
                                        {
                                            nis[added] = (int)i;
                                            added++;
                                        }
                                        else
                                        {
                                            if (Random.value > 0.5f)
                                            {
                                                nis[Mathf.RoundToInt(Random.Range(0, pool - 1))] = (int)i;
                                            }
                                        }
                                    }
                                    i++;
                                }
                                i = 0;
                                while (i < 3)
                                {
                                    p0 = UnityEngine.Object.Instantiate(this.pNeutron, this.transform.position, this.transform.rotation);
                                    ((Debris)p0.GetComponent(typeof(Debris))).velocity = dirs[nis[Mathf.RoundToInt(i)]] * 9;
                                    insO             = UnityEngine.Object.Instantiate(this.insetCamera);
                                    ins              = (InsetCamera)insO.GetComponent(typeof(InsetCamera));
                                    ins.targetObject = p0.transform;
                                    ins.pTexture     = (Texture2D)p0.GetComponent <Renderer>().material.mainTexture;
                                    ins.pCharge      = 0;
                                    ins.pSpeed       = 0.8f;
                                    ins.p            = 0;
                                    ins.n            = 1;
                                    i++;
                                }
                                toal = (int)(eOut = (int)(this.e - (eAmt * 2)));
                                while (eOut > 0)
                                {
                                    objOut = this.RipElectron();
                                    foreach (Transform t in objOut.transform)
                                    {
                                        t.GetComponent <Renderer>().material.color = Color.Lerp(Color.clear, t.GetComponent <Renderer>().material.color, 10f / toal);
                                    }
                                    eOut--;
                                }
                                TestGUI.cullBackAndCounter = true;
                                UnityEngine.Object.Destroy(this.gameObject);
                            }
                            else
                            {
                                Debug.Log(" oops: " + mode);
                            }
                        }
                    }
                }
            }
        }
        UserAtom.p = this.p;
        UserAtom.n = this.n;
        UserAtom.e = this.e;
    }
Exemple #3
0
 public Isotope()
 {
     this.decayMode = DecayMode.Stable;
     this.gamma     = true;
     this.onlyGamma = true;
 }
 private DecayingListChunk(DecayMode mode, string delimiter, params IChunk[] parts) : base(parts)
 {
     this._delimiter = delimiter;
     this._mode      = mode;
 }
 public DecayingListChunk(DecayMode mode, params IChunk[] parts) : this(mode, "/", parts)
 {
 }