protected override JSONObject ExportResource(ExportPreset preset) { WXHierarchyContext hierarchyContext = new WXHierarchyContext(preset, prefabPath); // 初始化输出的JSON对象 JSONObject prefabJSONObject = new JSONObject(JSONObject.Type.OBJECT); JSONObject metaJson = new JSONObject(JSONObject.Type.OBJECT); prefabJSONObject.AddField("meta", metaJson); // 填充meta metaJson.AddField("name", exportName); metaJson.AddField("type", /*WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD ? "2D" : */ "3D"); JSONObject configJson = new JSONObject(JSONObject.Type.OBJECT); metaJson.AddField("config", configJson); //if (WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD) //{ // JSONObject resolutionJson = new JSONObject(JSONObject.Type.ARRAY); // resolutionJson.Add(1280); // resolutionJson.Add(720); // configJson.AddField("resolution", resolutionJson); //} // 开始遍历 WXEntity rootEntity = /*WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD ? * hierarchyContext.Iterate2DGameObject(prefabRoot) : * hierarchyContext.Iterate3DGameObject(prefabRoot);*/hierarchyContext.IterateGameObject(prefabRoot, null); prefabJSONObject.AddField("gameObjectList", hierarchyContext.GetGameObjectListJSON()); prefabJSONObject.AddField("componentList", hierarchyContext.GetComponentListJSON()); JSONObject editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 2); prefabJSONObject.AddField("editorInfo", editorInfo); Debug.Log("Export Prefab " + prefabPath + " " + hierarchyContext.resourceList.Count); //WXResourceStore.AddJSONResource( // prefabPath, // "prefab", // prefabJSONObject, // metadata, // hierarchyContext.resourceList, // assetVersion // //AssetDatabase.GetAssetDependencyHash(prefabPath).ToString() //); //return prefabPath; foreach (string resource in hierarchyContext.resourceList) { AddDependencies(resource); } return(prefabJSONObject); }
public WXTouchInputComponent(BoxCollider boxCollider, GameObject _gameObj, WXEntity entity) : base(boxCollider, _gameObj, entity) { if (boxCollider != null) { float[] hitArea = { boxCollider.center.x - boxCollider.size.x / 2.0f, boxCollider.center.y - boxCollider.size.y / 2.0f, boxCollider.size.x, boxCollider.size.y }; this.hitArea = hitArea; } }
/** * 递归转换所有UnityGameObject为WXBBEntity */ public WXEntity IterateGameObject(GameObject go, WXEntity parent = null) { // 记录遍历起点的根节点 if (!_root) { _root = true; Root = go; } WXEntity entity = MakeEntity(go);// new WXEntity(go); // 处理prefab根节点,并生成prefab资源文件并存储prefab根节点以便于之后生成diffData if (entity.isOutermostPrefabRoot) { exportPrefabResource(go, entity); } entity.parent = parent; entity.name = go.name; /** * 转换规则 * 3D场景下,UI不转换 */ // UIRoot uiRootComponent = go.GetComponent(typeof(UIRoot)) as UIRoot; // if (uiRootComponent != null) // { // return entity; // } entity.active = go.activeSelf; if (preset.is2d) { if (go.GetComponent(typeof(Light)) != null || go.GetComponent(typeof(Camera)) != null) { return(entity); } } //Debug.Log("converterKeys " + ComponentConverters.Keys); foreach (string converterKey in ComponentConverters.Keys) { //Debug.Log("convertKey" + converterKey); Action <GameObject, WXEntity, WXHierarchyContext, ExportPreset> converter = ComponentConverters[converterKey]; converter.Invoke(go, entity, this, preset); } foreach (Transform child in go.transform) { if (shouldExport(child.gameObject)) { WXEntity childGameObject = IterateGameObject(child.gameObject, entity); } } return(entity); }
protected override JSONObject ExportResource(ExportPreset preset) { hierarchyContext = new WXHierarchyContext(preset, scenePath); // 初始化输出的JSON对象 JSONObject sceneJSONObject = new JSONObject(JSONObject.Type.OBJECT); JSONObject metaJson = new JSONObject(JSONObject.Type.OBJECT); sceneJSONObject.AddField("meta", metaJson); // 填充meta metaJson.AddField("name", exportName); metaJson.AddField("type", /*WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD ? "2D" : */ "3D"); JSONObject configJson = new JSONObject(JSONObject.Type.OBJECT); metaJson.AddField("config", configJson); JSONObject lightJson = new JSONObject(JSONObject.Type.OBJECT); GetLightConfig(lightJson, hierarchyContext); configJson.AddField("light", lightJson); GameObject[] root = gameScene.GetRootGameObjects(); // WXEntity rootObj = hierarchyContext.MakeEntity(null); // rootObj.active = true; // rootObj.name = "Scene<" + exportName + ">"; // rootObj.components.Add(hierarchyContext.AddComponent(new WXTransform3DComponent(null, true), null)); foreach (GameObject obj in root) { if ((preset.exportConfigs as HierarchyExportConfig).ignoreNonActive && (!obj.activeSelf || !obj.activeInHierarchy) ) { continue; } obj.name = "Scene<" + exportName + ">"; // 开始遍历 WXEntity leafEntity = hierarchyContext.IterateGameObject(obj); } sceneJSONObject.AddField("gameObjectList", hierarchyContext.GetGameObjectListJSON()); sceneJSONObject.AddField("componentList", hierarchyContext.GetComponentListJSON()); foreach (string resource in hierarchyContext.resourceList) { AddDependencies(resource); } JSONObject editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 2); sceneJSONObject.AddField("editorInfo", editorInfo); return(sceneJSONObject); }
private static void Iterate3DComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset) { BoxCollider boxCollider = go.GetComponent <BoxCollider>(); if (boxCollider != null) { obj.components.Add(context.AddComponent(new WXBoxCollider(boxCollider.center, boxCollider.size, boxCollider.isTrigger, boxCollider.sharedMaterial), boxCollider)); } CapsuleCollider capsuleCollider = go.GetComponent <CapsuleCollider>(); if (capsuleCollider != null) { obj.components.Add(context.AddComponent( new WXCapsuleCollider(capsuleCollider.isTrigger, capsuleCollider.sharedMaterial, capsuleCollider.center, capsuleCollider.radius, capsuleCollider.height, capsuleCollider.direction), capsuleCollider)); } MeshCollider meshCollider = go.GetComponent <MeshCollider>(); if (meshCollider != null) { obj.components.Add(context.AddComponent( new WXMeshCollider(meshCollider.convex, meshCollider.isTrigger, #if UNITY_2017_1_OR_NEWER (int)meshCollider.cookingOptions, #endif meshCollider.sharedMaterial, meshCollider.sharedMesh), meshCollider)); } Rigidbody rigidbody = go.GetComponent <Rigidbody>(); if (rigidbody != null) { obj.components.Add(context.AddComponent(new WXRigidbody(rigidbody), rigidbody)); } SphereCollider sphereCollider = go.GetComponent <SphereCollider>(); if (sphereCollider != null) { obj.components.Add(context.AddComponent(new WXSphereCollider(sphereCollider.isTrigger, sphereCollider.sharedMaterial, sphereCollider.center, sphereCollider.radius), sphereCollider)); } CharacterController characterController = go.GetComponent <CharacterController>(); if (characterController != null) { obj.components.Add(context.AddComponent(new WXCharactorController(characterController.slopeLimit, characterController.stepOffset, characterController.skinWidth, characterController.minMoveDistance, characterController.center, characterController.radius, characterController.height))); } }
public WXEntity MakeEntity(GameObject gameObject) { if (gameObject != null && entityMap.ContainsKey(gameObject)) { return(entityMap[gameObject]); } WXEntity entity = new WXEntity(gameObject, gameObjectList.Count(), resourcePath); if (gameObject != null) { entityMap.Add(gameObject, entity); } gameObjectList.Add(entity); return(entity); }
public static JSONObject AddInteractionScript(GameObject gameObject, WXEntity entity, WXHierarchyContext context, bool needTouchInputComponent) { //判断是否可以点击 bool isClickable = false; JSONObject scriptList = new JSONObject(JSONObject.Type.ARRAY); var bes = gameObject.GetComponents <MonoBehaviour>(); for (var i = 0; i < bes.Length; i++) { var type = bes[i].GetType(); if (Regex.Match(type.ToString(), @"^UnityEngine\.UI\b").Length == 0) { if ( typeof(IPointerClickHandler).IsAssignableFrom(type) || typeof(IPointerDownHandler).IsAssignableFrom(type) || typeof(IPointerUpHandler).IsAssignableFrom(type) ) { isClickable = true; } var scripts = new JSONObject(JSONObject.Type.OBJECT); scripts.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(bes[i]), bes[i])); scriptList.Add(scripts); } } if (isClickable && needTouchInputComponent) { entity.components.Add(context.AddComponent(new WXUGUITouchInputComponent(gameObject, entity), null)); } return(scriptList); }
private void exportPrefabResource(GameObject go, WXEntity entity) { #if UNITY_2018_4_OR_NEWER GameObject sourceObj = PrefabUtility.GetCorrespondingObjectFromOriginalSource(go); if (preset.is2d) { // Debug.LogError("preset.is2d" + preset.is2d); // Debug.LogError(prefab2dType); // prefabPath WXResource prefabInstance = (WXResource)Activator.CreateInstance(prefab2dType, new object[] { sourceObj, entity.prefabPath, false, false }); AddResource(prefabInstance.Export(preset)); } else { // Debug.LogError("preset.is2d" + preset.is2d); WXPrefab prefab = new WXPrefab(sourceObj, entity.unityAssetPath); AddResource(prefab.Export(preset)); } #else GameObject sourceObj = PrefabUtility.GetPrefabParent(go) as GameObject; if (preset.is2d) { // Debug.LogError("preset.is2d" + preset.is2d); // Debug.LogError(prefab2dType); WXResource prefabInstance = (WXResource)Activator.CreateInstance(prefab2dType, new object[] { sourceObj, entity.prefabPath, false, false }); AddResource(prefabInstance.Export(preset)); // WXNGUITree prefab = new WXNGUITree(sourceObj, entity.prefabPath, false); // AddResource(prefab.Export(preset)); } else { // Debug.LogError("preset.is2d" + preset.is2d); WXPrefab prefab = new WXPrefab(sourceObj, entity.unityAssetPath); AddResource(prefab.Export(preset)); } #endif }
public WXUIUGraphicScript(Graphic graphic, GameObject go, WXEntity entity) { this.graphic = graphic; this.go = go; this.entity = entity; }
public WXUIUCanvas(Canvas _uiCanvas, GameObject gameObject, WXEntity entity) : base(_uiCanvas, gameObject, entity) { this.uiCanvas = _uiCanvas; }
public WXUIUMask(Mask mask, GameObject gameObject, WXEntity entity) : base(mask, gameObject, entity) { this.mask = mask; }
public void AddChild(WXEntity entity) { entity.parent = this; }
private static void IterateUguiComponent( GameObject gameObject, WXEntity entity, WXHierarchyContext context, ExportPreset preset ) { if (!preset.presetKey.Contains("ugui")) { return; } //Canvas uiCanvas = gameObject.GetComponent(typeof(Canvas)) as Canvas; //if (uiCanvas != null) //{ // entity.components.Add(context.AddComponent(new WXUIUCanvas(uiCanvas, gameObject, entity), uiCanvas)); //} Image uiSprite = gameObject.GetComponent(typeof(Image)) as Image; if (uiSprite != null) { entity.components.Add(context.AddComponent(new WXUIUSprite(uiSprite, gameObject, entity), uiSprite)); } Text uiLabel = gameObject.GetComponent(typeof(Text)) as Text; if (uiLabel != null) { entity.components.Add(context.AddComponent(new WXUIULabel(uiLabel, gameObject, entity), uiLabel)); } Button button = gameObject.GetComponent(typeof(Button)) as Button; if (button != null) { entity.components.Add(context.AddComponent(new WXUIUButton(button, gameObject, entity), button)); } Toggle toggle = gameObject.GetComponent(typeof(Toggle)) as Toggle; if (toggle != null) { entity.components.Add(context.AddComponent(new WXUIUToggle(toggle, gameObject, entity), toggle)); } ToggleGroup toggleGroup = gameObject.GetComponent(typeof(ToggleGroup)) as ToggleGroup; if (toggleGroup != null) { entity.components.Add(context.AddComponent(new WXUIUToggleGroup(toggleGroup, gameObject, entity), toggleGroup)); } ScrollRect scrollRect = gameObject.GetComponent(typeof(ScrollRect)) as ScrollRect; if (scrollRect != null) { entity.components.Add(context.AddComponent(new WXUIUScrollRect(scrollRect, gameObject, entity), scrollRect)); } Mask mask = gameObject.GetComponent(typeof(Mask)) as Mask; if (mask != null) { entity.components.Add(context.AddComponent(new WXUIUMask(mask, gameObject, entity), mask)); } InputField input = gameObject.GetComponent(typeof(InputField)) as InputField; if (input != null) { entity.components.Add(context.AddComponent(new WXUIUInputField(input, gameObject, entity), input)); } WXUGUITransform2DComponent transform2D = new WXUGUITransform2DComponent(gameObject.transform); entity.components.Add(context.AddComponent(transform2D, gameObject.transform)); }
public WXUIUSpriteScript(Image image, GameObject go, WXEntity entity) { this.image = image; this.go = go; this.entity = entity; }
private static void Iterate3DComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset) { // 导UI的时候报bug,先注释掉 MonoBehaviour[] scripts = go.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour script in scripts) { if (script == null) { continue; } string __uuid = ""; Type type = script.GetType(); // 从public property中获取tsPath属性 foreach (System.Reflection.FieldInfo fieldInfo in type.GetFields()) { if (fieldInfo.Name == "__beefballSerialize" && (string)fieldInfo.GetValue(script) != "") { __uuid = (string)fieldInfo.GetValue(script); } } // 从attribute中获取的tsPath属性 // foreach (System.Object attributes in type.GetCustomAttributes(false)) // { // BeefballSerialize bs = (BeefballSerialize)attributes; // if (bs != null) // { // __uuid = bs.__beefballSerialize; // } // } // __uuid是导出标签,只有找到__uuid属性,才加入到components列表 if (__uuid != "" && __uuid != null) { obj.components.Add(context.AddComponent(new WXScript(script, go, __uuid), script)); } } ParticleSystem particle = go.GetComponent <ParticleSystem>(); if (particle != null) { //Debug.Log("addComponentParticleSystem"); obj.components.Add(context.AddComponent(new WXParticleSystem(particle, go), particle)); } MeshRenderer meshRenderer = go.GetComponent(typeof(MeshRenderer)) as MeshRenderer; if ((UnityEngine.Object)meshRenderer != (UnityEngine.Object)null) { obj.components.Add(context.AddComponent(new WXMeshRenderer(meshRenderer), meshRenderer)); } LineRenderer lineRenderer = go.GetComponent(typeof(LineRenderer)) as LineRenderer; if ((UnityEngine.Object)lineRenderer != (UnityEngine.Object)null) { obj.components.Add(context.AddComponent(new WXLineRenderer(lineRenderer), lineRenderer)); } TrailRenderer trailRenderer = go.GetComponent(typeof(TrailRenderer)) as TrailRenderer; if ((UnityEngine.Object)trailRenderer != (UnityEngine.Object)null) { obj.components.Add(context.AddComponent(new WXTrailRenderer(trailRenderer), trailRenderer)); } SkinnedMeshRenderer skinnedMeshRenderer = go.GetComponent(typeof(SkinnedMeshRenderer)) as SkinnedMeshRenderer; if ((UnityEngine.Object)skinnedMeshRenderer != (UnityEngine.Object)null) { obj.components.Add(context.AddComponent(new WXSkinnedMeshRenderer(skinnedMeshRenderer), skinnedMeshRenderer)); } Animator animator = go.GetComponent(typeof(Animator)) as Animator; if ((UnityEngine.Object)animator != (UnityEngine.Object)null) { obj.components.Add(context.AddComponent(new WXAnimator(animator, go), animator)); } Animation animation = go.GetComponent(typeof(Animation)) as Animation; if ((UnityEngine.Object)animation != (UnityEngine.Object)null) { obj.components.Add(context.AddComponent(new WXAnimation(animation, go), animation)); } // DirectionalLight, // PointLight, // SpotLight, Light light = go.GetComponent(typeof(Light)) as Light; if ((UnityEngine.Object)light != (UnityEngine.Object)null) { // baked的灯光不导出 bool isBaked = false; #if UNITY_5_6_OR_NEWER isBaked = light.lightmapBakeType == LightmapBakeType.Baked; #else isBaked = light.lightmappingMode == LightmappingMode.Baked; #endif if (!isBaked) { obj.components.Add(context.AddComponent(new WXLight(light), light)); } } Camera camera = go.GetComponent(typeof(Camera)) as Camera; if (camera != null) { obj.components.Add(context.AddComponent(new WXCamera(camera), camera)); } WXPostProcess postProcess = go.GetComponent <WXPostProcess>(); if (postProcess != null) { obj.components.Add(context.AddComponent(new WXEnginePostProcess(postProcess), postProcess)); } // obj.active = go.activeSelf; if (!preset.is2d) { obj.components.Add(context.AddComponent(new WXTransform3DComponent(go.transform), go.transform)); } WXRawResourceCollection collection = go.GetComponent <WXRawResourceCollection>(); if ((UnityEngine.Object)collection != (UnityEngine.Object)null) { obj.components.Add(context.AddComponent(new WXEngineRawResourceCollection(collection), collection)); } }
public WXUIULabelScript(Text label, GameObject go, WXEntity entity) { this.uiLabel = label; this.go = go; this.entity = entity; }
public WXUIUButton(Button button, GameObject gameObject, WXEntity entity) : base(button, gameObject, entity) { this.button = button; }
public WXUITexture(UITexture _uiTexture, GameObject gameObject, WXEntity entity) : base(_uiTexture, gameObject, entity) { this.uiTexture = _uiTexture; }
public WXUGUIKeyboardInputComponent(InputField _uiInput, GameObject gameObject, WXEntity entity) : base(_uiInput, gameObject, entity) { this.uiInput = _uiInput; }
public WXUIUInputFieldScript(InputField input, GameObject go, WXEntity entity) { this.input = input; this.go = go; this.entity = entity; }
public WXUIScrollView(UIScrollView _uiScrollView, GameObject gameObject, WXEntity entity) : base(_uiScrollView, gameObject, entity) { this.uiScrollView = _uiScrollView; }
public ExportErrorReporter setEntity(WXEntity entity) { this.entity = entity; return(this); }
public WXUIUToggleGroup(ToggleGroup toggleGroup, GameObject gameObject, WXEntity entity) : base(toggleGroup, gameObject, entity) { this.toggleGroup = toggleGroup; }
public WXUGUITouchInputComponent(GameObject _gameObj, WXEntity entity) : base(null, _gameObj, entity) { }
public WXUIUButtonScript(Button button, GameObject go, WXEntity entity) { this.button = button; this.go = go; this.entity = entity; }
public WXUISprite(UISprite _uiSprite, GameObject gameObject, WXEntity entity) : base(_uiSprite, gameObject, entity) { this.uiSprite = _uiSprite; }
public WXUIButtonScript(UIButton btn, GameObject go, WXEntity entity) { this.uiButton = btn; this.go = go; this.entity = entity; }
public WXKeyboardInputComponent(UIInput _uiInput, GameObject gameObject, WXEntity entity) : base(_uiInput, gameObject, entity) { this.uiInput = _uiInput; }
public WXUIAnchor(UIAnchor _uiAnchor, GameObject _gameObj, WXEntity entity) : base(_uiAnchor, _gameObj, entity) { this.uiAnchor = _uiAnchor; }
public WXUIAtlas(UIAtlas _uiAtlas, GameObject gameObject, WXEntity entity) : base(_uiAtlas, gameObject, entity) { this.uiAtlas = _uiAtlas; }