public override bool CanDrop(Draggable d)
    {
        Draggable_Nucleon nuc = d as Draggable_Nucleon;

        if (nuc)
        {
            PType type = nuc.type;
            int   newp = this.p;
            int   newn = this.n;
            if (type == PType.P)
            {
                newp++;
            }
            else
            {
                if (type == PType.N)
                {
                    newn++;
                }
            }
            return((newp <= Ngnome.MaxProtons()) && (AtomChart.elements[newp - 1].nuclides[newn] != null) ? true : false);
        }
        return(false);
    }
Exemple #2
0
    public virtual void Update()
    {
        float fieldAmt  = Mathf.Log(Mathf.Abs(this.p - this.e)) * 0.22f;
        float colorAmt  = Mathf.Lerp(this.minFieldAmt, this.maxFieldAmt, fieldAmt);
        float fieldSize = Mathf.Lerp(this.minFieldSize, this.maxFieldSize, fieldAmt);

        this.field.GetComponent <Renderer>().enabled = this.p != this.e;
        float alpha1   = (190f / 256) * colorAmt;
        Color theColor = this.p > this.e ? fieldColorRed : fieldColorBlue;

        this.field.GetComponent <Renderer>().material.color = new Color(theColor.r, theColor.g, theColor.b, alpha1);
        this.field.transform.localScale = Vector3.one * fieldSize;
        float nucAmt = UnityScript.Lang.UnityBuiltins.parseFloat(this.p) / Ngnome.MaxProtons();

        this.nucleus.transform.localScale = (Vector3.one * Mathf.Lerp(this.minNucSize, this.maxNucSize, nucAmt)) * 0.5f;
        this.rbody.mass     = Mathf.Lerp(this.minMass, this.maxMass, nucAmt);
        this.rbody.drag     = Mathf.Lerp(this.minDrag, this.maxDrag, nucAmt) * Mathf.Max(Mathf.Abs(Input.GetAxis("Horizontal")), Mathf.Abs(Input.GetAxis("Vertical")));
        this.coll.isTrigger = this.e == 0;
        float minSize = 31f;
        float maxSize = 260f;
        float ionAmt  = UnityScript.Lang.UnityBuiltins.parseFloat(this.e) / this.p;

        if ((ionAmt > 0) && (ionAmt < 0.2f))
        {
            ionAmt = 0.2f;
        }
        float sizeAmt = (UnityScript.Lang.UnityBuiltins.parseFloat(AtomChart.elements[this.p - 1].size) - minSize) / maxSize;

        var electronsScale = Vector3.one * Mathf.Lerp(this.minEScale, this.maxEScale, sizeAmt * ionAmt);

        this.electrons.transform.localScale  = electronsScale;
        this.electrons2.transform.localScale = electronsScale;

        float electronsStartSize = Mathf.Lerp(this.minEScale, this.maxEScale, sizeAmt * ionAmt);
        var   mainModule         = this.electrons.main;
        var   mainModule2        = this.electrons2.main;

        mainModule.startSize  = new ParticleSystem.MinMaxCurve(electronsStartSize, electronsStartSize);
        mainModule2.startSize = new ParticleSystem.MinMaxCurve(electronsStartSize, electronsStartSize);

        Color c1 = this.electrons.GetComponent <Renderer>().material.GetColor("_TintColor");
        Color c2 = this.electrons2.GetComponent <Renderer>().material.GetColor("_TintColor");

        this.electrons.GetComponent <Renderer>().material.SetColor("_TintColor", new Color(c1.r, c1.g, c1.b, (this.originalETrans1 * Mathf.Clamp01((1f - sizeAmt) + 0.5f)) * ionAmt));
        this.electrons2.GetComponent <Renderer>().material.SetColor("_TintColor", new Color(c2.r, c2.g, c2.b, (this.originalETrans2 * Mathf.Clamp01((1f - sizeAmt) + 0.5f)) * ionAmt));

        if (!this.electrons.isPlaying)
        {
            this.electrons.Play();
            this.electrons2.Play();
        }

        string hash = (((("" + this.p) + "") + this.n) + "") + this.e;

        if (this.last != hash)
        {
            // TODO need to replace this logic??
            // ParticleSystem.Particle[] noneParticles = new ParticleSystem.Particle[0];
            // this.electrons.SetParticles(noneParticles, 0);
            // UnityEngine.Object.Destroy((ParticlesRightAway) this.electrons.GetComponent(typeof(ParticlesRightAway)));
            // this.electrons.gameObject.AddComponent(typeof(ParticlesRightAway));
            this.last = hash;
        }
    }
    public override void Content()
    {
        int i = 0;

        GUILayout.BeginHorizontal(new GUILayoutOption[] {});
        GUILayout.Label("New Atom: ", this.labelStyle, new GUILayoutOption[] { GUILayout.Height(30) });
        string[] outs  = new string[3];
        int[]    nvals = new int[3];
        GUILayout.BeginVertical(new GUILayoutOption[] {});
        i = 0;
        while (i < 3)
        {
            GUILayout.BeginHorizontal(new GUILayoutOption[] {});
            GUILayout.Label(("     " + this.names[i]) + "s", this.labelStyle, new GUILayoutOption[] {});
            GUILayout.Space(7);
            //GUI.SetNextControlName("field" + i);
            outs[i] = GUILayout.TextField("" + (this.vals[i] == -1 ? "" : this.vals[i].ToString()), this.fieldStyle, new GUILayoutOption[] { GUILayout.Width(40), GUILayout.Height(19) });
            GUILayout.EndHorizontal();
            outs[i] = outs[i] == "" ? "-1" : outs[i];
            if (int.TryParse(outs[i], out nvals[i]))
            {
                if (this.vals[i] != nvals[i])
                {
                    this.lastMove = Time.time;
                }
                this.vals[i] = nvals[i];
            }
            i++;
        }
        GUILayout.EndVertical();
        nvals[0] = Mathf.Clamp(this.vals[0], 1, Ngnome.MaxProtons());
        nvals[1] = AtomChart.ClosestExistingNuclide(nvals[0], this.vals[1]);
        nvals[2] = Mathf.Clamp(this.vals[2], 0, this.vals[0] + 1);
        bool changed = false;

        i = 0;
        while (i < 3)
        {
            if (this.vals[i] != nvals[i])
            {
                changed    = true;
                this.check = false;
            }
            i++;
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(6);
        GUILayout.BeginHorizontal(new GUILayoutOption[] {});
        GUILayout.FlexibleSpace();
        if (this.check || !changed)
        {
            i = 0;
            while (i < 3)
            {
                this.vals[i] = nvals[i];
                i++;
            }
            this.lastControl = GUIUtility.keyboardControl;
            bool buttonDown = GUILayout.Button("Ok", this.buttonStyle, new GUILayoutOption[] { GUILayout.Width(40), GUILayout.Height(30) });
            if (buttonDown)
            {
                UserAtom.p = this.vals[0];
                UserAtom.n = this.vals[1];
                UserAtom.e = this.vals[2];
                Application.LoadLevel(0);
            }
        }
        else
        {
            if (GUILayout.Button("Check", this.buttonStyle, new GUILayoutOption[] { GUILayout.Width(60), GUILayout.Height(30) }))
            {
                this.check = true;
                i          = 0;
                while (i < 3)
                {
                    this.vals[i] = nvals[i];
                    i++;
                }
            }
        }
        GUILayout.EndHorizontal();
    }