private string GetLuaLibStr(string path) { if (path != null) { return(CapsResInfoEditor.GetAssetNormPath(path)); } return(null); }
private void ShowTypeSelWinFor(int index) { if (index >= 0 && index < rawindices.Count) { var kvp = rawindices[index]; var val = kvp.Value; if ((val is Object || index == newindex2) && val != null || val == null && specifiedTypes[index] == typeof(Object)) { GenericMenu menu = new GenericMenu(); if (rawindices != null && index >= 0 && index < rawindices.Count) { if (val is GameObject || val is Component) { System.Action <Object> addMenuItem = (obj) => { var type = obj.GetType(); menu.AddItem(new GUIContent(type.Name), object.Equals(val, obj), (selcomp) => { if (!object.Equals(val, selcomp)) { EditField(index, kvp.Key, selcomp); } }, obj); }; var go = val is GameObject ? val as GameObject : ((Component)val).gameObject; addMenuItem(go); HashSet <Type> compTypes = new HashSet <Type>(); foreach (var comp in go.GetComponents <Component>()) { var comptype = comp.GetType(); var attrs = comptype.GetCustomAttributes(typeof(DataDictionaryComponentTypeAttribute), true); if (attrs != null && attrs.Length > 0) { var attr = attrs[0] as DataDictionaryComponentTypeAttribute; if (attr != null) { if (attr.Type == DataDictionaryComponentTypeAttribute.DataDictionaryComponentType.Main) { addMenuItem(comp); compTypes.Add(comptype); } else if (attr.Type == DataDictionaryComponentTypeAttribute.DataDictionaryComponentType.Sub) { compTypes.Add(comptype); } } } } var transcomp = go.GetComponent <Transform>(); if (transcomp != null) { compTypes.Add(transcomp.GetType()); addMenuItem(transcomp); } bool sepAdded = false; foreach (var comp in go.GetComponents <Component>()) { var comptype = comp.GetType(); if (!compTypes.Contains(comptype)) { if (!sepAdded) { menu.AddSeparator(""); sepAdded = true; } addMenuItem(comp); } } if (index != newindex2) { menu.AddSeparator(""); } } if (index != newindex2) { menu.AddItem(new GUIContent("Plain"), false, () => { string path = null; if (val is Object && ((Object)val) != null) { try { path = AssetDatabase.GetAssetPath(val as Object); } catch (Exception e) { Debug.LogException(e); } } if (!string.IsNullOrEmpty(path)) { path = CapsResInfoEditor.GetAssetNormPath(path); } specifiedTypes[index] = null; EditField(index, kvp.Key, path); }); } } menu.ShowAsContext(); } else if (!(val is Object && ((Object)val) == null) && !(index == newindex2 && val == null)) { GenericMenu menu = new GenericMenu(); if (rawindices != null && index >= 0 && index < rawindices.Count) { var KeepStringType = specifiedTypes[index] == typeof(string); System.Action <string> addMenuItem = (name) => { string valstr = val == null ? "null" : val.ToString(); if (val is string && (string.IsNullOrEmpty(valstr) || name != "Auto")) { valstr = "\"" + valstr + "\""; } var title = name + " (" + valstr + ")"; menu.AddItem(new GUIContent(title), KeepStringType != (name == "Auto"), (x) => { var oldType = specifiedTypes[index]; object newType = null; if (name != "Auto") { newType = typeof(string); } specifiedTypes[index] = newType; if (oldType != newType) { EditField(index, kvp.Key, val); } }, name); }; addMenuItem("Auto"); addMenuItem("String"); if (index != newindex1) { menu.AddSeparator(""); menu.AddItem(new GUIContent("Object"), false, () => { specifiedTypes[index] = typeof(Object); object oldval; oldDict.TryGetValue(kvp.Key, out oldval); Object newval = null; if (oldval is string) { var path = oldval as string; { var real = CapsResInfoEditor.FindDistributeAsset(path); if (real != null) { try { var obj = AssetDatabase.LoadMainAssetAtPath(real); if (obj != null) { newval = obj; } } catch (Exception e) { Debug.LogException(e); } } } if (newval == null && !path.Contains('/')) { path = path.Replace('.', '/'); path = "CapsSpt/" + path + ".lua"; var real = ResManager.EditorResLoader.CheckDistributePath(path); if (real != null) { try { var obj = AssetDatabase.LoadMainAssetAtPath(real); if (obj != null) { newval = obj; } } catch (Exception e) { Debug.LogException(e); } } } } EditField(index, kvp.Key, newval); }); } { object oldval; if (index == newindex1) { oldval = val; } else { oldDict.TryGetValue(kvp.Key, out oldval); } if (oldval is string) { var strval = oldval as string; menu.AddSeparator(""); menu.AddItem(new GUIContent("Find Asset"), false, () => { var real = CapsResInfoEditor.FindDistributeAsset(strval); if (real != null) { try { var obj = AssetDatabase.LoadMainAssetAtPath(real); if (obj != null) { EditorGUIUtility.PingObject(obj); return; } } catch (Exception e) { Debug.LogException(e); } } }); menu.AddItem(new GUIContent("Find Script"), false, () => { var path = strval.Replace('.', '/'); path = "CapsSpt/" + path + ".lua"; var real = ResManager.EditorResLoader.CheckDistributePath(path); if (real != null) { try { var obj = AssetDatabase.LoadMainAssetAtPath(real); if (obj != null) { EditorGUIUtility.PingObject(obj); return; } } catch (Exception e) { Debug.LogException(e); } } }); } } } menu.ShowAsContext(); } else if ((val is Object && ((Object)val) == null) || (val == null && specifiedTypes[index] == typeof(Object))) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Auto"), true, () => { }); menu.AddItem(new GUIContent("Plain"), false, () => { specifiedTypes[index] = null; EditField(index, kvp.Key, null); }); menu.ShowAsContext(); } } }
public override void OnInspectorGUI() { bool prefabChanged = false; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Sync Data")) { //stubButtonClicked = true; Target.SyncDynamicChildStubs(); } if (GUILayout.Button("Merge Stub")) { prefabChanged = Target.MergeDynamicChildStubs(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Re-create Stub")) { prefabChanged = Target.CreateDynamicChildStubs(); } EditorGUILayout.EndHorizontal(); if (prefabChanged) { PrefabStageExtensions.TrySavePrefabStage(); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(Target.gameObject.scene); } soTarget.Update(); EditorGUILayout.PropertyField(spSource, new GUIContent("Source")); if (oldSource != spSource.stringValue) { oldSource = spSource.stringValue ?? ""; oldPrefab = null; var path = ResManager.EditorResLoader.CheckDistributePath("CapsRes/" + oldSource, true); if (path != null) { oldPrefab = AssetDatabase.LoadMainAssetAtPath(path); if (!justEnabled) { Target.MergeStubFromPrefab(oldPrefab as GameObject); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(Target.gameObject.scene); } } } justEnabled = false; Object oldObj = oldPrefab; var newObj = EditorGUILayout.ObjectField("Prefab", oldObj, typeof(GameObject), false); if (newObj != oldObj) { string newNorm = null; if (newObj != null) { var newPath = AssetDatabase.GetAssetPath(newObj); newNorm = CapsResInfoEditor.GetAssetNormPath(newPath); } newNorm = newNorm ?? ""; spSource.stringValue = newNorm; oldPrefab = newObj; oldSource = newNorm; } EditorGUILayout.PropertyField(spEvent, new GUIContent("On Dynamic Child Loaded")); soTarget.ApplyModifiedProperties(); }