public void DrawUnitNatoIcon_Rec(Treeview_DataModel item)
    {
        if (!item.IsUnit || item.IsAggregated || item.WorldPosition == null)
        {
            return;
        }

        foreach (Treeview_DataModel child in item.Children)
        {
            DrawUnitNatoIcon_Rec(child);
        }

        if (item.NATO_Icon == null)
        {
            return;
        }

        var   positionOnScreen = Camera.main.WorldToScreenPoint((Vector3)item.WorldPosition);
        float iconWidth        = Constants.NatoIconWidth;
        float iconHeight       = Constants.NatoIconHeight;

        if (positionOnScreen.z > 0 && positionOnScreen.x >= 0 - iconWidth / 2 && positionOnScreen.x <= Screen.width + iconWidth / 2 &&
            positionOnScreen.y >= 0 - iconHeight / 2 && positionOnScreen.y <= Screen.height + iconHeight / 2)
        {
            GUI.DrawTexture(new Rect(positionOnScreen.x - iconWidth / 2, Screen.height - positionOnScreen.y - iconHeight / 2,
                                     iconWidth, iconHeight), item.NATO_Icon);
        }
    }
    public void RaycastSystems_Rec(Treeview_DataModel item, int layerMask_terrain)
    {
        foreach (var child in item.Children)
        {
            if (child.IsUnit)
            {
                RaycastSystems_Rec(child, layerMask_terrain);
            }
            else if (child.GameObject.transform.position.y < -5000 || child.IsAirborne)
            {
                continue;
            }
            else
            {
                Vector3    position = child.GameObject.transform.position;
                RaycastHit hit;

                if (Physics.Raycast(new Vector3(position.x, 10000, position.z), Vector3.down, out hit, Mathf.Infinity, (1 << layerMask_terrain)))
                {
                    position.y = hit.point.y;
                    child.GameObject.transform.position = position;
                    child.GameObject.transform.up       = hit.normal;
                }
            }
        }
    }
        // Updates health of ancestors.
        public static void UpdateHealthOfAncestors_Rec(Treeview_DataModel item)
        {
            double             health = 0f;
            Treeview_DataModel parent = item.Father;

            foreach (var child in parent.Children)
            {
                if (child.IsUnit)
                {
                    health += child.Health;
                }
                else
                {
                    health += (3 - (float)child.Health) * 100 / 3;
                }
            }

            if (parent.Children.Count > 0)
            {
                health /= parent.Children.Count;
            }

            // rounding
            parent.Health = (int)(health + 0.5);

            if (parent.Father != null)
            {
                UpdateHealthOfAncestors_Rec(parent);
            }
        }
    // called only on start
    private Treeview_DataModel Treeview_FillWithItems_Ent(Dictionary <int, UnitNode> forces, string origin, Treeview_DataModel father)
    {
        Treeview_DataModel dataModel = new Treeview_DataModel {
            Text = origin, EntityID = 0, IsUnit = true, Health = 100, Father = father
        };

        Dictionary <string, UnitType> unitDictionary = this.entityTypes.UnitDictionary;

        if (unitDictionary.ContainsKey(origin + origin))
        {
            WWW www = new WWW("file:///" + Application.dataPath + "/" + unitDictionary[origin + origin].NatoSymbolFile);
            StartCoroutine(LoadTextureViaWWW(www, dataModel));
        }
        else
        {
            WWW www = new WWW("file:///" + Application.dataPath + "/" + unitDictionary["UNKNOWN" + origin].NatoSymbolFile);
            StartCoroutine(LoadTextureViaWWW(www, dataModel));
        }

        foreach (var key in forces.Keys)
        {
            Treeview_FillWithItems_Rec(dataModel, forces[key], origin);
        }

        return(dataModel);
    }
    // moveUnits should be called only for ancesters
    // use world position
    // problem when moving (call on move)
    public List <Vector3> MoveUnits_Rec(Treeview_DataModel father)
    {
        List <Vector3> positions = new List <Vector3>();

        foreach (var son in father.Children)
        {
            if (son.IsUnit)
            {
                List <Vector3> sonsPositions = MoveUnits_Rec(son);
                foreach (var position in sonsPositions)
                {
                    positions.Add(position);
                }
            }
            else
            {
                if (son.GameObject.transform.position.y > -2000)
                {
                    positions.Add(son.GameObject.transform.position);
                }
            }
        }

        if (positions.Count < 1)
        {
            return(positions);
        }

        Vector3 averangePosition = Vector3.zero;

        foreach (var position in positions)
        {
            averangePosition += position;
        }

        // TODO test at first
        if (father.NATO_Icon != null && !father.Father.IsAggregated)
        {
            var   positionOnScreen = Camera.main.WorldToScreenPoint(averangePosition / positions.Count);
            float iconWidth        = Constants.NatoIconWidth;
            float iconHeight       = Constants.NatoIconHeight;

            if (positionOnScreen.z > 0 && positionOnScreen.x >= 0 - iconWidth / 2 && positionOnScreen.x <= Screen.width + iconWidth / 2 &&
                positionOnScreen.y >= 0 - iconHeight / 2 && positionOnScreen.y <= Screen.height + iconHeight / 2)
            {
                //if(IsInCameraRange(averangePosition / positions.Count))
                GUI.DrawTexture(new Rect(positionOnScreen.x - iconWidth / 2, Screen.height - positionOnScreen.y - iconHeight / 2,
                                         iconWidth, iconHeight), father.NATO_Icon);
            }
        }

        return(positions);
    }
 private void DisableShadows(Treeview_DataModel member)
 {
     foreach (Transform grandchild in member.GameObject.transform)
     {
         foreach (Transform grandgrandchild in grandchild.transform)
         {
             grandgrandchild.GetComponent <Renderer>().shadowCastingMode    = ShadowCastingMode.Off;
             grandgrandchild.GetComponent <Renderer>().receiveShadows       = false;
             grandgrandchild.GetComponent <Renderer>().useLightProbes       = false;
             grandgrandchild.GetComponent <Renderer>().reflectionProbeUsage = ReflectionProbeUsage.Off;
         }
     }
 }
 public void ScaleSystems_Rec(Treeview_DataModel item, float scale)
 {
     foreach (var child in item.Children)
     {
         if (child.IsUnit)
         {
             ScaleSystems_Rec(child, scale);
         }
         else
         {
             child.GameObject.transform.localScale = new Vector3(scale, scale, scale);
         }
     }
 }
 private void DisableShadows_Rec(Treeview_DataModel item)
 {
     foreach (var child in item.Children)
     {
         if (child.IsUnit)
         {
             DisableShadows_Rec(child);
         }
         else
         {
             DisableShadows(child);
         }
     }
 }
    // Use this for initialization
    public void Start()
    {
        this.treeviewHandlerScript.InitilizeTreeview();
        // branje XMLjev
        // mapiranje entitet
        this.entityTypes = XmlReader.ParseMappedEntityTypes(Application.dataPath + Constants.MappedEntityTypes);
        // branje vhodnih podatkov

        // TODO uncomment after adding initial screen

        Dictionary <int, UnitNode> blueForces    = ParseJcatsXml(resourceHandlerScript.blueFilePath, materialFrendlyForces);
        Dictionary <int, UnitNode> neutralForces = ParseJcatsXml(resourceHandlerScript.neutralFilePath, materialNeutralForces);
        Dictionary <int, UnitNode> redForces     = ParseJcatsXml(resourceHandlerScript.redFilePath, materialHostileForces);

        /*
         * Dictionary<int, UnitNode> blueForces = ParseJcatsXml(Application.dataPath + "/Resources/XMLs/kosa-m.xml", materialFrendlyForces);
         * Dictionary<int, UnitNode> neutralForces = ParseJcatsXml(Application.dataPath + "/Resources/XMLs/kosa-o.xml", materialNeutralForces);
         * Dictionary<int, UnitNode> redForces = ParseJcatsXml(Application.dataPath + "/Resources/XMLs/kosa-r.xml", materialHostileForces);
         */
        // Supply the treeview with the data - this is where you replace this code with your own..
        Treeview_DataModel itemsSource = new Treeview_DataModel {
            Text = "Show forces", EntityID = -1, IsUnit = true, Father = null
        };

        Treeview_DataModel blueItems    = Treeview_FillWithItems_Ent(blueForces, "FRIEND", itemsSource);
        Treeview_DataModel neutralItems = Treeview_FillWithItems_Ent(neutralForces, "NEUTRAL", itemsSource);
        Treeview_DataModel redItems     = Treeview_FillWithItems_Ent(redForces, "HOSTILE", itemsSource);

        itemsSource.Children.Add(blueItems);
        itemsSource.Children.Add(neutralItems);
        itemsSource.Children.Add(redItems);
        Treeview_DataModel yellowItems = new Treeview_DataModel {
            Text = "UNKNOWN", EntityID = 0, IsUnit = true, Father = itemsSource
        };
        WWW www = new WWW("file:///" + Application.dataPath + "/" + "Resources/NATO_MilitarySymbols/LandUnit_U.png");

        StartCoroutine(LoadTextureViaWWW(www, yellowItems));
        itemsSource.Children.Add(yellowItems);

        // assign gameobjects to treeview items
        RecursionUtil.Treeview_SetGameObjects_Rec(itemsSource);
        DisableShadows_Rec(itemsSource);
        this.treeviewHandlerScript.TreeView.ItemsSource = itemsSource;

        this.treeviewHandlerScript.finishedInitEntityHandler = true;
    }
 // Sets game objects to Treeview_DataModel object
 public static void Treeview_SetGameObjects_Rec(Treeview_DataModel father)
 {
     foreach (var son in father.Children)
     {
         if (son.IsUnit)
         {
             Treeview_SetGameObjects_Rec(son);
         }
         else
         {
             if (son.GameObject == null)
             {
                 son.GameObject = GameObject.Find("" + son.EntityID) as GameObject;
             }
         }
     }
 }
        // Returns number of recursive systems
        public static int GetNumberOfSystems_Rec(Treeview_DataModel father)
        {
            int count = 0;

            foreach (var son in father.Children)
            {
                if (son.IsUnit)
                {
                    count += GetNumberOfSystems_Rec(son);
                }
                else
                {
                    count++;
                }
            }

            return(count);
        }
    public void SendDisEvent(DetonationPdu detonationPdu)
    {
        DateTime timestamp = DateTime.Now;

        Vector3D geographicalCoordinates = CalculationUtil.ConvertToGeographicalCoordinates(new Vector3D(detonationPdu.LocationInWorldCoordinates.X, detonationPdu.LocationInWorldCoordinates.Y, detonationPdu.LocationInWorldCoordinates.Z));
        string   message = String.Format("Detonation at {0:0.000000}° lat, {1:0.000000}° lon. by entity", geographicalCoordinates.y, geographicalCoordinates.x);

        Treeview_DataModel firingEntity = RecursionUtil.GetTreeviewItemByEntityId(detonationPdu.FiringEntityID.Entity, this.treeviewHandlerScript.TreeView.ItemsSource);

        if (firingEntity == null)
        {
            message += " \"UNK\".";
        }
        else
        {
            message += " \"" + firingEntity.Text + "\".";
        }

        this.treeviewHandlerScript.AddEventToLog(new DisEvent(timestamp, message));
    }
    // called only on start
    private void Treeview_FillWithItems_Rec(Treeview_DataModel father, UnitNode unit, string origin)
    {
        Treeview_DataModel son = new Treeview_DataModel {
            Text = unit.NAME, EntityID = unit.JCATS_ID, IsUnit = true, Health = 100, Father = father
        };

        Dictionary <string, UnitType> unitDictionary = this.entityTypes.UnitDictionary;

        if (unitDictionary.ContainsKey(XmlReader.CutString(unit.NAME) + origin))
        {
            WWW www = new WWW("file:///" + Application.dataPath + "/" + unitDictionary[XmlReader.CutString(unit.NAME) + origin].NatoSymbolFile);
            StartCoroutine(LoadTextureViaWWW(www, son));
        }
        else
        {
            WWW www = new WWW("file:///" + Application.dataPath + "/" + unitDictionary["UNKNOWN" + origin].NatoSymbolFile);
            StartCoroutine(LoadTextureViaWWW(www, son));
        }

        foreach (var s in unit.Systems)
        {
            son.Children.Add(new Treeview_DataModel {
                Text = s.JCATS_SystemCharName, EntityID = s.EntityID, IsUnit = false, Health = 0, Father = son
            });                                                                                                                                          // || m.NAME
        }

        father.Children.Add(son);

        if (unit.Subunits.Count < 0)
        {
            return;
        }

        foreach (var subunit in unit.Subunits)
        {
            Treeview_FillWithItems_Rec(son, subunit, origin);
        }

        // TODO is this correct; I moved up
        //father.Children.Add(son);
    }
        // Returns treeview item with entityID.
        public static Treeview_DataModel GetTreeviewItemByEntityId(int entityId, Treeview_DataModel father)
        {
            foreach (var son in father.Children)
            {
                if (son.EntityID == entityId)
                {
                    return(son);
                }

                if (son.IsUnit)
                {
                    Treeview_DataModel result = GetTreeviewItemByEntityId(entityId, son);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(null);
        }
        public static void SetWorldPositionOfParentUnit_Rec(Treeview_DataModel item)
        {
            Treeview_DataModel parent = item.Father;

            List <Vector3> positions = new List <Vector3>();

            foreach (var child in parent.Children)
            {
                if (child.IsUnit && child.WorldPosition != null)
                {
                    positions.Add((Vector3)child.WorldPosition);
                }
                else if (!child.IsUnit && child.GameObject.transform.position.y > -2000)
                {
                    positions.Add(child.GameObject.transform.position);
                }
            }

            // should not occur
            if (positions.Count < 1)
            {
                Debug.Log("Error in SetWorldPositionOfAncestorUnits_Rec: shouldNotOccur -> positions.Count < 1");
                parent.WorldPosition = null;
            }

            Vector3 averangePosition = Vector3.zero;

            foreach (var position in positions)
            {
                averangePosition += position;
            }

            parent.WorldPosition = averangePosition / positions.Count;

            if (parent.Father != null)
            {
                SetWorldPositionOfParentUnit_Rec(parent);
            }
        }
        // Moves all entites that are moving.
        public static void MoveEntities_Rec(Treeview_DataModel father, int layerMask_terrain)
        {
            foreach (var son in father.Children)
            {
                // TODO test
                if (son.IsAggregated)
                {
                    continue;
                }
                // end test
                if (son.IsUnit)
                {
                    MoveEntities_Rec(son, layerMask_terrain);
                }

                if (!son.Moving)
                {
                    continue;
                }

                Vector3 position = son.GameObject.transform.position;
                position += son.MovingDirection * son.MovingSpeed * Time.deltaTime;

                if (!son.IsAirborne)
                {
                    RaycastHit hit;
                    if (Physics.Raycast(new Vector3(position.x, 10000, position.z), Vector3.down, out hit, Mathf.Infinity, (1 << layerMask_terrain)))
                    {
                        position.y = hit.point.y;
                        son.GameObject.transform.up = hit.normal;
                    }
                }

                son.GameObject.transform.position = position;
                SetWorldPositionOfParentUnit_Rec(son);
            }
        }
    public void SendDisEvent(FirePdu firePdu)
    {
        DateTime timestamp = DateTime.Now;
        string   message;

        Treeview_DataModel firingEntity = RecursionUtil.GetTreeviewItemByEntityId(firePdu.FiringEntityID.Entity, this.treeviewHandlerScript.TreeView.ItemsSource);

        if (firingEntity == null)
        {
            message = "Entity \"UNK\" fired";
        }
        else
        {
            message = "Entity \"" + firingEntity.Text + "\" fired";
        }

        if (firePdu.TargetEntityID.Entity != 0)
        {
            Treeview_DataModel targetEntity = RecursionUtil.GetTreeviewItemByEntityId(firePdu.TargetEntityID.Entity, this.treeviewHandlerScript.TreeView.ItemsSource);

            if (targetEntity == null)
            {
                message += " upon entity \"UNK\"";
            }
            else
            {
                message += " upon entity \"" + targetEntity.Text + "\"";
            }
        }

        Vector3D geographicalCoordinates = CalculationUtil.ConvertToGeographicalCoordinates(new Vector3D(firePdu.LocationInWorldCoordinates.X, firePdu.LocationInWorldCoordinates.Y, firePdu.LocationInWorldCoordinates.Z));

        message += String.Format(" at {0:0.000000}° lat, {1:0.000000}° lon.", geographicalCoordinates.y, geographicalCoordinates.x);

        this.treeviewHandlerScript.AddEventToLog(new DisEvent(timestamp, message));
    }
        // TODO not used
        // Updates health to all systems and units.
        public static void UpdateHealth_Rec(Treeview_DataModel father)
        {
            int health = 0;

            foreach (var son in father.Children)
            {
                if (son.IsUnit)
                {
                    UpdateHealth_Rec(son);
                    health += son.Health;
                }
                else
                {
                    health += (3 - son.Health) * 100 / 3;
                }
            }

            if (father.Children.Count > 0)
            {
                health /= father.Children.Count;
            }

            father.Health = health;
        }
    public IEnumerator LoadTextureViaWWW(WWW www, Treeview_DataModel datamodel)
    {
        yield return(www);

        datamodel.NATO_Icon = www.texture;
    }
    //////////////////////////////////////////////////////
    //// FUNCIONS FOR EXTERNAL ACCESS

    public void SetEntityMovementAndDamage(int entityID, bool moving, Vector3 moveDirection, float speed, int entityDamage, Vector3D geodeticLocation, Vector3 position, byte entityDomain)
    {
        // find entity in treeview
        Treeview_DataModel treeviewEntity = RecursionUtil.GetTreeviewItemByEntityId(entityID, this.treeviewHandlerScript.TreeView.ItemsSource);
        string             message        = "";
        bool newEntitySpawned             = false;

        if (treeviewEntity == null)
        {
            newEntitySpawned = true;

            Debug.Log("Entity " + entityID + " wasn't found!");
            this.treeviewHandlerScript.AddUnknownEntityToTreeview(entityID);
            treeviewEntity = RecursionUtil.GetTreeviewItemByEntityId(entityID, this.treeviewHandlerScript.TreeView.ItemsSource);
            message        = "New entity";

            treeviewEntity.Health = -1;

            // TODO move to SetEntityMovementAndDamage
            // set airborne
            if (entityDomain == 2)
            {
                treeviewEntity.IsAirborne = true;
            }
        }
        else if (treeviewEntity.GameObject.transform.position.y < -2000)
        {
            newEntitySpawned = true;
            message          = "Known entity";

            if (entityDomain == 2)
            {
                treeviewEntity.IsAirborne = true;
            }
        }

        // update geodetic location
        treeviewEntity.GeographicCoordinates = geodeticLocation;

        // send entity state event
        if (newEntitySpawned)
        {
            DateTime timestamp = DateTime.Now;
            message += String.Format(" \"{0}\" spawned at {1:0.000000}° lat, {2:0.000000}° lon.", treeviewEntity.Text,
                                     treeviewEntity.GeographicCoordinates.y, treeviewEntity.GeographicCoordinates.x);
            this.treeviewHandlerScript.AddEventToLog(new DisEvent(timestamp, message));
        }


        if (!treeviewEntity.IsUnit)
        {
            // set entity position
            // TODO check maybe needs to be deleted to be faster
            if (!CalculationUtil.HaveSameValues(position, treeviewEntity.GameObject.transform.position))
            {
                treeviewEntity.GameObject.transform.position = position;
                RecursionUtil.SetWorldPositionOfParentUnit_Rec(treeviewEntity);
            }

            // set entity rotation
            if (moveDirection != Vector3.zero)
            {
                treeviewEntity.GameObject.transform.rotation = Quaternion.LookRotation(moveDirection);
            }

            if (treeviewEntity.Health != entityDamage)
            {
                // TODO 1 if(treeviewEntity.Health != entityDamage) (set new health && updateHealth)
                // TODO 2 UpdateHealth change to go up
                // update entity damage
                treeviewEntity.Health = entityDamage;

                // TODO confirm that it is working
                //RecursionUtil.UpdateHealth_Rec(this.treeviewHandlerScript.treeview.ItemsSource);
                RecursionUtil.UpdateHealthOfAncestors_Rec(treeviewEntity);
            }
        }

        // set entity movement
        if (!moving)
        {
            treeviewEntity.Moving = false;
        }
        else
        {
            treeviewEntity.Moving          = true;
            treeviewEntity.MovingSpeed     = speed;
            treeviewEntity.MovingDirection = moveDirection;
        }
    }
    public void DrawInfoWindow()
    {
        if (this.treeview.SelectedItem.EntityID < 0)
        {
            return;
        }

        Treeview_DataModel selected = this.treeview.SelectedItem;
        float width  = 280;
        float height = 20;
        float left   = Screen.width - width - 10;
        float index  = 54;

        if (!selected.IsUnit && selected.GeographicCoordinates != null)
        {
            index += 22 * 6;
        }
        else if (selected.IsUnit)
        {
            index += 22 * (3 + selected.Children.Count);
        }
        else
        {
            index += 22 * 3;
        }

        if (index < 120)
        {
            index = 120;
        }

        // draw background
        //GUI.Box(new Rect(left - 15, 10, width + 15, index + 30), "");
        GUI.DrawTexture(new Rect(left - 15, 10, width + 15, 28), this.texture_TitleWindow);
        GUI.DrawTexture(new Rect(left - 15, 40, width + 15, index), this.texture_BackgroundWindow);

        if (GUI.Button(new Rect(left + width - 23, 13, 20, height), "×"))
        {
            this.treeview.SelectedItem = null;
        }

        if (selected.IsUnit)
        {
            GUI.Label(new Rect(left + 103, 15, width, height), "UNIT INFO");
            GUI.DrawTexture(new Rect(left - 15, 10, Constants.NatoIconWidth * 1.5f, Constants.NatoIconHeight * 1.5f), selected.NATO_Icon);
        }
        else
        {
            GUI.Label(new Rect(left + 90, 15, width, height), "SYSTEM INFO");
            GUI.DrawTexture(new Rect(left - 15, 10, Constants.NatoIconWidth * 1.5f, Constants.NatoIconHeight * 1.5f), selected.Father.NATO_Icon);
        }

        index = 22;

        GUI.Label(new Rect(left + 110, index += 22, width, height), "Name: " + selected.Text);

        if (!selected.IsUnit && selected.GeographicCoordinates != null)
        {
            if (!selected.Moving)
            {
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Latitude: " + CalculationUtil.ConvertToDegMinSec(selected.GeographicCoordinates.y));
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Longitude: " + CalculationUtil.ConvertToDegMinSec(selected.GeographicCoordinates.x));
            }
            else
            {
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Latitude: " +
                          CalculationUtil.ConvertToDegMinSec(CalculationUtil.Latitude_LeftBottom + selected.GameObject.transform.position.z / CalculationUtil.DMR_map_size));
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Longitude: " +
                          CalculationUtil.ConvertToDegMinSec(CalculationUtil.Longitude_LeftBottom + selected.GameObject.transform.position.x / CalculationUtil.DMR_map_size));
            }

            GUI.Label(new Rect(left + 110, index += 22, width, height), String.Format("Altitude: {0:0.00} m", selected.GeographicCoordinates.z));
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Health: " + ((3 - selected.Health) * 100 / 3) + " %");
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Visible: " + (!selected.IsAggregated).ToString().ToUpper());
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Moving: " + selected.Moving.ToString().ToUpper());

            if (selected.Moving)
            {
                GUI.Label(new Rect(left + 110, index += 22, width, height), String.Format("Speed: {0:0.00} km/h",
                                                                                          CalculationUtil.CalculateSpeedInKmPerH(selected.MovingSpeed, selected.MovingDirection)));
            }
        }
        else if (selected.IsUnit)
        {
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Health: " + selected.Health + " %");
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Num. of systems: " + RecursionUtil.GetNumberOfSystems_Rec(selected));
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Visible: " + (!selected.Father.IsAggregated).ToString().ToUpper());
            index += 15;
            //GUI.Label(new Rect(left + 110, index += 22, width, height), "Subunits: ");

            for (int i = 0; i < selected.Children.Count; i++)
            {
                /*GUI.Label(new Rect(left, index += 22, width, height), "      " + (
                 * i + 1) + ".)  " + selected.Children[i].Text);
                 *
                 */
                /*if (GUI.Button(new Rect(left + 110, index += 22, width, height), "      " + (i + 1) + ".)  " + selected.Children[i].Text, "Label"))
                 *  this.treeview.SelectedItem = selected.Children[i];
                 *
                 * if (selected.Children[i].IsUnit)
                 *  GUI.DrawTexture(new Rect(Screen.width - 40, index-17, 55 * 612 / 792, 55), selected.Children[i].NATO_Icon);
                 */

                if (GUI.Button(new Rect(left + 50, index += 22, width, height), selected.Children[i].Text, "Label"))
                {
                    this.treeview.SelectedItem = selected.Children[i];
                }

                if (selected.Children[i].IsUnit)
                {
                    GUI.DrawTexture(new Rect(left, index - 17, 55 * 612 / 792, 55), selected.Children[i].NATO_Icon);
                }
                else
                {
                    GUI.DrawTexture(new Rect(left, index - 17, 55 * 612 / 792, 55), selected.Children[i].Father.NATO_Icon);
                }
            }
        }
        else
        {
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Health: " + ((3 - selected.Health) * 100 / 3) + " %");
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Visible: " + (!selected.IsAggregated).ToString().ToUpper());
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Moving: " + selected.Moving.ToString().ToUpper());
        }
    }