├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── docs ├── README.md ├── basic │ ├── image │ │ ├── ngui1.png │ │ ├── ngui2.png │ │ ├── ngui3.png │ │ ├── nguispriteframe1.png │ │ ├── nguispriteframe2.png │ │ ├── overview.jpg │ │ ├── quickstart1.png │ │ ├── quickstart10.png │ │ ├── quickstart2.png │ │ ├── quickstart3.png │ │ ├── quickstart4.png │ │ ├── quickstart5.png │ │ ├── quickstart6.png │ │ ├── quickstart7.png │ │ ├── quickstart8.png │ │ └── quickstart9.png │ └── quickstart.md ├── image │ └── wxqrcode.png ├── package.json └── plugin │ ├── contribution.md │ ├── image │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ ├── 25.png │ ├── 26.png │ ├── 27.png │ ├── 31.png │ ├── 32.png │ ├── 33.png │ ├── adaptor.png │ ├── addclass.png │ ├── addimage.png │ ├── addimagescript.png │ ├── c2j.png │ ├── export.png │ ├── folder.png │ ├── imagedes.png │ ├── ngui1.png │ ├── ngui2.png │ ├── ngui3.png │ ├── nguispriteframe1.png │ ├── nguispriteframe2.png │ ├── overview.jpg │ ├── raw.png │ ├── script0.png │ ├── script1.png │ ├── script10.png │ ├── script11.png │ ├── script12.png │ ├── script13.png │ ├── script2.png │ ├── script3.png │ ├── script4.png │ ├── script5.png │ ├── script6.png │ ├── script7.png │ ├── script8.png │ ├── script9.png │ ├── sprite.png │ ├── spritescript.png │ ├── uguiwhite.png │ └── yl.png │ ├── install.md │ ├── material │ ├── custom.md │ ├── image │ │ ├── myshader.png │ │ ├── myshader_file.png │ │ ├── myshader_mat.png │ │ ├── parser_file.png │ │ ├── standard.png │ │ ├── surface_shader.png │ │ ├── unity_shader.png │ │ ├── unlit_shader.png │ │ └── wxbbshader.png │ ├── index.md │ └── parser.md │ ├── ngui-spriteframe.md │ ├── ngui-tree.md │ ├── prefab.md │ ├── raw.md │ └── scene.md └── unity-plugin ├── core ├── Common │ ├── Shaders │ │ ├── BlinnPhong.shader │ │ ├── Editor │ │ │ ├── BlinnPhongGUI.cs │ │ │ ├── EffectGUI.cs │ │ │ └── StandardLitGUI.cs │ │ ├── Effect.shader │ │ ├── ForwardLit │ │ │ ├── input.hlsl │ │ │ ├── light.hlsl │ │ │ ├── lit.hlsl │ │ │ ├── material.hlsl │ │ │ └── math.hlsl │ │ ├── Line.shader │ │ ├── Particle.shader │ │ ├── PostProcess │ │ │ └── Bloom.shader │ │ ├── Skybox.shader │ │ ├── StandardLit.shader │ │ └── Trail.shader │ └── Tools │ │ ├── Model_Mac │ │ └── model.exe ├── editor │ ├── CoreExportModule.cs │ ├── WXConfig.cs │ ├── customMaterialParser │ │ └── CustomMaterialParser.cs │ ├── lib │ │ ├── ErrorUtil.cs │ │ ├── MathUtil.cs │ │ ├── UnityUtil.cs │ │ ├── WXEditorHelper.cs │ │ ├── WXEngineUtil.cs │ │ └── fileUtil │ │ │ ├── FileUtil.cs │ │ │ ├── MacFileUtil.cs │ │ │ └── WinFileUtil.cs │ ├── physics │ │ ├── Component │ │ │ ├── WXCharactorController.cs │ │ │ ├── WXEngineBoxCollider.cs │ │ │ ├── WXEngineCapsuleCollider.cs │ │ │ ├── WXEngineMeshCollider.cs │ │ │ ├── WXEngineRegisterPhysics.cs │ │ │ ├── WXEngineRigidbody.cs │ │ │ └── WXEngineSphereCollider.cs │ │ └── Resource │ │ │ └── WXPhysicsMaterial.cs │ └── src │ │ ├── Component │ │ ├── PostProcess │ │ │ ├── Effect │ │ │ │ └── BloomEditor.cs │ │ │ ├── WXPostProcessBaseEditor.cs │ │ │ ├── WXPostProcessEditor.cs │ │ │ ├── WXPostProcessEnv.cs │ │ │ ├── WXPostProcessProfileEditor.cs │ │ │ └── WXPostProcessProfileEditorDefault.cs │ │ ├── WXAudioDistortionFilter.cs │ │ ├── WXAudioEchoFilter.cs │ │ ├── WXAudioHighPassFilter.cs │ │ ├── WXAudioListener.cs │ │ ├── WXAudioLowPassFilter.cs │ │ ├── WXEngineAnimation.cs │ │ ├── WXEngineAnimator.cs │ │ ├── WXEngineAudioSource.cs │ │ ├── WXEngineCamera.cs │ │ ├── WXEngineLight.cs │ │ ├── WXEngineLineRenderer.cs │ │ ├── WXEngineLodGroup.cs │ │ ├── WXEngineMeshRenderer.cs │ │ ├── WXEngineParticleSystem.cs │ │ ├── WXEnginePlayableDirector.cs │ │ ├── WXEnginePostProcess.cs │ │ ├── WXEngineRawResourceCollection.cs │ │ ├── WXEngineSkinnedMeshRenderer.cs │ │ ├── WXEngineTrailRenderer.cs │ │ ├── WXEngineTransform.cs │ │ ├── WXScript.cs │ │ └── register │ │ │ └── WXEngineRegister3D.cs │ │ ├── CubemapToEquirectangular │ │ ├── CubemapToEquirectangular.shader │ │ └── CubemapToEquirectangularWizard.cs │ │ ├── ExportPreset │ │ ├── AnimatorExportPreset.cs │ │ ├── AssetExportPreset.cs │ │ ├── PrefabExportPreset.cs │ │ ├── PrefabFolderExportPreset.cs │ │ ├── ProjectConfigExportPreset.cs │ │ ├── SceneExportPreset.cs │ │ ├── ScriptableObject │ │ │ ├── HierarchyExportConfig.cs │ │ │ └── HierarchyExportConfigEditor.cs │ │ └── lib │ │ │ └── PresetUtil.cs │ │ ├── Resource │ │ ├── AssetFile │ │ │ ├── WXEngineBinaryFile.cs │ │ │ ├── WXEngineCopyFile.cs │ │ │ ├── WXEngineImageFile.cs │ │ │ ├── WXEngineJSONFile.cs │ │ │ └── WXEngineTextFile.cs │ │ ├── HLSLTemplate │ │ │ ├── BaseHLSLTemplate.cs │ │ │ ├── PixelHLSLTemplate.cs │ │ │ └── VertexHLSLTemplate.cs │ │ ├── Hierarchy │ │ │ └── WXHierarchyContext.cs │ │ ├── WXEngineAnimationClip.cs │ │ ├── WXEngineAnimatorController.cs │ │ ├── WXEngineAudioClip.cs │ │ ├── WXEngineAvatar.cs │ │ ├── WXEngineAvatarMask.cs │ │ ├── WXEngineEffect.cs │ │ ├── WXEngineEnvironmentMap.cs │ │ ├── WXEngineLightMap.cs │ │ ├── WXEngineMaterial.cs │ │ ├── WXEngineMesh.cs │ │ ├── WXEnginePrefab.cs │ │ ├── WXEngineRawResource.cs │ │ ├── WXEngineScene.cs │ │ ├── WXEngineSkinnedMesh.cs │ │ ├── WXEngineTexture.cs │ │ ├── WXEngineTextureCube.cs │ │ ├── WXEngineTimelineAssets.cs │ │ └── material │ │ │ ├── TextureUtil.cs │ │ │ ├── WXBeefBallSkyboxParser.cs │ │ │ ├── WXBlinnPhongNewParser.cs │ │ │ ├── WXEngineBlinnPhongParser.cs │ │ │ ├── WXEngineEffectParser.cs │ │ │ ├── WXEngineLineParser.cs │ │ │ ├── WXEngineMaterialParser.cs │ │ │ ├── WXEngineShurikenParticleParser.cs │ │ │ ├── WXEngineSkyBoxParser.cs │ │ │ ├── WXEngineStandardLitParser.cs │ │ │ └── WXEngineTrailParser.cs │ │ ├── WXEngineBase.cs │ │ └── base │ │ ├── BeefBallConfig.cs │ │ ├── ExportPreset.cs │ │ ├── ExportStore.cs │ │ └── ExportWindow.cs └── runtime │ ├── PostProcess │ ├── Effect │ │ └── WXPostProcessEffectBloom.cs │ ├── WXPostProcess.cs │ ├── WXPostProcessEditorAttribute.cs │ ├── WXPostProcessEffectNameAttribute.cs │ ├── WXPostProcessEffectSetting.cs │ └── WXPostProcessProfile.cs │ ├── WXRawResourceCollection.cs │ └── lib │ ├── AttributeUtil.cs │ └── JSONObject.cs ├── framework ├── editor │ ├── core │ │ ├── BeefBall.cs │ │ ├── JSONObject.cs │ │ ├── PluginHub.cs │ │ ├── ProjectCreator.cs │ │ └── UnityVersion.cs │ ├── directoryBuilder │ │ ├── DirectoryBuilder.cs │ │ ├── DirectoryStructure.cs │ │ └── DirectoryUtil.cs │ ├── editorUI │ │ ├── AnalyzeMenu.cs │ │ ├── HubWindow.cs │ │ └── SupportMenu.cs │ └── module │ │ └── ExportModule.cs └── reference │ └── editor │ ├── ICSharpCode.SharpZipLib.dll │ └── Pri.LongPath.dll └── ngui └── editor ├── Component ├── WXBaseUIComponent.cs ├── WXKeyboardInputComponent.cs ├── WXTouchInputComponent.cs ├── WXTransform2DComponent.cs ├── WXUIAnchor.cs ├── WXUIAtlas.cs ├── WXUIButton.cs ├── WXUIGraphic.cs ├── WXUIGrid.cs ├── WXUILabel.cs ├── WXUIMask.cs ├── WXUIPanel.cs ├── WXUIRoot.cs ├── WXUIScrollView.cs ├── WXUISprite.cs ├── WXUITable.cs ├── WXUITextInput.cs ├── WXUITexture.cs ├── WXUIToggle.cs ├── WXUIWidget.cs └── register │ └── WXEngineRegisterNGUI.cs ├── ExportPreset ├── NGUIAssetPreset.cs ├── NGUIPrefabFolderPreset.cs ├── NGUIScenePreset.cs ├── NGUITreePreset.cs └── ScriptableObject │ ├── NGUIExportConfig.cs │ ├── NGUIExportConfigEditor.cs │ ├── NGUIRootExportConfig.cs │ └── NGUIRootExportConfigEditor.cs ├── NGUIExportModule.cs └── Resource ├── WXEngineBitmapFont.cs ├── WXEngineFont.cs ├── WXEngineNGUIPrefab.cs └── WXEngineSpriteFrame.cs /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | #### 2020.7.7 3 | 1. Beta发布 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # minigame-adaptor (Beta) 3 | 4 | **重要事项**:如果有任何使用上的问题,欢迎通过扫描本文档最后的二维码联系我们。 5 | 6 | `minigame-adaptor`是微信提供的用来降低小游戏开发成本的工具链。 7 | 8 | 你可以使用这套工具链将`Unity`上的美术资源,迁移到微信小游戏平台,进而在小游戏平台上进行二次开发。 9 | 10 | 使用`minigame-adaptor`迁移出来的游戏,小游戏平台会使用`微信小游戏性能优化方案`进行加速。相比 webgl,渲染性能提升 3 倍。 11 | 12 | 13 | ## 接入与开发流程 14 | 15 | 目前我们探索出开发流程,经过不同游戏的验证。开发者在在Unity编辑器导出 "美术资源",然后直接在小游戏平台上,使用 js/ts 在`微信小游戏性能优化方案`的基础上开发游戏逻辑。该方案有比较好的 Unity 兼容性,兼容至 Unity3D 5.5+。 16 | 17 | ![](./docs/basic/image/overview.jpg) 18 | 19 | 20 | ## 更多资料 21 | 22 | `docs`目录为本项目汇总 [文档](./docs/README.md) 23 | 24 | ## 更新日志 25 | 详见 [CHANGELOG](./CHANGELOG.md); 26 | 27 | ## 联系我们 28 | 29 | 对于该项目有疑问或建议,可加入我们的官方微信群进行讨论: 30 | ![扫码联系](./docs/image/wxqrcode.png) 31 | 32 | 也可以加QQ群:945479925 33 | 34 | ## 名词 35 | - 微信小游戏性能优化方案:该方案是整个工具链的核心,后续简称"微信方案",详见 [该文档](https://developers.weixin.qq.com/minigame/dev/game-engine/) 36 | - 微信小游戏性能优化方案工具:微信小游戏性能优化方案提供的开发者工具,后续简称"微信方案工具"。 [该文档](https://developers.weixin.qq.com/minigame/dev/game-engine/) 37 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | * [迁移方案总览](../README.md) 2 | * 资源导出方案 3 | * [方案介绍](./basic/flow.md) 4 | * [quickstart](./basic/quickstart.md) 5 | 6 | * [Unity 插件安装](./plugin/install.md) 7 | * 资源导出方案参考 8 | * [原始资源导出与使用](./plugin/raw.md) 9 | * [材质导出](./plugin/material/index.md) 10 | * NGUI导出 11 | * [NGUI节点导出](./plugin/ngui-tree.md) 12 | * [图集导出](./plugin/ngui-spriteframe.md) 13 | 14 | * 扩展或重写你的导出适配工作流 15 | * [导出插件运行流程](./plugin/contribution/architecture.md) 16 | * 扩展指引 17 | * [新增一种导出模式](./plugin/contribution/custom-preset.md) 18 | * [新增一种Unity Shader导出](./plugin/material/parser.md) 19 | * [新增一种Unity组件导出](./plugin/contribution/custom-component.md) 20 | 21 | * 错误字典 22 | -------------------------------------------------------------------------------- /docs/basic/image/ngui1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/ngui1.png -------------------------------------------------------------------------------- /docs/basic/image/ngui2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/ngui2.png -------------------------------------------------------------------------------- /docs/basic/image/ngui3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/ngui3.png -------------------------------------------------------------------------------- /docs/basic/image/nguispriteframe1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/nguispriteframe1.png -------------------------------------------------------------------------------- /docs/basic/image/nguispriteframe2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/nguispriteframe2.png -------------------------------------------------------------------------------- /docs/basic/image/overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/overview.jpg -------------------------------------------------------------------------------- /docs/basic/image/quickstart1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart1.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart10.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart2.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart3.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart4.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart5.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart6.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart7.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart8.png -------------------------------------------------------------------------------- /docs/basic/image/quickstart9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/basic/image/quickstart9.png -------------------------------------------------------------------------------- /docs/basic/quickstart.md: -------------------------------------------------------------------------------- 1 | ## 快速入门 2 | 本文档演示一个极简Unity工程如何利用导出插件导出资源然后使用微信方案工具二次开发。 3 | 4 | 温馨提示: 5 | * 本示例采用Unity2018.4.11.c1; 6 | * 文档最后更新时间:2020.6.16; 7 | 8 | ### Unity 原始工程 9 | 本示例的逻辑非常简单,场景内有 Ground 和 Tank 两个Prefab,整个游戏有两个脚本,第一个为 Fllow,保证相机跟随坦克,第二个脚本为 TankMovement,用于监听事件并控制坦克移动。 10 | 11 | ![流程概览](./image/quickstart1.png) 12 | ``` 13 | // Follow 14 | using UnityEngine; 15 | using System.Collections; 16 | 17 | public class Fllow : MonoBehaviour 18 | { 19 | public Transform player; // 主角位置 20 | public float speed = 5f; // 相机速度 21 | Vector3 distance; // 主角和摄像机之间的距离 22 | 23 | 24 | void Start() 25 | { 26 | 27 | distance = transform.position - player.position; 28 | } 29 | 30 | void Update() 31 | { 32 | Vector3 targetCamPos = player.position + distance; 33 | 34 | transform.position = targetCamPos; 35 | } 36 | } 37 | 38 | ``` 39 | 40 | ``` 41 | // TankMovement 42 | using UnityEngine; 43 | 44 | public class TankMovement : MonoBehaviour { 45 | private ParticleSystem[] m_particleSystems; // References to all the particles systems used by the Tanks 46 | 47 | private bool flag = false; 48 | private UnityEngine.Vector3 origin; 49 | public const float sensitivity = 0.01f; 50 | 51 | private void OnEnable () { 52 | m_particleSystems = GetComponentsInChildren (); 53 | for (int i = 0; i < m_particleSystems.Length; ++i) { 54 | m_particleSystems[i].Play (); 55 | } 56 | } 57 | 58 | private void Update () { 59 | if (UnityEngine.Input.GetMouseButtonDown (0)) { 60 | if (!flag) { 61 | flag = true; 62 | origin = UnityEngine.Input.mousePosition; 63 | } 64 | 65 | } 66 | if (flag) { 67 | var dir = new UnityEngine.Vector3 ((origin.x - UnityEngine.Input.mousePosition.x) * sensitivity, 68 | 0.0f, (origin.y - UnityEngine.Input.mousePosition.y) * sensitivity); 69 | 70 | if (dir.magnitude < 0.00000001f) { 71 | if (UnityEngine.Input.GetMouseButtonUp (0)) { 72 | flag = false; 73 | } 74 | return; 75 | } 76 | 77 | if (dir.magnitude > 0.1f) { 78 | dir = dir.normalized * 0.1f; 79 | } 80 | var backup = this.gameObject.transform.position; 81 | 82 | this.gameObject.transform.position = this.gameObject.transform.position - dir; 83 | this.gameObject.transform.forward = -dir.normalized; 84 | } 85 | if (UnityEngine.Input.GetMouseButtonUp (0)) { 86 | flag = false; 87 | } 88 | } 89 | } 90 | ``` 91 | 可以直接 Unity 添加工程 examples/QuickStart 并运行游戏来查看效果。 92 | 93 | ### 2.下载导入插件 94 | 95 | [点击下载](https://dldir1.qq.com/WechatWebDev/plugins/BeefBallEngine-unitytool/1.0.0/UnityTool.unitypackage)插件,下载完成之后双击即可安装插件。 96 | ![流程概览](./image/quickstart2.png) 97 | 98 | 当插件安装完成之后,会多出一个**微信小游戏**的菜单,我们点击`微信小游戏->拓展模块管理->核心模块->安装`来安装模块。 99 | ![流程概览](./image/quickstart3.png) 100 | 101 | ### 3.执行导出 102 | 插件安装完成后,在 All Materials 菜单将材质设置为 WXBBShader/BlinnPhong,其中 Dust 需要特殊设置为 WXBBShader/ShurikenParticle 103 | ![流程概览](./image/quickstart9.png) 104 | 105 | Shader设置完成之后就可以执行资源导出操作了。 106 | ![流程概览](./image/quickstart4.png) 107 | 首先我们需要创建一个空的小游戏工程,点击"创建小游戏项目模板"即可开始执行导出操作,先执行**当前场景**导出 108 | ![流程概览](./image/quickstart5.png) 109 | 导出完成后会生成下列文件: 110 | ![流程概览](./image/quickstart6.png) 111 | 112 | ### 4.导入开发工具 113 | 接下来我们在微信开发者工具进行调试预览工作,首先[下载](https://developers.weixin.qq.com/miniprogram/dev/devtools/nightly.html)最新的微信开发者工具,下载完成之后导入刚才新建的小游戏工程。 114 | 115 | 导入工程之后,点击方案工具,进入微信方案编辑器。 116 | ![流程概览](./image/quickstart7.png) 117 | 118 | 右键选中assets可以批量解包: 119 | ![流程概览](./image/quickstart8.png) 120 | 121 | 解包完成,双击打开解压出来的场景,可以发现IDE内已经可以展示场景了,但并不能移动,因为挂载的脚本都没有导出,这里需要重新开发。 122 | ![流程概览](./image/quickstart10.png) 123 | 124 | ### 5.游戏逻辑开发 125 | 接下来我们要进行游戏逻辑开发, 也就是将上面提到的 Fllow 和 TankMovement 用微信引擎的方式开发一遍。 126 | -------------------------------------------------------------------------------- /docs/image/wxqrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/image/wxqrcode.png -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adaptor", 3 | "version": "1.0.0", 4 | "description": "1. 安装Node 2. 安装tnpm: 3. 安装webpack: npm install --save-dev webpack", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "webpack --config webpack.config.js --watch", 8 | "build": "webpack --config webpack.config.js" 9 | }, 10 | "author": "", 11 | "license": "MIT", 12 | "devDependencies": { 13 | "@babel/core": "^7.8.7", 14 | "@babel/preset-env": "^7.8.7", 15 | "babel-loader": "^8.0.6", 16 | "webpack": "^4.42.0" 17 | }, 18 | "dependencies": { 19 | "webpack-cli": "^3.3.11", 20 | "webpack-dev-server": "^3.10.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/plugin/contribution.md: -------------------------------------------------------------------------------- 1 | 2 | # 贡献指引 3 | 4 | ## 开发插件须知 5 | * 开发者将unity-plugin拷贝到Unity Assets目录下进行开发 6 | * NGUI导出模块依赖NGUI,请下载相应的包,或主动删除unity-plugin/ngui文件夹 或改名为 unity-plugin/ngui~ 7 | 8 | ## 目录结构介绍 9 | 插件代码目录目前较为简单如下: 10 | 11 | ![插件代码目录](./image/folder.png) 12 | 13 | * core目录为基础脚本,负责材质导出,引擎内置组件导出等基础功能; 14 | 15 | * framework目录为相关导出菜单窗口代码; 16 | 17 | * ngui目录作用类似ugui目录,如果不使用ngui可以将该目录删除,以免未按装ngui插件时导出插件报错 18 | 19 | ## MR规范 20 | * MR前请先自测通过确保资源导出和代码导出正常,并写清楚MR的详情。 21 | 22 | ## Issue规范 23 | 为帮助我们定位问题,请提供以下信息: 24 | * Unity版本 25 | * 导出面板的配置截图 26 | * 小游戏引擎版本(在小游戏项目的engine.ide.json文件中的 engineVersion字段) 27 | * 报错截图 28 | * 最好能提供简单可复现的demo 29 | 30 | -------------------------------------------------------------------------------- /docs/plugin/image/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/11.png -------------------------------------------------------------------------------- /docs/plugin/image/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/12.png -------------------------------------------------------------------------------- /docs/plugin/image/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/13.png -------------------------------------------------------------------------------- /docs/plugin/image/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/14.png -------------------------------------------------------------------------------- /docs/plugin/image/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/15.png -------------------------------------------------------------------------------- /docs/plugin/image/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/16.png -------------------------------------------------------------------------------- /docs/plugin/image/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/21.png -------------------------------------------------------------------------------- /docs/plugin/image/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/22.png -------------------------------------------------------------------------------- /docs/plugin/image/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/23.png -------------------------------------------------------------------------------- /docs/plugin/image/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/24.png -------------------------------------------------------------------------------- /docs/plugin/image/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/25.png -------------------------------------------------------------------------------- /docs/plugin/image/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/26.png -------------------------------------------------------------------------------- /docs/plugin/image/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/27.png -------------------------------------------------------------------------------- /docs/plugin/image/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/31.png -------------------------------------------------------------------------------- /docs/plugin/image/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/32.png -------------------------------------------------------------------------------- /docs/plugin/image/33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/33.png -------------------------------------------------------------------------------- /docs/plugin/image/adaptor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/adaptor.png -------------------------------------------------------------------------------- /docs/plugin/image/addclass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/addclass.png -------------------------------------------------------------------------------- /docs/plugin/image/addimage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/addimage.png -------------------------------------------------------------------------------- /docs/plugin/image/addimagescript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/addimagescript.png -------------------------------------------------------------------------------- /docs/plugin/image/c2j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/c2j.png -------------------------------------------------------------------------------- /docs/plugin/image/export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/export.png -------------------------------------------------------------------------------- /docs/plugin/image/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/folder.png -------------------------------------------------------------------------------- /docs/plugin/image/imagedes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/imagedes.png -------------------------------------------------------------------------------- /docs/plugin/image/ngui1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/ngui1.png -------------------------------------------------------------------------------- /docs/plugin/image/ngui2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/ngui2.png -------------------------------------------------------------------------------- /docs/plugin/image/ngui3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/ngui3.png -------------------------------------------------------------------------------- /docs/plugin/image/nguispriteframe1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/nguispriteframe1.png -------------------------------------------------------------------------------- /docs/plugin/image/nguispriteframe2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/nguispriteframe2.png -------------------------------------------------------------------------------- /docs/plugin/image/overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/overview.jpg -------------------------------------------------------------------------------- /docs/plugin/image/raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/raw.png -------------------------------------------------------------------------------- /docs/plugin/image/script0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script0.png -------------------------------------------------------------------------------- /docs/plugin/image/script1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script1.png -------------------------------------------------------------------------------- /docs/plugin/image/script10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script10.png -------------------------------------------------------------------------------- /docs/plugin/image/script11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script11.png -------------------------------------------------------------------------------- /docs/plugin/image/script12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script12.png -------------------------------------------------------------------------------- /docs/plugin/image/script13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script13.png -------------------------------------------------------------------------------- /docs/plugin/image/script2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script2.png -------------------------------------------------------------------------------- /docs/plugin/image/script3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script3.png -------------------------------------------------------------------------------- /docs/plugin/image/script4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script4.png -------------------------------------------------------------------------------- /docs/plugin/image/script5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script5.png -------------------------------------------------------------------------------- /docs/plugin/image/script6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script6.png -------------------------------------------------------------------------------- /docs/plugin/image/script7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script7.png -------------------------------------------------------------------------------- /docs/plugin/image/script8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script8.png -------------------------------------------------------------------------------- /docs/plugin/image/script9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/script9.png -------------------------------------------------------------------------------- /docs/plugin/image/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/sprite.png -------------------------------------------------------------------------------- /docs/plugin/image/spritescript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/spritescript.png -------------------------------------------------------------------------------- /docs/plugin/image/uguiwhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/uguiwhite.png -------------------------------------------------------------------------------- /docs/plugin/image/yl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/image/yl.png -------------------------------------------------------------------------------- /docs/plugin/install.md: -------------------------------------------------------------------------------- 1 | # 如何安装 2 | 下载转换工具的核心模块。 3 | [点我下载](https://dldir1.qq.com/WechatWebDev/plugins/BeefBallEngine-unitytool/1.0.0/UnityTool.unitypackage) 4 | 5 | 下载下来会是一个unitypackage,所以你马上就能想到你可以双击导入它。 6 | 7 | ![image.png](./image/11.png) 8 | 接下来你可以看到在你的unity菜单栏出现了新的导出能力,就说明你已经成功安装好了导出工具了 9 | 10 | 这时候选择扩展模块管理 11 | ![image.png](./image/12.png) 12 | 13 | 以下这个新弹出的面板,是下载扩展导出模块的地方,在这里你可以选择下载你需要的导出能力,如后文会提到的**NGUI导出能力**或是**代码导出能力**。 14 | 但这个时候我们暂不需要在这做任何事情。 15 | ![image.png](./image/13.png) 16 | 17 | ------------------------------------------------------------ 18 | 19 | 回到菜单里选择**导出**,会弹出资源导出面板,后续的资源导出都会通过这个面板完成。 20 | ![image.png](./image/14.png) 21 | 第一步你需要在这个面板里指定你的资源导出位置,你在这里可以选择快速创建一个引擎示例项目,将该项目作为你的导出路径。又或是你直接指定一个已存在的目录作为导出路径。 22 | ![image.png](./image/15.png) 23 | 24 | 选择好路径之后,就可以开始进行导出了。可以看到导出面板里会出现几种导出模式供你选择。 25 | ![image.png](./image/16.png) 26 | 27 | ------------------------------------------------------------ 28 | 29 | [下一节](./scene.md) 我们将会开始导出第一个场景 -------------------------------------------------------------------------------- /docs/plugin/material/image/myshader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/myshader.png -------------------------------------------------------------------------------- /docs/plugin/material/image/myshader_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/myshader_file.png -------------------------------------------------------------------------------- /docs/plugin/material/image/myshader_mat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/myshader_mat.png -------------------------------------------------------------------------------- /docs/plugin/material/image/parser_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/parser_file.png -------------------------------------------------------------------------------- /docs/plugin/material/image/standard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/standard.png -------------------------------------------------------------------------------- /docs/plugin/material/image/surface_shader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/surface_shader.png -------------------------------------------------------------------------------- /docs/plugin/material/image/unity_shader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/unity_shader.png -------------------------------------------------------------------------------- /docs/plugin/material/image/unlit_shader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/unlit_shader.png -------------------------------------------------------------------------------- /docs/plugin/material/image/wxbbshader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/docs/plugin/material/image/wxbbshader.png -------------------------------------------------------------------------------- /docs/plugin/material/index.md: -------------------------------------------------------------------------------- 1 | # 材质导出 2 | 3 | 微信小游戏性能优化方案里的材质资源(material)和Unity3D里的材质资源的设计理念比较一致,都是在选择了一个shader的基础上,设置该shader需要的参数(包括选择贴图)。 4 | ![image.png](./image/unity_shader.png) 5 | 6 | 但在微信方案里,与UnityShader这个概念对应概念叫effect。两者最不一样的地方是,由于渲染管线不一样,着色器代码的运行上会有差异,因此插件暂时没有办法完成Unity3D的shader到微信方案的effect的全自动转换。 7 | 8 | 所以如果要将Unity3D内的自定义材质导出至微信方案,要满足两点: 9 | 1. 在微信方案内,要有一个对应的effect能实现和在Unity3D里的shader一样的显示效果。 10 | 2. 在Unity3D导出插件里,要能将UnityShader所使用到的参数,也就是材质上的属性,转化成微信方案里的材质的属性。 11 | 目前导出插件主要提供了两条通路协助你完成这两项工作。 12 | 13 | ## 通过修改为使用导出插件自带Shader完成材质导出 14 | 15 | 导出插件里包含了一系列 `WXBBShader`为前缀的UnityShader,当你的场景/预制体(prefab)里包括的材质用到的是这些shader时,情况就会很简单。 16 | 17 | 导出插件会自动帮你将导出的mgepackage里的material,选择成对应的微信方案里的effect,比如当你在Unity3D里选择`WXBBShader/BlinnPhong`时,导出之后在微信方案里就会自动使用`@system/blinnPhongNew`。其渲染效果由微信方案团队保证,两侧应是一致的。 18 | ![image.png](./image/wxbbshader.png) 19 | 20 | 理论上目前大部分较为常规的渲染shader,都可以切换为`WXBBShader/BlinnPhong`或者`WXBBShader/Effect`等,再搭配调参等手段实现想要的效果。这样的物体可以非常容易地完成材质导出。 21 | 22 | ## 通过实现微信方案effect+编写导出插件MaterialParser完成材质导出 23 | 24 | 当你在Unity3D里使用的材质,引用的是你自己编写的shader,并且它们不能直接将所使用的Shader修改为导出插件自带Shader的时候。你可以通过以下两个步骤完成材质迁移: 25 | 26 | 1. 根据微信方案的官方文档,编写一个与你的UnityShader显示效果一致的[微信方案effect。](https://developers.weixin.qq.com/minigame/dev/game-engine/render/shading/effect.html) 27 | 2. [编写一个导出插件内的MaterialParser](./parser.md),使其在导出过程中能生成出带有合适属性的的微信方案material,且其使用的effect名字与你在微信方案里编写的effect名字相同。 28 | -------------------------------------------------------------------------------- /docs/plugin/material/parser.md: -------------------------------------------------------------------------------- 1 | # 自己实现MaterialParser 2 | 3 | ## 一个将Standard parse为@system/blinnPhongNew的例子 4 | 比如说场景里有一些材质使用了Unity *Standard* Shader。 5 | 我要将所有使用了*Standard*的材质在导出时替换成*WXBBShader/BlinnPhong*。 6 | 7 | 1. 在任意editor目录下下新建一个C# Script,起名MyMaterialParser(例)。 8 | 这个脚本主要是为了选择Effect,以及填充material参数。 9 | 10 | 11 | 12 | 2. 点开C#脚本编写代码: 13 | ```cs 14 | using System; 15 | using UnityEngine; 16 | 17 | namespace WeChat 18 | { 19 | [InitializeOnLoad] 20 | class MyMaterialParser : WXMaterialParser 21 | { 22 | 23 | static MyMaterialParser() 24 | { 25 | WXMaterial.registerParser("Standard", new MyMaterialParser()); 26 | } 27 | 28 | // 原样保留即可 29 | protected override void SetEffect(String effect) 30 | { 31 | m_mainJson.SetField("effect", effect); 32 | } 33 | 34 | // 主要进行代码编写的位置 35 | public override void onParse(WXMaterial wxbb_material) 36 | { 37 | Material material = m_material; 38 | 39 | // 将材质所使用的Effect指定成方案内置Effect 40 | // 如果你有自己写好的effect,则这里填入你写的effect的名字 41 | SetEffect("@system/blinnPhongNew"); 42 | 43 | // 导出Tiling和Offset参数 44 | Vector2 textureScale = material.GetTextureScale("_MainTex"); 45 | Vector2 textureOffset = material.GetTextureOffset("_MainTex"); 46 | AddShaderParam("_MainTex_ST", new float[4] { textureScale.x, textureScale.y, textureOffset.x, textureOffset.y }); 47 | 48 | // 导出Albedo贴图 49 | AddTexture("_MainTex", "_MainTex"); 50 | 51 | // 导出Smoothness 52 | AddShaderParam("_Shininess", material.GetFloat("_Glossiness")); 53 | } 54 | } 55 | 56 | } 57 | ``` 58 | 59 | 3. 清缓存后再次进行导出就会发现,材质的shader被替换成了*BlinnPhong*。 60 | -------------------------------------------------------------------------------- /docs/plugin/ngui-spriteframe.md: -------------------------------------------------------------------------------- 1 | # 导出NGUI spriteframe 2 | 选中NGUI Atlas Maker创建出来的prefab,点击导出ngui-prefab 3 | ![image.png](./image/nguispriteframe1.png) 4 | 5 | 6 | 可以看到导出的mgepackage里包含了这个atlas下的所有sprite,将该mgepackage导入微信方案,即可使用他们 7 | ![image.png](./image/nguispriteframe2.png) -------------------------------------------------------------------------------- /docs/plugin/ngui-tree.md: -------------------------------------------------------------------------------- 1 | # 导出NGUI节点树 2 | 3 | 当你拥有一个类似这样的NGUI场景时,你可以轻松地使用导出插件的NGUI导出能力,将其导出至微信方案内 4 | 5 | ![image.png](./image/ngui1.png) 6 | 7 | 8 | 首先将属于NGUI的部分拖成一个预制体 9 | 10 | ![image.png](./image/ngui2.png) 11 | 12 | 13 | 选择这个预制体,在导出窗口上选择导出NGUI-Tree 14 | 15 | ![image.png](./image/ngui3.png) 16 | 17 | 注意此时可以选择将其导出成微信方案的预制体,也可以选择导出成微信方案的场景 18 | 19 | 20 | 21 | 22 | 得到mgepackage后在微信开发者工具内导入即可 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------- 30 | 31 | 除了NGUI节点树之外,还有一个比较常见的需求就是导出NGUI的精灵图,以备有需要的时候加载并替换进游戏。 32 | 33 | [下一节](./ngui-spriteframe.md) 会给你介绍一下怎么做。 -------------------------------------------------------------------------------- /docs/plugin/prefab.md: -------------------------------------------------------------------------------- 1 | # 其它导出模式 2 | 3 | 除了导出当前场景之外,你其实可以在上节课的截图中看到还有一个**选中的prefab**的选项,这个就是导出插件提供的另一种`导出模式`。 4 | ![image.png](./image/31.png) 5 | 下面我们尝试一下导出一个prefab,解释一下`导出模式`为何物。 6 | 7 | ------------------------------------------------------------ 8 | 9 | 首先选中场景里的一个prefab,接下来你可以看到在导出面板中出现了**选中的prefab**选项。此时选择**导出**,在目标目录会生成一个与该prefab相关的mgepackage。 10 | ![image.png](./image/32.png) 11 | 12 | 以上就是另一个`导出模式`的使用方法。与之前上一节课导出场景不同,这节课我们导出了一个prefab。 13 | 14 | ------------------------------------------------------------ 15 | 16 | 除了**导出场景**和**导出prefab**两种`导出模式`,本导出插件还支持很多种其他的`导出模式`。 17 | 18 | 你可以回到第一节里提到的模块安装窗口里,安装其他导出模块。这将会提供给你更多的`导出模式`。 19 | ![image.png](./image/33.png) 20 | 21 | 比如安装NGUI导出模块后,那么当你项目里包含NGUI的资源的时候,你就可以选择把它导出成微信方案的2D场景和2D prefab。 22 | 23 | ------------------------------------------------------------ 24 | 25 | 接下来 26 | 如果你对美术资源的进阶导出知识有兴趣,参见[资源导出方案注意点](../basic/flow.md)。 27 | 如果你对代码导出有兴趣,参见[完整项目导出方案文档](../monobehavior/about.md)。 28 | -------------------------------------------------------------------------------- /docs/plugin/raw.md: -------------------------------------------------------------------------------- 1 | # 原始资源导出与使用 2 | 在游戏开发中,经常会遇到需要使用json配置、音频、视频等文件的情况。这种文件和游戏逻辑本身其实并没有强关联,因此本文将其称之为`原始资源` 3 | 4 | 由于微信小游戏性能优化方案有一套高智能的,根据游戏资源依赖关系进行加载的资源系统,这个资源系统能对游戏的资源进行统一的优化,但对于上述的文件,就需要使用`原始资源`的概念进行封装,才能通过资源系统加载。 5 | 6 | ## 原始资源的导出 7 | 如果你使用的不是[完整项目导出](../fullproject/flow.md),且希望这些配置文件能和你的游戏场景一起加载,那么你可以选择给任意GameObject添加 WX Raw Resource Collection这个组件,并将这些文件都挂载上去。 8 | ![image.png](./image/raw.png) 9 | 导出并导入到微信方案后,你就能从对应的游戏节点上,获取`RawResourceCollection`组件,就能得到这些资源 10 | 11 | 又或者你只是想导出这些文件过去,随后自己通过`loader.load`加载。那么只要你选择使用`导出选中资源`模式,就可以将这类文件导出成微信方案的`原始资源`,将其导入微信方案即可。 12 | 13 | ## 原始资源的使用 14 | 15 | 不管是通过`RawResourceCollection`得到,或者是直接使用`loader.load`加载,你最终得到的会是一个微信方案的`RawResource`实例。此时通过`rawResource.value`就能获取到你原本文件的内容。 16 | 17 | 其中,json配置、纯文本等会以字符串形式返回。音频、视频会以url形式返回,正好可以用于调用微信小游戏的音频、视频api。 -------------------------------------------------------------------------------- /docs/plugin/scene.md: -------------------------------------------------------------------------------- 1 | # 导出第一个场景 2 | 3 | 选中你unity项目里的一个场景,打开它 4 | ![image.png](./image/21.png) 5 | 6 | 可以看到图中场景里是一片紫红色,这是因为笔者选用的这个场景里,所有material都没有选中合适的Shader。 7 | 8 | 当然如果你现在打开的是自己的游戏工程,可能会是稍微正常的表现 9 | 10 | ------------------------------------------------------------ 11 | 12 | 但无论你的场景是否正常,都请你先框选这个场景用到的所有Material,并将其Shader设置为WXBBShader/BlinnPhong。 13 | > 为什么要这么做?由于Unity和微信方案在Shader上的不一致,你的Shader导出后无法直接在微信侧对应使用,但本插件提供的WXBBShader/BlinnPhong可以。你后续可以查看[材质导出](../basic/material/index.md)了解更多知识。 14 | > 理论上不是所有材质都可以改用BlinnPhong,但这里为了演示可以先粗暴处理。 15 | 16 | ![image.png](./image/22.png) 17 | 18 | 19 | 选择好之后,可以看到你的场景变成了这样 20 | ![image.png](./image/23.png) 21 | 22 | 23 | 这时候,点击导出面板,选中**导出当前场景**。再点击**导出**即可将当前Unity场景导出。你可以点击**打开**跳到文件夹目录查看导出结果。 24 | ![image.png](./image/25.png) 25 | 26 | 27 | 28 | 29 | 可以看到在目标目录生成了一个.mgepackage,这时候你就可以把这个mgepackage放入微信开发者工具里导入使用。 30 | ![image.png](./image/24.png) 31 | 32 | 33 | 导入微信开发者工具并预览,详细请参见[微信方案的官方文档](https://developers.weixin.qq.com/minigame/dev/game-engine/tutorial/daorumgepackageziyuan.html) 34 | ![image.png](./image/26.png) 35 | ![image.png](./image/27.png) 36 | ------------------------------------------------------------ 37 | 38 | 除了场景导出外,本导出插件还有很多种`导出模式`,协助你导出各种资源 39 | [下一节](./prefab.md) 将会简单介绍一下其它的`导出模式` 40 | -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/Effect.shader: -------------------------------------------------------------------------------- 1 | Shader "WXBBShader/Effect" { 2 | Properties { 3 | _MainTex("Main Texture", 2D) = "white" {} 4 | _MaskTex("Mask Texture", 2D) = "white" {} 5 | _Bright("Bright",Range(0, 10)) = 2.0 6 | _TintColor("Tint Color", Color) = (0.5,0.5,0.5,0.5) 7 | 8 | [HideInInspector] _ZWrite("ZWrite Value", Float) = 0.0 9 | [HideInInspector] _ZTest("Ztest Value", Float) = 4.0 10 | 11 | [HideInInspector] _Cutoff("Cutoff Value", Range(0.0, 1.0)) = 0.01 12 | [HideInInspector] _Cull ("Cull", Float) = 0.0 13 | 14 | [HideInInspector] _SrcBlend ("SrcBlend", Float) = 5.0 15 | [HideInInspector] _DstBlend ("DstBlend", Float) = 10.0 16 | 17 | [HideInInspector] _Mode ("Mode", Float) = 1.0 18 | [HideInInspector] _RenderQueue("Render Queue", Float) = 3000.0 19 | } 20 | SubShader { 21 | Tags {"RenderType"="Transparent" "Queue"="Transparent" "IgnoreProjector"="True" } 22 | Pass { 23 | Tags { "LightMode"="ForwardBase" } 24 | Blend [_SrcBlend] [_DstBlend] 25 | Cull Off 26 | ZWrite Off 27 | Lighting On 28 | ColorMask RGB 29 | 30 | 31 | CGPROGRAM 32 | 33 | #pragma vertex VertexProgram 34 | #pragma fragment FragmentProgram 35 | 36 | #pragma shader_feature ADDTIVEFOG 37 | #pragma multi_compile_fog 38 | 39 | #include "UnityCG.cginc" 40 | 41 | sampler2D _MainTex; 42 | sampler2D _MaskTex; 43 | float4 _MainTex_ST; 44 | float4 _TintColor; 45 | float _Bright; 46 | 47 | struct VertexInput { 48 | float4 pos : POSITION; 49 | float4 color : COLOR; 50 | float2 uv : TEXCOORD0; 51 | }; 52 | 53 | struct Interpolators { 54 | float4 pos : SV_POSITION; 55 | float4 color : COLOR; 56 | float2 uv : TEXCOORD0; 57 | UNITY_FOG_COORDS(1) 58 | }; 59 | 60 | Interpolators VertexProgram(VertexInput input) 61 | { 62 | Interpolators output; 63 | 64 | output.color = input.color; 65 | output.uv = TRANSFORM_TEX(input.uv, _MainTex); 66 | output.pos = UnityObjectToClipPos(input.pos); 67 | 68 | UNITY_TRANSFER_FOG(output, output.pos); 69 | return output; 70 | } 71 | 72 | fixed4 FragmentProgram(Interpolators input) : SV_Target 73 | { 74 | float4 color = input.color * tex2D(_MainTex, input.uv) * _Bright * _TintColor; 75 | 76 | half mask = tex2D(_MaskTex, input.uv).r; 77 | color.w = color.w * mask; 78 | 79 | #if ADDTIVEFOG 80 | UNITY_APPLY_FOG_COLOR(input.fogCoord, color, fixed4(0, 0, 0, 0)); 81 | #else 82 | UNITY_APPLY_FOG(input.fogCoord, color); 83 | #endif 84 | 85 | color = clamp(color, 0, 1); 86 | return color; 87 | } 88 | ENDCG 89 | } 90 | } 91 | CustomEditor "WeChat.EffectGUI" 92 | } 93 | -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/ForwardLit/light.hlsl: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __LIGHT_HLSL_ 3 | #define __LIGHT_HLSL_ 4 | 5 | struct Light{ 6 | half3 direction; 7 | half attenuation; 8 | }; 9 | 10 | // distance attenuation 11 | float distanceAttenuation(float distanceSqr, float2 distAtten) 12 | { 13 | float atten = rcp(distanceSqr); 14 | /* 15 | * 从80%Range开始smooth fade: 16 | * fadeDistance = (0.8 * 0.8 *rangeSqr) 17 | * smoothFactor = (rangeSqr - distanceSqr) / (rangeSqr - fadeDistance) 18 | * 简化为: 19 | * smoothFactor = d2 * (-1/(0.36*r2)) + 1/0.36 20 | * distAtten.x = -1/(0.36*r2), distAtten.y = 1/0.36 21 | */ 22 | float smoothFactor = saturate(distanceSqr * distAtten.x + distAtten.y); 23 | return atten * smoothFactor; 24 | } 25 | 26 | // angle attenuation 27 | float angleAttenuation(float3 spotDir, float3 lightDir, half2 spotAtten) 28 | { 29 | /* 30 | * 线性spot atten: (SdotL - cosOutAngle)/(cosInnerAngle - cosOutAngle) 31 | * spotAtten.x = 1/(cosInnerAngle - cosOuterAngle) 32 | * spotAtten.y = (-cosOuterAngle * spotAtten.x) 33 | * 点光源 spotAtten.x = (0, 1) return 1; 34 | */ 35 | half sol = dot(spotDir, lightDir); 36 | half atten = saturate(sol * spotAtten.x + spotAtten.y); 37 | return atten * atten; 38 | } 39 | 40 | Light GetAdditionalLight(float4 posWorld){ 41 | 42 | Light light; 43 | #ifdef USING_DIRECTIONAL_LIGHT 44 | light.attenuation = 1.0; 45 | light.direction = _WorldSpaceLightPos0.xyz; 46 | #else 47 | float3 lightPosWS = _WorldSpaceLightPos0.xyz; 48 | float3 lightVec = lightPosWS - posWorld.xyz; 49 | float distanceSqr = max(dot(lightVec, lightVec), HALF_MIN); 50 | 51 | half3 lightDirection = half3(lightVec * rsqrt(distanceSqr)); 52 | half4 distanceAndSpotAtten = float4(0, 2.8, 0, 1); 53 | 54 | // trick get light range 55 | float4 lightCoord=mul(unity_WorldToLight, float4(posWorld.xyz, 1)); 56 | float range = length(lightVec) / length(lightCoord.xyz); 57 | 58 | distanceAndSpotAtten.x = -2.8 /(range * range); 59 | float atten = distanceAttenuation(distanceSqr, distanceAndSpotAtten.xy); 60 | 61 | #if defined(SPOT) 62 | // trick get spot angle 63 | float cotanHalfSpotAngle = 2. * lightCoord.z / lightCoord.w; 64 | float outSpotAngle = atan(1/cotanHalfSpotAngle); 65 | float innerSpotAngle = outSpotAngle * 0.8; 66 | float cosInner = cos(innerSpotAngle); 67 | float cosOuter = cos(outSpotAngle); 68 | distanceAndSpotAtten.z = 1/(cosInner - cosOuter); 69 | distanceAndSpotAtten.w = -(cosOuter * distanceAndSpotAtten.z); 70 | // trick get spot direction 71 | float3 spotDirection = normalize(mul(float3(0,0,-1), (float3x3)unity_WorldToLight)); 72 | atten = atten * angleAttenuation(spotDirection, lightDirection, distanceAndSpotAtten.zw); 73 | #endif 74 | light.direction = lightDirection; 75 | light.attenuation = atten; 76 | #endif 77 | 78 | return light; 79 | } 80 | 81 | #endif // __LIGHT_HLSL_ -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/ForwardLit/math.hlsl: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __MATH_HLSL_ 3 | #define __MATH_HLSL_ 4 | 5 | #define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number 6 | #define HALF_MIN 6.103515625e-5 7 | #define kDieletricSpec half4(0.04, 0.04, 0.04, 1.0 - 0.04) 8 | 9 | #define PositivePow(a,b) pow(a,b) 10 | 11 | fixed3 TransformTangentToWorld(fixed3 vectorTS, fixed3x3 tangentToWorld) 12 | { 13 | return mul(vectorTS, tangentToWorld); 14 | } 15 | 16 | half3 SafeNormalize(half3 inVec) 17 | { 18 | half3 dp3 = max(HALF_MIN, dot(inVec, inVec)); 19 | return inVec * rsqrt(dp3); 20 | } 21 | 22 | float pow5( float x ) 23 | { 24 | float xx = x*x; 25 | return xx * xx * x; 26 | } 27 | 28 | half pow4(half x){ 29 | half xx = x*x; 30 | return xx*xx; 31 | } 32 | 33 | #endif//__MATH_H_ -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/Line.shader: -------------------------------------------------------------------------------- 1 | Shader "WXBBShader/Line" { 2 | Properties { 3 | _MainTex("Main Texture", 2D) = "white" {} 4 | _MaskTex("Mask Texture", 2D) = "white" {} 5 | _Bright("Bright",Range(0, 10)) = 2.0 6 | _TintColor("Tint Color", Color) = (0.5,0.5,0.5,0.5) 7 | 8 | [HideInInspector] _ZWrite("ZWrite Value", Float) = 0.0 9 | [HideInInspector] _ZTest("Ztest Value", Float) = 4.0 10 | 11 | [HideInInspector] _Cutoff("Cutoff Value", Range(0.0, 1.0)) = 0.01 12 | [HideInInspector] _Cull ("Cull", Float) = 0.0 13 | 14 | [HideInInspector] _SrcBlend ("SrcBlend", Float) = 5.0 15 | [HideInInspector] _DstBlend ("DstBlend", Float) = 10.0 16 | 17 | [HideInInspector] _Mode ("Mode", Float) = 1.0 18 | [HideInInspector] _RenderQueue("Render Queue", Float) = 3000.0 19 | } 20 | SubShader { 21 | Tags {"RenderType"="Transparent" "Queue"="Transparent" "IgnoreProjector"="True" } 22 | Pass { 23 | Tags { "LightMode"="ForwardBase" } 24 | Blend [_SrcBlend] [_DstBlend] 25 | Cull Off 26 | ZWrite Off 27 | Lighting On 28 | ColorMask RGB 29 | 30 | 31 | CGPROGRAM 32 | 33 | #pragma vertex VertexProgram 34 | #pragma fragment FragmentProgram 35 | 36 | #pragma shader_feature ADDTIVEFOG 37 | #pragma multi_compile_fog 38 | 39 | #include "UnityCG.cginc" 40 | 41 | sampler2D _MainTex; 42 | sampler2D _MaskTex; 43 | float4 _MainTex_ST; 44 | float4 _TintColor; 45 | float _Bright; 46 | 47 | struct VertexInput { 48 | float4 pos : POSITION; 49 | float4 color : COLOR; 50 | float2 uv : TEXCOORD0; 51 | }; 52 | 53 | struct Interpolators { 54 | float4 pos : SV_POSITION; 55 | float4 color : COLOR; 56 | float2 uv : TEXCOORD0; 57 | UNITY_FOG_COORDS(1) 58 | }; 59 | 60 | Interpolators VertexProgram(VertexInput input) 61 | { 62 | Interpolators output; 63 | 64 | output.color = input.color; 65 | output.uv = TRANSFORM_TEX(input.uv, _MainTex); 66 | output.pos = UnityObjectToClipPos(input.pos); 67 | 68 | UNITY_TRANSFER_FOG(output, output.pos); 69 | return output; 70 | } 71 | 72 | fixed4 FragmentProgram(Interpolators input) : SV_Target 73 | { 74 | float4 color = input.color * tex2D(_MainTex, input.uv) * _Bright * _TintColor; 75 | 76 | half mask = tex2D(_MaskTex, input.uv).r; 77 | color.w = color.w * mask; 78 | 79 | #if ADDTIVEFOG 80 | UNITY_APPLY_FOG_COLOR(input.fogCoord, color, fixed4(0, 0, 0, 0)); 81 | #else 82 | UNITY_APPLY_FOG(input.fogCoord, color); 83 | #endif 84 | 85 | color = clamp(color, 0, 1); 86 | return color; 87 | } 88 | ENDCG 89 | } 90 | } 91 | CustomEditor "WeChat.LineGUI" 92 | } 93 | -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/Particle.shader: -------------------------------------------------------------------------------- 1 | Shader "WXBBShader/ShurikenParticle" { 2 | Properties { 3 | _MainTex("Main Texture", 2D) = "white" {} 4 | _MaskTex("Mask Texture", 2D) = "white" {} 5 | _Bright("Bright",Range(0, 10)) = 2.0 6 | _TintColor("Tint Color", Color) = (0.5,0.5,0.5,0.5) 7 | 8 | [HideInInspector] _ZWrite("ZWrite Value", Float) = 0.0 9 | [HideInInspector] _ZTest("Ztest Value", Float) = 4.0 10 | 11 | [HideInInspector] _Cutoff("Cutoff Value", Range(0.0, 1.0)) = 0.01 12 | [HideInInspector] _Cull ("Cull", Float) = 0.0 13 | 14 | [HideInInspector] _Mode ("Mode", Float) = 1.0 15 | [HideInInspector] _RenderQueue("Render Queue", Float) = 3000.0 16 | 17 | [HideInInspector] _SrcBlend ("SrcBlend", Float) = 5.0 18 | [HideInInspector] _DstBlend ("DstBlend", Float) = 10.0 19 | } 20 | SubShader { 21 | Tags {"RenderType"="Transparent" "Queue"="Transparent" "IgnoreProjector"="True" } 22 | Pass { 23 | Tags { "LightMode"="ForwardBase" } 24 | Blend [_SrcBlend] [_DstBlend] 25 | Cull Off 26 | ZWrite Off 27 | Lighting On 28 | ColorMask RGB 29 | 30 | 31 | CGPROGRAM 32 | 33 | #pragma vertex VertexProgram 34 | #pragma fragment FragmentProgram 35 | 36 | #pragma shader_feature ADDTIVEFOG 37 | #pragma multi_compile_fog 38 | 39 | #include "UnityCG.cginc" 40 | 41 | sampler2D _MainTex; 42 | sampler2D _MaskTex; 43 | float4 _MainTex_ST; 44 | float4 _TintColor; 45 | float _Bright; 46 | 47 | struct VertexInput { 48 | float4 pos : POSITION; 49 | float4 color : COLOR; 50 | float2 uv : TEXCOORD0; 51 | }; 52 | 53 | struct Interpolators { 54 | float4 pos : SV_POSITION; 55 | float4 color : COLOR; 56 | float2 uv : TEXCOORD0; 57 | UNITY_FOG_COORDS(1) 58 | }; 59 | 60 | Interpolators VertexProgram(VertexInput input) 61 | { 62 | Interpolators output; 63 | 64 | output.color = input.color; 65 | output.uv = TRANSFORM_TEX(input.uv, _MainTex); 66 | output.pos = UnityObjectToClipPos(input.pos); 67 | 68 | UNITY_TRANSFER_FOG(output, output.pos); 69 | return output; 70 | } 71 | 72 | fixed4 FragmentProgram(Interpolators input) : SV_Target 73 | { 74 | float4 color = input.color * tex2D(_MainTex, input.uv) * _Bright * _TintColor; 75 | 76 | half mask = tex2D(_MaskTex, input.uv).r; 77 | color.w = color.w * mask; 78 | 79 | #if ADDTIVEFOG 80 | UNITY_APPLY_FOG_COLOR(input.fogCoord, color, fixed4(0, 0, 0, 0)); 81 | #else 82 | UNITY_APPLY_FOG(input.fogCoord, color); 83 | #endif 84 | 85 | color = clamp(color, 0, 1); 86 | return color; 87 | } 88 | ENDCG 89 | } 90 | } 91 | CustomEditor "WeChat.EffectGUI" 92 | } 93 | -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/PostProcess/Bloom.shader: -------------------------------------------------------------------------------- 1 | Shader "WXPostProcess/Bloom" { 2 | Properties { 3 | _MainTex ("Texture", 2D) = "white" {} 4 | } 5 | 6 | CGINCLUDE 7 | #include "UnityCG.cginc" 8 | 9 | sampler2D _MainTex, _SourceTex; 10 | float4 _MainTex_TexelSize; 11 | 12 | half4 _Filter; 13 | 14 | half _Intensity; 15 | 16 | struct VertexData { 17 | float4 vertex : POSITION; 18 | float2 uv : TEXCOORD0; 19 | }; 20 | 21 | struct Interpolators { 22 | float4 pos : SV_POSITION; 23 | float2 uv : TEXCOORD0; 24 | }; 25 | 26 | Interpolators VertexProgram (VertexData v) { 27 | Interpolators i; 28 | i.pos = UnityObjectToClipPos(v.vertex); 29 | i.uv = v.uv; 30 | return i; 31 | } 32 | 33 | half3 Sample (float2 uv) { 34 | return tex2D(_MainTex, uv).rgb; 35 | } 36 | 37 | half3 SampleBox (float2 uv, float delta) { 38 | float4 o = _MainTex_TexelSize.xyxy * float2(-delta, delta).xxyy; 39 | half3 s = 40 | Sample(uv + o.xy) + Sample(uv + o.zy) + 41 | Sample(uv + o.xw) + Sample(uv + o.zw); 42 | return s * 0.25f; 43 | } 44 | 45 | half3 Prefilter (half3 c) { 46 | half brightness = max(c.r, max(c.g, c.b)); 47 | half soft = brightness - _Filter.y; 48 | soft = clamp(soft, 0, _Filter.z); 49 | soft = soft * soft * _Filter.w; 50 | half contribution = max(soft, brightness - _Filter.x); 51 | contribution /= max(brightness, 0.00001); 52 | return c * contribution; 53 | } 54 | 55 | ENDCG 56 | 57 | SubShader { 58 | Cull Off 59 | ZTest Always 60 | ZWrite Off 61 | 62 | Pass { // 0 63 | CGPROGRAM 64 | #pragma vertex VertexProgram 65 | #pragma fragment FragmentProgram 66 | 67 | half4 FragmentProgram (Interpolators i) : SV_Target { 68 | //return half4(0, 0, 0, 1); 69 | //return half4(Prefilter(SampleBox(i.uv, 1)), 1); 70 | return half4(Prefilter(Sample(i.uv)), 1); 71 | } 72 | ENDCG 73 | } 74 | 75 | Pass { // 1 76 | CGPROGRAM 77 | #pragma vertex VertexProgram 78 | #pragma fragment FragmentProgram 79 | 80 | half4 FragmentProgram (Interpolators i) : SV_Target { 81 | return half4(SampleBox(i.uv, 1), 1); 82 | } 83 | ENDCG 84 | } 85 | 86 | Pass { // 2 87 | Blend One One 88 | 89 | CGPROGRAM 90 | #pragma vertex VertexProgram 91 | #pragma fragment FragmentProgram 92 | 93 | half4 FragmentProgram (Interpolators i) : SV_Target { 94 | return half4(SampleBox(i.uv, 0.5), 1); 95 | } 96 | ENDCG 97 | } 98 | 99 | Pass { // 3 100 | CGPROGRAM 101 | #pragma vertex VertexProgram 102 | #pragma fragment FragmentProgram 103 | 104 | half4 FragmentProgram (Interpolators i) : SV_Target { 105 | half4 c = tex2D(_SourceTex, i.uv); 106 | c.rgb += _Intensity * SampleBox(i.uv, 0.5); 107 | return c; 108 | } 109 | ENDCG 110 | } 111 | 112 | Pass { // 4 113 | CGPROGRAM 114 | #pragma vertex VertexProgram 115 | #pragma fragment FragmentProgram 116 | 117 | half4 FragmentProgram (Interpolators i) : SV_Target { 118 | return half4(_Intensity * SampleBox(i.uv, 0.5), 1); 119 | } 120 | ENDCG 121 | } 122 | 123 | // For Test 124 | Pass { 125 | CGPROGRAM 126 | #pragma vertex VertexProgram 127 | #pragma fragment FragmentProgram 128 | 129 | half4 FragmentProgram (Interpolators i) : SV_Target { 130 | return half4(Sample(i.uv) - 1, 1); 131 | } 132 | ENDCG 133 | } 134 | } 135 | } -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/Skybox.shader: -------------------------------------------------------------------------------- 1 | 2 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 3 | 4 | Shader "WXBBShader/Skybox" { 5 | Properties{ 6 | _TintColor("_TintColor", Color) = (.5, .5, .5, .5) 7 | [Gamma] _Exposure("_Exposure", Range(0, 8)) = 1.0 8 | _Rotation("_Rotation", Range(0, 360)) = 0 9 | [NoScaleOffset] _Tex("_MainTex", Cube) = "" {} 10 | } 11 | 12 | SubShader{ 13 | Tags { "Queue" = "Background" "RenderType" = "Background" "PreviewType" = "Skybox" } 14 | Cull Off ZWrite Off 15 | 16 | Pass { 17 | 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | #pragma target 2.0 22 | 23 | #include "UnityCG.cginc" 24 | 25 | samplerCUBE _Tex; 26 | half4 _Tex_HDR; 27 | half4 _TintColor; 28 | half _Exposure; 29 | float _Rotation; 30 | 31 | float3 RotateAroundYInDegrees(float3 vertex, float degrees) 32 | { 33 | float alpha = degrees * UNITY_PI / 180.0; 34 | float sina, cosa; 35 | sincos(alpha, sina, cosa); 36 | float2x2 m = float2x2(cosa, -sina, sina, cosa); 37 | return float3(mul(m, vertex.xz), vertex.y).xzy; 38 | } 39 | 40 | struct appdata_t { 41 | float4 vertex : POSITION; 42 | UNITY_VERTEX_INPUT_INSTANCE_ID 43 | }; 44 | 45 | struct v2f { 46 | float4 vertex : SV_POSITION; 47 | float3 texcoord : TEXCOORD0; 48 | UNITY_VERTEX_OUTPUT_STEREO 49 | }; 50 | 51 | v2f vert(appdata_t v) 52 | { 53 | v2f o; 54 | UNITY_SETUP_INSTANCE_ID(v); 55 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); 56 | float3 rotated = RotateAroundYInDegrees(v.vertex, _Rotation); 57 | o.vertex = UnityObjectToClipPos(rotated); 58 | o.texcoord = v.vertex.xyz; 59 | return o; 60 | } 61 | 62 | fixed4 frag(v2f i) : SV_Target 63 | { 64 | half4 tex = texCUBE(_Tex, i.texcoord); 65 | half3 c = DecodeHDR(tex, _Tex_HDR); 66 | c = c * _TintColor.rgb * unity_ColorSpaceDouble.rgb; 67 | c *= _Exposure; 68 | return half4(c, 1); 69 | } 70 | ENDCG 71 | } 72 | } 73 | 74 | 75 | Fallback Off 76 | 77 | } -------------------------------------------------------------------------------- /unity-plugin/core/Common/Shaders/Trail.shader: -------------------------------------------------------------------------------- 1 | Shader "WXBBShader/Trail" { 2 | Properties { 3 | _MainTex("Main Texture", 2D) = "white" {} 4 | _MaskTex("Mask Texture", 2D) = "white" {} 5 | _Bright("Bright",Range(0, 10)) = 2.0 6 | _TintColor("Tint Color", Color) = (0.5,0.5,0.5,0.5) 7 | 8 | [HideInInspector] _ZWrite("ZWrite Value", Float) = 0.0 9 | [HideInInspector] _ZTest("Ztest Value", Float) = 4.0 10 | 11 | [HideInInspector] _Cutoff("Cutoff Value", Range(0.0, 1.0)) = 0.01 12 | [HideInInspector] _Cull ("Cull", Float) = 0.0 13 | 14 | [HideInInspector] _Mode ("Mode", Float) = 1.0 15 | [HideInInspector] _RenderQueue("Render Queue", Float) = 3000.0 16 | 17 | [HideInInspector] _SrcBlend ("SrcBlend", Float) = 5.0 18 | [HideInInspector] _DstBlend ("DstBlend", Float) = 10.0 19 | } 20 | SubShader { 21 | Tags {"RenderType"="Transparent" "Queue"="Transparent" "IgnoreProjector"="True" } 22 | Pass { 23 | Tags { "LightMode"="ForwardBase" } 24 | Blend [_SrcBlend] [_DstBlend] 25 | Cull Off 26 | ZWrite Off 27 | Lighting On 28 | ColorMask RGB 29 | 30 | 31 | CGPROGRAM 32 | 33 | #pragma vertex VertexProgram 34 | #pragma fragment FragmentProgram 35 | 36 | #pragma shader_feature ADDTIVEFOG 37 | #pragma multi_compile_fog 38 | 39 | #include "UnityCG.cginc" 40 | 41 | sampler2D _MainTex; 42 | sampler2D _MaskTex; 43 | float4 _MainTex_ST; 44 | float4 _TintColor; 45 | float _Bright; 46 | 47 | struct VertexInput { 48 | float4 pos : POSITION; 49 | float4 color : COLOR; 50 | float2 uv : TEXCOORD0; 51 | }; 52 | 53 | struct Interpolators { 54 | float4 pos : SV_POSITION; 55 | float4 color : COLOR; 56 | float2 uv : TEXCOORD0; 57 | UNITY_FOG_COORDS(1) 58 | }; 59 | 60 | Interpolators VertexProgram(VertexInput input) 61 | { 62 | Interpolators output; 63 | 64 | output.color = input.color; 65 | output.uv = TRANSFORM_TEX(input.uv, _MainTex); 66 | output.pos = UnityObjectToClipPos(input.pos); 67 | 68 | UNITY_TRANSFER_FOG(output, output.pos); 69 | return output; 70 | } 71 | 72 | fixed4 FragmentProgram(Interpolators input) : SV_Target 73 | { 74 | float4 color = input.color * tex2D(_MainTex, input.uv) * _Bright * _TintColor; 75 | 76 | half mask = tex2D(_MaskTex, input.uv).r; 77 | color.w = color.w * mask; 78 | 79 | #if ADDTIVEFOG 80 | UNITY_APPLY_FOG_COLOR(input.fogCoord, color, fixed4(0, 0, 0, 0)); 81 | #else 82 | UNITY_APPLY_FOG(input.fogCoord, color); 83 | #endif 84 | 85 | color = clamp(color, 0, 1); 86 | return color; 87 | } 88 | ENDCG 89 | } 90 | } 91 | CustomEditor "WeChat.EffectGUI" 92 | } 93 | -------------------------------------------------------------------------------- /unity-plugin/core/Common/Tools/Model_Mac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/unity-plugin/core/Common/Tools/Model_Mac -------------------------------------------------------------------------------- /unity-plugin/core/Common/Tools/model.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/unity-plugin/core/Common/Tools/model.exe -------------------------------------------------------------------------------- /unity-plugin/core/editor/WXConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using UnityEditor; 6 | using UnityEngine; 7 | 8 | namespace WeChat { 9 | 10 | public enum OSVersion { 11 | Windows = 0, 12 | MacOS, 13 | } 14 | 15 | public class WXConfig { 16 | 17 | public static DirectoryStructure commons; 18 | public static string moduleCDNPrefix = "https://dldir1.qq.com/WechatWebDev/plugins/BeefBallEngine-unitytool/"; 19 | 20 | public static OSVersion GetOperateSystem () { 21 | OSVersion version = (Application.platform == RuntimePlatform.WindowsEditor) ? OSVersion.Windows : OSVersion.MacOS; 22 | return version; 23 | } 24 | 25 | public static string GetModelToolPath () { 26 | 27 | string toolDir = ""; 28 | WXConfig.commons = DirectoryBuilder.RegisterDirectory("commons", new DirectoryStructure("Common")); 29 | if (Application.platform == RuntimePlatform.WindowsEditor) { 30 | toolDir = commons["Tools"].GetFilePath ("model.exe"); 31 | } else if (Application.platform == RuntimePlatform.OSXEditor) { 32 | toolDir = commons["Tools"].GetFilePath ("Model_Mac"); 33 | } 34 | return toolDir; 35 | } 36 | 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/customMaterialParser/CustomMaterialParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using WeChat; 5 | namespace WeChat { 6 | [InitializeOnLoad] 7 | internal class CustomMaterialParser : WXMaterialParser 8 | 9 | { 10 | static CustomMaterialParser () { 11 | WXMaterial.registerParser ("CustomShader", new CustomMaterialParser ()); 12 | } 13 | 14 | public override void onParse (WXMaterial wxbb_material) { 15 | 16 | Material material = this.m_material; 17 | 18 | // 生成shader模板 19 | Shader shader = m_material.shader; 20 | WXEffect wxbb_effect = new WXEffect (shader); 21 | this.dependenciesAdder (wxbb_effect); 22 | 23 | if (shader == null) { 24 | Debug.LogErrorFormat ("材质{0}缺少自定义shader", material.name); 25 | return; 26 | } 27 | 28 | // 指定shader名字 29 | SetEffect (wxbb_effect.Export (null)); 30 | 31 | for (int i = 0; i < ShaderUtil.GetPropertyCount (shader); i++) { 32 | string name = ShaderUtil.GetPropertyName (shader, i); 33 | ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType (shader, i); 34 | switch (type) { 35 | case ShaderUtil.ShaderPropertyType.Float: 36 | case ShaderUtil.ShaderPropertyType.Range: 37 | AddShaderParam (name, material.GetFloat (name)); 38 | break; 39 | case ShaderUtil.ShaderPropertyType.Vector: 40 | Vector4 v = material.GetVector (name); 41 | AddShaderParam (name, new float[] { v.x, v.y, v.z, v.w }); 42 | break; 43 | case ShaderUtil.ShaderPropertyType.Color: 44 | AddShaderParam (name, material.GetColor (name), true); 45 | break; 46 | case ShaderUtil.ShaderPropertyType.TexEnv: 47 | AddTexture (name, name); 48 | Vector4 st = material.GetVector (name + "_ST"); 49 | AddShaderParam (name + "_ST", new float[] { st.x, st.y, st.z, st.w }); 50 | break; 51 | } 52 | } 53 | } 54 | 55 | protected override void SetEffect (String effect) { 56 | m_mainJson.SetField ("effect", effect); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/lib/UnityUtil.cs: -------------------------------------------------------------------------------- 1 | namespace WeChat 2 | { 3 | /** 4 | * 工具函数 5 | */ 6 | public class UnityUtil 7 | { 8 | private static bool IsInMacOS 9 | { 10 | get 11 | { 12 | return UnityEngine.SystemInfo.operatingSystem.IndexOf("Mac OS") != -1; 13 | } 14 | } 15 | 16 | private static bool IsInWinOS 17 | { 18 | get 19 | { 20 | return UnityEngine.SystemInfo.operatingSystem.IndexOf("Windows") != -1; 21 | } 22 | } 23 | 24 | private static void OpenInMac(string path) 25 | { 26 | bool openInsidesOfFolder = false; 27 | 28 | // try mac 29 | string macPath = path.Replace("\\", "/"); // mac finder doesn't like backward slashes 30 | 31 | if (System.IO.Directory.Exists(macPath)) // if path requested is a folder, automatically open insides of that folder 32 | { 33 | openInsidesOfFolder = true; 34 | } 35 | 36 | if (!macPath.StartsWith("\"")) 37 | { 38 | macPath = "\"" + macPath; 39 | } 40 | 41 | if (!macPath.EndsWith("\"")) 42 | { 43 | macPath = macPath + "\""; 44 | } 45 | 46 | string arguments = (openInsidesOfFolder ? "" : "-R ") + macPath; 47 | 48 | try 49 | { 50 | System.Diagnostics.Process.Start("open", arguments); 51 | } 52 | catch (System.ComponentModel.Win32Exception e) 53 | { 54 | // tried to open mac finder in windows 55 | // just silently skip error 56 | // we currently have no platform define for the current OS we are in, so we resort to this 57 | e.HelpLink = ""; // do anything with this variable to silence warning about not using it 58 | } 59 | } 60 | 61 | private static void OpenInWin(string path) 62 | { 63 | bool openInsidesOfFolder = false; 64 | 65 | // try windows 66 | string winPath = path.Replace("/", "\\"); // windows explorer doesn't like forward slashes 67 | 68 | if (System.IO.Directory.Exists(winPath)) // if path requested is a folder, automatically open insides of that folder 69 | { 70 | openInsidesOfFolder = true; 71 | } 72 | 73 | try 74 | { 75 | System.Diagnostics.Process.Start("explorer.exe", (openInsidesOfFolder ? "/root," : "/select,") + winPath); 76 | } 77 | catch (System.ComponentModel.Win32Exception e) 78 | { 79 | // tried to open win explorer in mac 80 | // just silently skip error 81 | // we currently have no platform define for the current OS we are in, so we resort to this 82 | e.HelpLink = ""; // do anything with this variable to silence warning about not using it 83 | } 84 | } 85 | 86 | public static void ShowInExplorer(string path) 87 | { 88 | if (IsInWinOS) 89 | { 90 | OpenInWin(path); 91 | } 92 | else if (IsInMacOS) 93 | { 94 | OpenInMac(path); 95 | } 96 | else // couldn't determine OS 97 | { 98 | OpenInWin(path); 99 | OpenInMac(path); 100 | } 101 | } 102 | 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Component/WXCharactorController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEditor; 7 | using UnityEditor.Animations; 8 | using UnityEngine; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXCharactorController : WXComponent 14 | { 15 | private float slopeLimit; 16 | private float stepOffset; 17 | private float skinWidth; 18 | private float minMoveDistance; 19 | private Vector3 center; 20 | private float radius; 21 | private float height; 22 | 23 | 24 | public override string getTypeName() 25 | { 26 | return "CharacterController"; 27 | } 28 | 29 | public WXCharactorController(float slopeLimit, float stepOffset, float skinWidth, float minMoveDistane, Vector3 center, float radius, float height) 30 | { 31 | this.slopeLimit = slopeLimit; 32 | this.stepOffset = stepOffset; 33 | this.skinWidth = skinWidth; 34 | this.minMoveDistance = minMoveDistane; 35 | this.center = center; 36 | this.radius = radius; 37 | this.height = height; 38 | 39 | } 40 | 41 | protected override JSONObject ToJSON(WXHierarchyContext context) 42 | { 43 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 44 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 45 | json.AddField("type", getTypeName()); 46 | json.AddField("data", data); 47 | data.AddField("active", true); 48 | 49 | { 50 | data.AddField("slopeLimit", this.slopeLimit); 51 | data.AddField("stepOffet", this.stepOffset); 52 | data.AddField("skinWidth", this.skinWidth); 53 | data.AddField("minMoveDistane", this.minMoveDistance); 54 | 55 | JSONObject center = new JSONObject(JSONObject.Type.ARRAY); 56 | center.Add(-this.center.x); 57 | center.Add(this.center.y); 58 | center.Add(this.center.z); 59 | data.AddField("center", center); 60 | 61 | data.AddField("radius", this.radius); 62 | data.AddField("height", this.height); 63 | } 64 | 65 | return json; 66 | } 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Component/WXEngineBoxCollider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEditor; 7 | using UnityEditor.Animations; 8 | using UnityEngine; 9 | 10 | namespace WeChat { 11 | 12 | public class WXBoxCollider : WXComponent { 13 | 14 | private Vector3 center; 15 | private Vector3 size; 16 | private Boolean isTrigger; 17 | PhysicMaterial material; 18 | 19 | public override string getTypeName () { 20 | return "BoxCollider"; 21 | } 22 | 23 | public WXBoxCollider (Vector3 center, Vector3 size, bool isTrigger, PhysicMaterial material) { 24 | this.center = center; 25 | this.size = size; 26 | this.isTrigger = isTrigger; 27 | this.material = material; 28 | } 29 | 30 | protected override JSONObject ToJSON (WXHierarchyContext context) { 31 | JSONObject json = new JSONObject (JSONObject.Type.OBJECT); 32 | JSONObject data = new JSONObject (JSONObject.Type.OBJECT); 33 | json.AddField ("type", getTypeName ()); 34 | json.AddField ("data", data); 35 | data.AddField ("active", true); 36 | 37 | data.AddField ("isTrigger", this.isTrigger); 38 | if (material != null) { 39 | WXPhysicsMaterial materialConverter = new WXPhysicsMaterial (material); 40 | string materialPath = materialConverter.Export (context.preset); 41 | if (materialPath != null && materialPath != "") { 42 | data.AddField ("material", materialPath); 43 | context.AddResource (materialPath); 44 | } 45 | } 46 | 47 | JSONObject center = new JSONObject (JSONObject.Type.ARRAY); 48 | center.Add (-this.center.x); 49 | center.Add (this.center.y); 50 | center.Add (this.center.z); 51 | data.AddField ("center", center); 52 | 53 | JSONObject size = new JSONObject (JSONObject.Type.ARRAY); 54 | size.Add (this.size.x); 55 | size.Add (this.size.y); 56 | size.Add (this.size.z); 57 | data.AddField ("size", size); 58 | 59 | return json; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Component/WXEngineCapsuleCollider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEditor; 7 | using UnityEditor.Animations; 8 | using UnityEngine; 9 | 10 | namespace WeChat { 11 | 12 | public class WXCapsuleCollider : WXComponent { 13 | private Boolean isTrigger; 14 | private PhysicMaterial material; 15 | private Vector3 center; 16 | private float radius; 17 | private float height; 18 | private int direction; 19 | 20 | public override string getTypeName () { 21 | return "CapsuleCollider"; 22 | } 23 | 24 | public WXCapsuleCollider (Boolean isTrigger, PhysicMaterial material, Vector3 center, float radius, float height, int dir) { 25 | this.isTrigger = isTrigger; 26 | this.material = material; 27 | this.center = center; 28 | this.radius = radius; 29 | this.height = height; 30 | this.direction = dir; 31 | } 32 | 33 | protected override JSONObject ToJSON (WXHierarchyContext context) { 34 | JSONObject json = new JSONObject (JSONObject.Type.OBJECT); 35 | JSONObject data = new JSONObject (JSONObject.Type.OBJECT); 36 | json.AddField ("type", getTypeName ()); 37 | json.AddField ("data", data); 38 | data.AddField ("active", true); 39 | 40 | { 41 | data.AddField ("isTrigger", this.isTrigger); 42 | if (material != null) { 43 | WXPhysicsMaterial materialConverter = new WXPhysicsMaterial (this.material); 44 | string materialPath = materialConverter.Export (context.preset); 45 | if (materialPath != null && materialPath != "") { 46 | data.AddField ("material", materialPath); 47 | context.AddResource (materialPath); 48 | } 49 | } 50 | 51 | JSONObject center = new JSONObject (JSONObject.Type.ARRAY); 52 | center.Add (-this.center.x); 53 | center.Add (this.center.y); 54 | center.Add (this.center.z); 55 | data.AddField ("center", center); 56 | 57 | data.AddField ("radius", this.radius); 58 | data.AddField ("height", this.height); 59 | data.AddField ("direction", this.direction); 60 | } 61 | 62 | return json; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Component/WXEngineMeshCollider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEditor; 7 | using UnityEditor.Animations; 8 | using UnityEngine; 9 | 10 | namespace WeChat { 11 | 12 | public class WXMeshCollider : WXComponent { 13 | private bool convex; 14 | private bool isTrigger; 15 | private int cookingOptions; 16 | private PhysicMaterial material; 17 | private Mesh sharedMesh; 18 | 19 | public override string getTypeName () { 20 | return "MeshCollider"; 21 | } 22 | 23 | public WXMeshCollider (bool convex, bool isTrigger, 24 | #if UNITY_2017_1_OR_NEWER 25 | int cookingOptions, 26 | #endif 27 | PhysicMaterial material, Mesh mesh) { 28 | this.convex = convex; 29 | this.isTrigger = isTrigger; 30 | #if UNITY_2017_1_OR_NEWER 31 | this.cookingOptions = cookingOptions; 32 | #endif 33 | this.material = material; 34 | this.sharedMesh = mesh; 35 | } 36 | 37 | protected override JSONObject ToJSON (WXHierarchyContext context) { 38 | JSONObject json = new JSONObject (JSONObject.Type.OBJECT); 39 | JSONObject data = new JSONObject (JSONObject.Type.OBJECT); 40 | json.AddField ("type", getTypeName ()); 41 | json.AddField ("data", data); 42 | data.AddField ("active", true); 43 | 44 | // if (this.collider != null) 45 | { 46 | data.AddField ("convex", this.convex); 47 | data.AddField ("isTrigger", this.isTrigger); 48 | #if UNITY_2017_1_OR_NEWER 49 | data.AddField ("cookingOptions", (int) this.cookingOptions); 50 | #endif 51 | if (material != null) { 52 | WXPhysicsMaterial materialConverter = new WXPhysicsMaterial (material); 53 | string materialPath = materialConverter.Export (context.preset); 54 | if (materialPath != null && materialPath != "") { 55 | data.AddField ("material", materialPath); 56 | context.AddResource (materialPath); 57 | } 58 | } 59 | 60 | Mesh mesh = this.sharedMesh; 61 | if (mesh != null) { 62 | WXMesh meshConverter = new WXMesh (mesh); 63 | string meshPath = meshConverter.Export (context.preset); 64 | data.AddField ("mesh", meshPath); 65 | context.AddResource (meshPath); 66 | } 67 | } 68 | 69 | return json; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Component/WXEngineRegisterPhysics.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEditor; 4 | 5 | namespace WeChat 6 | { 7 | [InitializeOnLoad] 8 | class WXEngineRegisterPhysics 9 | { 10 | static WXEngineRegisterPhysics() 11 | { 12 | WXHierarchyContext.registerComponentConverter("060", Iterate3DComponent); 13 | } 14 | 15 | private static void Iterate3DComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset) 16 | { 17 | BoxCollider boxCollider = go.GetComponent(); 18 | if (boxCollider != null) 19 | { 20 | obj.components.Add(context.AddComponent(new WXBoxCollider(boxCollider.center, boxCollider.size, boxCollider.isTrigger, boxCollider.sharedMaterial), boxCollider)); 21 | } 22 | 23 | CapsuleCollider capsuleCollider = go.GetComponent(); 24 | if (capsuleCollider != null) 25 | { 26 | obj.components.Add(context.AddComponent( 27 | new WXCapsuleCollider(capsuleCollider.isTrigger, capsuleCollider.sharedMaterial, capsuleCollider.center, capsuleCollider.radius, capsuleCollider.height, capsuleCollider.direction), 28 | capsuleCollider)); 29 | } 30 | 31 | MeshCollider meshCollider = go.GetComponent(); 32 | if (meshCollider != null) 33 | { 34 | obj.components.Add(context.AddComponent( 35 | new WXMeshCollider(meshCollider.convex, meshCollider.isTrigger, 36 | #if UNITY_2017_1_OR_NEWER 37 | (int)meshCollider.cookingOptions, 38 | #endif 39 | meshCollider.sharedMaterial, meshCollider.sharedMesh), 40 | meshCollider)); 41 | } 42 | 43 | Rigidbody rigidbody = go.GetComponent(); 44 | if (rigidbody != null) 45 | { 46 | obj.components.Add(context.AddComponent(new WXRigidbody(rigidbody), rigidbody)); 47 | } 48 | 49 | SphereCollider sphereCollider = go.GetComponent(); 50 | if (sphereCollider != null) 51 | { 52 | obj.components.Add(context.AddComponent(new WXSphereCollider(sphereCollider.isTrigger, sphereCollider.sharedMaterial, sphereCollider.center, sphereCollider.radius), sphereCollider)); 53 | } 54 | 55 | CharacterController characterController = go.GetComponent(); 56 | 57 | if (characterController != null) { 58 | obj.components.Add(context.AddComponent(new WXCharactorController(characterController.slopeLimit, characterController.stepOffset, characterController.skinWidth, characterController.minMoveDistance, characterController.center, characterController.radius, characterController.height))); 59 | } 60 | 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Component/WXEngineRigidbody.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXRigidbody : WXComponent 14 | { 15 | private Rigidbody rigidbody; 16 | 17 | public override string getTypeName() { 18 | return "Rigidbody"; 19 | } 20 | 21 | public WXRigidbody(Rigidbody rigidbody) 22 | { 23 | this.rigidbody = rigidbody; 24 | } 25 | 26 | protected override JSONObject ToJSON(WXHierarchyContext context) 27 | { 28 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 29 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", getTypeName()); 31 | json.AddField("data", data); 32 | data.AddField("active", true); 33 | 34 | if (this.rigidbody != null) 35 | { 36 | data.AddField("mass", this.rigidbody.mass); 37 | data.AddField("linearDamping", this.rigidbody.drag); 38 | data.AddField("angularDamping", this.rigidbody.angularDrag); 39 | data.AddField("useGravity", this.rigidbody.useGravity); 40 | data.AddField("isKinematic", this.rigidbody.isKinematic); 41 | data.AddField("interpolation", (int)this.rigidbody.interpolation); 42 | data.AddField("collisionDetection", (int)this.rigidbody.collisionDetectionMode); 43 | int constraints = (int)this.rigidbody.constraints; 44 | data.AddField("constraints", constraints >>1 ); 45 | 46 | } 47 | 48 | return json; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Component/WXEngineSphereCollider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEditor; 7 | using UnityEditor.Animations; 8 | using UnityEngine; 9 | 10 | namespace WeChat { 11 | public class WXSphereCollider : WXComponent { 12 | private Boolean isTrigger; 13 | private PhysicMaterial material; 14 | private Vector3 center; 15 | private float radius; 16 | 17 | public override string getTypeName () { 18 | return "SphereCollider"; 19 | } 20 | 21 | public WXSphereCollider (Boolean isTrigger, PhysicMaterial material, Vector3 center, float radius) { 22 | this.center = center; 23 | this.radius = radius; 24 | this.isTrigger = isTrigger; 25 | this.material = material; 26 | } 27 | 28 | protected override JSONObject ToJSON (WXHierarchyContext context) { 29 | JSONObject json = new JSONObject (JSONObject.Type.OBJECT); 30 | JSONObject data = new JSONObject (JSONObject.Type.OBJECT); 31 | json.AddField ("type", getTypeName ()); 32 | json.AddField ("data", data); 33 | data.AddField ("active", true); 34 | 35 | // if (this.collider != null) 36 | { 37 | data.AddField ("isTrigger", this.isTrigger); 38 | if (material != null) { 39 | WXPhysicsMaterial materialConverter = new WXPhysicsMaterial (material); 40 | string materialPath = materialConverter.Export (context.preset); 41 | if (materialPath != null && materialPath != "") { 42 | data.AddField ("material", materialPath); 43 | context.AddResource (materialPath); 44 | } 45 | } 46 | 47 | JSONObject center = new JSONObject (JSONObject.Type.ARRAY); 48 | center.Add (-this.center.x); 49 | center.Add (this.center.y); 50 | center.Add (this.center.z); 51 | data.AddField ("center", center); 52 | 53 | data.AddField ("radius", this.radius); 54 | } 55 | 56 | return json; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/physics/Resource/WXPhysicsMaterial.cs: -------------------------------------------------------------------------------- 1 | 2 | using UnityEngine; 3 | using UnityEditor; 4 | 5 | namespace WeChat { 6 | public class WXPhysicsMaterial : WXResource { 7 | private PhysicMaterial material; 8 | string path; 9 | string _fileName; 10 | public WXPhysicsMaterial (PhysicMaterial mat): base(AssetDatabase.GetAssetPath(mat.GetInstanceID())) { 11 | this.material = mat; 12 | this.path = wxFileUtil.cleanIllegalChar(unityAssetPath, false); 13 | _fileName = this.path.Split('.')[0]; 14 | } 15 | 16 | protected override string GetResourceType () { 17 | return "physicmaterial"; 18 | } 19 | public override string GetExportPath () { 20 | return _fileName + ".physicmaterial"; 21 | } 22 | 23 | public override string GetHash () { 24 | return WXUtility.GetMD5FromString(path); 25 | } 26 | 27 | protected override JSONObject ExportResource (ExportPreset preset) { 28 | //JSONObject meta = JSONObject.Create ("{\"file\": {}}"); 29 | JSONObject metadata = new JSONObject(); 30 | WritePhysicsMaterial(ref metadata); 31 | //meta.AddField("data", metadata); 32 | //meta.AddField("version", 2); 33 | return metadata; 34 | } 35 | 36 | public JSONObject WritePhysicsMaterial (ref JSONObject data) { 37 | 38 | if (this.material != null) 39 | { 40 | data.AddField("name", this.material.name); 41 | data.AddField("dynamicFriction", this.material.dynamicFriction); 42 | data.AddField("staticFriction", this.material.staticFriction); 43 | data.AddField("bounciness", this.material.bounciness); 44 | data.AddField("frictionCombine", (int)this.material.frictionCombine); 45 | data.AddField("bounceCombine", (int)this.material.bounceCombine); 46 | } 47 | 48 | return data; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/PostProcess/Effect/BloomEditor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | namespace WeChat { 7 | public class WXPostProcessBloomEditor : WXPostProcessBaseEditor 8 | { 9 | SerializedProperty m_Intensity; 10 | 11 | public override void OnEnable() 12 | { 13 | m_Intensity = this.serializedObject.FindProperty("intensity"); 14 | } 15 | 16 | public override void OnGUI() 17 | { 18 | this.serializedObject.Update(); 19 | EditorGUILayout.PropertyField(m_Intensity); 20 | this.serializedObject.ApplyModifiedProperties(); 21 | } 22 | } 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/PostProcess/WXPostProcessBaseEditor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | namespace WeChat { 7 | public class WXPostProcessBaseEditor 8 | { 9 | internal WXPostProcessEffectSetting target { get; private set; } 10 | internal SerializedObject serializedObject { get; private set; } 11 | 12 | internal SerializedProperty baseProperty; 13 | 14 | internal SerializedProperty activeProperty; 15 | 16 | internal void Init(WXPostProcessEffectSetting target) 17 | { 18 | this.target = target; 19 | this.serializedObject = new SerializedObject(target); 20 | this.activeProperty = serializedObject.FindProperty("active"); 21 | this.OnEnable(); 22 | } 23 | 24 | public virtual void OnEnable() { } 25 | 26 | public virtual void OnDisable() { } 27 | 28 | public virtual void OnGUI() 29 | { 30 | serializedObject.Update(); 31 | 32 | SerializedProperty property = serializedObject.GetIterator(); 33 | property.NextVisible(true); 34 | property.NextVisible(true); 35 | do 36 | { 37 | EditorGUILayout.PropertyField(property); 38 | 39 | } while (property.NextVisible(false)); 40 | 41 | serializedObject.ApplyModifiedProperties(); 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/PostProcess/WXPostProcessEditor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | using System.IO; 6 | 7 | 8 | namespace WeChat { 9 | [CustomEditor(typeof(WXPostProcess))] 10 | public class WXPostProcessEditor : Editor 11 | { 12 | SerializedProperty m_Profile; 13 | WXPostProcessProfileEditor editor; 14 | WXPostProcessProfile lastProfile; 15 | private void OnEnable() 16 | { 17 | m_Profile = serializedObject.FindProperty("profile"); 18 | var profile = m_Profile.objectReferenceValue as WXPostProcessProfile; 19 | InitEditor(profile); 20 | } 21 | 22 | private void InitEditor(WXPostProcessProfile profile) 23 | { 24 | if (profile != null && profile != lastProfile) 25 | { 26 | editor = new WXPostProcessProfileEditor(profile); 27 | editor.OnEnable(); 28 | } 29 | lastProfile = profile; 30 | } 31 | 32 | public override void OnInspectorGUI() 33 | { 34 | serializedObject.Update(); 35 | var profile = m_Profile.objectReferenceValue as WXPostProcessProfile; 36 | InitEditor(profile); 37 | EditorGUILayout.PropertyField(m_Profile); 38 | Rect lastRect = GUILayoutUtility.GetLastRect(); 39 | var buttonRect = new Rect(lastRect.x + 60, lastRect.y, 45, 18); 40 | if (GUI.Button(buttonRect, new GUIContent("New"))) 41 | { 42 | profile = CreateProfile(); 43 | m_Profile.objectReferenceValue = profile; 44 | } 45 | else if (profile != null && editor != null) 46 | { 47 | editor.OnGUI(); 48 | } 49 | serializedObject.ApplyModifiedProperties(); 50 | } 51 | 52 | private WXPostProcessProfile CreateProfile() 53 | { 54 | CheckDir(); 55 | var profile = (WXPostProcessProfile)ScriptableObject.CreateInstance(typeof(WXPostProcessProfile)); 56 | int i = 0; 57 | while (File.Exists(GetNewProfilePath(i))) 58 | { 59 | i++; 60 | } 61 | AssetDatabase.CreateAsset(profile, GetNewProfilePath(i)); 62 | AssetDatabase.SaveAssets(); 63 | return profile; 64 | } 65 | 66 | const string profileDir = "Assets/WXEngineAuto/PostProcess"; 67 | 68 | private string GetNewProfilePath(int index) 69 | { 70 | return string.Format("{0}/profile_{1}.asset", profileDir, index); 71 | } 72 | 73 | private void CheckDir() 74 | { 75 | if (!Directory.Exists(profileDir)) 76 | { 77 | Directory.CreateDirectory(profileDir); 78 | } 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/PostProcess/WXPostProcessEnv.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | using System.Reflection; 6 | 7 | namespace WeChat { 8 | [InitializeOnLoad] 9 | public static class WXPostProcessEnv 10 | { 11 | public static Dictionary PostProcessTypeMap = new Dictionary(); 12 | static WXPostProcessEnv() 13 | { 14 | Add(typeof(WXPostProcessEffectBloom)); 15 | } 16 | 17 | 18 | private static void Add(System.Type t) 19 | { 20 | var attr = wxAttributeUtil.GetAttribute(t); 21 | if (attr == null) 22 | { 23 | PostProcessTypeMap.Add(t, typeof(WXPostProcessBaseEditor)); 24 | } 25 | else 26 | { 27 | PostProcessTypeMap.Add(t, attr.settingsType); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/PostProcess/WXPostProcessProfileEditorDefault.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | namespace WeChat { 7 | [CustomEditor(typeof(WXPostProcessProfile))] 8 | public class WXPostProcessProfileEditorDefault : Editor 9 | { 10 | WXPostProcessProfileEditor editor; 11 | private void OnEnable() 12 | { 13 | editor = new WXPostProcessProfileEditor(target as WXPostProcessProfile); 14 | editor.OnEnable(); 15 | } 16 | 17 | public override void OnInspectorGUI() 18 | { 19 | editor.OnGUI(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXAudioDistortionFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace WeChat 5 | { 6 | class WXAudioDistortionFilter : WXComponent 7 | { 8 | private AudioDistortionFilter audioDistortionFilter; 9 | private GameObject gameObject; 10 | 11 | private string _genId() 12 | { 13 | System.Random rd = new System.Random(); 14 | string str = ""; 15 | for (int i = 1; i < 29; i++) 16 | { 17 | str += rd.Next(0, 10); 18 | } 19 | return str; 20 | } 21 | public override string getTypeName() 22 | { 23 | return "AudioDistortion"; 24 | } 25 | 26 | public WXAudioDistortionFilter(AudioDistortionFilter audioDistortionFilter, GameObject gameObject) 27 | { 28 | this.gameObject = gameObject; 29 | this.audioDistortionFilter = audioDistortionFilter; 30 | } 31 | 32 | protected override JSONObject ToJSON(WXHierarchyContext context) 33 | { 34 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 35 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 36 | JSONObject effectNodeData = new JSONObject(JSONObject.Type.OBJECT); 37 | json.AddField("type", getTypeName()); 38 | json.AddField("data", data); 39 | data.AddField("effectNodeData", effectNodeData); 40 | effectNodeData.AddField("id", this._genId()); 41 | effectNodeData.AddField("__typeName", "AudioDistortionNode"); 42 | effectNodeData.AddField("level", audioDistortionFilter.distortionLevel); 43 | 44 | return json; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXAudioEchoFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace WeChat 5 | { 6 | class WXAudioEchoFilter : WXComponent 7 | { 8 | private AudioEchoFilter audioEchoFilter; 9 | private GameObject gameObject; 10 | 11 | private string _genId() 12 | { 13 | System.Random rd = new System.Random(); 14 | string str = ""; 15 | for (int i = 1; i < 29; i++) 16 | { 17 | str += rd.Next(0, 10); 18 | } 19 | return str; 20 | } 21 | public override string getTypeName() 22 | { 23 | return "AudioEcho"; 24 | } 25 | 26 | public WXAudioEchoFilter(AudioEchoFilter audioEchoFilter, GameObject gameObject) 27 | { 28 | this.gameObject = gameObject; 29 | this.audioEchoFilter = audioEchoFilter; 30 | } 31 | 32 | protected override JSONObject ToJSON(WXHierarchyContext context) 33 | { 34 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 35 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 36 | JSONObject effectNodeData = new JSONObject(JSONObject.Type.OBJECT); 37 | json.AddField("type", getTypeName()); 38 | json.AddField("data", data); 39 | data.AddField("effectNodeData", effectNodeData); 40 | effectNodeData.AddField("id", this._genId()); 41 | effectNodeData.AddField("__typeName", "AudioEchoNode"); 42 | effectNodeData.AddField("decay", audioEchoFilter.decayRatio); 43 | effectNodeData.AddField("delay", audioEchoFilter.delay); 44 | effectNodeData.AddField("dryMix", audioEchoFilter.dryMix); 45 | effectNodeData.AddField("wetMix", audioEchoFilter.wetMix); 46 | 47 | return json; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXAudioHighPassFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace WeChat 5 | { 6 | class WXAudioHighPassFilter : WXComponent 7 | { 8 | private AudioHighPassFilter audioHighPassFilter; 9 | private GameObject gameObject; 10 | 11 | private string _genId() 12 | { 13 | System.Random rd = new System.Random(); 14 | string str = ""; 15 | for (int i = 1; i < 29; i++) 16 | { 17 | str += rd.Next(0, 10); 18 | } 19 | return str; 20 | } 21 | public override string getTypeName() 22 | { 23 | return "AudioHighPassFilter"; 24 | } 25 | 26 | public WXAudioHighPassFilter(AudioHighPassFilter audioHighPassFilter, GameObject gameObject) 27 | { 28 | this.gameObject = gameObject; 29 | this.audioHighPassFilter = audioHighPassFilter; 30 | } 31 | 32 | protected override JSONObject ToJSON(WXHierarchyContext context) 33 | { 34 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 35 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 36 | JSONObject effectNodeData = new JSONObject(JSONObject.Type.OBJECT); 37 | json.AddField("type", getTypeName()); 38 | json.AddField("data", data); 39 | data.AddField("effectNodeData", effectNodeData); 40 | effectNodeData.AddField("id", this._genId()); 41 | effectNodeData.AddField("__typeName", "AudioHighPassFilterNode"); 42 | effectNodeData.AddField("frequency", audioHighPassFilter.cutoffFrequency); 43 | effectNodeData.AddField("Q", audioHighPassFilter.highpassResonanceQ); 44 | 45 | return json; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXAudioListener.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace WeChat 5 | { 6 | class WXAudioListener : WXComponent 7 | { 8 | private AudioListener audioListener; 9 | private GameObject gameObject; 10 | 11 | private string _genId() 12 | { 13 | System.Random rd = new System.Random(); 14 | string str = ""; 15 | for (int i = 1; i < 29; i++) 16 | { 17 | str += rd.Next(0, 10); 18 | } 19 | return str; 20 | } 21 | public override string getTypeName() 22 | { 23 | return "AudioListener"; 24 | } 25 | 26 | public WXAudioListener(AudioListener audioListener, GameObject gameObject) 27 | { 28 | this.gameObject = gameObject; 29 | this.audioListener = audioListener; 30 | } 31 | 32 | protected override JSONObject ToJSON(WXHierarchyContext context) 33 | { 34 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 35 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 36 | JSONObject effectNodeData = new JSONObject(JSONObject.Type.OBJECT); 37 | 38 | json.AddField("type", getTypeName()); 39 | json.AddField("data", data); 40 | data.AddField("effectNodeData", effectNodeData); 41 | effectNodeData.AddField("id", this._genId()); 42 | effectNodeData.AddField("__typeName", "AudioListenerNode"); 43 | return json; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXAudioLowPassFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace WeChat 5 | { 6 | class WXAudioLowPassFilter : WXComponent 7 | { 8 | private AudioLowPassFilter audioLowPassFilter; 9 | private GameObject gameObject; 10 | 11 | private string _genId() 12 | { 13 | System.Random rd = new System.Random(); 14 | string str = ""; 15 | for (int i = 1; i < 29; i++) 16 | { 17 | str += rd.Next(0, 10); 18 | } 19 | return str; 20 | } 21 | 22 | public override string getTypeName() 23 | { 24 | return "AudioLowPassFilter"; 25 | } 26 | 27 | public WXAudioLowPassFilter(AudioLowPassFilter audioLowPassFilter, GameObject gameObject) 28 | { 29 | this.gameObject = gameObject; 30 | this.audioLowPassFilter = audioLowPassFilter; 31 | } 32 | 33 | protected override JSONObject ToJSON(WXHierarchyContext context) 34 | { 35 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 36 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 37 | JSONObject effectNodeData = new JSONObject(JSONObject.Type.OBJECT); 38 | json.AddField("type", getTypeName()); 39 | json.AddField("data", data); 40 | data.AddField("effectNodeData", effectNodeData); 41 | effectNodeData.AddField("id", this._genId()); 42 | effectNodeData.AddField("frequency", audioLowPassFilter.cutoffFrequency); 43 | effectNodeData.AddField("Q", audioLowPassFilter.lowpassResonanceQ); 44 | effectNodeData.AddField("__typeName", "AudioLowPassFilterNode"); 45 | 46 | return json; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXEngineAnimation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | using System.Runtime.CompilerServices; 4 | 5 | [assembly: InternalsVisibleToAttribute("ScriptExport")] 6 | namespace WeChat 7 | { 8 | 9 | class WXAnimation : WXComponent 10 | { 11 | 12 | private Animation animation; 13 | private GameObject gameObject; 14 | 15 | public override string getTypeName() 16 | { 17 | return "Animation"; 18 | } 19 | 20 | public WXAnimation(Animation animation, GameObject gameObject) 21 | { 22 | this.gameObject = gameObject; 23 | this.animation = animation; 24 | } 25 | 26 | protected override JSONObject ToJSON(WXHierarchyContext context) 27 | { 28 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 29 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", getTypeName()); 31 | json.AddField("data", data); 32 | List> clips = new List>(); 33 | string defaultClip = null; 34 | foreach (var anim in animation) 35 | { 36 | if (anim.GetType() == typeof(AnimationState)) 37 | { 38 | var uid = HandleAnimationClip(context, (anim as AnimationState).clip); 39 | clips.Add(new KeyValuePair((anim as AnimationState).clip.name, uid)); 40 | if (animation.clip == (anim as AnimationState).clip) 41 | { 42 | defaultClip = (anim as AnimationState).clip.name; 43 | } 44 | } 45 | } 46 | if (defaultClip == null) 47 | { 48 | data.AddField("clip", new JSONObject(JSONObject.Type.NULL)); 49 | } 50 | else 51 | { 52 | data.AddField("clip", defaultClip); 53 | } 54 | JSONObject clipsJSON = new JSONObject(JSONObject.Type.ARRAY); 55 | data.AddField("clips", clipsJSON); 56 | for (int i = 0; i < clips.Count; i++) 57 | { 58 | var childClip = clips[i]; 59 | JSONObject clipInfo = new JSONObject(JSONObject.Type.OBJECT); 60 | clipInfo.AddField("name", childClip.Key); 61 | clipInfo.AddField("clip", childClip.Value); 62 | clipsJSON.Add(clipInfo); 63 | } 64 | data.AddField("autoPlay", animation.playAutomatically); 65 | return json; 66 | } 67 | public string HandleAnimationClip(WXHierarchyContext context, AnimationClip animationClip) 68 | { 69 | string uid = new WXAnimationClip(animationClip).Export(context.preset); 70 | 71 | // 因为AnimationClip没走AddFile,这里要手动加dependenices 72 | //WXBeefBallExportContext.instance.keys.Add(uid, true); 73 | context.AddResource(uid); 74 | return uid; 75 | } 76 | 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXEngineAnimator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using UnityEditor; 8 | using UnityEditor.Animations; 9 | using UnityEngine; 10 | using System.Runtime.CompilerServices; 11 | 12 | [assembly: InternalsVisibleToAttribute("ScriptExport")] 13 | namespace WeChat 14 | { 15 | 16 | class WXAnimator : WXComponent 17 | { 18 | public static Dictionary ParameterType = new Dictionary 19 | { 20 | {AnimatorControllerParameterType.Float,1 }, 21 | {AnimatorControllerParameterType.Int,3 }, 22 | {AnimatorControllerParameterType.Bool,4 }, 23 | {AnimatorControllerParameterType.Trigger,9 } 24 | }; 25 | 26 | private Animator animator; 27 | private GameObject gameObject; 28 | private bool curNodeHasLegalChild = false; 29 | private JSONObject dependencies = new JSONObject(JSONObject.Type.ARRAY); 30 | 31 | public override string getTypeName() 32 | { 33 | return "Animator"; 34 | } 35 | 36 | public WXAnimator(Animator animator, GameObject gameObject) 37 | { 38 | this.gameObject = gameObject; 39 | this.animator = animator; 40 | } 41 | 42 | protected override JSONObject ToJSON(WXHierarchyContext context) 43 | { 44 | List linkSprite = new List(); 45 | JSONObject child = new JSONObject(JSONObject.Type.ARRAY); 46 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 47 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 48 | JSONObject layers = new JSONObject(JSONObject.Type.ARRAY); 49 | json.AddField("type", getTypeName()); 50 | json.AddField("data", data); 51 | Avatar avatar = animator.avatar; 52 | if ((UnityEngine.Object)avatar != (UnityEngine.Object)null) 53 | { 54 | AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(avatar.GetInstanceID())); 55 | ModelImporter mImporter = importer as ModelImporter; 56 | if (mImporter && mImporter.optimizeGameObjects) 57 | { 58 | WXAvatar converter = new WXAvatar(avatar, gameObject); 59 | string avatarPath = converter.Export(context.preset); 60 | if (avatarPath != null && avatarPath != "") 61 | { 62 | data.AddField("avatar", avatarPath); 63 | context.AddResource(avatarPath); 64 | } 65 | } 66 | } 67 | 68 | if (gameObject.GetComponent().runtimeAnimatorController != null) 69 | { 70 | //string controllerId = SaveController(gameObject); 71 | WXResource controllerConverter = (WXResource)WXResource.getConverter( 72 | gameObject.GetComponent().runtimeAnimatorController, 73 | gameObject 74 | ); 75 | string animatorControllerPath = controllerConverter.Export(context.preset); 76 | data.AddField("controller", animatorControllerPath); 77 | context.AddResource(animatorControllerPath); 78 | } 79 | data.AddField("cullingMode", (uint)animator.cullingMode); 80 | return json; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXEngineCamera.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXCamera : WXComponent 14 | { 15 | private Camera camera; 16 | 17 | public enum CameraProjectionType 18 | { 19 | Perspective = 0, 20 | Orthographic = 1 21 | } 22 | 23 | public override string getTypeName() 24 | { 25 | return "Camera"; 26 | } 27 | 28 | public WXCamera(Camera camera) 29 | { 30 | this.camera = camera; 31 | } 32 | 33 | protected override JSONObject ToJSON(WXHierarchyContext context) 34 | { 35 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 36 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 37 | json.AddField("type", getTypeName()); 38 | json.AddField("data", data); 39 | if (camera != null) 40 | { 41 | data.AddField("cullingMask", camera.cullingMask); 42 | data.AddField("depth", camera.depth); 43 | if (camera.orthographic) // 正交 44 | { 45 | data.AddField("projectionType", 1); 46 | data.AddField("orthographicSize", camera.orthographicSize); 47 | } 48 | else // 透视 49 | { 50 | data.AddField("projectionType", 0); 51 | data.AddField("fieldOfView", camera.fieldOfView); 52 | } 53 | data.AddField("aspect", camera.aspect); 54 | data.AddField("nearClipPlane", camera.nearClipPlane); 55 | data.AddField("farClipPlane", camera.farClipPlane); 56 | RenderTexture targetTexture = camera.targetTexture; 57 | if (targetTexture != null) 58 | { 59 | Debug.LogError("WX Tool targetTexture didn`t null ,now don`t support"); 60 | } 61 | } 62 | 63 | return json; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXEngineLight.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXLight : WXComponent 14 | { 15 | 16 | public override string getTypeName() 17 | { 18 | return "Light"; 19 | } 20 | 21 | private Light light; 22 | public WXLight(Light _light) 23 | { 24 | this.light = _light; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 30 | 31 | 32 | if ((UnityEngine.Object)light != (UnityEngine.Object)null) 33 | { 34 | 35 | 36 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 37 | JSONObject jSONObject = new JSONObject(JSONObject.Type.ARRAY); 38 | Color color = light.color; 39 | jSONObject.Add(color.r); 40 | jSONObject.Add(color.g); 41 | jSONObject.Add(color.b); 42 | data.AddField("color", jSONObject); 43 | data.AddField("intensity", light.intensity); 44 | if (light.type == LightType.Directional) { 45 | json.AddField("type", "DirectionalLight"); 46 | data.AddField("shadowBias", light.shadowBias); 47 | data.AddField("shadowNormalBias", light.shadowNormalBias); 48 | data.AddField("shadowStrength", light.shadowStrength); 49 | data.AddField("shadowNearPlane", light.shadowNearPlane); 50 | data.AddField("shadowNearPlane", light.shadowNearPlane); 51 | // cookie�ݲ�֧�� 52 | // data.AddField("cookieSize", light.cookieSize); 53 | // data.AddField("cookie", light.cookie); 54 | } else if (light.type == LightType.Point) { 55 | json.AddField("type", "PointLight"); 56 | data.AddField("range", light.range); 57 | } else if (light.type == LightType.Spot) { 58 | json.AddField("type", "SpotLight"); 59 | data.AddField("range", light.range); 60 | data.AddField("spotAngle", light.spotAngle); 61 | } 62 | 63 | 64 | json.AddField("data", data); 65 | } 66 | 67 | return json; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXEnginePostProcess.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace WeChat 5 | { 6 | public class WXEnginePostProcess : WXComponent 7 | { 8 | private readonly WXPostProcess pp; 9 | 10 | public WXEnginePostProcess(WXPostProcess pp) 11 | { 12 | this.pp = pp; 13 | } 14 | 15 | public override string getTypeName() 16 | { 17 | return "PostProcess"; 18 | } 19 | 20 | protected override JSONObject ToJSON(WXHierarchyContext context) 21 | { 22 | JSONObject m_json = new JSONObject(JSONObject.Type.OBJECT); 23 | JSONObject m_data = new JSONObject(JSONObject.Type.OBJECT); 24 | m_json.AddField("type", getTypeName()); 25 | m_json.AddField("data", m_data); 26 | 27 | JSONObject m_effects = new JSONObject(JSONObject.Type.ARRAY); 28 | m_data.AddField("effects", m_effects); 29 | 30 | var profile = this.pp.profile; 31 | if (profile != null && profile.settings.Count > 0) 32 | { 33 | foreach (var effect in profile.settings) { 34 | m_effects.Add(effect.Export()); 35 | } 36 | } 37 | 38 | return m_json; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXEngineRawResourceCollection.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.IO; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | 8 | 9 | namespace WeChat 10 | { 11 | public class WXEngineRawResourceCollection : WXComponent 12 | { 13 | WXRawResourceCollection collection_; 14 | 15 | public override string getTypeName() 16 | { 17 | return "RawResourceCollection"; 18 | } 19 | 20 | public WXEngineRawResourceCollection(WXRawResourceCollection collection) 21 | { 22 | collection_ = collection; 23 | } 24 | 25 | protected override JSONObject ToJSON(WXHierarchyContext context) 26 | { 27 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 28 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 29 | json.AddField("type", getTypeName()); 30 | json.AddField("data", data); 31 | 32 | JSONObject res_paths_json = new JSONObject(JSONObject.Type.ARRAY); 33 | data.AddField("resources", res_paths_json); 34 | 35 | 36 | foreach (Object file in collection_.ResourceFiles) 37 | { 38 | if (file != null) 39 | { 40 | string file_path = AssetDatabase.GetAssetPath(file.GetInstanceID()); 41 | WXRawResource resourceConverter = new WXRawResource(file_path); 42 | string ret_path = resourceConverter.Export(context.preset); 43 | if (ret_path != "") 44 | { 45 | res_paths_json.Add(ret_path); 46 | context.AddResource(ret_path); 47 | } 48 | } 49 | } 50 | 51 | return json; 52 | } 53 | 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXEngineTransform.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | 4 | namespace WeChat 5 | { 6 | 7 | public class WXTransform3DComponent : WXComponent 8 | { 9 | private Transform transform; 10 | private Boolean usingDefault = false; 11 | 12 | public override string getTypeName() 13 | { 14 | return "Transform3D"; 15 | } 16 | 17 | public WXTransform3DComponent(Transform transform, Boolean usingDefault = false) 18 | { 19 | this.transform = transform; 20 | this.usingDefault = usingDefault; 21 | } 22 | 23 | protected override JSONObject ToJSON(WXHierarchyContext context) 24 | { 25 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 26 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 27 | 28 | // 位置信息 29 | JSONObject position = new JSONObject(JSONObject.Type.ARRAY); 30 | if (usingDefault) 31 | { 32 | position.Add(0f); 33 | position.Add(0f); 34 | position.Add(0f); 35 | } 36 | else 37 | { 38 | position.Add(this.transform.localPosition.x * -1f); 39 | position.Add(this.transform.localPosition.y); 40 | position.Add(this.transform.localPosition.z); 41 | } 42 | 43 | // 旋转信息 44 | JSONObject rotation = new JSONObject(JSONObject.Type.ARRAY); 45 | if (usingDefault) 46 | { 47 | rotation.Add(0f); 48 | rotation.Add(0f); 49 | rotation.Add(0f); 50 | rotation.Add(1f); 51 | } 52 | else 53 | { 54 | rotation.Add(this.transform.localRotation.x * -1f); 55 | rotation.Add(this.transform.localRotation.y); 56 | rotation.Add(this.transform.localRotation.z); 57 | rotation.Add(this.transform.localRotation.w * -1f); 58 | } 59 | 60 | // 缩放信息 61 | JSONObject scale = new JSONObject(JSONObject.Type.ARRAY); 62 | if (usingDefault) 63 | { 64 | scale.Add(1f); 65 | scale.Add(1f); 66 | scale.Add(1f); 67 | } 68 | else 69 | { 70 | scale.Add(this.transform.localScale.x); 71 | scale.Add(this.transform.localScale.y); 72 | scale.Add(this.transform.localScale.z); 73 | } 74 | 75 | json.AddField("type", this.getTypeName()); 76 | json.AddField("data", data); 77 | data.AddField("position", position); 78 | data.AddField("rotation", rotation); 79 | data.AddField("scale", scale); 80 | 81 | return json; 82 | } 83 | } 84 | 85 | // WXBeefBallComponentExporter.TypeStruct data = new WXBeefBallComponentExporter.TypeStruct(); 86 | // data.componentType = typeof(Transform); 87 | // data.exporterType = typeof(WXBBTransform3DComponent); 88 | // WXBeefBallComponentExporter.typeMap.Add() 89 | } 90 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Component/WXScript.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | // [AttributeUsage(AttributeTargets.Class | 8 | // AttributeTargets.Constructor | 9 | // AttributeTargets.Field | 10 | // AttributeTargets.Method | 11 | // AttributeTargets.Property, 12 | // AllowMultiple = true)] 13 | 14 | // public class BeefballSerialize : Attribute 15 | // { 16 | // public string __beefballSerialize; 17 | 18 | // public BeefballSerialize(string __beefballSerialize) 19 | // { 20 | // this.__beefballSerialize = __beefballSerialize; 21 | // } 22 | // } 23 | 24 | class WXScript : WXComponent 25 | { 26 | 27 | private MonoBehaviour script; 28 | private GameObject gameObject; 29 | private string __uuid; 30 | 31 | public override string getTypeName() 32 | { 33 | return "__ScriptEditorComponent"; 34 | } 35 | 36 | public WXScript(MonoBehaviour script, GameObject gameObject, string __uuid) 37 | { 38 | this.gameObject = gameObject; 39 | this.script = script; 40 | this.__uuid = __uuid; 41 | } 42 | 43 | protected override JSONObject ToJSON(WXHierarchyContext context) 44 | { 45 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 46 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 47 | 48 | json.AddField("type", getTypeName()); 49 | json.AddField("data", data); 50 | data.AddField("__uuid", this.__uuid); 51 | return json; 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/CubemapToEquirectangular/CubemapToEquirectangular.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "Conversion/CubemapToEquirectangular" { 4 | Properties { 5 | _MainTex ("Cubemap (RGB)", CUBE) = "" {} 6 | _Mipmap("Mipmap", Float) = 0.0 7 | _TilingOffset("TilingOffset", Vector) = (1.0, 1.0, 0.0, 0.0) 8 | } 9 | 10 | Subshader { 11 | Pass { 12 | ZTest Always Cull Off ZWrite Off 13 | Fog { Mode off } 14 | 15 | CGPROGRAM 16 | #pragma vertex vert 17 | #pragma fragment frag 18 | #pragma fragmentoption ARB_precision_hint_fastest 19 | //#pragma fragmentoption ARB_precision_hint_nicest 20 | #include "UnityCG.cginc" 21 | 22 | #define PI 3.141592653589793 23 | #define TWOPI 6.283185307179587 24 | 25 | struct v2f { 26 | float4 pos : POSITION; 27 | float2 uv : TEXCOORD0; 28 | }; 29 | 30 | float _Mipmap; 31 | float4 _TilingOffset; 32 | samplerCUBE _MainTex; 33 | 34 | v2f vert( appdata_img v ) 35 | { 36 | v2f o; 37 | o.pos = UnityObjectToClipPos(v.vertex); 38 | float2 posSC = ((o.pos + 1.0) * 0.5).xy; 39 | posSC.x = posSC.x * _TilingOffset.x + _TilingOffset.y; 40 | posSC.y = posSC.y * _TilingOffset.z + _TilingOffset.w; 41 | 42 | o.pos.x = posSC.x * 2.0 - 1.0; 43 | o.pos.y = posSC.y * 2.0 - 1.0; 44 | 45 | o.uv = v.texcoord.xy * float2(TWOPI, PI); 46 | return o; 47 | } 48 | 49 | 50 | fixed4 frag(v2f i) : COLOR 51 | { 52 | float theta = i.uv.y; 53 | float phi = i.uv.x; 54 | float3 unit = float3(0,0,0); 55 | 56 | unit.x = sin(phi) * sin(theta) * -1; 57 | unit.y = cos(theta) * -1; 58 | unit.z = cos(phi) * sin(theta) * -1; 59 | 60 | half4 tex = texCUBElod(_MainTex, float4(unit, _Mipmap)); 61 | half3 c = DecodeHDR (tex, 1.0); 62 | return float4(c, 1.0); 63 | } 64 | ENDCG 65 | } 66 | } 67 | Fallback Off 68 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/ExportPreset/AnimatorExportPreset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using UnityEngine.SceneManagement; 6 | 7 | namespace WeChat 8 | { 9 | 10 | [InitializeOnLoad] 11 | [DeclarePreset("prefab", null)] 12 | class AnimatorExportPreset : ExportPreset 13 | { 14 | static AnimatorExportPreset() 15 | { 16 | } 17 | 18 | public AnimatorExportPreset(): base() 19 | { 20 | } 21 | 22 | public override string GetChineseName() 23 | { 24 | return "当前节点的动作控制器"; 25 | } 26 | 27 | protected override void DoExport() 28 | { 29 | GameObject activeGameObject = (GameObject)Selection.activeObject; 30 | WXAnimatorController converter = new WXAnimatorController(activeGameObject.GetComponent(), activeGameObject); 31 | PresetUtil.writeGroup(converter, this/*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); 32 | } 33 | 34 | public override bool WillPresetShow() 35 | { 36 | if (Selection.activeObject == null) { 37 | return false; 38 | } 39 | 40 | try 41 | { 42 | return ((UnityEngine.GameObject)Selection.activeObject).GetComponent(typeof(Animator)); 43 | } 44 | catch (Exception e) 45 | { 46 | return false; 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/ExportPreset/PrefabExportPreset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEditor.SceneManagement; 4 | using UnityEngine; 5 | using UnityEngine.SceneManagement; 6 | 7 | namespace WeChat 8 | { 9 | // 导出选中的prefab 10 | [InitializeOnLoad] 11 | [DeclarePreset("prefab", typeof(HierarchyExportConfig))] 12 | class PrefabExportPreset : ExportPreset 13 | { 14 | static PrefabExportPreset() 15 | { 16 | ExportPreset.registerExportPreset("prefab", new PrefabExportPreset()); 17 | } 18 | 19 | public PrefabExportPreset() : base() 20 | { 21 | } 22 | 23 | public override string GetChineseName() 24 | { 25 | return "选中的prefab"; 26 | } 27 | 28 | protected override void DoExport() 29 | { 30 | GameObject[] prefabRoots = Selection.gameObjects; 31 | 32 | Scene gameScene = SceneManager.GetActiveScene(); 33 | EditorSceneManager.SaveScene(gameScene, gameScene.path); 34 | 35 | // foreach (GameObject prefabRoot in prefabRoots) { 36 | // WXUtility.TraverseSceneTreeToSave(prefabRoot, gameScene); 37 | // } 38 | 39 | foreach (GameObject prefabRoot in prefabRoots) 40 | { 41 | WXPrefab converter = new WXPrefab( 42 | prefabRoot, 43 | AssetDatabase.GetAssetPath(WXUtility.GetPrefabSource(prefabRoot)) 44 | ); 45 | 46 | PresetUtil.writeGroup(converter, this/*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); 47 | } 48 | } 49 | 50 | public override bool WillPresetShow() 51 | { 52 | if (Selection.activeObject == null) 53 | { 54 | return false; 55 | } 56 | try 57 | { 58 | return WXUtility.GetPrefabSource(Selection.activeObject); 59 | } 60 | catch (Exception e) 61 | { 62 | return false; 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/ExportPreset/SceneExportPreset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEditor.SceneManagement; 5 | using UnityEngine; 6 | using UnityEngine.SceneManagement; 7 | 8 | namespace WeChat 9 | { 10 | [InitializeOnLoad] 11 | [DeclarePreset("scene", typeof(HierarchyExportConfig))] 12 | public class SceneExportPreset : ExportPreset 13 | { 14 | static SceneExportPreset() 15 | { 16 | ExportPreset.registerExportPreset("scene", new SceneExportPreset()); 17 | } 18 | 19 | public SceneExportPreset() : base() 20 | { 21 | } 22 | 23 | public override string GetChineseName() 24 | { 25 | return "当前场景"; 26 | } 27 | 28 | protected override void DoExport() 29 | { 30 | Scene gameScene = SceneManager.GetActiveScene(); 31 | 32 | GameObject[] root = gameScene.GetRootGameObjects(); 33 | List rootList = new List(); 34 | 35 | foreach (GameObject obj in root) 36 | { 37 | // obj.transform.SetParent(dummySceneRootGO.transform); 38 | rootList.Add(obj); 39 | } 40 | 41 | GameObject dummySceneRootGO = new GameObject("sceneDummyRoot"); 42 | foreach (GameObject obj in rootList) { 43 | obj.transform.SetParent(dummySceneRootGO.transform); 44 | } 45 | EditorSceneManager.SaveScene(gameScene, gameScene.path); 46 | 47 | // WXUtility.TraverseSceneTreeToSave(dummySceneRootGO, gameScene); 48 | 49 | WXScene converter = new WXScene(gameScene, gameScene.path); 50 | PresetUtil.writeGroup(converter, this/*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); 51 | 52 | List transList = new List(); 53 | foreach (Transform child in dummySceneRootGO.transform) 54 | { 55 | transList.Add(child); 56 | } 57 | foreach (Transform child in transList) { 58 | child.SetParent(null); 59 | } 60 | UnityEngine.Object.DestroyImmediate(dummySceneRootGO); 61 | EditorSceneManager.SaveScene(gameScene, gameScene.path); 62 | } 63 | 64 | public override bool WillPresetShow() 65 | { 66 | return true; 67 | //return Selection.activeObject == null; 68 | } 69 | 70 | } 71 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/ExportPreset/ScriptableObject/HierarchyExportConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace WeChat 7 | { 8 | public class HierarchyExportConfig : ExportConfig 9 | { 10 | public bool ignoreNonActive = false; 11 | public bool ignoreParticle = false; 12 | public bool createEffectTemplate = false; 13 | } 14 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/ExportPreset/ScriptableObject/HierarchyExportConfigEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | namespace WeChat 5 | { 6 | [CustomEditor(typeof(HierarchyExportConfig))] 7 | public class HierarchyExportConfigEditor : Editor 8 | { 9 | public override void OnInspectorGUI() 10 | { 11 | //base.OnInspectorGUI(); 12 | SerializedProperty ignoreNonActive = serializedObject.FindProperty("ignoreNonActive"); 13 | SerializedProperty ignoreParticle = serializedObject.FindProperty("ignoreParticle"); 14 | 15 | EditorGUILayout.BeginVertical(); 16 | EditorGUILayout.PropertyField(ignoreNonActive, new GUIContent("忽略非激活节点")); 17 | EditorGUILayout.PropertyField(ignoreParticle, new GUIContent("忽略粒子系统")); 18 | 19 | serializedObject.ApplyModifiedProperties(); 20 | 21 | EditorGUILayout.EndVertical(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/ExportPreset/lib/PresetUtil.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | using System; 5 | using System.IO; 6 | 7 | namespace WeChat 8 | { 9 | public class PresetUtil 10 | { 11 | public static void writeGroup(WXResource resource, ExportPreset preset) 12 | { 13 | try 14 | { 15 | EditorUtility.DisplayProgressBar( 16 | "导出资源", 17 | "资源读取中...", 18 | 0.33f 19 | ); 20 | string resourcePath = resource.Export(preset); 21 | 22 | EditorUtility.DisplayProgressBar( 23 | "导出资源", 24 | "文件写入中...", 25 | 0.66f 26 | ); 27 | 28 | string packageName = WXUtility.GetFileNameFromPath(resourcePath); 29 | if (packageName == "") 30 | { 31 | packageName = "Untitled"; 32 | } 33 | 34 | ExportStore.GenerateResourcePackage( 35 | packageName, 36 | resourcePath 37 | ); 38 | } 39 | catch (Exception e) 40 | { 41 | Debug.LogException(e); 42 | } 43 | finally 44 | { 45 | EditorUtility.ClearProgressBar(); 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/AssetFile/WXEngineBinaryFile.cs: -------------------------------------------------------------------------------- 1 | namespace WeChat 2 | { 3 | internal abstract class WXEngineBinaryFile : WXAssetFile 4 | { 5 | public WXEngineBinaryFile(string unityAssetPath) : base(unityAssetPath) { } 6 | 7 | protected override bool DoExport() 8 | { 9 | ExportStore.AddBinaryFile( 10 | GetExportPath(), 11 | GetContent(), 12 | GetHash() 13 | ); 14 | 15 | return true; 16 | } 17 | 18 | protected abstract byte[] GetContent(); 19 | } 20 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/AssetFile/WXEngineCopyFile.cs: -------------------------------------------------------------------------------- 1 | namespace WeChat 2 | { 3 | public class WXEngineCopyFile : WXAssetFile 4 | { 5 | public override string GetExportPath() 6 | { 7 | return unityAssetPath; 8 | } 9 | 10 | private string fileType; 11 | public WXEngineCopyFile(string assetPath, string fileType) : base(assetPath) 12 | { 13 | this.fileType = fileType; 14 | } 15 | 16 | protected override bool DoExport() 17 | { 18 | ExportStore.AddCopyFile( 19 | GetExportPath(), 20 | fileType, 21 | GetHash() 22 | ); 23 | 24 | return true; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/AssetFile/WXEngineImageFile.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | namespace WeChat { 4 | public abstract class WXEngineImageFile : WXAssetFile { 5 | public WXEngineImageFile (string unityAssetPath) : base (unityAssetPath) { } 6 | 7 | protected override bool DoExport () { 8 | ExportStore.AddImageFile ( 9 | GetExportPath (), 10 | GetContent (), 11 | GetHash () 12 | ); 13 | 14 | return true; 15 | } 16 | 17 | protected abstract byte[] GetContent (); 18 | } 19 | 20 | // 被cubemap所使用的图片文件 21 | internal class WXCubeMapTextureImage : WXEngineImageFile { 22 | private TextureUtil.EnumTexFileExt ext; 23 | private Texture2D texture; 24 | private string faceName; 25 | 26 | public WXCubeMapTextureImage ( 27 | Texture2D texture, 28 | TextureUtil.EnumTexFileExt ext, 29 | string faceName, 30 | string texturePath 31 | ) : base (texturePath) { 32 | this.ext = ext; 33 | this.texture = texture; 34 | this.faceName = faceName; 35 | } 36 | 37 | protected override byte[] GetContent () { 38 | switch (ext) { 39 | case TextureUtil.EnumTexFileExt.JPG: 40 | return texture.EncodeToJPG (); 41 | case TextureUtil.EnumTexFileExt.PNG: 42 | return texture.EncodeToPNG (); 43 | default: 44 | return null; 45 | } 46 | } 47 | 48 | public override string GetExportPath () { 49 | switch (ext) { 50 | case TextureUtil.EnumTexFileExt.JPG: 51 | return wxFileUtil.cleanIllegalChar (unityAssetPath.Split ('.') [0], false) + '.' + faceName + ".jpg"; 52 | case TextureUtil.EnumTexFileExt.PNG: 53 | return wxFileUtil.cleanIllegalChar (unityAssetPath.Split ('.') [0], false) + '.' + faceName + ".png"; 54 | default: 55 | return ""; 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/AssetFile/WXEngineJSONFile.cs: -------------------------------------------------------------------------------- 1 | namespace WeChat 2 | { 3 | internal abstract class WXEngineJSONFile : WXAssetFile 4 | { 5 | public WXEngineJSONFile(string unityAssetPath) : base(unityAssetPath) { } 6 | 7 | protected override bool DoExport() 8 | { 9 | ExportStore.AddJSONFile( 10 | GetExportPath(), 11 | GetContent(), 12 | GetHash() 13 | ); 14 | 15 | return true; 16 | } 17 | 18 | protected abstract JSONObject GetContent(); 19 | } 20 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/AssetFile/WXEngineTextFile.cs: -------------------------------------------------------------------------------- 1 | namespace WeChat 2 | { 3 | public abstract class WXEngineTextFile : WXAssetFile 4 | { 5 | public WXEngineTextFile(string unityAssetPath) : base(unityAssetPath) { } 6 | 7 | protected override bool DoExport() 8 | { 9 | ExportStore.AddTextFile( 10 | GetExportPath(), 11 | GetContent(), 12 | GetHash() 13 | ); 14 | 15 | return true; 16 | } 17 | 18 | protected abstract string GetContent(); 19 | } 20 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/HLSLTemplate/BaseHLSLTemplate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | namespace WeChat 4 | { 5 | class BaseHLSLTemplate 6 | { 7 | static Dictionary typeMap = new Dictionary 8 | { 9 | { "Float", "float"}, 10 | { "Vector4", "float4"}, 11 | { "Vector3", "float3"} 12 | }; 13 | static protected string GetUniformString(WXEffect wxbb_shader) 14 | { 15 | string result = "cbuffer custom {\n"; 16 | foreach (WXEffect.property property in wxbb_shader.properties) 17 | { 18 | string typeName; 19 | if (!typeMap.TryGetValue(property.type, out typeName)) 20 | { 21 | typeName = "float"; 22 | } 23 | result += string.Format(" {0} {1};\n", typeName, property.key); 24 | } 25 | foreach (WXEffect.property texture in wxbb_shader.textures) 26 | { 27 | result += string.Format(" float4 {0}_ST;\n", texture.key); 28 | } 29 | return result + "}\n"; 30 | } 31 | static public string Export(WXEffect wxbb_shader) 32 | { 33 | return ""; 34 | } 35 | 36 | static protected string GetTextureDeclaration(WXEffect wxbb_shader) 37 | { 38 | string result = ""; 39 | foreach (WXEffect.property texture in wxbb_shader.textures) 40 | { 41 | if (texture.type == "TextureCube") 42 | { 43 | result += string.Format("DECLARE_CUBEMAP({0});\n", texture.key); 44 | } 45 | else 46 | { 47 | result += string.Format("DECLARE_TEXTURE({0});\n", texture.key); 48 | } 49 | } 50 | return result; 51 | } 52 | 53 | } 54 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/HLSLTemplate/PixelHLSLTemplate.cs: -------------------------------------------------------------------------------- 1 | namespace WeChat 2 | { 3 | class PixelHLSLTemplate : BaseHLSLTemplate 4 | { 5 | public new static string Export(WXEffect wxbb_shader) 6 | { 7 | return string.Format( 8 | "#include \n\n// vertex的输出,pixel的输入,请和.vertex.hlsl文件保持一致\nstruct FVertexOutput\n{{\n float4 Position : SV_Position;\n float2 TexCoord : TEXCOORD0; }};\n\n// 根据原shader的properties自动生成\n{0}\n\n// 根据原shader的properties自动生成\n{1}\n\nfloat4 Main(in FVertexOutput In) : SV_Target0\n{{\n // 请根据原shader的frag函数填充代码\n return SAMPLE_TEXTURE(_MainTex, In.TexCoord);\n}}\n", 9 | GetUniformString(wxbb_shader), 10 | GetTextureDeclaration(wxbb_shader) 11 | ); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/HLSLTemplate/VertexHLSLTemplate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace WeChat 3 | { 4 | class VertexHLSLTemplate : BaseHLSLTemplate 5 | { 6 | public new static string Export(WXEffect wxbb_shader) 7 | { 8 | return string.Format( 9 | "#include \n\n// vertex的输出,pixel的输入,请根据原shader文件修改\nstruct FVertexOutput\n{{\n float4 Position : SV_Position;\n float2 TexCoord : TEXCOORD0;\n}};\n\n// 根据原shader的properties自动生成\n{0}\n\n// 根据原shader的properties自动生成\n{1}\n\nvoid Main(in FEffect3DVertexInput In, out FVertexOutput Out)\n{{\n FVertexProcessOutput VPOut;\n Effect3DVertexProcess(In, VPOut);\n\n Out.Position = WorldToClipPosition(VPOut.WorldPosition);\n\n Out.TexCoord = TRANSFER_TEXCOORD(VPOut.TexCoord, _MainTex_ST);\n }}", 10 | GetUniformString(wxbb_shader), 11 | GetTextureDeclaration(wxbb_shader) 12 | ); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/WXEngineAvatarMask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEditor; 5 | using UnityEditor.Animations; 6 | using UnityEngine; 7 | using System.IO; 8 | using System.Text; 9 | using System.Threading; 10 | 11 | namespace WeChat 12 | { 13 | 14 | class WXAvatarMask : WXResource 15 | { 16 | protected override string GetResourceType() 17 | { 18 | return "avatarmask"; 19 | } 20 | 21 | public override string GetHash() 22 | { 23 | return WXUtility.GetMD5FromAssetPath(unityAssetPath) + WXUtility.GetMD5FromString(avatarMask.name); 24 | } 25 | 26 | public override string GetExportPath() 27 | { 28 | int index = unityAssetPath.LastIndexOf('.'); 29 | string filename = index == -1 ? unityAssetPath : unityAssetPath.Substring(0, index); 30 | return wxFileUtil.cleanIllegalChar(filename, false) + ".avatarmask"; 31 | } 32 | 33 | protected override JSONObject ExportResource(ExportPreset preset) 34 | { 35 | JSONObject avatarMaskJSON = new JSONObject(JSONObject.Type.OBJECT); 36 | avatarMaskJSON.AddField("name", avatarMask.name); 37 | JSONObject elementsJSON = new JSONObject(JSONObject.Type.OBJECT); 38 | avatarMaskJSON.AddField("paths", elementsJSON); 39 | for (int i = 0; i < avatarMask.transformCount; i++) 40 | { 41 | elementsJSON.AddField("/" + avatarMask.GetTransformPath(i), avatarMask.GetTransformActive(i) ? 1 : 0); 42 | } 43 | return avatarMaskJSON; 44 | } 45 | 46 | public AvatarMask avatarMask; 47 | 48 | public WXAvatarMask(AvatarMask _avatarMask) : base(AssetDatabase.GetAssetPath(_avatarMask.GetInstanceID())) 49 | { 50 | avatarMask = _avatarMask; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/WXEngineRawResource.cs: -------------------------------------------------------------------------------- 1 |  2 | using System.IO; 3 | using System; 4 | using System.Runtime.CompilerServices; 5 | //using System.Collections.Generic; 6 | //using System.Linq; 7 | //using System.Text; 8 | //using System.Threading.Tasks; 9 | 10 | [assembly: InternalsVisibleToAttribute("ScriptExport")] 11 | namespace WeChat 12 | { 13 | internal class WXRawResource : WXResource 14 | { 15 | 16 | public WXRawResource(string iPath): base(iPath) 17 | { 18 | if (unityAssetPath == null || unityAssetPath == "") 19 | { 20 | ErrorUtil.ExportErrorReporter.create() 21 | .setResource(this) 22 | .error(ErrorUtil.ErrorCode.RawResource_PathError, "RawResource文件的unity路径为空"); 23 | } 24 | } 25 | 26 | private static string GetFileType(string path) 27 | { 28 | // unity supported audio/video formats 29 | string[] audio_video_formats = { ".map", ".ogg", ".wav", ".aiff", ".aif", ".mod", ".it", ".s3m", ".xm", // audio 30 | ".mp4", ".asf", ".avi", ".dv", ".m4v", ".mov", ".mpg", ".mpeg", ".ogv", ".vp8", ".webm", ".wmv" // video 31 | }; 32 | 33 | // unity supported text formats 34 | string[] text_formats = { ".txt", ".html", ".htm", ".xml", ".bytes", ".csv", ".yaml", ".fnt" }; 35 | 36 | // unity supported image formats 37 | string[] image_formats = { ".bmp", ".exr", ".jpg", ".iff", ".pict", ".png", ".psd", ".tga", ".tiff"/*,".gif", ".hdr", ""*/ }; 38 | 39 | // json format 40 | string[] json_formats = { ".json" }; 41 | 42 | int dot_index = path.IndexOf('.'); 43 | 44 | if (dot_index == -1) return "arraybuffer"; 45 | 46 | string suffix_name = path.Substring(dot_index); 47 | 48 | if (Array.IndexOf(audio_video_formats, suffix_name) != -1) return "url"; 49 | else if (Array.IndexOf(text_formats, suffix_name) != -1) return "text"; 50 | else if (Array.IndexOf(image_formats, suffix_name) != -1) return "image"; 51 | else if (Array.IndexOf(json_formats, suffix_name) != -1) return "json"; 52 | // 为了做fbx导出做的逻辑 详讯jasonjwang 53 | else if (suffix_name == ".fbx") return "url"; 54 | 55 | return ""; 56 | } 57 | 58 | public override string GetHash() 59 | { 60 | string asset_version = WXUtility.GetMD5FromAssetPath(unityAssetPath); 61 | return asset_version; 62 | } 63 | 64 | protected override string GetResourceType() 65 | { 66 | return "raw"; 67 | } 68 | 69 | public override string GetExportPath() 70 | { 71 | return unityAssetPath + ".raw"; 72 | } 73 | 74 | protected override JSONObject ExportResource(ExportPreset preset) 75 | { 76 | JSONObject metadata = JSONObject.Create("{\"file\": {}}"); 77 | 78 | string file_type = GetFileType(unityAssetPath); 79 | metadata.GetField("file").SetField("src", AddFile(new WXEngineCopyFile(unityAssetPath, file_type))); 80 | 81 | return metadata; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXBeefBallSkyboxParser.cs: -------------------------------------------------------------------------------- 1 | /* todo shanexy 2 | using System; 3 | using System.Collections.Generic; 4 | using UnityEditor; 5 | using UnityEngine; 6 | namespace WeChat 7 | { 8 | class WXSkyboxParser : WXMaterialParser 9 | { 10 | 11 | public static Texture2D GetCubeMapTextureData(Color[] color) 12 | { 13 | int num = 0; 14 | int num2; 15 | int num3 = num2 = (int)Mathf.Sqrt((float)color.Length); 16 | Texture2D texture2D = new Texture2D(num3, num2); 17 | for (int i = 0; i < num2; i++) 18 | { 19 | for (int j = 0; j < num3; j++) 20 | { 21 | texture2D.SetPixel(j, num2 - 1 - i, color[num++]); 22 | } 23 | } 24 | return texture2D; 25 | } 26 | 27 | public static string SaveSkyboxMaterial(Material material) 28 | { 29 | string name = material.shader.name; 30 | if (name == "Skybox/6 Sided") 31 | { 32 | List dependencies = new List(); 33 | JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); 34 | string frontID = MaterialUtil.SaveMaterialFile(material, "_FrontTex", ref dependencies); 35 | jsonFile.AddField("front", frontID); 36 | string backID = MaterialUtil.SaveMaterialFile(material, "_BackTex", ref dependencies); 37 | jsonFile.AddField("back", backID); 38 | string leftID = MaterialUtil.SaveMaterialFile(material, "_LeftTex", ref dependencies); 39 | jsonFile.AddField("left", leftID); 40 | string rightID = MaterialUtil.SaveMaterialFile(material, "_RightTex", ref dependencies); 41 | jsonFile.AddField("right", rightID); 42 | string upID = MaterialUtil.SaveMaterialFile(material, "_UpTex", ref dependencies); 43 | jsonFile.AddField("up", upID); 44 | string downID = MaterialUtil.SaveMaterialFile(material, "_DownTex", ref dependencies); 45 | jsonFile.AddField("down", downID); 46 | 47 | int instanceID = material.GetInstanceID(); 48 | string path = AssetDatabase.GetAssetPath(instanceID); 49 | path = wxFileUtil.cleanIllegalChar(path.Split('.')[0], false) + ".cubemap.json"; 50 | JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); 51 | metadata.AddField("version", 1); 52 | WXBeefBall.exportContext.AddJSONResource(path, "texturecube", jsonFile, metadata, dependencies); 53 | return path; 54 | } 55 | else if (name == "Skybox/Cubemap") 56 | { 57 | List dependencies = new List(); 58 | JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); 59 | if (material.HasProperty("_Tex")) 60 | { 61 | Cubemap cubemap = (Cubemap)material.GetTexture("_Tex"); 62 | if (cubemap != null) 63 | { 64 | return WXResource.GetExport(cubemap); 65 | } 66 | } 67 | } 68 | return null; 69 | } 70 | 71 | public override void onParse(WXMaterial wxbb_material) 72 | { 73 | 74 | Material material = this.m_material; 75 | 76 | SetEffect("@system/skybox"); 77 | m_dependencies.Add(SaveSkyboxMaterial(material)); 78 | } 79 | 80 | protected override void SetEffect(String effect) 81 | { 82 | m_mainJson.SetField("effect", effect); 83 | } 84 | } 85 | } 86 | */ -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXBlinnPhongNewParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | using System; 6 | using UnityEditor; 7 | using UnityEngine; 8 | 9 | namespace WeChat 10 | { 11 | class WXBlinnPhongNewParser : WXMaterialParser 12 | { 13 | public override void onParse(WXMaterial wxbb_material) 14 | { 15 | Material material = m_material; 16 | 17 | SetEffect("@system/blinnPhongNew"); 18 | 19 | // diffuse texture 20 | AddTexture("_MainTex","_MainTex"); 21 | // diffuse texture scale offset 22 | Vector2 textureScale = material.GetTextureScale("_MainTex"); 23 | Vector2 textureOffset = material.GetTextureOffset("_MainTex"); 24 | AddShaderParam("_MainTex_ST",new float[4] {textureScale.x,textureScale.y,textureOffset.x,textureOffset.y}); 25 | // diffuse intensity 26 | AddShaderParam("_AlbedoIntensity",material.GetFloat("_AlbedoIntensity")); 27 | // diffuse color 28 | AddShaderParam("_Color", material.GetColor("_Color"), true); 29 | // shininess 30 | AddShaderParam("_Shininess", material.GetFloat("_Shininess")); 31 | // specular color 32 | AddShaderParam("_SpecColor", material.GetColor("_SpecColor"), true); 33 | 34 | AddShaderParam("_Cutoff", material.GetFloat("_Cutoff")); 35 | 36 | AddShaderParam("_EmissionColor",material.GetColor("_EmissionColor"),true); 37 | 38 | AddShaderDefination("USE_FOG", (double)material.GetFloat("_Fog") == 1.0 ? false : true); 39 | 40 | // alpha test 41 | if (material.IsKeywordEnabled("_ALPHATEST_ON")) 42 | { 43 | AddShaderDefination("USE_ALPHA_TEST", true); 44 | } 45 | 46 | // spec map 47 | if (material.GetTexture("_SpecGlossMap") != null) 48 | { 49 | AddTexture("_SpecGlossMap", "_SpecGlossMap"); 50 | AddShaderDefination("USE_SPECMAP", true); 51 | } 52 | 53 | // normal map 54 | if (material.GetTexture("_BumpMap") != null) 55 | { 56 | AddTexture("_BumpMap", "_BumpMap"); 57 | AddShaderDefination("USE_NORMALMAP", true); 58 | } 59 | 60 | // emission map 61 | if (material.GetTexture("_EmissionMap") != null) 62 | { 63 | AddTexture("_EmissionMap","_EmissionMap"); 64 | AddShaderDefination("USE_EMISSIONMAP", true); 65 | } 66 | 67 | // alpha blend 68 | if(material.IsKeywordEnabled("_ALPHABLEND_ON")){ 69 | SetBlendOn(true); 70 | SetBlendFactor(ConvertBlendFactor(material.GetInt("_SrcBlend")) ,ConvertBlendFactor(material.GetInt("_DstBlend"))); 71 | }else{ 72 | SetBlendOn(false); 73 | } 74 | // depth write 75 | SetDepthWrite(material.GetInt("_ZWrite") == 1? true:false); 76 | // depth test 77 | SetDepthTest(ConvertCompareFunc(material.GetInt("_ZTest"))); 78 | // cull 79 | SetCullMode(ConvertCullMode(material.GetInt("_Cull"))); 80 | } 81 | 82 | protected override void SetEffect(String effect) 83 | { 84 | m_mainJson.SetField("effect", effect); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXEngineBlinnPhongParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | class WXBlinnPhongParser : WXMaterialParser 8 | { 9 | public override void onParse(WXMaterial wxbb_material) 10 | { 11 | 12 | Material material = this.m_material; 13 | 14 | SetEffect("@system/blinnPhong3d"); 15 | 16 | // diffuse texture 17 | AddTexture("_MainTex", "_MainTex"); 18 | // diffuse texture scale offset 19 | Vector2 textureScale = material.GetTextureScale("_MainTex"); 20 | Vector2 textureOffset = material.GetTextureOffset("_MainTex"); 21 | AddShaderParam("_MainTex_ST", new float[4] { textureScale.x, textureScale.y, textureOffset.x, textureOffset.y }); 22 | // diffuse intensity 23 | AddShaderParam("_AlbedoIntensity", material.GetFloat("_AlbedoIntensity")); 24 | // diffuse color 25 | AddShaderParam("_Color", material.GetColor("_Color"), true); 26 | // shininess 27 | AddShaderParam("_Shininess", material.GetFloat("_Shininess")); 28 | // specular color 29 | AddShaderParam("_SpecColor", material.GetColor("_SpecColor"), false); 30 | 31 | AddShaderParam("_Cutoff", material.GetFloat("_Cutoff")); 32 | 33 | AddShaderParam("_EmissionColor", material.GetColor("_EmissionColor"), true); 34 | 35 | AddShaderDefination("USE_LIGHTING", (double)material.GetFloat("_Lighting") == 0.0 ? true : false); 36 | 37 | // laya里面,这个shader属性是写反了的 38 | AddShaderDefination("USE_FOG", (double)material.GetFloat("_Fog") == 1.0 ? false : true); 39 | 40 | // alpha test 41 | if (material.IsKeywordEnabled("_ALPHATEST_ON")) 42 | { 43 | AddShaderDefination("USE_ALPHA_TEST", true); 44 | } 45 | 46 | // spec map 47 | if (material.GetTexture("_SpecGlossMap") != null) 48 | { 49 | AddTexture("_SpecGlossMap", "_SpecGlossMap"); 50 | AddShaderDefination("USE_SPECMAP", true); 51 | } 52 | 53 | // normal map 54 | if (material.GetTexture("_BumpMap") != null) 55 | { 56 | AddTexture("_BumpMap", "_BumpMap"); 57 | AddShaderDefination("USE_NORMALMAP", true); 58 | } 59 | 60 | // emission map 61 | if (material.GetTexture("_EmissionMap") != null) 62 | { 63 | AddTexture("_EmissionMap", "_EmissionMap"); 64 | AddShaderDefination("USE_EMISSIONMAP", true); 65 | } 66 | 67 | // alpha blend 68 | if (material.IsKeywordEnabled("_ALPHABLEND_ON")) 69 | { 70 | SetBlendOn(true); 71 | SetBlendFactor(ConvertBlendFactor(material.GetInt("_SrcBlend")), ConvertBlendFactor(material.GetInt("_DstBlend"))); 72 | } 73 | else 74 | { 75 | SetBlendOn(false); 76 | } 77 | // depth write 78 | SetDepthWrite(material.GetInt("_ZWrite") == 1 ? true : false); 79 | // depth test 80 | SetDepthTest(ConvertCompareFunc(material.GetInt("_ZTest"))); 81 | // cull 82 | SetCullMode(ConvertCullMode(material.GetInt("_Cull"))); 83 | } 84 | 85 | protected override void SetEffect(String effect) 86 | { 87 | m_mainJson.SetField("effect", effect); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXEngineEffectParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | 8 | class WXEffectParser : WXMaterialParser 9 | { 10 | public override void onParse(WXMaterial wxbb_material) 11 | { 12 | 13 | Material material = this.m_material; 14 | SetEffect("@system/effect3d"); 15 | 16 | // main texture 17 | AddTexture("_MainTex", "_MainTex"); 18 | // main texture scale offset 19 | Vector2 textureScale = material.GetTextureScale("_MainTex"); 20 | Vector2 textureOffset = material.GetTextureOffset("_MainTex"); 21 | AddShaderParam("_MainTex_ST", new float[4] { textureScale.x, textureScale.y, textureOffset.x, textureOffset.y }); 22 | // tint color 23 | AddShaderParam("_TintColor", material.GetColor("_TintColor"), true); 24 | if (material.HasProperty("_Bright")) 25 | { 26 | AddShaderParam("_Bright", material.GetFloat("_Bright")); 27 | } 28 | 29 | // mask texture 30 | AddTexture("_MaskTex", "_MaskTex"); 31 | // additive fog 32 | AddShaderDefination("USE_ADDITIVE_FOG", material.IsKeywordEnabled("ADDTIVEFOG") ? true : false); 33 | 34 | // alpha blend 35 | SetBlendOn(true); 36 | SetBlendFactor(ConvertBlendFactor(material.GetInt("_SrcBlend")), ConvertBlendFactor(material.GetInt("_DstBlend"))); 37 | // // depth write 38 | // SetDepthWrite(material.GetInt("_ZWrite") == 1? true:false); 39 | // // depth test 40 | // SetDepthTest(ConvertCompareFunc(material.GetInt("_ZTest"))); 41 | // // cull 42 | // SetCullMode(ConvertCullMode(material.GetInt("_Cull"))); 43 | } 44 | 45 | protected override void SetEffect(String effect) 46 | { 47 | m_mainJson.SetField("effect", effect); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXEngineLineParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | class WXLineParser : WXMaterialParser 8 | { 9 | public override void onParse(WXMaterial wxbb_material) 10 | { 11 | 12 | Material material = this.m_material; 13 | SetEffect("@system/line"); 14 | 15 | // main texture 16 | AddTexture("_MainTex", "_MainTex"); 17 | // main texture scale offset 18 | Vector2 textureScale = material.GetTextureScale("_MainTex"); 19 | Vector2 textureOffset = material.GetTextureOffset("_MainTex"); 20 | AddShaderParam("_MainTex_ST", new float[4] { textureScale.x, textureScale.y, textureOffset.x, textureOffset.y }); 21 | // tint color 22 | AddShaderParam("_TintColor", material.GetColor("_TintColor"), true); 23 | if (material.HasProperty("_Bright")) 24 | { 25 | AddShaderParam("_Bright", material.GetFloat("_Bright")); 26 | } 27 | 28 | // mask texture 29 | AddTexture("_MaskTex", "_MaskTex"); 30 | // additive fog 31 | AddShaderDefination("USE_ADDITIVE_FOG", material.IsKeywordEnabled("ADDTIVEFOG") ? true : false); 32 | 33 | // alpha blend 34 | SetBlendOn(true); 35 | SetBlendFactor(ConvertBlendFactor(material.GetInt("_SrcBlend")), ConvertBlendFactor(material.GetInt("_DstBlend"))); 36 | // // depth write 37 | // SetDepthWrite(material.GetInt("_ZWrite") == 1? true:false); 38 | // // depth test 39 | // SetDepthTest(ConvertCompareFunc(material.GetInt("_ZTest"))); 40 | // // cull 41 | // SetCullMode(ConvertCullMode(material.GetInt("_Cull"))); 42 | } 43 | 44 | protected override void SetEffect(string effect) 45 | { 46 | m_mainJson.SetField("effect", effect); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXEngineShurikenParticleParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | class WXShurikenParticleParser : WXMaterialParser 8 | { 9 | public override void onParse(WXMaterial wxbb_material) 10 | { 11 | 12 | Material material = this.m_material; 13 | SetEffect("@system/particle3d"); 14 | 15 | // main texture 16 | AddTexture("_MainTex", "_MainTex"); 17 | // main texture scale offset 18 | Vector2 textureScale = material.GetTextureScale("_MainTex"); 19 | Vector2 textureOffset = material.GetTextureOffset("_MainTex"); 20 | AddShaderParam("_MainTex_ST", new float[4] { textureScale.x, textureScale.y, textureOffset.x, textureOffset.y }); 21 | // tint color 22 | AddShaderParam("_TintColor", material.GetColor("_TintColor"), true); 23 | if (material.HasProperty("_Bright")) 24 | { 25 | AddShaderParam("_Bright", material.GetFloat("_Bright")); 26 | } 27 | 28 | // mask texture 29 | AddTexture("_MaskTex", "_MaskTex"); 30 | // additive fog 31 | AddShaderDefination("USE_ADDITIVE_FOG", material.IsKeywordEnabled("ADDTIVEFOG") ? true : false); 32 | 33 | // alpha blend 34 | SetBlendOn(true); 35 | SetBlendFactor(ConvertBlendFactor(material.GetInt("_SrcBlend")), ConvertBlendFactor(material.GetInt("_DstBlend"))); 36 | // // depth write 37 | // SetDepthWrite(material.GetInt("_ZWrite") == 1 ? true : false); 38 | // // depth test 39 | // SetDepthTest(ConvertCompareFunc(material.GetInt("_ZTest"))); 40 | // // cull 41 | // SetCullMode(ConvertCullMode(material.GetInt("_Cull"))); 42 | } 43 | 44 | protected override void SetEffect(String effect) 45 | { 46 | m_mainJson.SetField("effect", effect); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXEngineSkyBoxParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | class WXSkyBoxParser:WXMaterialParser 8 | { 9 | 10 | public override void onParse(WXMaterial wxbb_material) 11 | { 12 | Material material = this.m_material; 13 | 14 | SetEffect("@system/skybox"); 15 | 16 | AddTexture("_MainTex", "_Tex"); 17 | 18 | AddShaderParam("_TintColor", material.GetColor("_TintColor"), true); 19 | 20 | AddShaderParam("_Exposure", material.GetFloat("_Exposure")); 21 | AddShaderParam("_Rotation", material.GetFloat("_Rotation")); 22 | 23 | } 24 | 25 | 26 | protected override void SetEffect(String effect) 27 | { 28 | m_mainJson.SetField("effect", effect); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/Resource/material/WXEngineTrailParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | 8 | class WXTrailParser : WXMaterialParser 9 | { 10 | public override void onParse(WXMaterial wxbb_material) 11 | { 12 | 13 | Material material = this.m_material; 14 | SetEffect("@system/trail"); 15 | 16 | // main texture 17 | AddTexture("_MainTex", "_MainTex"); 18 | // main texture scale offset 19 | Vector2 textureScale = material.GetTextureScale("_MainTex"); 20 | Vector2 textureOffset = material.GetTextureOffset("_MainTex"); 21 | AddShaderParam("_MainTex_ST", new float[4] { textureScale.x, textureScale.y, textureOffset.x, textureOffset.y }); 22 | // tint color 23 | AddShaderParam("_TintColor", material.GetColor("_TintColor"), true); 24 | if (material.HasProperty("_Bright")) 25 | { 26 | AddShaderParam("_Bright", material.GetFloat("_Bright")); 27 | } 28 | 29 | // mask texture 30 | AddTexture("_MaskTex", "_MaskTex"); 31 | // additive fog 32 | AddShaderDefination("USE_ADDITIVE_FOG", material.IsKeywordEnabled("ADDTIVEFOG") ? true : false); 33 | 34 | // alpha blend 35 | SetBlendOn(true); 36 | SetBlendFactor(ConvertBlendFactor(material.GetInt("_SrcBlend")), ConvertBlendFactor(material.GetInt("_DstBlend"))); 37 | // depth write 38 | // SetDepthWrite(material.GetInt("_ZWrite") == 1? true:false); 39 | // // depth test 40 | // SetDepthTest(ConvertCompareFunc(material.GetInt("_ZTest"))); 41 | // // cull 42 | // SetCullMode(ConvertCullMode(material.GetInt("_Cull"))); 43 | } 44 | 45 | protected override void SetEffect(string effect) 46 | { 47 | m_mainJson.SetField("effect", effect); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /unity-plugin/core/editor/src/base/BeefBallConfig.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | namespace WeChat 5 | { 6 | public class BeefBallConfig : ScriptableObject 7 | { 8 | public string storagePath; 9 | 10 | public string exportPath; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /unity-plugin/core/runtime/PostProcess/WXPostProcess.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * @File 后处理component,加在相机物体上使用 3 | * @Author shanexyzhou 4 | * @Date 2020.1.6 5 | */ 6 | 7 | using UnityEngine; 8 | 9 | namespace WeChat 10 | { 11 | [ExecuteInEditMode, ImageEffectAllowedInSceneView] 12 | [AddComponentMenu("WeChat/Post Process", 0)] 13 | public class WXPostProcess : MonoBehaviour 14 | { 15 | public WXPostProcessProfile profile; 16 | 17 | void OnRenderImage(RenderTexture source, RenderTexture destination) 18 | { 19 | if (profile == null) 20 | { 21 | Graphics.Blit(source, destination); 22 | return; 23 | } 24 | profile.OnRender(source, destination); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /unity-plugin/core/runtime/PostProcess/WXPostProcessEditorAttribute.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * @Attribute 由于后处理editor没有继承Editor,所以用这个attr来声明editor, 3 | * 如果没有声明editor,就会用unity默认的inspector面板 4 | * @Author shanexyzhou 5 | * @Date 2020.1.7 6 | */ 7 | 8 | using System; 9 | 10 | namespace WeChat { 11 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 12 | public class WXPostProcessEditorAttribute : Attribute 13 | { 14 | public readonly Type settingsType; 15 | 16 | public WXPostProcessEditorAttribute(Type settingsType) 17 | { 18 | this.settingsType = settingsType; 19 | } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /unity-plugin/core/runtime/PostProcess/WXPostProcessEffectNameAttribute.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * @Attribute 用来注册effect的名字,如果没注册的话就显示类名 3 | * @Author shanexyzhou 4 | * @Date 2020.1.7 5 | */ 6 | using System; 7 | 8 | namespace WeChat { 9 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 10 | public class WXPostProcessEffectNameAttribute : Attribute 11 | { 12 | public readonly string effectName; 13 | 14 | public WXPostProcessEffectNameAttribute(string effectName) 15 | { 16 | this.effectName = effectName; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /unity-plugin/core/runtime/PostProcess/WXPostProcessEffectSetting.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * @File 后处理的某一步effect,作为asset依附于某一个profile存在,在hierarchy中隐藏 3 | * @Author shanexyzhou 4 | * @Date 2020.1.6 5 | */ 6 | 7 | using UnityEngine; 8 | using System; 9 | 10 | namespace WeChat { 11 | [Serializable] 12 | public abstract class WXPostProcessEffectSetting : ScriptableObject 13 | { 14 | [HideInInspector] 15 | public bool active = true; 16 | 17 | public abstract void OnRender(RenderTexture source, RenderTexture destination); 18 | 19 | public abstract JSONObject Export(); 20 | } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /unity-plugin/core/runtime/PostProcess/WXPostProcessProfile.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * @File 后处理profile,作为asset独立存在,多个后处理component可以引用同一个profile 3 | * @Author shanexyzhou 4 | * @Date 2020.1.6 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using UnityEngine; 10 | 11 | namespace WeChat { 12 | public class WXPostProcessProfile : ScriptableObject 13 | { 14 | public List settings = new List(); 15 | 16 | RenderTexture[] mid = new RenderTexture[2]; 17 | 18 | [NonSerialized] 19 | public bool isDirty = true; 20 | 21 | public void OnRender(RenderTexture source, RenderTexture destination) 22 | { 23 | #if UNITY_2017_1_OR_NEWER 24 | mid[0] = RenderTexture.GetTemporary(source.descriptor); 25 | mid[1] = RenderTexture.GetTemporary(source.descriptor); 26 | #else 27 | mid[0] = RenderTexture.GetTemporary(source.width, source.height, source.depth, source.format, 28 | RenderTextureReadWrite.Default, source.antiAliasing); 29 | mid[1] = RenderTexture.GetTemporary(source.width, source.height, source.depth, source.format, 30 | RenderTextureReadWrite.Default, source.antiAliasing); 31 | #endif 32 | int flip = 1; 33 | Graphics.Blit(source, mid[0]); 34 | foreach (var setting in settings) 35 | { 36 | if (!setting.active) continue; 37 | setting.OnRender(mid[1 - flip], mid[flip]); 38 | flip = 1 - flip; 39 | } 40 | Graphics.Blit(mid[1 - flip], destination); 41 | RenderTexture.ReleaseTemporary(mid[0]); 42 | RenderTexture.ReleaseTemporary(mid[1]); 43 | } 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /unity-plugin/core/runtime/WXRawResourceCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.IO; 5 | 6 | 7 | namespace WeChat 8 | { 9 | public class WXRawResourceCollection : MonoBehaviour 10 | { 11 | public Object[] ResourceFiles; 12 | } 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /unity-plugin/core/runtime/lib/AttributeUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | namespace WeChat { 4 | public static class wxAttributeUtil { 5 | public static T GetAttribute (System.Type t) where T : Attribute { 6 | object[] attrs = t.GetCustomAttributes (typeof (T), true); 7 | if (attrs.Length == 0) { 8 | return null; 9 | } else { 10 | return (attrs[0] as T); 11 | } 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /unity-plugin/framework/editor/core/BeefBall.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | using System; 5 | 6 | namespace WeChat 7 | { 8 | [InitializeOnLoad] 9 | public class BeefBall : ScriptableObject 10 | { 11 | static BeefBall() 12 | { 13 | onInitializeCheckers = new List(); 14 | } 15 | // 插件各处用于初始化操作的delegate 16 | public delegate void OnExportInitializeChecker(); 17 | static public List onInitializeCheckers; 18 | static public void DoInstallationCheck() 19 | { 20 | if (onInitializeCheckers != null && onInitializeCheckers.Count != 0) 21 | { 22 | EditorUtility.DisplayProgressBar("初始化导出", "正在初始化0/" + onInitializeCheckers.Count, 0); 23 | try 24 | { 25 | for (int i = 0; i < onInitializeCheckers.Count; i++) 26 | { 27 | OnExportInitializeChecker checker = onInitializeCheckers[i]; 28 | checker(); 29 | EditorUtility.DisplayProgressBar( 30 | "初始化导出", 31 | "正在初始化" + i + "/" + onInitializeCheckers.Count, 32 | (float)i / onInitializeCheckers.Count 33 | ); 34 | } 35 | } 36 | catch (Exception e) 37 | { 38 | Debug.LogError("导出初始化失败:" + e.Message); 39 | Debug.LogError(e.StackTrace); 40 | } 41 | finally 42 | { 43 | EditorUtility.ClearProgressBar(); 44 | } 45 | } 46 | } 47 | 48 | // preset 运行完成后的回调 49 | public delegate void OnPresetCompletedEvent(); 50 | static private OnPresetCompletedEvent onPresetCompletedEvents; 51 | static public void RegisterPresetCompleteEvent(OnPresetCompletedEvent onCompleted) 52 | { 53 | onPresetCompletedEvents += onCompleted; 54 | } 55 | static public void UnregisterPresetCompleteEvent(OnPresetCompletedEvent onCompleted) 56 | { 57 | onPresetCompletedEvents -= onCompleted; 58 | } 59 | static public void OnPresetComplete() 60 | { 61 | if (onPresetCompletedEvents != null) 62 | { 63 | onPresetCompletedEvents(); 64 | } 65 | } 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /unity-plugin/framework/editor/core/PluginHub.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using UnityEngine.Networking; 6 | using System.Runtime.CompilerServices; 7 | using System.IO; 8 | 9 | [assembly: InternalsVisibleToAttribute("Core"), InternalsVisibleToAttribute("ScriptExport")] 10 | namespace WeChat { 11 | /** 12 | * 模块管理窗口 13 | */ 14 | public class PluginHub { 15 | //[MenuItem ("微信小游戏/测试用", false, 111)] 16 | //static void test () { 17 | // TextAsset text = Resources.Load ("WeChatGameConfig/index"); 18 | // Debug.Log (text); 19 | //} 20 | 21 | [MenuItem ("微信小游戏/扩展模块管理", false, 111)] 22 | static void showPluginUI () { 23 | string title = "安装扩展模块"; 24 | HubWindow window = (HubWindow) EditorWindow.GetWindow (typeof (HubWindow), true, title); 25 | } 26 | 27 | // 导出插件版本。该字符串会在构建流程里被修改,请勿改动 28 | private static string _frameworkVersion = "0.7.0"; 29 | 30 | // 分辨是源码版还是发布后的代码版 31 | public static readonly string distribution = "Debug"; 32 | 33 | public static string frameworkVersion { 34 | get { return _frameworkVersion; } 35 | 36 | set { 37 | 38 | string pluginVersionPath = Path.Combine (DirectoryStructure.TopRoot, "version.md"); 39 | 40 | if (_frameworkVersion == value && File.Exists (pluginVersionPath)) { 41 | return; 42 | } 43 | 44 | _frameworkVersion = value; 45 | using (StreamWriter sw = new StreamWriter (pluginVersionPath)) { 46 | sw.Write (_frameworkVersion); 47 | } 48 | } 49 | } 50 | public static string readVersionFromFile () { 51 | string pluginVersionPath = Path.Combine (DirectoryStructure.TopRoot, "version.md"); 52 | if (File.Exists (pluginVersionPath)) { 53 | using (var sr = new StreamReader (pluginVersionPath)) { 54 | _frameworkVersion = sr.ReadToEnd (); 55 | } 56 | } 57 | return _frameworkVersion; 58 | } 59 | public static List versionList = new List (new string[] { "0.7.0" }); 60 | public static int versionIndex = 0; 61 | public static ExportPluginModule coreModule = null; 62 | public static ExportPluginModule nguiModule = null; 63 | } 64 | } -------------------------------------------------------------------------------- /unity-plugin/framework/editor/core/UnityVersion.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace WeChat 5 | { 6 | public static class UnityVersion 7 | { 8 | 9 | public static bool UNITY_2019_4_OR_NEWER 10 | { 11 | get 12 | { 13 | return Application.unityVersion.StartsWith("2019.4"); 14 | } 15 | } 16 | public static bool UNITY_2019_3_OR_NEWER 17 | { 18 | get 19 | { 20 | return Application.unityVersion.StartsWith("2019.3") || UnityVersion.UNITY_2019_4_OR_NEWER; 21 | } 22 | } 23 | public static bool UNITY_2019_2_OR_NEWER 24 | { 25 | get 26 | { 27 | return Application.unityVersion.StartsWith("2019.2") || UnityVersion.UNITY_2019_3_OR_NEWER; 28 | } 29 | } 30 | public static bool UNITY_2019_1_OR_NEWER 31 | { 32 | get 33 | { 34 | return Application.unityVersion.StartsWith("2019.1") || UnityVersion.UNITY_2019_2_OR_NEWER; 35 | } 36 | } 37 | public static bool UNITY_2018_4_OR_NEWER 38 | { 39 | get 40 | { 41 | return Application.unityVersion.StartsWith("2018.4") || UnityVersion.UNITY_2019_1_OR_NEWER; 42 | } 43 | } 44 | public static bool UNITY_2018_3_OR_NEWER 45 | { 46 | get 47 | { 48 | return Application.unityVersion.StartsWith("2018.3") || UnityVersion.UNITY_2018_4_OR_NEWER; 49 | } 50 | } 51 | public static bool UNITY_2018_2_OR_NEWER 52 | { 53 | get 54 | { 55 | return Application.unityVersion.StartsWith("2018.2") || UnityVersion.UNITY_2018_3_OR_NEWER; 56 | } 57 | } 58 | 59 | public static bool UNITY_2018_1_OR_NEWER 60 | { 61 | get 62 | { 63 | return Application.unityVersion.StartsWith("2018.1") || UnityVersion.UNITY_2018_2_OR_NEWER; 64 | } 65 | } 66 | 67 | public static bool UNITY_2017_4_OR_NEWER 68 | { 69 | get 70 | { 71 | return Application.unityVersion.StartsWith("2017.4") || UnityVersion.UNITY_2018_1_OR_NEWER; 72 | } 73 | } 74 | 75 | public static bool UNITY_2017_1_OR_NEWER 76 | { 77 | get 78 | { 79 | return Application.unityVersion.StartsWith("2017.1") || UnityVersion.UNITY_2017_4_OR_NEWER; 80 | } 81 | } 82 | 83 | public static bool UNITY_5_6_OR_NEWER 84 | { 85 | get 86 | { 87 | return Application.unityVersion.StartsWith("5.6") || UnityVersion.UNITY_2017_1_OR_NEWER; 88 | } 89 | 90 | } 91 | 92 | public static bool UNITY_5_5_OR_NEWER 93 | { 94 | get 95 | { 96 | return Application.unityVersion.StartsWith("5.5") || UnityVersion.UNITY_5_6_OR_NEWER; 97 | } 98 | 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /unity-plugin/framework/editor/editorUI/AnalyzeMenu.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | namespace WeChat 5 | { 6 | /** 7 | * 8 | * 9 | */ 10 | // public class AnalyzeMenu : ScriptableObject 11 | // { 12 | // [MenuItem("微信小游戏/项目分析/bridge分析", false, 121)] 13 | // static void bridge() 14 | // { 15 | 16 | // } 17 | // [MenuItem("微信小游戏/项目分析/代码分析", false, 122)] 18 | // static void code() 19 | // { 20 | 21 | // } 22 | // [MenuItem("微信小游戏/项目分析/依赖分析", false, 123)] 23 | // static void dep() 24 | // { 25 | 26 | // } 27 | // } 28 | 29 | } -------------------------------------------------------------------------------- /unity-plugin/framework/editor/editorUI/SupportMenu.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | namespace WeChat 5 | { 6 | /** 7 | * 8 | * 9 | */ 10 | public class SupportMenu 11 | { 12 | 13 | [MenuItem("微信小游戏/技术支持/github", false, 131)] 14 | static void Github1() 15 | { 16 | Application.OpenURL("https://github.com/wechat-miniprogram/minigame-adaptor"); 17 | } 18 | 19 | // [MenuItem("微信小游戏/技术支持/test", false, 131)] 20 | // static void test() 21 | // { 22 | // Debug.Log(Selection.activeObject.GetType()); 23 | // } 24 | 25 | [MenuItem("微信小游戏/技术支持/下载微信开发者工具", false, 132)] 26 | static void Devtool() 27 | { 28 | Application.OpenURL("https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html"); 29 | } 30 | 31 | [MenuItem("微信小游戏/技术支持/微信小游戏性能优化方案文档", false, 133)] 32 | static void Doc() 33 | { 34 | Application.OpenURL("https://developers.weixin.qq.com/minigame/dev/game-engine/"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /unity-plugin/framework/editor/module/ExportModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | /** 8 | * 表示导出插件一个子模块的抽象类 9 | * 10 | */ 11 | public abstract class ExportPluginModule 12 | { 13 | // 核心模块 14 | public static ExportPluginModule coreModule; 15 | // ngui模块 16 | public static ExportPluginModule nguiModule; 17 | 18 | 19 | public static void registerExportPluginModule(string name, ExportPluginModule pluginModule) 20 | { 21 | if (name == "core") 22 | { 23 | coreModule = pluginModule; 24 | } 25 | if (name == "ngui") 26 | { 27 | nguiModule = pluginModule; 28 | } 29 | } 30 | 31 | public string ModuleName 32 | { 33 | get; set; 34 | } 35 | 36 | public string ModuleVersion 37 | { 38 | get; set; 39 | } 40 | 41 | // 首次安装回调,只应执行一次 42 | public virtual void OnModuleInstall() 43 | { 44 | 45 | } 46 | 47 | // 现在没有卸载了,先删掉 48 | //public virtual void OnModuleUninstall() 49 | //{ 50 | 51 | //} 52 | 53 | // 初始化回调 54 | // 每次重新编译后都会走到 55 | public virtual void OnModuleInit() 56 | { 57 | 58 | } 59 | 60 | // 要清资源 61 | public virtual void OnModuleVersionChange() 62 | { 63 | 64 | } 65 | 66 | 67 | public ExportPluginModule(string moduleName = "module", string moduleVersion = "1.0.0") 68 | { 69 | this.ModuleName = moduleName; 70 | this.ModuleVersion = moduleVersion; 71 | // Debug.Log(moduleName); 72 | BeefBall.onInitializeCheckers.Add(OnModuleInit); 73 | OnModuleInstall(); 74 | } 75 | 76 | public override string ToString() 77 | { 78 | return "[WXEngineModule]: <" + this.ModuleName + "> (" + this.ModuleVersion + ")"; 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /unity-plugin/framework/reference/editor/ICSharpCode.SharpZipLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/unity-plugin/framework/reference/editor/ICSharpCode.SharpZipLib.dll -------------------------------------------------------------------------------- /unity-plugin/framework/reference/editor/Pri.LongPath.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-adaptor/3ccb9639a46b9b948b18e427351a3287e5b7699c/unity-plugin/framework/reference/editor/Pri.LongPath.dll -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXBaseUIComponent.cs: -------------------------------------------------------------------------------- 1 |  2 | using UnityEngine; 3 | 4 | namespace WeChat 5 | { 6 | 7 | public abstract class WXNGUIComponent : WXComponent 8 | { 9 | protected GameObject gameObject; 10 | protected WXEntity entity; 11 | public WXNGUIComponent(Component nativeComponent, GameObject gameObject, WXEntity entity) { 12 | this.gameObject = gameObject; 13 | this.entity = entity; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXKeyboardInputComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXKeyboardInputComponent : WXNGUIComponent 14 | { 15 | 16 | public override string getTypeName() 17 | { 18 | return "KeyboardInputComponent"; 19 | } 20 | 21 | private UIInput uiInput; 22 | public WXKeyboardInputComponent(UIInput _uiInput, GameObject gameObject, WXEntity entity): base(_uiInput, gameObject, entity) 23 | { 24 | this.uiInput = _uiInput; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", "KeyboardInputComponent"); 31 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 32 | subJSON.AddField("active", this.uiInput.enabled); 33 | json.AddField("data", subJSON); 34 | return json; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXTouchInputComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXTouchInputComponent : WXNGUIComponent 14 | { 15 | 16 | public override string getTypeName() 17 | { 18 | return "TouchInputComponent"; 19 | } 20 | 21 | private UIButton uiButton; 22 | private float[] hitArea = null; 23 | public WXTouchInputComponent(BoxCollider boxCollider, GameObject _gameObj, WXEntity entity) : base(boxCollider, _gameObj, entity) 24 | { 25 | if (boxCollider != null) 26 | { 27 | float[] hitArea = { boxCollider.center.x - boxCollider.size.x / 2.0f, boxCollider.center.y - boxCollider.size.y / 2.0f, boxCollider.size.x, boxCollider.size.y }; 28 | this.hitArea = hitArea; 29 | } 30 | } 31 | 32 | protected override JSONObject ToJSON(WXHierarchyContext context) 33 | { 34 | 35 | // Debug.Log("WXBeefBallTouchInputComponent:"); 36 | // var output = JsonUtility.ToJson(gameObj, true); 37 | // Debug.Log(output); 38 | 39 | 40 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 41 | json.AddField("type", "TouchInputComponent"); 42 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 43 | subJSON.AddField("touchThrough", false); 44 | if (hitArea != null) 45 | { 46 | JSONObject hitJSON = new JSONObject(JSONObject.Type.ARRAY); 47 | for (int i = 0; i < hitArea.Length; i++) 48 | { 49 | hitJSON.Add(hitArea[i]); 50 | } 51 | subJSON.AddField("hitArea", hitJSON); 52 | subJSON.AddField("useAchor", true); 53 | } 54 | json.AddField("data", subJSON); 55 | 56 | if (gameObject.transform.parent) 57 | { 58 | var isScrollitem = isScrollChild(gameObject.transform.parent.gameObject); 59 | subJSON.AddField("touchThrough", isScrollitem); 60 | } 61 | else 62 | { 63 | subJSON.AddField("touchThrough", false); 64 | } 65 | 66 | 67 | return json; 68 | } 69 | 70 | private bool isScrollChild(GameObject go) 71 | { 72 | if (go.transform.parent == null) 73 | { 74 | return false; 75 | } 76 | 77 | var isScrollView = go.GetComponent(typeof(UIScrollView)) as UIScrollView; 78 | if (isScrollView) 79 | { 80 | return true; 81 | } 82 | else 83 | { 84 | return isScrollChild(go.transform.parent.gameObject); 85 | } 86 | } 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIAnchor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using UnityEditor.Animations; 8 | using System.IO; 9 | using System.Text; 10 | namespace WeChat 11 | 12 | { 13 | 14 | public class WXUIAnchor : WXNGUIComponent 15 | { 16 | public override string getTypeName() 17 | { 18 | return "UIAnchor"; 19 | } 20 | 21 | private UIAnchor uiAnchor; 22 | public WXUIAnchor(UIAnchor _uiAnchor, GameObject _gameObj, WXEntity entity): base(_uiAnchor, _gameObj, entity) 23 | { 24 | this.uiAnchor = _uiAnchor; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | var a = JsonUtility.ToJson(uiAnchor, true); 30 | 31 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 32 | json.AddField("type", "UIAnchor"); 33 | 34 | 35 | JSONObject data = new JSONObject(JSONObject.Type.OBJECT); 36 | data.AddField("side", uiAnchor.side.ToString()); 37 | 38 | JSONObject pixelOffset = new JSONObject(JSONObject.Type.ARRAY); 39 | pixelOffset.Add(uiAnchor.pixelOffset.x); 40 | pixelOffset.Add(uiAnchor.pixelOffset.y); 41 | data.AddField("pixelOffset", pixelOffset); 42 | 43 | JSONObject relativeOffset = new JSONObject(JSONObject.Type.ARRAY); 44 | relativeOffset.Add(uiAnchor.relativeOffset.x); 45 | relativeOffset.Add(uiAnchor.relativeOffset.y); 46 | data.AddField("relativeOffset", relativeOffset); 47 | 48 | json.AddField("data", data); 49 | 50 | return json; 51 | } 52 | } 53 | 54 | 55 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIAtlas.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | 12 | { 13 | 14 | public class WXUIAtlas : WXNGUIComponent 15 | { 16 | 17 | public override string getTypeName() 18 | { 19 | return "UIAtlas"; 20 | } 21 | 22 | private UIAtlas uiAtlas; 23 | public WXUIAtlas(UIAtlas _uiAtlas, GameObject gameObject, WXEntity entity): base(_uiAtlas, gameObject, entity) 24 | { 25 | this.uiAtlas = _uiAtlas; 26 | } 27 | 28 | protected override JSONObject ToJSON(WXHierarchyContext context) 29 | { 30 | Texture2D texture2D = (Texture2D)(uiAtlas.spriteMaterial).GetTexture("_MainTex"); 31 | if (texture2D != null) 32 | { 33 | string path = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); 34 | string texturePath = new WXTexture(texture2D).Export(context.preset); 35 | context.AddResource(texturePath); 36 | 37 | for (int i = 0; i < uiAtlas.spriteList.Count; i++) 38 | { 39 | string spriteframePath = new WXSpriteFrame(uiAtlas.spriteList[i], texturePath, path).Export(context.preset); 40 | context.AddResource(spriteframePath); 41 | } 42 | } 43 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 44 | json.AddField("type", "UIAtlas"); 45 | return json; 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIGraphic.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXUIGraphic : WXComponent 14 | { 15 | 16 | public override string getTypeName() 17 | { 18 | return "UIGraphic"; 19 | } 20 | private int shape; 21 | public WXUIGraphic(int shape) 22 | { 23 | this.shape = shape; 24 | } 25 | 26 | protected override JSONObject ToJSON(WXHierarchyContext context) 27 | { 28 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 29 | json.AddField("type", "UIGraphic"); 30 | 31 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 32 | 33 | int shape = this.shape; 34 | subJSON.AddField("shape", (int)shape); 35 | 36 | json.AddField("data", subJSON); 37 | 38 | return json; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIGrid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | 12 | { 13 | 14 | public class WXUIGrid : WXNGUIComponent 15 | { 16 | 17 | public override string getTypeName() 18 | { 19 | return "UIGrid"; 20 | } 21 | private UIGrid uiGrid; 22 | public WXUIGrid(UIGrid _uiGrid, GameObject gameObject, WXEntity entity) : base(_uiGrid, gameObject, entity) 23 | { 24 | this.uiGrid = _uiGrid; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", "UIGrid"); 31 | 32 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 33 | 34 | //var a = JsonUtility.ToJson(uiGrid, true); 35 | //Debug.Log("========================"); 36 | //Debug.Log(a); 37 | //Debug.Log("------------"); 38 | //Debug.Log(uiGrid.pivot); 39 | 40 | UIGrid.Arrangement arrangement = uiGrid.arrangement; 41 | subJSON.AddField("arrangement", (int)arrangement); 42 | 43 | float cellWidth = uiGrid.cellWidth; 44 | subJSON.AddField("cellWidth", (float)cellWidth); 45 | 46 | float cellHeight = uiGrid.cellHeight; 47 | subJSON.AddField("cellHeight", (float)cellHeight); 48 | 49 | int columns = uiGrid.maxPerLine; // 命名兼容UITable,每行|列最多个数,0为自动 50 | subJSON.AddField("columns", (int)columns); 51 | 52 | int paddingX = 0; // 命名兼容UITable 53 | subJSON.AddField("paddingX", (int)paddingX); 54 | 55 | int paddingY = 0; // 命名兼容UITable 56 | subJSON.AddField("paddingY", (int)paddingY); 57 | 58 | bool autoSize = false; // Grid指定大小,不需要自动撑大,此处为兼容UITable 59 | subJSON.AddField("autoSize", autoSize); 60 | 61 | 62 | json.AddField("data", subJSON); 63 | 64 | return json; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIMask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | 12 | { 13 | 14 | public class WXUIMask : WXComponent 15 | { 16 | 17 | public override string getTypeName() 18 | { 19 | return "UIMask"; 20 | } 21 | public WXUIMask() 22 | { 23 | } 24 | 25 | protected override JSONObject ToJSON(WXHierarchyContext context) 26 | { 27 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 28 | json.AddField("type", "UIMask"); 29 | 30 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 31 | 32 | json.AddField("data", subJSON); 33 | 34 | return json; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIPanel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | public class WXUIPanel : WXNGUIComponent 13 | { 14 | 15 | public override string getTypeName() 16 | { 17 | return "UIPanel"; 18 | } 19 | 20 | private UIPanel uiPanel; 21 | public WXUIPanel(UIPanel _uiPanel, GameObject gameObject, WXEntity entity) : base(_uiPanel, gameObject, entity) 22 | { 23 | this.uiPanel = _uiPanel; 24 | } 25 | 26 | protected override JSONObject ToJSON(WXHierarchyContext context) 27 | { 28 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 29 | json.AddField("type", "UIPanel"); 30 | // json.AddField("alpha", uiPanel.alpha); 31 | // json.AddField("depth", uiPanel.depth); 32 | 33 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 34 | json.AddField("data", subJSON); 35 | 36 | return json; 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIRoot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXBBUIRoot : WXNGUIComponent 14 | { 15 | 16 | public override string getTypeName() 17 | { 18 | return "UICanvas"; 19 | } 20 | 21 | private UIRoot uiRoot; 22 | public WXBBUIRoot(UIRoot _uiRoot, GameObject gameObject, WXEntity entity) : base(_uiRoot, gameObject, entity) 23 | { 24 | this.uiRoot = _uiRoot; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", this.getTypeName()); 31 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 32 | json.AddField("data", subJSON); 33 | return json; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUITable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using UnityEditor.Animations; 8 | using System.IO; 9 | using System.Text; 10 | 11 | namespace WeChat 12 | { 13 | 14 | public class WXUITable : WXNGUIComponent 15 | { 16 | 17 | public override string getTypeName() 18 | { 19 | return "UIGrid"; 20 | } 21 | private UITable uiTable; 22 | public WXUITable(UITable _uiTable, GameObject gameObject, WXEntity entity) : base(_uiTable, gameObject, entity) 23 | { 24 | this.uiTable = _uiTable; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", "UIGrid"); 31 | 32 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 33 | 34 | // var a = JsonUtility.ToJson(uiTable, true); 35 | // Debug.Log("++++++++++++++++++"); 36 | // Debug.Log(a); 37 | 38 | int arrangement = 1; // 仅用于兼容Grid参数,水平 39 | subJSON.AddField("arrangement", (int)arrangement); 40 | 41 | float cellWidth = 0; // 仅用于兼容Grid参数,Table会自动获取子元素高度撑大自身 42 | subJSON.AddField("cellWidth", (float)cellWidth); 43 | 44 | float cellHeight = 0; // 仅用于兼容Grid参数,Table会自动获取子元素高度撑大自身 45 | subJSON.AddField("cellHeight", (float)cellHeight); 46 | 47 | int columns = uiTable.columns; 48 | subJSON.AddField("columns", (int)columns); 49 | 50 | var cellAlignmentValue = WXUtility.TryGetContainField(uiTable, "cellAlignment"); 51 | // Debug.Log(cellAlignmentValue); 52 | if (cellAlignmentValue != null) 53 | { 54 | UIWidget.Pivot cellPivot = (UIWidget.Pivot)cellAlignmentValue; 55 | float cellAlignmentX = ( 56 | cellPivot == UIWidget.Pivot.Left || 57 | cellPivot == UIWidget.Pivot.TopLeft || 58 | cellPivot == UIWidget.Pivot.BottomLeft 59 | ) ? 0.0f : (( 60 | cellPivot == UIWidget.Pivot.Center || 61 | cellPivot == UIWidget.Pivot.Top || 62 | cellPivot == UIWidget.Pivot.Bottom) ? 0.5f : 1.0f); 63 | 64 | float cellAlignmentY = ( 65 | cellPivot == UIWidget.Pivot.Bottom || 66 | cellPivot == UIWidget.Pivot.BottomLeft || 67 | cellPivot == UIWidget.Pivot.BottomRight 68 | ) ? 0.0f : (( 69 | cellPivot == UIWidget.Pivot.Left || 70 | cellPivot == UIWidget.Pivot.Center || 71 | cellPivot == UIWidget.Pivot.Right) ? 0.5f : 1.0f); 72 | subJSON.AddField("cellAlignmentX", cellAlignmentX); 73 | subJSON.AddField("cellAlignmentY", cellAlignmentY); 74 | } 75 | 76 | bool autoSize = true; // 表格则自动由子元素撑大本身单元格大小 77 | subJSON.AddField("autoSize", (bool)autoSize); 78 | 79 | int paddingX = (int)uiTable.padding.x; // 横向间距大小 80 | subJSON.AddField("paddingX", (int)paddingX); 81 | 82 | int paddingY = (int)uiTable.padding.y; // 纵向间距大小 83 | subJSON.AddField("paddingY", (int)paddingY); 84 | 85 | int columnLimit = uiTable.columns; // 每行|列最多个数,0为自动 86 | subJSON.AddField("columnLimit", (int)columnLimit); 87 | 88 | json.AddField("data", subJSON); 89 | 90 | return json; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUITextInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXUITextInput : WXNGUIComponent 14 | { 15 | public override string getTypeName() 16 | { 17 | return "UITextInput"; 18 | } 19 | 20 | private UIInput uiInput; 21 | public WXUITextInput(UIInput _uiInput, GameObject gameObject, WXEntity entity): base(_uiInput, gameObject, entity) 22 | { 23 | this.uiInput = _uiInput; 24 | this.entity = entity; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", "UITextInput"); 31 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 32 | 33 | 34 | if (uiInput.label) 35 | { 36 | subJSON.AddField("label", context.AddComponentInProperty(new WXUILabel(uiInput.label, gameObject, entity), uiInput.label)); 37 | } 38 | 39 | WXUIMask mask = new WXUIMask(); 40 | WXUIGraphic graphic = new WXUIGraphic(0); 41 | WXKeyboardInputComponent keyboardInput = new WXKeyboardInputComponent(this.uiInput, gameObject, entity); 42 | 43 | entity.components.Add(context.AddComponent(keyboardInput, null)); 44 | entity.components.Add(context.AddComponent(mask, null)); 45 | entity.components.Add(context.AddComponent(graphic, null)); 46 | 47 | subJSON.AddField("maxChars", uiInput.characterLimit); 48 | 49 | subJSON.AddField("active", this.uiInput.enabled); 50 | json.AddField("data", subJSON); 51 | return json; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUITexture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UnityEditor.Animations; 7 | using System.IO; 8 | using System.Text; 9 | 10 | namespace WeChat 11 | { 12 | 13 | public class WXUITexture : WXNGUIComponent 14 | { 15 | 16 | public override string getTypeName() 17 | { 18 | return "UISprite"; 19 | } 20 | 21 | private UITexture uiTexture; 22 | public WXUITexture(UITexture _uiTexture, GameObject gameObject, WXEntity entity): base(_uiTexture, gameObject, entity) 23 | { 24 | this.uiTexture = _uiTexture; 25 | } 26 | 27 | protected override JSONObject ToJSON(WXHierarchyContext context) 28 | { 29 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 30 | json.AddField("type", "UISprite"); 31 | 32 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 33 | 34 | JSONObject color = new JSONObject(JSONObject.Type.ARRAY); 35 | color.Add(255f * uiTexture.color.r); 36 | color.Add(255f * uiTexture.color.g); 37 | color.Add(255f * uiTexture.color.b); 38 | color.Add(255f * uiTexture.color.a); 39 | subJSON.AddField("color", color); 40 | subJSON.AddField("colorBlendType", 0); 41 | 42 | UI2DSprite.Type type = uiTexture.type; 43 | subJSON.AddField("type", (int)type); 44 | 45 | UI2DSprite.Flip flipType = uiTexture.flip; 46 | subJSON.AddField("flip", (int)flipType); 47 | subJSON.AddField("fillCenter", uiTexture.centerType == UI2DSprite.AdvancedType.Sliced); 48 | subJSON.AddField("fillDir", (int)uiTexture.fillDirection); 49 | subJSON.AddField("fillAmount", uiTexture.fillAmount); 50 | subJSON.AddField("invertFill", uiTexture.invert); 51 | 52 | string texturePath = ""; 53 | if (uiTexture.mainTexture != null) 54 | { 55 | Texture2D texture2D = (Texture2D)uiTexture.mainTexture; 56 | if (texture2D != null) 57 | { 58 | string path = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); 59 | 60 | texturePath = new WXTexture(texture2D).Export(context.preset);// MaterialUtil.SaveTextureFile(texture2D); 61 | context.AddResource(texturePath); 62 | 63 | UISpriteData data = new UISpriteData(); 64 | data.width = uiTexture.mainTexture.width; 65 | data.height = uiTexture.mainTexture.height; 66 | 67 | WXSpriteFrame spriteFrame = new WXSpriteFrame(data, texturePath, path); 68 | string key = spriteFrame.Export(context.preset); 69 | 70 | subJSON.AddField("spriteFrame", key); 71 | context.AddResource(key); 72 | } 73 | 74 | } 75 | else 76 | { 77 | JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL); 78 | subJSON.AddField("spriteFrame", nullJSON); 79 | } 80 | 81 | subJSON.AddField("active", uiTexture.enabled); 82 | 83 | json.AddField("data", subJSON); 84 | 85 | return json; 86 | } 87 | 88 | private Texture2D DuplicateTexture(Texture2D source) 89 | { 90 | RenderTexture renderTex = RenderTexture.GetTemporary( 91 | source.width, 92 | source.height, 93 | 0, 94 | RenderTextureFormat.Default, 95 | RenderTextureReadWrite.Linear); 96 | 97 | Graphics.Blit(source, renderTex); 98 | RenderTexture previous = RenderTexture.active; 99 | RenderTexture.active = renderTex; 100 | Texture2D readableText = new Texture2D(source.width, source.height); 101 | readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0); 102 | readableText.Apply(); 103 | RenderTexture.active = previous; 104 | RenderTexture.ReleaseTemporary(renderTex); 105 | return readableText; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Component/WXUIToggle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using System.Linq; 7 | using UnityEditor.Animations; 8 | using System.IO; 9 | using System.Text; 10 | 11 | namespace WeChat 12 | { 13 | 14 | public class WXUIToggle : WXNGUIComponent 15 | { 16 | 17 | public override string getTypeName() 18 | { 19 | return "UIToggle"; 20 | } 21 | 22 | private UIToggle uiToggle; 23 | public WXUIToggle(UIToggle _uiToggle, GameObject gameObject, WXEntity entity): base(_uiToggle, gameObject, entity) 24 | { 25 | this.uiToggle = _uiToggle; 26 | } 27 | 28 | public string getStateSprite(WXHierarchyContext context, UISprite uiSprite, string spriteName) 29 | { 30 | 31 | string uuid = WXSpriteFrame.getSprite(uiSprite.atlas, spriteName, context.preset); 32 | return uuid; 33 | } 34 | 35 | protected override JSONObject ToJSON(WXHierarchyContext context) 36 | { 37 | JSONObject json = new JSONObject(JSONObject.Type.OBJECT); 38 | json.AddField("type", "UIToggle"); 39 | 40 | 41 | JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); 42 | 43 | var activeSprite = uiToggle.activeSprite; 44 | if (uiToggle.activeSprite) 45 | { 46 | var compType = uiToggle.activeSprite.GetType(); 47 | 48 | if (compType == typeof(UILabel)) 49 | { 50 | var addComp = new WXUILabel(uiToggle.activeSprite as UILabel, gameObject, entity); 51 | subJSON.AddField("target", context.AddComponentInProperty( 52 | addComp, 53 | uiToggle.activeSprite 54 | )); 55 | } 56 | else if (compType == typeof(UISprite)) 57 | { 58 | var addComp = new WXUISprite(uiToggle.activeSprite as UISprite, gameObject, entity); 59 | subJSON.AddField("target", context.AddComponentInProperty( 60 | addComp, 61 | uiToggle.activeSprite 62 | )); 63 | } 64 | } 65 | 66 | subJSON.AddField("isChecked", uiToggle.startsActive); 67 | 68 | object toggleIndex = TryGetContainField(uiToggle, "index"); 69 | if (toggleIndex != null) 70 | { 71 | subJSON.AddField("index", (int)toggleIndex); 72 | } 73 | 74 | subJSON.AddField("active", uiToggle.enabled); 75 | 76 | json.AddField("data", subJSON); 77 | 78 | return json; 79 | } 80 | 81 | private object TryGetContainField(object instance, string FieldName) 82 | { 83 | if (instance != null && !string.IsNullOrEmpty(FieldName)) 84 | { 85 | 86 | FieldInfo _findedFieldInfo = instance.GetType().GetField(FieldName); 87 | if (_findedFieldInfo != null) 88 | { 89 | return _findedFieldInfo.GetValue(instance); 90 | } 91 | } 92 | return null; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/ExportPreset/NGUIScenePreset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEditor.SceneManagement; 4 | using UnityEngine; 5 | using UnityEngine.SceneManagement; 6 | 7 | namespace WeChat 8 | { 9 | // 导出场景树中的第一个UIRoot 为Scene2D 10 | [InitializeOnLoad] 11 | [DeclarePreset("ngui-rootScene", typeof(NGUIRootExportConfig))] 12 | internal class NGUISceneExportPreset : ExportPreset 13 | { 14 | 15 | UIRoot sceneRoot = null; 16 | GameObject objectRoot = null; 17 | 18 | static NGUISceneExportPreset() 19 | { 20 | ExportPreset.registerExportPreset("ngui-rootScene", new NGUISceneExportPreset()); 21 | } 22 | 23 | public NGUISceneExportPreset() : base() 24 | { 25 | is2d = true; 26 | } 27 | 28 | public override string GetChineseName() 29 | { 30 | return "导出UI场景"; 31 | } 32 | 33 | protected override void DoExport() 34 | { 35 | Scene gameScene = SceneManager.GetActiveScene(); 36 | string path = gameScene.path; 37 | 38 | EditorSceneManager.SaveScene(gameScene, path); 39 | 40 | WXNGUITree converter = new WXNGUITree(objectRoot, path, true, true); 41 | PresetUtil.writeGroup(converter, this); 42 | } 43 | 44 | public override bool WillPresetShow() 45 | { 46 | try 47 | { 48 | FindNGUIRootInScene(); 49 | return sceneRoot != null; 50 | } 51 | catch (Exception e) 52 | { 53 | return false; 54 | } 55 | } 56 | 57 | private void FindNGUIRootInScene() { 58 | foreach (GameObject rootObj in SceneManager.GetActiveScene().GetRootGameObjects()) 59 | { 60 | sceneRoot = rootObj.GetComponent(typeof(UIRoot)) as UIRoot; 61 | if (sceneRoot) 62 | { 63 | objectRoot = rootObj; 64 | return; 65 | } 66 | 67 | } 68 | } 69 | 70 | } 71 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/ExportPreset/NGUITreePreset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEditor.SceneManagement; 4 | using UnityEngine; 5 | using UnityEngine.SceneManagement; 6 | 7 | namespace WeChat { 8 | // 导出选中的prefab 9 | 10 | // 后续更新:这里已经支持了导出2D scene。某些变量名和常量还保持prefab只是为了保护历史包袱 11 | [InitializeOnLoad] 12 | [DeclarePreset ("ngui-prefab", typeof (NGUIExportConfig))] 13 | internal class NGUITreeExportPreset : ExportPreset { 14 | static NGUITreeExportPreset () { 15 | ExportPreset.registerExportPreset ("ngui-prefab", new NGUITreeExportPreset ()); 16 | } 17 | 18 | public NGUITreeExportPreset () : base () { 19 | is2d = true; 20 | } 21 | 22 | public override string GetChineseName () { 23 | return "选中的ngui节点"; 24 | } 25 | 26 | protected override void DoExport () { 27 | // GameObject prefabRoot = (GameObject) Selection.activeObject; 28 | 29 | GameObject[] prefabRoots = Selection.gameObjects; 30 | 31 | Scene gameScene = SceneManager.GetActiveScene (); 32 | if (!gameScene.isDirty || gameScene.isDirty && EditorUtility.DisplayDialog ("提示", "检测到当前场景未保存,导出会自动进行保存场景,是否要继续导出", "导出", "暂不导出")) { 33 | string path = gameScene.path; 34 | 35 | EditorSceneManager.SaveScene (gameScene, path); 36 | 37 | foreach (GameObject prefabRoot in prefabRoots) { 38 | WXNGUITree converter = new WXNGUITree ( 39 | prefabRoot, 40 | AssetDatabase.GetAssetPath (WXUtility.GetPrefabSource (prefabRoot)), 41 | (this.exportConfigs as NGUIExportConfig).exportAsScene 42 | ); 43 | 44 | PresetUtil.writeGroup (converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/ ); 45 | } 46 | 47 | } 48 | } 49 | 50 | public override bool WillPresetShow () { 51 | if (Selection.activeObject == null) { 52 | return false; 53 | } 54 | try { 55 | return WXUtility.GetPrefabSource (Selection.activeObject); 56 | } catch (Exception e) { 57 | return false; 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/ExportPreset/ScriptableObject/NGUIExportConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace WeChat 7 | { 8 | internal class NGUIExportConfig : HierarchyExportConfig 9 | { 10 | public bool exportAsScene = false; 11 | } 12 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/ExportPreset/ScriptableObject/NGUIExportConfigEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | namespace WeChat 5 | { 6 | [CustomEditor(typeof(NGUIExportConfig))] 7 | internal class NGUIExportConfigEditor : Editor 8 | { 9 | public override void OnInspectorGUI() 10 | { 11 | //base.OnInspectorGUI(); 12 | SerializedProperty ignoreNonActive = serializedObject.FindProperty("ignoreNonActive"); 13 | SerializedProperty ignoreParticle = serializedObject.FindProperty("ignoreParticle"); 14 | SerializedProperty exportAsScene = serializedObject.FindProperty("exportAsScene"); 15 | 16 | EditorGUILayout.BeginVertical(); 17 | EditorGUILayout.PropertyField(ignoreNonActive, new GUIContent("忽略非激活节点")); 18 | EditorGUILayout.PropertyField(ignoreParticle, new GUIContent("忽略粒子系统")); 19 | EditorGUILayout.PropertyField(exportAsScene, new GUIContent("导出为场景")); 20 | serializedObject.ApplyModifiedProperties(); 21 | 22 | EditorGUILayout.EndVertical(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/ExportPreset/ScriptableObject/NGUIRootExportConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace WeChat 7 | { 8 | internal class NGUIRootExportConfig : HierarchyExportConfig 9 | { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/ExportPreset/ScriptableObject/NGUIRootExportConfigEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | namespace WeChat 5 | { 6 | [CustomEditor(typeof(NGUIRootExportConfig))] 7 | internal class NGUIRootExportConfigEditor : Editor 8 | { 9 | public override void OnInspectorGUI() 10 | { 11 | //base.OnInspectorGUI(); 12 | SerializedProperty ignoreNonActive = serializedObject.FindProperty("ignoreNonActive"); 13 | SerializedProperty ignoreParticle = serializedObject.FindProperty("ignoreParticle"); 14 | 15 | EditorGUILayout.BeginVertical(); 16 | EditorGUILayout.PropertyField(ignoreNonActive, new GUIContent("忽略非激活节点")); 17 | EditorGUILayout.PropertyField(ignoreParticle, new GUIContent("忽略粒子系统")); 18 | serializedObject.ApplyModifiedProperties(); 19 | 20 | EditorGUILayout.EndVertical(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/NGUIExportModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace WeChat 6 | { 7 | // example inherit class 8 | [InitializeOnLoad] 9 | public class NGUIExportModule : ExportPluginModule 10 | { 11 | static NGUIExportModule() 12 | { 13 | ExportPluginModule.registerExportPluginModule("ngui", new NGUIExportModule()); 14 | } 15 | 16 | // 0.7.0为导出插件版本。该字符串会在构建流程里被修改,请勿改动 17 | public NGUIExportModule() : base("ngui", "0.7.0") 18 | { 19 | 20 | } 21 | 22 | public override void OnModuleInstall() 23 | { 24 | Debug.Log(this.ToString() + " install callback"); 25 | } 26 | 27 | //public override void OnModuleUninstall() 28 | //{ 29 | // Debug.Log(this.ToString() + " uninstall callback"); 30 | //} 31 | 32 | public override void OnModuleInit() 33 | { 34 | Debug.Log(this.ToString() + " init callback"); 35 | } 36 | 37 | 38 | public override void OnModuleVersionChange() 39 | { 40 | Debug.Log(this.ToString() + " version change callback"); 41 | } 42 | 43 | } 44 | } -------------------------------------------------------------------------------- /unity-plugin/ngui/editor/Resource/WXEngineFont.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using System.Text.RegularExpressions; 6 | using System.IO; 7 | 8 | namespace WeChat 9 | { 10 | class WXFont : WXResource 11 | { 12 | public WXFont(string fontPath): base(fontPath) 13 | { 14 | } 15 | 16 | public override string GetHash() 17 | { 18 | return WXUtility.GetMD5FromAssetPath(unityAssetPath); 19 | } 20 | 21 | protected override string GetResourceType() 22 | { 23 | return "font"; 24 | } 25 | 26 | public override string GetExportPath() 27 | { 28 | return unityAssetPath + ".font"; 29 | } 30 | 31 | protected override JSONObject ExportResource(ExportPreset preset) 32 | { 33 | string fileName = Path.GetFileName(unityAssetPath); 34 | string lowerFileName = fileName.ToLower(); 35 | string _fontPath = unityAssetPath.Replace(fileName, lowerFileName); 36 | 37 | JSONObject jsonFile = JSONObject.Create("{\"file\": {}}"); 38 | jsonFile.GetField("file").AddField( 39 | "src", 40 | AddFile(new WXEngineCopyFile(_fontPath, "font")) 41 | ); 42 | 43 | jsonFile.AddField("version", 2); 44 | return jsonFile; 45 | } 46 | 47 | } 48 | } 49 | --------------------------------------------------------------------------------