示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (portalTime <= 0)
        {
            orangePortal.SetActive(false);
            GetComponent <SpriteRenderer>().enabled = false;
            GetComponent <BoxCollider>().enabled    = true;
        }
        else
        {
            portalTime -= Time.deltaTime;
        }
        if (blocRigidbody != null && bloc != null && blocRigidbody.velocity.magnitude <= 0.01f)
        {
            GetComponent <SpriteRenderer>().enabled = true;
            orangePortal.SetActive(true);
            List <Bloc> blocs = new List <Bloc>();
            blocs.Add(bloc);

            for (int i = 1; i < bloc.size; i++)
            {
                Bloc newBloc = Instantiate(bloc);
                newBloc.InitText(bloc.GetInstanceID().ToString());
                newBloc.gameObject.SetActive(false);
                blocs.Add(newBloc);
            }

            int startIdx = mM.AllocateMemory(blocs);

            if (startIdx != -1)
            {
                //GameObject key = Instantiate(keyPrefab, new Vector3(0, 0, 0), new Quaternion());
                //key.transform.Find("KeyModel").GetComponent<Renderer>().material.color = bloc.GetComponent<Renderer>().material.color;
                //key.transform.Find("KeyText").GetComponent<TextMesh>().text = bloc.GetComponentInChildren<TextMesh>().text;
                foreach (Bloc b in blocs)
                {
                    b.gameObject.SetActive(true);
                }
            }
            else
            {
                print("no more space");
                foreach (Bloc b in blocs)
                {
                    Destroy(b);
                }
                Destroy(bloc.prog.gameObject);
                Destroy(bloc.gameObject);
            }



            bloc          = null;
            blocRigidbody = null;
        }
    }
示例#2
0
    public void DefragMemory2()
    {
        Debug.Log("defrag");
        int         spaceCount     = 0;
        MemoryBlock currentData    = null;
        int         currentDataIdx = -1;
        int         startIdx       = 0;

        for (int i = 0; i < memoriesBlock.Count; i++)
        {
            if (!memoriesBlock[i].isOccupied)
            {
                if (spaceCount == 0)
                {
                    startIdx = i;
                }
                spaceCount++;
            }
            //on decale pour remplir l'espace vide
            else if (i != 0 && spaceCount > 0)
            {
                spaceCount  = 0;
                currentData = memoriesBlock[i];
                if (currentData != null)
                {
                    currentDataIdx = i;
                    Bloc b = currentData.Data.GetComponent <Bloc>();

                    for (int j = startIdx; j < startIdx + b.size; j++)
                    {
                        memoriesBlock[j].Data = memoriesBlock[currentDataIdx + j - startIdx].Data;
                        memoriesBlock[currentDataIdx + j - startIdx].Data       = null;
                        memoriesBlock[currentDataIdx + j - startIdx].isOccupied = false;
                        memoriesBlock[j].Data.transform.position = memoriesBlock[j].transform.position;
                    }
                    addressDisplay.AddAdress(b.GetInstanceID(), startIdx);
                    i = startIdx + b.size - 1;
                }
            }
        }
    }