Exemple #1
0
 void Init(GlitchMissingLinkGuard gp)
 {
     if (gp.instanceIDs == null || gp.path == null)
     {
         gp.instanceIDs = new List <int>();
         gp.path        = new List <string>();
         gp.properties  = new List <string>();
         gp.component   = new List <string>();
     }
 }
Exemple #2
0
    void RecoverValue(int instanceID, GlitchMissingLinkGuard gp)
    {
        Init(gp);
        if (gp.messages == null)
        {
            return;
        }

        var index = gp.instanceIDs.IndexOf(instanceID);

        if (index >= 0)
        {
            gp.messages.Add("Missing reference pointing to:"
                            + "\nComponent: " + gp.component[index]
                            + "\nProperty: " + gp.properties[index]
                            + "\nPath: " + gp.path[index]
                            );

            if (gp.autoFix)
            {
                if (gp.path[index] == "")
                {
                    gp.messages.Add("AUTOFIX FAILED: No path, possibly this was never a prefab.");
                }
                else
                {
                    GameObject prefab = null;
                    try
                    {
                        prefab = AssetDatabase.LoadAssetAtPath(gp.path[index], typeof(GameObject)) as GameObject;
                    }
                    catch (UnityException)
                    {
                        gp.messages.Add("AUTOFIX FAILED: Path does not point to a prefab.");
                    }

                    if (prefab == null)
                    {
                        gp.messages.Add("AUTOFIX FAILED: Path does not point to a prefab.");
                    }
                    else
                    {
                        var component = gp.GetComponent(gp.component[index]);
                        var prop      = component.GetType().GetField(gp.properties[index]);

                        prop.SetValue(component, prefab.GetComponent(prop.FieldType.Name));
                    }
                }
            }
        }
        else
        {
            gp.messages.Add("Missing reference, no info");
        }
    }
Exemple #3
0
    void SaveValue(int instanceID, string name, string path, string componentName, string property, GlitchMissingLinkGuard gp)
    {
        Init(gp);
        var index = gp.instanceIDs.IndexOf(instanceID);

        if (index >= 0)
        {
            if (gp.path[index] != path)
            {
                gp.path[index]       = path;
                gp.properties[index] = property;
                gp.component[index]  = componentName;
                dirty = true;
            }
        }
        else
        {
            gp.instanceIDs.Add(instanceID);
            gp.path.Add(path);
            gp.properties.Add(property);
            gp.component.Add(componentName);

            dirty = true;
        }
    }