public override void Drop(Draggable d)
    {
        Draggable_Nucleon nuc = d as Draggable_Nucleon;

        if (nuc.type == PType.P)
        {
            this.p++;
            this.Rebuild();
        }
        else
        {
            if (nuc.type == PType.N)
            {
                this.n++;
                this.Rebuild();
            }
            else
            {
                if (nuc.type == PType.E)
                {
                    this.background.Drop(d);
                }
            }
        }
    }
    public virtual IEnumerator ElectronToTray()
    {
        TrayGUI[] allTrays = (TrayGUI[])UnityEngine.Object.FindObjectsOfType(typeof(TrayGUI));
        TrayGUI   theTray  = null;
        int       i        = 0;

        while (i < allTrays.Length)
        {
            if (allTrays[i].acceptTypes[2] == 1)
            {
                theTray = allTrays[i];
            }
            i++;
        }
        Vector2           origin = DragNDrop.WorldToScreen(Vector3.right * this.orbitals.shells[this.orbitals.outerShell].radius);
        GameObject        obj    = new GameObject("Draggable");
        Draggable_Nucleon dr     = (Draggable_Nucleon)obj.AddComponent(typeof(Draggable_Nucleon));

        dr.type = PType.E;
        float time      = 0.8f;
        float startTime = Time.time;

        while (Time.time < (startTime + time))
        {
            float amt = (Time.time - startTime) / time;
            dr.position = (origin * (1f - amt)) + ((theTray.position - new Vector2(0, ((UnityScript.Lang.UnityBuiltins.parseFloat(theTray.dimensions.y) - 0.5f) * theTray.itemSize.y) * 0.5f)) * amt);
            yield return(null);
        }
        theTray.Drop(dr);
        dr.Die();
    }
 public override Draggable OnDragEvent(DragEventType type, int id, Draggable current, DraggableType target)
 {
     if (type == DragEventType.Over)
     {
         this.mouseOver = id;
     }
     else
     {
         if (type == DragEventType.Down)
         {
             if (this.contents[id].type != PType.Empty)
             {
                 GameObject        obj = new GameObject("Draggable");
                 Draggable_Nucleon dr  = (Draggable_Nucleon)obj.AddComponent(typeof(Draggable_Nucleon));
                 dr.type = this.contents[id].type;
                 this.contents[id].type = PType.Empty;
                 this.mouseDown         = id;
                 return(dr);
             }
         }
         else
         {
             if (type == DragEventType.Up)
             {
                 if (target && target.CanDrop(current))
                 {
                     target.Drop(current);
                     current.Die();
                 }
                 else
                 {
                     if (current)
                     {
                         current.FailDrag();
                         this.Drop(current);
                     }
                 }
                 this.mouseDown = -1;
                 return(null);
             }
             else
             {
                 if (type == DragEventType.Exit)
                 {
                     this.mouseOver = -1;
                 }
             }
         }
     }
     return(current);
 }
    public override void Drop(Draggable d)
    {
        Draggable_Nucleon nuc = d as Draggable_Nucleon;
        int i = this.contents.Length - 1;

        while (i >= 0)
        {
            if (this.contents[i].type == PType.Empty)
            {
                this.contents[i].type = nuc.type;
                i = -1;
            }
            i--;
        }
    }
    public override bool CanDrop(Draggable d)
    {
        bool space            = false;
        Draggable_Nucleon nuc = d as Draggable_Nucleon;

        if (nuc && (this.acceptTypes[((int)(nuc.type - 1))] != 0))
        {
            int i = 0;
            while (i < this.contents.Length)
            {
                if (this.contents[i].type == PType.Empty)
                {
                    space = true;
                    i     = this.contents.Length;
                }
                i++;
            }
        }
        return(space);
    }
    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);
    }
    public override Draggable OnDragEvent(DragEventType type, int id, Draggable current, DraggableType target)
    {
        if (type == DragEventType.Over)
        {
            this.mouseOver = id;
            this.Rebuild();
        }
        else
        {
            if (type == DragEventType.Down)
            {
                int newp = this.p;
                int newn = this.n;
                if (this.points[id].state == PType.P)
                {
                    newp--;
                }
                else
                {
                    newn--;
                }

                if (newp > 0 && AtomChart.elements[newp - 1].nuclides[newn] != null)
                {
                    this.p = newp;
                    this.n = newn;
                    GameObject        obj = new GameObject("Draggable");
                    Draggable_Nucleon dr  = (Draggable_Nucleon)obj.AddComponent(typeof(Draggable_Nucleon));
                    dr.type             = this.points[id].state;
                    this.randomizeOrder = Random.value;
                    this.mouseDown      = id;
                    this.Rebuild();
                    return(dr);
                }
            }
            else
            {
                if (type == DragEventType.Up)
                {
                    if (target && target.CanDrop(current))
                    {
                        target.Drop(current);
                        if ((target != this) && ((UserAtom.p + 1) <= UserAtom.e))
                        {
                            Draggable_Nucleon nuc = current as Draggable_Nucleon;
                            if (nuc.type == PType.P)
                            {
                                this.orbitals.RemoveElectron(false);
                                if ((target as Orbitals) || ((target as CreatorBackground) && (this.background.mouseOver == 0)))
                                {
                                    this.StartCoroutine(this.ElectronToProton());
                                }
                                else
                                {
                                    if (target as TrayGUI)
                                    {
                                        this.StartCoroutine(this.ElectronToTray());
                                    }
                                }
                            }
                        }
                        current.Die();
                    }
                    else
                    {
                        if (current)
                        {
                            current.FailDrag();
                            this.Drop(current);
                        }
                    }
                    this.randomizeOrder = Random.value;
                    this.mouseDown      = -1;
                    this.Rebuild();
                    return(null);
                }
                else
                {
                    if (type == DragEventType.Exit)
                    {
                        this.mouseOver = -1;
                        this.Rebuild();
                    }
                }
            }
        }
        return(current);
    }
    public override void Drop(Draggable d)
    {
        float             time         = 0f;
        Draggable_Nucleon nuc          = d as Draggable_Nucleon;
        Vector3           pos          = DragNDrop.ScreenToWorld(Input.mousePosition) + Vector3.forward;
        Vector3           outDir       = new Vector3(pos.x, pos.y, 0).normalized;
        GameObject        particleObj  = UnityEngine.Object.Instantiate(this.particlePrefab, pos, Quaternion.identity);
        CreatorParticle   mover        = (CreatorParticle)particleObj.GetComponent(typeof(CreatorParticle));
        string            resourceName = nuc.type == PType.E ? "Electron_TIF" : (nuc.type == PType.P ? "Proton_TIF" : "Neutron_TIF");

        particleObj.GetComponent <Renderer>().material.mainTexture = (Texture2D)Resources.Load(resourceName);
        if (this.mouseOver == 0)
        {
            if (nuc.type == PType.E)
            {
                if ((UserAtom.p >= UserAtom.e) && (AtomChart.elements[UserAtom.p - 1].grabElectron || (UserAtom.e < UserAtom.p)))
                {
                    float   speed     = 3f;
                    Vector3 targetPos = Vector3.right * this.orbitals.shells[this.orbitals.outerShell].radius;
                    speed          = Mathf.Clamp(speed * (targetPos - pos).magnitude, 3, 10);
                    time           = (pos - targetPos).magnitude / speed;
                    mover.velocity = (targetPos - pos).normalized * speed;
                    mover.lifetime = time;
                    this.StartCoroutine(this.AddToOrbitalsRoutine(time));
                }
                else
                {
                    mover.velocity = outDir * (UserAtom.p < UserAtom.e ? 4 : 1);
                    mover.lifetime = 10;
                }
            }
            else
            {
                if (nuc.type == PType.N)
                {
                    mover.velocity = outDir;
                    mover.lifetime = 10;
                }
                else
                {
                    float ratio = Mathf.Min(pos.magnitude / this.orbitals.shells[this.orbitals.outerShell].radius, 1);
                    mover.velocity = outDir * Mathf.Lerp(8, 1, ratio);
                    mover.lifetime = 10;
                }
            }
        }
        else
        {
            // mouseOver == 1
            if (nuc.type == PType.E)
            {
                mover.velocity = outDir * 8;
                mover.lifetime = 3;
            }
            else
            {
                mover.velocity = outDir * -4;
                time           = 0.2f;
                mover.lifetime = time;
                this.StartCoroutine(this.AddToNucleusRoutine(time, nuc.type));
            }
        }
    }