private void GroupPreviewFromBundles() { BundlePreview.Data data = new BundlePreview.Data(); var assetUrl = rbundlesProp.serializedObject.FindProperty("assetUrl"); var menu = rbundlesProp.serializedObject.FindProperty("menu"); Debug.Log(assetUrl); data.assetUrl = assetUrl.stringValue; data.menu = menu.stringValue; for (int i = 0; i < rbundlesProp.arraySize; i++) { var itemProp = rbundlesProp.GetArrayElementAtIndex(i); var assetProp = itemProp.FindPropertyRelative("assetName"); var bundleProp = itemProp.FindPropertyRelative("bundleName"); //var rematrixProp = itemProp.FindPropertyRelative("rematrix"); var bdinfo = new BundleInfo(); bdinfo.assetName = assetProp.stringValue; bdinfo.bundleName = bundleProp.stringValue; //bdinfo.rematrix = rematrixProp.boolValue; data.rbundles.Add(bdinfo); } var path = AssetDatabase.GUIDToAssetPath("018159907ea26db409399b839477ad27"); UnityEditor.SceneManagement.EditorSceneManager.OpenScene(path); GameObject holder = new GameObject("holder"); BundlePreview preview = holder.AddComponent <BundlePreview>(); preview.data = data; EditorApplication.ExecuteMenuItem("Edit/Play"); }
protected override void DrawObjectField(Rect acceptRect) { if (!string.IsNullOrEmpty(assetNameProp.stringValue) && !string.IsNullOrEmpty(assetNameProp.stringValue)) { if (GUI.Button(acceptRect, "", EditorStyles.objectFieldMiniThumb)) { var select = EditorUtility.DisplayDialog("提示", "是否打开新场景并加载资源", "是", "否"); if (!select) { return; } BundlePreview.Data data = new BundlePreview.Data(); var assetUrl = serializedObject.FindProperty("assetUrl"); var menu = serializedObject.FindProperty("menu"); if (string.IsNullOrEmpty(assetUrl.stringValue) || string.IsNullOrEmpty(menu.stringValue)) { return; } data.assetUrl = assetUrl.stringValue; data.menu = menu.stringValue; var bdinfo = new BundleInfo(); bdinfo.assetName = assetNameProp.stringValue; bdinfo.bundleName = bundleNameProp.stringValue; //bdinfo.rematrix = rematrixProp.boolValue; data.rbundles.Add(bdinfo); var path = AssetDatabase.GUIDToAssetPath("018159907ea26db409399b839477ad27"); UnityEditor.SceneManagement.EditorSceneManager.OpenScene(path); GameObject holder = new GameObject("holder"); BundlePreview preview = holder.AddComponent <BundlePreview>(); preview.data = data; EditorApplication.ExecuteMenuItem("Edit/Play"); } } else { var obj = EditorGUI.ObjectField(acceptRect, null, typeof(GameObject), false); if (obj != null) { assetNameProp.stringValue = obj.name; var path = AssetDatabase.GetAssetPath(obj); AssetImporter import = AssetImporter.GetAtPath(path); if (!string.IsNullOrEmpty(import.assetBundleName)) { bundleNameProp.stringValue = import.assetBundleName; } } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var assetName = property.FindPropertyRelative("assetName"); var bundleName = property.FindPropertyRelative("bundleName"); var typeProp = property.FindPropertyRelative("type");; var parentLayerProp = property.FindPropertyRelative("parentLayer"); var resetProp = property.FindPropertyRelative("reset"); var buttonProp = property.FindPropertyRelative("button"); var toggleProp = property.FindPropertyRelative("toggle"); float height = EditorGUIUtility.singleLineHeight; Rect rect = new Rect(position.xMin, position.yMin, position.width * 0.9f, height); if (GUI.Button(rect, assetName.stringValue, EditorStyles.toolbar)) { //使用对象是UIGroupObj,将无法从button和Toggle加载 if (property.serializedObject.targetObject is UIGroupObj) { if (typeProp.enumValueIndex == (int)ItemInfoBase.Type.Button || typeProp.enumValueIndex == (int)ItemInfoBase.Type.Toggle) { typeProp.enumValueIndex = (int)ItemInfoBase.Type.Name; } } property.isExpanded = !property.isExpanded; } switch ((ItemInfoBase.Type)typeProp.enumValueIndex) { case ItemInfoBase.Type.Button: if (buttonProp.objectReferenceValue == null) { Worning(rect, "button lost!"); } break; case ItemInfoBase.Type.Toggle: if (toggleProp.objectReferenceValue == null) { Worning(rect, "toggle lost!"); } break; default: break; } rect = new Rect(position.max.x - position.width * 0.1f, position.yMin, position.width * 0.1f, height); if (GUI.Button(rect, "open", EditorStyles.textField)) { var select = EditorUtility.DisplayDialog("提示", "是否打开新场景并加载资源", "是", "否"); if (!select) { return; } BundlePreview.Data data = new BundlePreview.Data(); var assetUrl = property.serializedObject.FindProperty("assetUrl"); var menu = property.serializedObject.FindProperty("menu"); if (string.IsNullOrEmpty(assetUrl.stringValue) || string.IsNullOrEmpty(menu.stringValue)) { return; } data.assetUrl = assetUrl.stringValue; data.menu = menu.stringValue; var bdinfo = new BundleInfo(); bdinfo.assetName = assetName.stringValue; bdinfo.bundleName = bundleName.stringValue; bdinfo.reset = resetProp.boolValue; data.rbundles.Add(bdinfo); var path = AssetDatabase.GUIDToAssetPath("018159907ea26db409399b839477ad27"); UnityEditor.SceneManagement.EditorSceneManager.OpenScene(path); GameObject holder = new GameObject("holder"); BundlePreview preview = holder.AddComponent <BundlePreview>(); preview.data = data; EditorApplication.ExecuteMenuItem("Edit/Play"); } if (!property.isExpanded) { return; } rect = new Rect(position.xMin, position.yMin + height, position.width, height); EditorGUI.PropertyField(rect, assetName, new GUIContent("name")); rect.y += height; EditorGUI.PropertyField(rect, bundleName, new GUIContent("bundle")); rect.y += height; EditorGUI.PropertyField(rect, typeProp, new GUIContent("type")); switch ((ItemInfoBase.Type)typeProp.enumValueIndex) { case ItemInfoBase.Type.Name: break; case ItemInfoBase.Type.Button: rect.y += height; EditorGUI.PropertyField(rect, buttonProp, new GUIContent("Button")); break; case ItemInfoBase.Type.Toggle: rect.y += height; EditorGUI.PropertyField(rect, toggleProp, new GUIContent("Toggle")); break; case ItemInfoBase.Type.Enable: break; default: break; } rect.y += height; EditorGUI.PropertyField(rect, parentLayerProp, new GUIContent("parentLayer")); rect.y += height; EditorGUI.PropertyField(rect, resetProp, new GUIContent("reset")); }