示例#1
0
 /// <summary>
 /// Adds a component to the GameObject
 /// </summary>
 /// <param name="component">The component to add.</param>
 public void AddComponent(Classes.Component component)
 {
     if (component.Single) {
         foreach (Classes.Component comp in Components) {
             if (component.GetType() == comp.GetType()) {
                 Debug.Print("ERROR: Only one component of type " + component.ToString() + " is allowed per GameObject.");
                 break;
             }
         }
     }
     Components.Add(component);
 }
示例#2
0
 /// <summary>
 /// Replaces an already existing component. The component must be of a limited type.
 /// </summary>
 /// <param name="component">The object to use as an replacement.</param>
 public void ReplaceComponent(Classes.Component component)
 {
     if (component.Single) {
         int index = -1;
         for (int i = 0; i < Components.Count; i++) {
             if (component.GetType() == Components[i].GetType()) {
                 index = i;
                 break;
             }
         }
         if (index != -1)
             Components.RemoveAt(index);
         Components.Add(component);
     } else {
         Debug.Print("ERROR: Specified component is not of a limited type.");
     }
 }