public List <string> GetSurfaceGroups(GameObject obj)
    {
        if (obj.GetComponent <SurfaceAreaGroup>() != null)
        {
            SurfaceAreaGroup groups = obj.GetComponent <SurfaceAreaGroup>();
            return(groups.surfaceGroups);
        }

        return(null);
    }
 /// <summary>
 /// This function removes a surface group from the given gameObject
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="groupName"></param>
 public void RemoveSurfaceGroup(GameObject obj, string groupName)
 {
     if (obj.GetComponent <SurfaceAreaGroup>() != null)           // chek length of list maybe
     {
         SurfaceAreaGroup groups = obj.GetComponent <SurfaceAreaGroup>();
         if (groups.surfaceGroups.Contains(groupName))
         {
             groups.surfaceGroups.Remove(groupName);
         }
     }
 }
 /// <summary>
 /// This funciton turns on the surface calculations for this Gameobject and if it didnt have the component it adds it a well
 /// </summary>
 /// <param name="obj"></param>
 public void SetSurfaceGroupState(GameObject obj, bool state)
 {
     if (obj.GetComponent <SurfaceAreaGroup>() == null)
     {
         SurfaceAreaGroup groups = obj.AddComponent <SurfaceAreaGroup>();
         groups.surfaceOn = state;
     }
     else
     {
         SurfaceAreaGroup groups = obj.GetComponent <SurfaceAreaGroup>();
         groups.surfaceOn = state;
     }
 }
 /// <summary>
 /// This function add a surface group to a given object and if the object doesnt have a surfaceAreaGroup component it adds it as well
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="groupName"></param>
 public void AddSurfaceGroup(GameObject obj, string groupName)
 {
     if (obj.GetComponent <SurfaceAreaGroup>() == null)           // chek length of list maybe
     {
         SurfaceAreaGroup groups = obj.AddComponent <SurfaceAreaGroup>();
         groups.surfaceOn = true;
         groups.surfaceGroups.Add(groupName);
     }
     else
     {
         SurfaceAreaGroup groups = obj.GetComponent <SurfaceAreaGroup>();
         groups.surfaceOn = true;
         if (!groups.surfaceGroups.Contains(groupName))
         {
             groups.surfaceGroups.Add(groupName);
         }
     }
 }
    /// <summary>
    /// This function will calculate the total surface area for each surfaceGroup and also return the amount obects without a facing
    /// </summary>
    /// <param name="objList"></param>
    /// <returns></returns>
    public static Dictionary <string, float> TotalSurfaceAreaPerGroup(List <GameObject> objList)     // this function will use the calculatesurfaceArea function
    {
        Dictionary <string, float> groupTotals = new Dictionary <string, float>();
        List <string> groups;

        foreach (GameObject obj in objList)
        {
            if (obj.GetComponent <SurfaceAreaGroup>() == null)
            {
                obj.AddComponent <SurfaceAreaGroup>();
            }
            SurfaceAreaGroup objSurfaceGroup = obj.GetComponent <SurfaceAreaGroup>();
            groups = objSurfaceGroup.surfaceGroups;
            if (groups.Count != 0)                // NullReferenceException
            {
                float surfaceArea = CalculateSurfaceArea(obj);

                foreach (string group in groups)
                {
                    if (groupTotals.ContainsKey(group))
                    {
                        groupTotals[group] += surfaceArea;
                    }
                    else
                    {
                        groupTotals.Add(group, surfaceArea);
                    }
                }
            }
            else
            {
                if (groupTotals.ContainsKey("No Surface Group"))
                {
                    groupTotals["No Surface Group"] += 1;
                }
                else
                {
                    groupTotals.Add("No Surface Group", 1);
                }
            }
        }

        return(groupTotals);
    }