Beispiel #1
0
    public static Component AddComponent(this GameObject go, string name)
    {
        if (go == null)
        {
            throw new ArgumentNullException("go");
        }
        Type componentTypeByName = ComponentHelper.GetComponentTypeByName(name);

        return((componentTypeByName == null) ? null : go.AddComponent(componentTypeByName));
    }
Beispiel #2
0
 private static void ReadObject(GameObject obj, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.PropertyData propertyData = reader.ReadTypeAndName();
         if (propertyData.type == "Component")
         {
             string text;
             if (propertyData.name.Contains("."))
             {
                 text = propertyData.name.Substring(propertyData.name.LastIndexOf(".") + 1);
             }
             else
             {
                 text = propertyData.name;
             }
             Component component = obj.GetComponent(text);
             if (component == null)
             {
                 Type componentTypeByName = ComponentHelper.GetComponentTypeByName(text);
                 component = (componentTypeByName == null) ? null : obj.AddComponent(componentTypeByName);
             }
             if (component != null)
             {
                 if (component is ParticleSystem)
                 {
                     ObjectDeserializer.ReadParticleSystem((ParticleSystem)component, depth + 1, reader);
                 }
                 else
                 {
                     ObjectDeserializer.ReadComponent(component, depth + 1, reader);
                 }
             }
         }
         else if (propertyData.type == "GameObject")
         {
             GameObject gameObject = obj.transform.Find(propertyData.name).gameObject;
             if (gameObject)
             {
                 ObjectDeserializer.ReadObject(gameObject, depth + 1, reader);
             }
         }
     }
 }