DisplayIsUpdating() public method

public DisplayIsUpdating ( bool b ) : void
b bool
return void
Esempio n. 1
0
    private void Start()
	{
        mainController = MainController.Instance;
        if (mainController)
        {
            mainController.DisplayIsUpdating(false);
            foreach (string c in mainController.commands)
            {
                commands.Add(c);
            }
        }
    }
Esempio n. 2
0
 private void Start()
 {
     mainController = MainController.Instance;
     mainController.DisplayIsUpdating(false);
     if (mainController != null)
     {
         foreach (string c in mainController.commands)
         {
             commands.Add(c);
         }
     }
 }
Esempio n. 3
0
    private void Start()
    {
        mainController = MainController.Instance;
        citiesObjects = GameObject.FindGameObjectsWithTag("City");

        foreach (GameObject city in citiesObjects)
        {
            city.SetActive(false);
        }
        if (mainController != null)
        {
            mainController.DisplayIsUpdating(false);

            foreach (string c in mainController.commands)
            {
                commands.Add(c);
            }
        }
    }
Esempio n. 4
0
    private void Start()
    {
        mainController = MainController.Instance;
        citiesObjects  = GameObject.FindGameObjectsWithTag("City");

        foreach (GameObject city in citiesObjects)
        {
            city.SetActive(false);
        }
        if (mainController != null)
        {
            mainController.DisplayIsUpdating(false);

            foreach (string c in mainController.commands)
            {
                commands.Add(c);
            }
        }
    }
Esempio n. 5
0
    private void Start()
    {
        mainController = MainController.Instance;
        if (mainController)
        {
            mainController.DisplayIsUpdating(false);

            foreach (string c in mainController.commands)
            {
                commands.Add(c);
            }
        }

        R2D2 = GameObject.FindGameObjectWithTag("R2D2");

        if (R2D2 != null)
        {
            agent       = R2D2.GetComponent <NavMeshAgent>();
            initR2D2Pos = R2D2.transform.position;
        }
    }
Esempio n. 6
0
    private void Start()
	{
        mainController = MainController.Instance;
        if (mainController)
        {
            mainController.DisplayIsUpdating(false);

            foreach (string c in mainController.commands)
            {
                commands.Add(c);
            }
        }

        R2D2 = GameObject.FindGameObjectWithTag("R2D2");

        if (R2D2 != null)
        {
            agent = R2D2.GetComponent<NavMeshAgent>();
            initR2D2Pos = R2D2.transform.position;
        }
    }
Esempio n. 7
0
    // Update is called once per frame
    void Update()
    {
        // Check if new commands arrived
        if (mainController && lastUpdate != mainController.lastUpdate)
        {
            commands.RemoveAll(AllCommands);

            mainController.DisplayIsUpdating(false);
            foreach (string c in mainController.commands)
            {
                commands.Add(c);
            }
            lastUpdate = mainController.lastUpdate;
        }

        // Deal with received commands
        foreach (string elem in commands)
        {
            string[] data = elem.Split(';');

            if (data.Length > 1)
            {
                string command = data[0];

                if (command == "GALAXY_1.0")
                {
                    string name             = data[1];
                    string starCount        = data[2];
                    string description      = data[3];
                    string galaxyRadius     = data[4];
                    string coreRadius       = data[5];
                    string angularOffset    = data[6];
                    string coreExcentricity = data[7];
                    string edgeExcentricity = data[8];
//                    string sigma = data[9];
//                    string coreOrbitalVelocity = data[10];
//                    string edgeOrbitalVelocity = data[11];
                    string dustCount = data[9];

                    if (int.Parse(starCount) != m_pStars.Count || int.Parse(dustCount) != m_pDust.Count)
                    {
                        foreach (GameObject g in h2Stars)
                        {
                            h2Stars.Remove(g);
                            Destroy(g);
                        }
                        foreach (GameObject g in h2Stars)
                        {
                            h2Stars.Remove(g);
                            Destroy(g);
                        }
                        foreach (GameObject g in dust)
                        {
                            nodes.Remove(g);
                            Destroy(g);
                        }

                        NewGalaxy(int.Parse(galaxyRadius),        // radius of the galaxy
                                  int.Parse(coreRadius),          // radius of the core
                                  double.Parse(angularOffset),    // angular offset of the density wave per parsec of radius
                                  double.Parse(coreExcentricity), // excentricity at the edge of the core
                                  double.Parse(edgeExcentricity), // excentricity at the edge of the disk
                                                                  //double.Parse(sigma),                // Sigma
                                                                  //int.Parse(coreOrbitalVelocity),     // orbital velocity at the edge of the core
                                                                  //int.Parse(edgeOrbitalVelocity),     // orbital velocity at the edge of the disk
                                  int.Parse(starCount),           // total number of stars
                                  int.Parse(dustCount)            // amount of dust
                                  );

                        SingleTimeStep(100); //100 years
                        for (int i = 0; i < m_pH2.Count; i++)
                        {
                            GameObject h2 = (GameObject)Instantiate(H2Prefab, new Vector3(m_pH2[i].m_pos.x, 0, m_pH2[i].m_pos.y), new Quaternion(0, 0, 0, 0));
                            h2.transform.SetParent(gameObject.transform, false);
                            h2Stars.Add(h2);
                        }

                        for (int i = 0; i < m_pStars.Count; i++)
                        {
                            GameObject node = (GameObject)Instantiate(nodePrefab, new Vector3(m_pStars[i].m_pos.x, 0, m_pStars[i].m_pos.y), new Quaternion(0, 0, 0, 0));
                            node.transform.SetParent(gameObject.transform, false);
                            nodes.Add(node);
                        }
                        for (int i = 0; i < m_pDust.Count; i++)
                        {
                            // Let one dust go if it's a NaN
                            if (!float.IsNaN(m_pDust[i].m_pos.x) && !float.IsNaN(m_pDust[i].m_pos.y))
                            {
                                GameObject dustObject = (GameObject)Instantiate(dustPrefab, new Vector3(m_pDust[i].m_pos.x, 0, m_pDust[i].m_pos.y), new Quaternion(0, 0, 0, 0));
                                dustObject.transform.SetParent(gameObject.transform, false);
                                dust.Add(dustObject);
                            }
                        }
                    }
                }
            }
        }
        if (commands.Count > 0)
        {
            commands.RemoveAll(AllCommands);
        }

        SingleTimeStep(100000); //100 years

        for (int i = 0; i < nodes.Count; i++)
        {
            nodes[i].transform.position = new Vector3(m_pStars[i].m_pos.x, 0, m_pStars[i].m_pos.y);
        }
        for (int i = 0; i < dust.Count; i++)
        {
            if (!float.IsNaN(m_pDust[i].m_pos.x) && !float.IsNaN(m_pDust[i].m_pos.y))
            {
                dust[i].transform.position = new Vector3(m_pDust[i].m_pos.x, 0, m_pDust[i].m_pos.y);
            }
        }
        for (int i = 0; i < h2Stars.Count; i++)
        {
            h2Stars[i].transform.position = new Vector3(m_pH2[i].m_pos.x, 0, m_pH2[i].m_pos.y);
        }
    }
Esempio n. 8
0
    private void Update()
    {
        // See if within each site there is a new VM to move to position
        // or if a VM is shutting down
        for (int i = 0; i < instanceList1.Count; i++)
        {
            StartVM(instanceList1[i]);
            i = ShutdownVM(cluster1, instanceList1, i);
        }
        for (int i = 0; i < instanceList2.Count; i++)
        {
            StartVM(instanceList2[i]);
            i = ShutdownVM(cluster2, instanceList2, i);
        }

        // See if trucks have something to move
        if (!movingTruck1)
        {
            for (int i = 0; i < truckInstanceList1.Count; i++)
            {
                GameObject spotlight = truck1.transform.Find("Spotlight").gameObject;
                truckInstanceList1[i].instance.transform.position = Vector3.Lerp(truckInstanceList1[i].instance.transform.position, spotlight.transform.position, Time.deltaTime * speed);
            }
        }
        if (truckInstanceList1.Count > 0 && CompareVectors(truckInstanceList1[0].instance.transform.position, truck1.transform.Find("Spotlight").gameObject.transform.position))
        {
            countdown -= Time.deltaTime;

            SmoothFollow sf = Camera.main.GetComponent <SmoothFollow>();
            if (!movingTruck1)
            {
                NavMeshAgent agent;
                agent = truck1.GetComponent <NavMeshAgent>();
                agent.SetDestination(cluster2.transform.position);

                sf.SetDistance(70);
                sf.SetTarget(truck1.transform);
            }
            movingTruck1 = true;
            if (countdown <= 0)
            {
                if (truck1.GetComponent <NavMeshAgent>().remainingDistance <= 0)
                {
                    countdown = 2F;
                    sf.SetTarget(null);

                    if (messageList.Count == 0)
                    {
                        mainController.DisplayIsUpdating(false);
                    }

                    movingTruck1 = false;
                    truck1.GoToSource();

                    for (int i = 0; i < truckInstanceList1.Count; i++)
                    {
                        truckInstanceList1[i].instance.transform.SetParent(sphere2.transform, true);
                        instanceList2.Add(truckInstanceList1[i]);

                        Renderer renderer = sphere2.GetComponent <Renderer>();
                        float    radius   = renderer.bounds.extents.magnitude;
                        Vector3  pos      = sphere2.transform.position + UnityEngine.Random.insideUnitSphere * radius / 2;

                        truckInstanceList1[i].instance.transform.position = pos;
                        truckInstanceList1.Remove(truckInstanceList1[i]);
                        i--;
                    }
                }
            }
        }

        if (!movingTruck2)
        {
            for (int i = 0; i < truckInstanceList2.Count; i++)
            {
                GameObject spotlight = truck2.transform.Find("Spotlight").gameObject;
                truckInstanceList2[i].instance.transform.position = Vector3.Lerp(truckInstanceList2[i].instance.transform.position, spotlight.transform.position, Time.deltaTime * speed);
            }
        }
        if (truckInstanceList2.Count > 0 && CompareVectors(truckInstanceList2[0].instance.transform.position, truck2.transform.Find("Spotlight").gameObject.transform.position))
        {
            countdown -= Time.deltaTime;
            SmoothFollow sf = Camera.main.GetComponent <SmoothFollow>();
            if (!movingTruck2)
            {
                NavMeshAgent agent;
                agent = truck2.GetComponent <NavMeshAgent>();
                agent.SetDestination(cluster1.transform.position);

                sf.SetDistance(70);
                sf.SetTarget(truck2.transform);
            }

            movingTruck2 = true;
            if (countdown <= 0)
            {
                if (truck2.GetComponent <NavMeshAgent>().remainingDistance <= 0)
                {
                    countdown = 2F;
                    sf.SetTarget(null);
                    movingTruck2 = false;
                    if (messageList.Count == 0)
                    {
                        mainController.DisplayIsUpdating(false);
                    }

                    for (int i = 0; i < truckInstanceList2.Count; i++)
                    {
                        truckInstanceList2[i].instance.transform.SetParent(sphere1.transform, true);
                        instanceList1.Add(truckInstanceList2[i]);
                        Renderer renderer = sphere1.GetComponent <Renderer>();
                        float    radius   = renderer.bounds.extents.magnitude;
                        Vector3  pos      = sphere1.transform.position + UnityEngine.Random.insideUnitSphere * radius / 2;

                        truckInstanceList2[i].instance.transform.position = pos;
                        truckInstanceList2.Remove(truckInstanceList2[i]);
                        i--;
                    }

                    truck2.GoToSource();
                }
            }
        }

        // Check if new commands arrived
        if (mainController && lastUpdate != mainController.lastUpdate)
        {
            commands.Clear();

            foreach (string c in mainController.commands)
            {
                commands.Add(c);
            }
            lastUpdate = mainController.lastUpdate;
        }



        // Deal with received commands
        foreach (string elem in commands)
        {
            string[] data = elem.Split(';');

            if (data.Length > 1)
            {
                string command = data[0];

                if (command == "CLOUD_1.0")
                {
                    string VMname      = data[1];
                    string VMhost      = data[2];
                    string cluster     = data[3];
                    string site        = data[4];
                    string status      = data[5];
                    string description = data[6];

                    // tell the main controller that we're busy updating all the commands
                    mainController.DisplayIsUpdating(true);


                    InstanceVMData instanceData = new InstanceVMData();
                    instanceData.VMname      = VMname;
                    instanceData.site        = site;
                    instanceData.status      = status;
                    instanceData.cluster     = cluster;
                    instanceData.description = description;

                    //Debug.LogFormat("Command {0} {1} {2} {3} {4} {5} {6} {7} {8}", command, name, x, z, width, height, rotation, status, description);

                    bool found = false;
                    // See if the VM is currently moving to cluster 2
                    foreach (InstanceVMData instance in truckInstanceList1)
                    {
                        if (instance.VMname == VMname)
                        {
                            UpdateVM(instance, status);

                            found = true;
                            break;
                        }
                    }
                    // See if the VM is currently moving to cluster 1
                    foreach (InstanceVMData instance in truckInstanceList2)
                    {
                        if (instance.VMname == VMname)
                        {
                            UpdateVM(instance, status);
                            found = true;
                            break;
                        }
                    }
                    // See if the VM is currently in cluster 1
                    if (!found)
                    {
                        for (int i = 0; i < instanceList1.Count; i++)
                        {
                            if (instanceList1[i].VMname == VMname)
                            {
                                // See if the VM is to be moved to cluster 2
                                if (site == "2")
                                {
                                    string      now = DateTime.Now.ToString("H:mm:ss");
                                    MessageData m   = new MessageData();
                                    m.message = now + " " + VMname + ": moving to site " + nameSite2;
                                    m.status  = "1"; // white
                                    messageList.Add(m);

                                    instanceList1[i].instance.transform.SetParent(truck1.transform, true);
                                    truckInstanceList1.Add(instanceList1[i]);
                                    countdown = 2F;
                                    instanceList1.Remove(instanceList1[i]);
                                }
                                else
                                {
                                    // See if the VM status or description has changed
                                    if (instanceList1[i].status != status || instanceList1[i].description != description)
                                    {
                                        UpdateVM(instanceList1[i], status);

                                        instanceList1[i].status      = status;
                                        instanceList1[i].description = description;

                                        if (description != "")
                                        {
                                            string      now = DateTime.Now.ToString("H:mm:ss");
                                            MessageData m   = new MessageData();
                                            m.message = now + " " + VMname + ": " + description;
                                            m.status  = status;
                                            messageList.Add(m);
                                        }
                                    }
                                }
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found)
                    {
                        // See if the VM is in cluster 2
                        for (int i = 0; i < instanceList2.Count; i++)
                        {
                            if (instanceList2[i].VMname == VMname)
                            {
                                // See if the VM needs to be moved to Cluster 1
                                if (site == "1")
                                {
                                    string      now = DateTime.Now.ToString("H:mm:ss");
                                    MessageData m   = new MessageData();
                                    m.message = now + " " + VMname + ": moving to site " + nameSite1;
                                    m.status  = "1"; // white
                                    messageList.Add(m);

                                    instanceList2[i].instance.transform.SetParent(truck2.transform, true);
                                    truckInstanceList2.Add(instanceList2[i]);
                                    countdown = 2F;
                                    instanceList2.Remove(instanceList2[i]);
                                }
                                else
                                {
                                    // See if the VM status or description has changed
                                    if (instanceList2[i].status != status || instanceList2[i].description != description)
                                    {
                                        UpdateVM(instanceList2[i], status);

                                        instanceList2[i].status      = status;
                                        instanceList2[i].description = description;

                                        if (description != "")
                                        {
                                            string      now = DateTime.Now.ToString("H:mm:ss");
                                            MessageData m   = new MessageData();
                                            m.message = now + " " + VMname + ": " + description;
                                            m.status  = status;
                                            messageList.Add(m);
                                        }
                                    }
                                }
                                found = true;
                                break;
                            }
                        }
                    }
                    // Still not found? Then it's a brand new VM
                    if (!found)
                    {
                        GameObject sphere, targetCluster;
                        string     now = DateTime.Now.ToString("H:mm:ss");

                        if (site == "1")
                        {
                            sphere        = sphere1;
                            targetCluster = cluster1;
                        }
                        else
                        {
                            sphere        = sphere2;
                            targetCluster = cluster2;
                        }

                        Renderer renderer = sphere.GetComponent <Renderer>();
                        float    radius   = renderer.bounds.extents.magnitude;

                        if (status == "5")
                        {
                            instanceData.movingToPos  = true;
                            instanceData.targetPos    = sphere.transform.position + UnityEngine.Random.insideUnitSphere * radius / 2;
                            instanceData.targetSphere = sphere;
                            instanceData.instance     = (GameObject)Instantiate(VMprefab, targetCluster.transform.position, new Quaternion(0, 0, 0, 0));

                            MessageData m = new MessageData();
                            m.message = now + " " + VMname + ": is starting";
                            m.status  = status;
                            messageList.Add(m);
                        }
                        else if (status == "6")
                        {
                            instanceData.movingToPos = false;
                            // Do nothing this VM is shutting down
                        }
                        else
                        {
                            Vector3 pos = sphere.transform.position + UnityEngine.Random.insideUnitSphere * radius / 2;
                            instanceData.instance = (GameObject)Instantiate(VMprefab, pos, new Quaternion(0, 0, 0, 0));
                            instanceData.instance.transform.SetParent(sphere.transform, true);
                        }

                        if (status != "6")
                        {
                            if (site == "1")
                            {
                                instanceList1.Add(instanceData);
                            }
                            else
                            {
                                instanceList2.Add(instanceData);
                            }
                        }

                        UpdateVM(instanceData, status);
                    }
                }
                if (command == "CLOUDINFO_1.0")
                {
                    string name        = data[1];
                    string role        = data[2];
                    string location    = data[3];
                    string site        = data[4];
                    string status      = data[5];
                    string description = data[6];

                    GameObject cluster;
                    if (site == "1")
                    {
                        nameSite1 = name;
                        cluster   = cluster1;
                    }
                    else
                    {
                        nameSite2 = name;
                        cluster   = cluster2;
                    }

                    GameObject canvas = cluster.transform.Find("Canvas").gameObject;

                    GameObject nameObject = canvas.transform.Find("Name").gameObject;
                    Text       nameText   = nameObject.GetComponent <Text>();
                    nameText.text = name;

                    GameObject roleObject = canvas.transform.Find("Role").gameObject;
                    Text       roleText   = roleObject.GetComponent <Text>();
                    roleText.text = role;

                    GameObject locationObject = canvas.transform.Find("Location").gameObject;
                    Text       locationText   = locationObject.GetComponent <Text>();
                    locationText.text = location;
                }
            }
        }
        if (commands.Count > 0)
        {
            commands.Clear();
        }
    }