Exemple #1
0
    private static int currentId = 0;     // Id 0 corresponds to Prefab Root

    public void SavePrefabData(Transform trans, string relativePath, int pathId)
    {
        Transform  child;
        GameObject prefabParent;

                #if UNITY_EDITOR
        for (int i = 0; i < trans.childCount; i++)
        {
            child = trans.GetChild(i);

            prefabParent = PrefabUtility.GetPrefabParent(child.gameObject) as GameObject;

            if (prefabParent == null)
            {
                GameObjectData goData = new GameObjectData();

                currentId++;
                goData.id = currentId;

                goData.name            = child.name;
                goData.hierarchyPath   = relativePath;
                goData.hierarchyPathId = pathId;

                goData.CopyFrom(child);

                emptyObjectsData.Add(goData);

                SavePrefabData(child, relativePath + pathSeparator + child.name, goData.id);
            }
            else
            {
                NestedPrefabData data = new NestedPrefabData();

                data.prefabPath = AssetDatabase.GetAssetPath(prefabParent);
                Debug.Log("Prefab path = " + data.prefabPath);
                data.hierarchyPath = relativePath;
                Debug.Log("prefabHierarchyPath " + data.hierarchyPath);

                data.hierarchyPathId = pathId;

                data.CopyFrom(child);

                nestedPrefabsData.Add(data);
            }
        }
                #endif
    }