public static void ProjectWindowChanged() { double timer = Time.realtimeSinceStartup; foreach (string path in pb_Config.Resource_Folder_Paths) { foreach (GameObject go in (UnityEngine.Object[])Resources.LoadAll(path, typeof(GameObject))) { pb_MetaDataComponent md = go.GetComponent <pb_MetaDataComponent>(); if (!md) { md = go.AddComponent <pb_MetaDataComponent>(); } if (md.UpdateFileId()) { EditorUtility.SetDirty(go); } } } if ((Time.realtimeSinceStartup - timer) > 3f) { Debug.Log("Marking resources took: " + (Time.realtimeSinceStartup - timer) + " seconds"); } }
/** * Add a diff entry for a component. `component` points to the edited component, name is the variable name, and * value is the new value. */ public static void AddDiff(Component component, string name, object value) { GameObject go = component.gameObject; pb_MetaDataComponent md_component = go.GetComponent <pb_MetaDataComponent>(); if (md_component == null) { md_component = go.AddComponent <pb_MetaDataComponent>(); } pb_ComponentDiff diff = md_component.metadata.componentDiff; if (diff.modifiedValues.TryGetValue(component, out Dictionary <string, object> v)) { if (v.ContainsKey(name)) { v[name] = value; } else { v.Add(name, value); } } else { diff.modifiedValues.Add(component, new Dictionary <string, object>() { { name, value } }); } }
/** * Recursively build a scene graph using `root` as the root node. */ public pb_SceneNode(GameObject root) { name = root.name; components = new List <pb_ISerializable>(); pb_MetaDataComponent metadata_component = root.GetComponent <pb_MetaDataComponent>(); if (metadata_component == null) { metadata_component = root.AddComponent <pb_MetaDataComponent>(); } metadata = metadata_component.metadata; if (metadata.AssetType == AssetType.Instance) { foreach (Component c in root.GetComponents <Component>()) { if (c == null || c is Transform || c.GetType().GetCustomAttributes(true).Any(x => x is pb_JsonIgnoreAttribute)) { continue; } components.Add(pb_Serialization.CreateSerializableObject <Component>(c)); } } // avoid calling constructor which automatically rebuilds the matrix transform = new pb_Transform(); transform.SetTRS(root.transform); children = new List <pb_SceneNode>(); foreach (Transform t in root.transform) { if (!t.gameObject.activeSelf) { continue; } children.Add(new pb_SceneNode(t.gameObject)); } }
private static void SetMetadata(string path, string name) { switch (pb_FileUtility.GetPathType(path)) { case PathType.File: { UnityEngine.Object obj = AssetDatabase.LoadMainAssetAtPath(path); GameObject go = obj as GameObject; // [05.07.2019] https://www.reddit.com/r/Unity3D/comments/a8u4c1/obsolete_functions_i_have_no_idea_how_to_replace/ if (go != null && PrefabUtility.GetPrefabAssetType(go) == PrefabAssetType.Regular) { pb_MetaDataComponent metadata = go.GetComponent <pb_MetaDataComponent>(); if (!metadata) { metadata = go.AddComponent <pb_MetaDataComponent>(); } metadata.SetAssetBundleData(name, path); } break; } case PathType.Directory: { foreach (string subdir in Directory.GetDirectories(path)) { SetMetadata(subdir, name); } foreach (string asset in Directory.GetFiles(path)) { SetMetadata(asset, name); } break; } default: break; } }
private static void SetMetadata(string path, string name) { switch (pb_FileUtility.GetPathType(path)) { case PathType.File: { UnityEngine.Object obj = AssetDatabase.LoadMainAssetAtPath(path); GameObject go = obj as GameObject; if (go != null && PrefabUtility.GetPrefabType(go) == PrefabType.Prefab) { pb_MetaDataComponent metadata = go.GetComponent <pb_MetaDataComponent>(); if (!metadata) { metadata = go.AddComponent <pb_MetaDataComponent>(); } metadata.SetAssetBundleData(name, path); } break; } case PathType.Directory: { foreach (string subdir in Directory.GetDirectories(path)) { SetMetadata(subdir, name); } foreach (string asset in Directory.GetFiles(path)) { SetMetadata(asset, name); } break; } default: break; } }
/** * Convert this node into a GameObject. */ public GameObject ToGameObject() { GameObject go; if (metadata.AssetType == AssetType.Instance) { go = new GameObject(); foreach (pb_ISerializable serializedObject in components) { go.AddComponent(serializedObject); } } else { GameObject prefab = pb_ResourceManager.LoadPrefabWithMetadata(metadata); if (prefab != null) { go = GameObject.Instantiate(prefab); metadata.componentDiff.ApplyPatch(go); } else { go = new GameObject(); } } pb_MetaDataComponent mc = go.DemandComponent <pb_MetaDataComponent>(); mc.metadata = metadata; go.name = name; go.transform.SetTRS(transform); foreach (pb_SceneNode childNode in children) { GameObject child = childNode.ToGameObject(); child.transform.SetParent(go.transform); } return(go); }
void OnEnable() { data = (pb_MetaDataComponent)target; diff = data.metadata.componentDiff; }