Ejemplo n.º 1
0
    public GameObject getDisk(int round)
    {
        GameObject disk = null;

        if (free.Count > 0)
        {
            disk = free[0].gameObject;
            free.Remove(free[0]);
        }
        else
        {
            disk = GameObject.Instantiate <GameObject>(diskPrefab, Vector3.zero, Quaternion.identity);
            disk.AddComponent <DiskData>();
        }

        int start;

        switch (round)
        {
        case 0: start = 0; break;

        case 1: start = 100; break;

        default: start = 200; break;
        }
        int selectColor = Random.Range(start, round * 499);

        round = selectColor / 250;
        DiskData diskData      = disk.GetComponent <DiskData>();
        Renderer renderer      = disk.GetComponent <Renderer>();
        Renderer childRenderer = disk.transform.GetChild(0).GetComponent <Renderer>();
        float    ranX          = Random.Range(-1, 1) < 0 ? -1.2f : 1.2f;
        Vector3  direction     = new Vector3(ranX, 1, 0);

        switch (round)
        {
        case 0:
            diskData.setDiskData(new Vector3(1.35f, 1.35f, 1.35f), Color.white, 4.0f, direction);
            renderer.material.color      = Color.white;
            childRenderer.material.color = Color.white;
            break;

        case 1:
            diskData.setDiskData(new Vector3(1f, 1f, 1f), Color.gray, 6.0f, direction);
            renderer.material.color      = Color.gray;
            childRenderer.material.color = Color.gray;
            break;

        case 2:
            diskData.setDiskData(new Vector3(0.7f, 0.7f, 0.7f), Color.black, 8.0f, direction);
            renderer.material.color      = Color.black;
            childRenderer.material.color = Color.black;
            break;
        }
        used.Add(diskData);
        diskData.name             = diskData.GetInstanceID().ToString();
        disk.transform.localScale = diskData.getSize();

        return(disk);
    }
Ejemplo n.º 2
0
    private void Update()
    {
        foreach (var obj in beUsed.Values)
        {
            if (!obj.gameObject.activeSelf)
            {
                wait.Add(obj.GetInstanceID());
            }
        }

        //将beUsed里的飞碟free
        foreach (int obj in wait)
        {
            GameObject freeDisk = beUsed[obj].gameObject;
            DiskData   d        = null;
            foreach (DiskData i in beUsed.Values)
            {
                if (freeDisk.GetInstanceID() == i.gameObject.GetInstanceID())
                {
                    d = i;
                }
            }
            if (d != null)
            {
                d.gameObject.SetActive(false);
                free.Add(d);
                beUsed.Remove(d.GetInstanceID());
            }
        }
        wait.Clear();
    }
Ejemplo n.º 3
0
    public void FreeDisk(GameObject disk)
    {
        DiskData tmp = null;

        foreach (DiskData i in used.Values)
        {
            if (disk.GetInstanceID() == i.gameObject.GetInstanceID())
            {
                tmp = i;
            }
        }
        if (tmp != null)
        {
            tmp.gameObject.SetActive(false);
            free.Add(tmp);
            used.Remove(tmp.GetInstanceID());
        }
    }
Ejemplo n.º 4
0
    public GameObject GetDisk(int round, ActionMode mode)
    {
        GameObject newDisk = null;

        if (free.Count > 0)
        {
            newDisk = free[0].gameObject;
            free.Remove(free[0]);
        }
        else
        {
            newDisk = GameObject.Instantiate <GameObject>(diskPrefab, Vector3.zero, Quaternion.identity);
            newDisk.AddComponent <DiskData>();
        }

        int start = 0;

        if (round == 1)
        {
            start = 100;
        }
        if (round == 2)
        {
            start = 250;
        }
        int selectedColor = Random.Range(start, round * 499);

        if (selectedColor > 500)
        {
            round = 2;
        }
        else if (selectedColor > 300)
        {
            round = 1;
        }
        else
        {
            round = 0;
        }

        DiskData diskdata = newDisk.GetComponent <DiskData>();

        switch (round)
        {
        case 0:
        {
            diskdata.color = Color.yellow;
            diskdata.speed = 4.0f;
            float RanX = UnityEngine.Random.Range(-1f, 1f) < 0 ? -1 : 1;
            diskdata.direction = new Vector3(RanX, 1, 0);
            newDisk.GetComponent <Renderer>().material.color = Color.yellow;
            break;
        }

        case 1:
        {
            diskdata.color = Color.red;
            diskdata.speed = 6.0f;
            float RanX = UnityEngine.Random.Range(-1f, 1f) < 0 ? -1 : 1;
            diskdata.direction = new Vector3(RanX, 1, 0);
            newDisk.GetComponent <Renderer>().material.color = Color.red;
            break;
        }

        case 2:
        {
            diskdata.color = Color.black;
            diskdata.speed = 8.0f;
            float RanX = UnityEngine.Random.Range(-1f, 1f) < 0 ? -1 : 1;
            diskdata.direction = new Vector3(RanX, 1, 0);
            newDisk.GetComponent <Renderer>().material.color = Color.black;
            break;
        }
        }

        if (mode == ActionMode.PHYSIC)
        {
            newDisk.AddComponent <Rigidbody>();
        }

        used.Add(diskdata.GetInstanceID(), diskdata);
        newDisk.name = newDisk.GetInstanceID().ToString();
        return(newDisk);
    }
Ejemplo n.º 5
0
    public GameObject GetDisk(int round, ActionMode mode)
    {
        GameObject newDisk = null;

        if (free.Count > 0)
        {
            newDisk = free[0].gameObject;
            free.Remove(free[0]);
        }
        else
        {
            newDisk = GameObject.Instantiate <GameObject>(diskPre, Vector3.zero, Quaternion.identity);
            newDisk.AddComponent <DiskData>();
        }

        int seed = 0;

        if (round == 1)
        {
            seed = 150;
        }
        if (round == 2)
        {
            seed = 300;
        }
        int randomColor = Random.Range(seed, round * 499);

        if (randomColor > 500)
        {
            round = 2;
        }
        else if (randomColor > 300)
        {
            round = 1;
        }
        else
        {
            round = 0;
        }

        DiskData diskdata = newDisk.GetComponent <DiskData>();

        if (round == 0)
        {
            diskdata.color = Color.yellow;
            diskdata.speed = 4.0f;
            newDisk.GetComponent <Renderer>().material.color = Color.yellow;
        }
        else if (round == 1)
        {
            diskdata.color = Color.red;
            diskdata.speed = 6.0f;
            newDisk.GetComponent <Renderer>().material.color = Color.red;
        }
        else if (round == 2)
        {
            diskdata.color = Color.blue;
            diskdata.speed = 8.0f;
            newDisk.GetComponent <Renderer>().material.color = Color.blue;
        }

        float randomX = Random.Range(-1f, 1f) < 0 ? -1 : 1;

        diskdata.direction = new Vector3(randomX, 1, 0);

        //若选择物理模式,则添加刚体组件
        if (mode == ActionMode.PHYSICS)
        {
            newDisk.AddComponent <Rigidbody>();
        }

        beUsed.Add(diskdata.GetInstanceID(), diskdata);
        newDisk.name = newDisk.GetInstanceID().ToString();
        return(newDisk);
    }