public static void ReplaceModelWithPrefab()
    {
        Object obj = Selection.activeObject;

        if (obj == null)
        {
            return;
        }
        switch (PrefabUtility.GetPrefabAssetType(obj))
        {
        case PrefabAssetType.Model:
        case PrefabAssetType.MissingAsset:
        case PrefabAssetType.NotAPrefab:
            return;
        }
        GameObject prefab = (GameObject)obj;

        GameObject[] gos = GameObject.FindObjectsOfType <Transform>().Where(s => s.gameObject.name.StartsWith(obj.name) && PrefabUtility.GetPrefabAssetType(s.gameObject) == PrefabAssetType.Model).Select(s => s.gameObject).ToArray();

        foreach (GameObject model in gos)
        {
            GameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab, model.transform.parent);
            instance.transform.SetPositionAndRotation(model.transform.position, model.transform.rotation);
            Undo.RegisterCreatedObjectUndo(instance, "Replaced GameObject");
            Undo.DestroyObjectImmediate(model);
        }
        Unityx.SetSceneDirty();
        //AEDataEditor.fi
    }
Beispiel #2
0
    static void FindInGO(GameObject g)
    {
        go_count++;
        Component[] components = g.GetComponents <Component>();
        for (int i = 0; i < components.Length; i++)
        {
            components_count++;
            if (components[i] == null)
            {
                missing_count++;
                string    s = g.name;
                Transform t = g.transform;
                while (t.parent != null)
                {
                    s = t.parent.name + "/" + s;
                    t = t.parent;
                }
                Debug.Log(s + " has an empty script attached in position: " + i, g);

                GameObjectUtility.RemoveMonoBehavioursWithMissingScript(g);
                Unityx.SetSceneDirty();
            }
        }

        // Now recurse through each child GO (if there are any):
        foreach (Transform childT in g.transform)
        {
            FindInGO(childT.gameObject);
        }
    }
    public static void CleanNameOfSelectedPrefab()
    {
        GameObject go = Selection.activeGameObject;

        if (go == null)
        {
            return;
        }
        Undo.RecordObject(go, "Name changed");
        go.name = CleanNumberName(go.name);
        Unityx.SetSceneDirty();
    }
    public static void CleanNamesOfSelectedPrefab()
    {
        GameObject go = Selection.activeGameObject;

        if (go == null)
        {
            return;
        }
        if (go.name.Trim().EndsWith(")"))
        {
            string       nameToFind = CleanNumberName(go.name);
            GameObject[] gos        = GameObject.FindObjectsOfType <Transform>().Where(s => s.gameObject.name.StartsWith(nameToFind)).Select(s => s.gameObject).ToArray();
            Undo.RecordObjects(gos, "Names changed");
            gos.ForEach(s => s.name = CleanNumberName(s.name));
            Debug.Log($"{gos.Length} names changed");
        }
        Unityx.SetSceneDirty();
    }