void CollectMesh(Armature armature, List <List <CombineInstance> > combines, List <Material> mats) { List <Slot> slots = (armature.eventDispatcher as UnityArmatureComponent).sortedSlots; foreach (Slot slot in slots) { UnitySlot us = slot as UnitySlot; if (slot.childArmature != null) { CollectMesh(slot.childArmature, combines, mats); } var currentTextureData = us.currentTextureAtlasData; if (currentTextureData != null && currentTextureData.texture) { if (mats.Count == 0 || mats[mats.Count - 1] != currentTextureData.texture) { mats.Add(currentTextureData.texture); } if (combines.Count < mats.Count) { combines.Add(new List <CombineInstance>()); } if (us != null && us.mesh != null) { GameObject go = us.renderDisplay; if (go && go.activeSelf) { CombineInstance com = new CombineInstance(); com.mesh = us.mesh; com.transform = transform.worldToLocalMatrix * go.transform.localToWorldMatrix; combines[mats.Count - 1].Add(com); } } } } }
public void CollectMesh(Armature armature, List <CombineMeshInfo> combineSlots) { if (armature == null) { return; } var slots = new List <Slot>(armature.GetSlots()); if (slots.Count == 0) { return; } // var isBreakCombineMesh = false; var isSameMaterial = false; var isChildAramture = false; UnitySlot slotMeshProxy = null; GameObject slotDisplay = null; for (var i = 0; i < slots.Count; i++) { var slot = slots[i] as UnitySlot; slot.CancelCombineMesh(); isChildAramture = slot.childArmature != null; slotDisplay = slot.renderDisplay; if (slotMeshProxy != null) { if (slot._meshBuffer.name == string.Empty) { isSameMaterial = true; } else { isSameMaterial = slotMeshProxy._meshBuffer.name == slot._meshBuffer.name; } } else { isSameMaterial = slotMeshProxy == null; } //先检查这个slot会不会打断网格合并 isBreakCombineMesh = isChildAramture || slot._isIgnoreCombineMesh || !isSameMaterial; //如果会打断,那么先合并一次 if (isBreakCombineMesh) { if (combineSlots.Count > 0) { if (combineSlots[combineSlots.Count - 1].combines.Count == 1) { combineSlots.RemoveAt(combineSlots.Count - 1); } } slotMeshProxy = null; } // if (slotMeshProxy == null && !isBreakCombineMesh && slotDisplay != null && slotDisplay.activeSelf) { CombineMeshInfo combineSlot = new CombineMeshInfo(); combineSlot.proxySlot = slot; combineSlot.combines = new List <CombineInstance>(); combineSlot.slots = new List <UnitySlot>(); combineSlots.Add(combineSlot); slotMeshProxy = slot; } //如果不会合并,检查一下是否是子骨架 if (isChildAramture) { continue; } if (slotMeshProxy != null && slotDisplay != null && slotDisplay.activeSelf && !slot._isIgnoreCombineMesh) { var parentTransfrom = (slot._armature.proxy as UnityArmatureComponent).transform; CombineInstance com = new CombineInstance(); com.mesh = slot._meshBuffer.sharedMesh; com.transform = slotMeshProxy._renderDisplay.transform.worldToLocalMatrix * slotDisplay.transform.localToWorldMatrix; combineSlots[combineSlots.Count - 1].combines.Add(com); combineSlots[combineSlots.Count - 1].slots.Add(slot); } if (i != slots.Count - 1) { continue; } // if (combineSlots.Count > 0) { if (combineSlots[combineSlots.Count - 1].combines.Count == 1) { combineSlots.RemoveAt(combineSlots.Count - 1); } } slotMeshProxy = null; } }
/** * @private */ void Awake() { #if UNITY_5_6_OR_NEWER if (!isUGUI) { _sortingGroup = GetComponent <UnityEngine.Rendering.SortingGroup>(); if (_sortingGroup) { sortingMode = SortingMode.SortByOrder; _sortingLayerName = _sortingGroup.sortingLayerName; _sortingOrder = _sortingGroup.sortingOrder; } } #endif if (slotsRoot == null) { GameObject go = new GameObject("Slots"); go.transform.SetParent(transform); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; slotsRoot = go; go.hideFlags = HideFlags.NotEditable; } zorderIsDirty = true; if (unityData != null && unityData.dragonBonesJSON != null && unityData.textureAtlas != null) { var dragonBonesData = UnityFactory.factory.LoadData(unityData, isUGUI); if (dragonBonesData != null && !string.IsNullOrEmpty(armatureName)) { UnityFactory.factory.BuildArmatureComponent(armatureName, dragonBonesData.name, null, unityData.dataName, gameObject); } } if (_armature != null) { sortingLayerName = sortingLayerName; sortingOrder = sortingOrder; _armature.flipX = flipX; _armature.flipY = flipY; if (zSpace > 0) { foreach (var slot in _armature.GetSlots()) { var display = slot.display as GameObject; if (display != null) { display.transform.localPosition = new Vector3(display.transform.localPosition.x, display.transform.localPosition.y, -slot._zOrder * (_zSpace + 0.001f)); if (!isUGUI && sortingMode == SortingMode.SortByOrder) { UnitySlot us = slot as UnitySlot; if (us.meshRenderer != null) { us.meshRenderer.sortingOrder = slot._zOrder; } } } } } if (!string.IsNullOrEmpty(animationName)) { _armature.animation.Play(animationName); } CollectBones(); } }
void LateUpdate() { if (_armature == null) { return; } flipX = _armature.flipX; flipY = _armature.flipY; #if UNITY_EDITOR if (!Application.isPlaying) { #if UNITY_5_6_OR_NEWER if (!isUGUI) { _sortingGroup = GetComponent <UnityEngine.Rendering.SortingGroup>(); if (_sortingGroup) { sortingMode = SortingMode.SortByOrder; _sortingLayerName = _sortingGroup.sortingLayerName; _sortingOrder = _sortingGroup.sortingOrder; } } #endif foreach (var slot in _armature.GetSlots()) { var display = slot.display as GameObject; if (display != null) { display.transform.localPosition = new Vector3(display.transform.localPosition.x, display.transform.localPosition.y, -slot._zOrder * (_zSpace + 0.001f)); if (!isUGUI && sortingMode == SortingMode.SortByOrder) { UnitySlot us = slot as UnitySlot; if (us.meshRenderer != null) { us.meshRenderer.sortingOrder = slot._zOrder; } } } } } #endif if (zorderIsDirty) { _sortedSlots = new List <Slot>(_armature.GetSlots()); _sortedSlots.Sort(delegate(Slot x, Slot y) { return(x._zOrder - y._zOrder); }); for (int i = 0; i < _sortedSlots.Count; ++i) { Slot slot = _sortedSlots[i]; var display = slot.display as GameObject; if (display != null) { display.transform.SetSiblingIndex(i); if (!isUGUI && sortingMode == SortingMode.SortByOrder) { UnitySlot us = slot as UnitySlot; if (us.meshRenderer != null) { us.meshRenderer.sortingOrder = i; } } } } zorderIsDirty = false; } if (unityBones != null) { int len = unityBones.Count; for (int i = 0; i < len; ++i) { UnityBone bone = unityBones[i]; if (bone) { bone._Update(); } } } }
/** * @private */ void Awake() { #if UNITY_EDITOR if (_isPrefab()) { return; } #endif #if UNITY_5_6_OR_NEWER if (!isUGUI) { _sortingGroup = GetComponent <UnityEngine.Rendering.SortingGroup>(); if (_sortingGroup) { sortingMode = SortingMode.SortByOrder; _sortingLayerName = _sortingGroup.sortingLayerName; _sortingOrder = _sortingGroup.sortingOrder; } } #endif zorderIsDirty = true; //if(unityData != null && (unityData.dragonBonesJSON != null || unityData.dragonBonesBinary != null) && unityData.textureAtlas != null) if (unityData != null && unityData.dragonBonesJSON != null && unityData.textureAtlas != null) { var dragonBonesData = UnityFactory.factory.LoadData(unityData, isUGUI); if (dragonBonesData != null && !string.IsNullOrEmpty(armatureName)) { UnityFactory.factory.BuildArmatureComponent(armatureName, dragonBonesData.name, null, unityData.dataName, gameObject, isUGUI); } } if (_armature != null) { sortingLayerName = sortingLayerName; sortingOrder = sortingOrder; _armature.flipX = flipX; _armature.flipY = flipY; _armature.animation.timeScale = _timeScale; if (zSpace > 0 || sortingMode == SortingMode.SortByOrder) { foreach (var slot in _armature.GetSlots()) { var display = slot.display as GameObject; if (display != null) { display.transform.localPosition = new Vector3(display.transform.localPosition.x, display.transform.localPosition.y, -slot._zOrder * (zSpace + 0.001f)); if (!isUGUI && sortingMode == SortingMode.SortByOrder) { UnitySlot us = slot as UnitySlot; if (us.meshRenderer != null) { us.meshRenderer.sortingOrder = slot._zOrder; } } } } } if (!string.IsNullOrEmpty(animationName)) { _armature.animation.Play(animationName, _playTimes); } CollectBones(); } }