Ejemplo n.º 1
0
    public void SetCanvas(GameObject fish)
    {
        if (Fish != null)
        {
            //Fish.GetComponentInChildren<Renderer>().material.shader = Shader.Find("Diffuse");
            Fish.transform.FindChild("outline").GetComponent <SkinnedMeshRenderer>().enabled = false;
        }

        Fish = fish;

        //Fish.GetComponentInChildren<Renderer>().material.shader = Shader.Find("Self-Illumin/Outlined Diffuse");
        Fish.transform.FindChild("outline").GetComponent <SkinnedMeshRenderer>().enabled = true;

        //gameObject.SetActive (true);

        FishData fd = fish.GetComponent <FishData> ();

        if (fd.isSchoolLeader)
        {
            LeaderData.SetActive(true);
            FollowerData.SetActive(false);

            fd.GetNumberOfFish();

            TotalNodes.text   = fd.numberOfFollowers.ToString();
            WorkingNodes.text = fd.numberOfLivingFollowers.ToString();
            DeadNodes.text    = fd.numberOfDeadFollowers.ToString();

            TotalNodes.color   = fd.fishColor;
            WorkingNodes.color = fd.fishColor;
            DeadNodes.color    = fd.fishColor;

            LeaderData.GetComponent <Text> ().color = fd.fishColor;
        }
        else
        {
            LeaderData.SetActive(false);
            FollowerData.SetActive(true);

            MemoryUtilization.text = fd.GetMemoryUtilizationFormated();
            NumberCPU.text         = fd.cpuCount.ToString();
            LoadAverage.text       = fd.avgLoad.ToString();

            MemoryUtilization.color = fd.fishColor;
            NumberCPU.color         = fd.fishColor;
            LoadAverage.color       = fd.fishColor;

            FollowerData.GetComponent <Text> ().color = fd.fishColor;
        }
        FishName.GetComponent <Text> ().text  = fish.name;
        FishName.GetComponent <Text> ().color = fd.fishColor;
    }
Ejemplo n.º 2
0
    IEnumerator ParseXML(string xmlInput, string url, int port)
    {
        GameObject loadingFish;

        try {
            loadingFish = GameObject.Find("[CameraRig]").transform.FindChild("GUIcanvas").FindChild("LoadingFish").gameObject;
        } catch {
            loadingFish      = new GameObject();
            loadingFish.name = "loadingFish";
        }

        if (File.Exists("Downloader.exe") && (Application.platform == RuntimePlatform.LinuxPlayer || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor))
        {
            Process downloader = new Process();
            downloader.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            if (Application.platform == RuntimePlatform.LinuxPlayer)
            {
                downloader.StartInfo.FileName  = "mono";
                downloader.StartInfo.Arguments = "Downloader.exe " + xmlInput + " " + url + " " + port;
            }
            else
            {
                downloader.StartInfo.FileName  = "Downloader.exe";
                downloader.StartInfo.Arguments = xmlInput + " " + url + " " + port;
            }
            downloader.Start();
            while (!downloader.HasExited)
            {
                loadingFish.SetActive(true);
                yield return(null);
            }
        }
        else
        {
            try{
                string xml = tcpConnect(url, port);
                try{
                    File.WriteAllText(xmlInput, xml);
                }catch (IOException ioe) {
                    //File.AppendAllText("errorLog.txt", "\n" + ioe.ToString() + "\n");
                    UnityEngine.Debug.Log(ioe.ToString());
                }
            }catch (SocketException se) {
                //UnityEngine.Debug.LogException (se);
                //File.AppendAllText("errorLog.txt", "\n" + se.ToString() + "\n");
                UnityEngine.Debug.Log(se.ToString());
            }
        }

        GameObject[] listOfFish = GameObject.FindGameObjectsWithTag("fish");

        int fishCount = 0;

        XmlTextReader reader = null;

        try{
            reader = new XmlTextReader(xmlInput);
        }catch (FileNotFoundException fnfe) {
            //UnityEngine.Debug.LogException (e);
            //File.AppendAllText("errorLog.txt", "\n" + fnfe.ToString() + "\n");
            UnityEngine.Debug.Log(fnfe.ToString());
        }
        if (reader != null && reader.ReadToFollowing("CLUSTER"))
        {
            string clusterName = reader.GetAttribute("NAME");

            foreach (GameObject fish in listOfFish)
            {
                if (!fish.GetComponent <FishData>().isSchoolLeader&& fish.GetComponent <FishData>().school.Equals(clusterName))
                {
                    fish.GetComponent <FishData> ().isDead = true;
                }
            }

            GameObject clusterFish = GameObject.Find(clusterName);
            if (clusterFish == null)
            {
                clusterFish = fishSpawner.SpawnFish(clusterName, true);
                //create new leader fish
            }
            else
            {
                clusterFish.GetComponent <FishData> ().ReviveFish();
            }
            clusterFish.GetComponent <FishData> ().Resize(transform.localScale.x * (30) * fishScaleAmount);
            if (reader.ReadToDescendant("HOST"))
            {
                do
                {
                    string     hostName = reader.GetAttribute("NAME");
                    GameObject fish     = GameObject.Find(hostName);
                    if (fish == null)
                    {
                        fish      = fishSpawner.SpawnFish(clusterName, false);
                        fish.name = hostName;
                        //create new follower fish
                    }
                    else
                    {
                        fish.GetComponent <FishData> ().ReviveFish();
                    }
                    FishData fishData = fish.GetComponent <FishData> ();
                    fishData.Resize(transform.localScale.x * (24) * fishScaleAmount);
                    if (reader.ReadToDescendant("METRIC"))
                    {
                        do
                        {
                            //set the follower fish's data
                            string metricName = reader.GetAttribute("NAME");
                            if (metricName.Equals("procstat_gmond_mem"))
                            {
                                fishData.memoryUtilization = int.Parse(reader.GetAttribute("VAL"));
                            }
                            else if (metricName.Equals("load_one"))
                            {
                                fishData.avgLoad = float.Parse(reader.GetAttribute("VAL"));
                                if (fishData.cpuCount != 0)
                                {
                                    fishData.Resize();
                                }
                            }
                            else if (metricName.Equals("cpu_num"))
                            {
                                fishData.cpuCount = int.Parse(reader.GetAttribute("VAL"));
                                if (fishData.cpuCount != 0)
                                {
                                    fishData.Resize();
                                }
                            }
                        } while (reader.ReadToNextSibling("METRIC"));
                    }
                    fishCount++;
                    yield return(new WaitForFixedUpdate());

                    yield return(new WaitForFixedUpdate());

                    yield return(new WaitForFixedUpdate());

                    if (fishLimiter && fishCount >= 50)
                    {
                        break;
                    }
                } while (reader.ReadToNextSibling("HOST"));
            }


            foreach (GameObject fish in listOfFish)
            {
                if (fish.GetComponent <FishData> ().isDead&& fish.GetComponent <FishData>().school.Equals(clusterName))
                {
                    fish.GetComponent <FishData>().KillFish();
                }
            }

            FishData clusterData = clusterFish.GetComponent <FishData>();
            if (clusterData.isSchoolLeader)
            {
                clusterData.GetNumberOfFish();
            }
        }
        if (reader != null)
        {
            reader.Close();
        }
        loadingFish.SetActive(false);
        if (loadingFish.name.Equals("loadingFish"))
        {
            DestroyImmediate(loadingFish);
        }
    }