static internal void ExportB() { if (IsSelectingSingleGameObject()) { var go = Selection.activeGameObject; var path = UnityEditorExtensions.ShowExportDialog("Export to DataNode", go.name); if (!string.IsNullOrEmpty(path)) { EditorUtility.DisplayCancelableProgressBar("Working", "Creating a DataNode...", 0f); ComponentSerialization.ClearReferences(); var data = go.Serialize(true, true, true); if (data != null) { Save(data, path, DataNode.SaveType.Binary); } ComponentSerialization.ClearReferences(); EditorUtility.ClearProgressBar(); } } else { ExportAssets(DataNode.SaveType.Binary); } }
static internal void ImportSelected() { string path = UnityEditorExtensions.ShowImportDialog("Import DataNode"); if (!string.IsNullOrEmpty(path)) { var node = DataNode.Read(path, true); if (node != null) { if (node.GetChild("Prefabs") != null) { ComponentSerialization.DeserializeBundle(node); } else { Selection.activeGameObject = node.Instantiate(); } } else { Debug.LogError("Failed to parse " + path + " as DataNode"); } } }
public override void OnInspectorGUI() { TNAutoSync sync = target as TNAutoSync; List <Component> components = GetComponents(sync); string[] names = GetComponentNames(components); for (int i = 0; i < sync.entries.Count;) { GUILayout.BeginHorizontal(); { if (DrawTarget(sync, i, components, names)) { DrawProperties(sync, sync.entries[i]); ++i; } } GUILayout.EndHorizontal(); } GUI.backgroundColor = Color.green; if (GUILayout.Button("Add a New Synchronized Property")) { TNAutoSync.SavedEntry ent = new TNAutoSync.SavedEntry(); ent.target = components[0]; sync.entries.Add(ent); #if UNITY_4_7 EditorUtility.SetDirty(sync); #else UnityEditorExtensions.SetDirty(sync); #endif } GUI.backgroundColor = Color.white; GUILayout.Space(4f); float updates = EditorGUILayout.FloatField("Updates Per Second", sync.updatesPerSecond); bool persistent = EditorGUILayout.Toggle("Saved On Server", sync.isSavedOnServer); bool important = EditorGUILayout.Toggle("Important", sync.isImportant); bool owner = EditorGUILayout.Toggle("Only Owner Syncs", sync.onlyOwnerCanSync); if (sync.updatesPerSecond != updates || sync.isSavedOnServer != persistent || sync.isImportant != important || sync.onlyOwnerCanSync != owner) { sync.updatesPerSecond = updates; sync.isSavedOnServer = persistent; sync.isImportant = important; sync.onlyOwnerCanSync = owner; #if UNITY_4_7 EditorUtility.SetDirty(sync); #else UnityEditorExtensions.SetDirty(sync); #endif } }
/// <summary> /// Asset Bundle-like export, except using DataNode's deep serialization. /// </summary> static internal void ExportAssets(DataNode.SaveType type) { var path = UnityEditorExtensions.ShowExportDialog("Export to DataNode", "Assets"); if (!string.IsNullOrEmpty(path)) { ExportAssets(type, path); } }
static bool DrawTarget(TNAutoSync sync, int index, List <Component> components, string[] names) { TNAutoSync.SavedEntry ent = sync.entries[index]; if (ent.target == null) { ent.target = components[0]; #if UNITY_4_7 EditorUtility.SetDirty(sync); #else UnityEditorExtensions.SetDirty(sync); #endif } int oldIndex = 0; string tname = (ent.target != null) ? ent.target.GetType().ToString() : "<None>"; for (int i = 1; i < names.Length; ++i) { if (names[i] == tname) { oldIndex = i; break; } } GUI.backgroundColor = Color.red; bool delete = GUILayout.Button("X", GUILayout.Width(24f)); GUI.backgroundColor = Color.white; int newIndex = EditorGUILayout.Popup(oldIndex, names); if (delete) { sync.entries.RemoveAt(index); #if UNITY_4_7 EditorUtility.SetDirty(sync); #else UnityEditorExtensions.SetDirty(sync); #endif return(false); } if (newIndex != oldIndex) { ent.target = (newIndex == 0) ? null : components[newIndex - 1]; ent.propertyName = ""; #if UNITY_4_7 EditorUtility.SetDirty(sync); #else UnityEditorExtensions.SetDirty(sync); #endif } return(true); }
static void DrawProperties(TNAutoSync sync, TNAutoSync.SavedEntry saved) { if (saved.target == null) { return; } FieldInfo[] fields = saved.target.GetType().GetFields( BindingFlags.Instance | BindingFlags.Public); PropertyInfo[] properties = saved.target.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public); int oldIndex = 0; List <string> names = new List <string>(); names.Add("<None>"); for (int i = 0; i < fields.Length; ++i) { if (fields[i].Name == saved.propertyName) { oldIndex = names.size; } names.Add(fields[i].Name); } for (int i = 0; i < properties.Length; ++i) { PropertyInfo pi = properties[i]; if (pi.CanWrite && pi.CanRead) { if (pi.Name == saved.propertyName) { oldIndex = names.size; } names.Add(pi.Name); } } int newIndex = EditorGUILayout.Popup(oldIndex, names.ToArray(), GUILayout.Width(90f)); if (newIndex != oldIndex) { saved.propertyName = (newIndex == 0) ? "" : names[newIndex]; #if UNITY_4_7 EditorUtility.SetDirty(sync); #else UnityEditorExtensions.SetDirty(sync); #endif } }
static internal void ConvertC() { string path = UnityEditorExtensions.ShowImportDialog("Convert DataNode"); if (!string.IsNullOrEmpty(path)) { DataNode node = DataNode.Read(path, true); if (node != null) { Save(node, path, DataNode.SaveType.Compressed); } else { Debug.LogError("Failed to parse " + path + " as DataNode"); } } }
static internal void ExportD() { var go = Selection.activeGameObject; var path = UnityEditorExtensions.ShowExportDialog("Export AssetBundle", go.name); if (!string.IsNullOrEmpty(path)) { var node = new DataNode(go.name, go.GetInstanceID()); var selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); if (BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.StandaloneWindows)) { node.AddChild("assetBundle", System.IO.File.ReadAllBytes(path)); Save(node, path, DataNode.SaveType.Binary); } } }