private void ImportAll() { string path = EditorUtility.OpenFilePanel("请选择要导入的dsl文件", string.Empty, "dsl"); if (!string.IsNullOrEmpty(path) && File.Exists(path)) { var root = GameObject.Find("UiImportCanvas"); if (null == root) { GameObject obj = new GameObject("UiImportCanvas"); var canvas = obj.AddComponent <Canvas>(); var scaler = obj.AddComponent <CanvasScaler>(); obj.AddComponent <GraphicRaycaster>(); canvas.planeDistance = 800.0f; canvas.gameObject.layer = 5; canvas.pixelPerfect = false; scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; scaler.referenceResolution = new Vector2(1136, 640); if (Screen.width / Screen.height <= scaler.referenceResolution.x / scaler.referenceResolution.y) { scaler.matchWidthOrHeight = 0; } else { scaler.matchWidthOrHeight = 1; } Camera uiCamera; GameObject objUICamera = GameObject.FindGameObjectWithTag("UICamera"); if (objUICamera == null) { GameObject uiCamObj = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("UI/UICamera")); uiCamera = uiCamObj.GetComponent <Camera>(); GameObject.DontDestroyOnLoad(uiCamera.gameObject); } else { uiCamera = objUICamera.GetComponent <Camera>(); } uiCamera.ResetAspect(); float canvasScalerFator = 1 / ((Screen.width / scaler.referenceResolution.x) * (1 - scaler.matchWidthOrHeight) + (Screen.height / scaler.referenceResolution.y) * scaler.matchWidthOrHeight); uiCamera.orthographicSize = (Screen.height * canvasScalerFator) / 2; canvas.renderMode = RenderMode.ScreenSpaceCamera; canvas.worldCamera = uiCamera; root = obj; } UiEditUtility.Import(path, root); EditorUtility.DisplayDialog("提示", "处理完成", "ok"); } }
private void ExportSelectedSceneNodes() { string path = EditorUtility.SaveFilePanel("请选择要导出的dsl文件", string.Empty, string.Empty, "dsl"); if (!string.IsNullOrEmpty(path)) { if (File.Exists(path)) { File.Delete(path); } foreach (GameObject obj in Selection.gameObjects) { UiEditUtility.Export(path, obj); Debug.Log("BatchExportAll " + obj.name); } EditorUtility.DisplayDialog("提示", "处理完成", "ok"); } }
private void ExportSelectedPrefabs() { string path = EditorUtility.SaveFilePanel("请选择要导出的dsl文件", string.Empty, string.Empty, "dsl"); if (!string.IsNullOrEmpty(path)) { if (File.Exists(path)) { File.Delete(path); } foreach (ItemInfo item in m_Prefabs) { if (item.Selected) { if (null != item.Prefab) { UiEditUtility.Export(path, item.Prefab); Debug.Log("BatchExportAll " + item.Path); } } } EditorUtility.DisplayDialog("提示", "处理完成", "ok"); } }