//------------------------------------------------------------------------- // Compatibility glue-code: read all old parameters and set the new RegionIndependentParameters pendants accordingly. public static void CopyParametersToRegionIndependentParametersForBackwardsCompatibility(ref RegionIndependentParameters colliderParameters, AlphaMeshCollider oldReference) { colliderParameters.LiveUpdate = oldReference.mLiveUpdate; colliderParameters.AlphaOpaqueThreshold = oldReference.mAlphaOpaqueThreshold; colliderParameters.VertexReductionDistanceTolerance = oldReference.mVertexReductionDistanceTolerance; colliderParameters.DefaultMaxPointCount = oldReference.mDefaultMaxPointCount; colliderParameters.Thickness = oldReference.mThickness; colliderParameters.FlipHorizontal = oldReference.mFlipHorizontal; colliderParameters.FlipVertical = oldReference.mFlipVertical; colliderParameters.Convex = oldReference.mConvex; colliderParameters.FlipInsideOutside = oldReference.mFlipInsideOutside; colliderParameters.CustomRotation = oldReference.mCustomRotation; colliderParameters.CustomScale = oldReference.mCustomScale; colliderParameters.CustomOffset = oldReference.mCustomOffset; colliderParameters.CopyOTSpriteFlipping = oldReference.mCopyOTSpriteFlipping; colliderParameters.CopySmoothMovesSpriteDimensions = oldReference.mCopySmoothMovesSpriteDimensions; colliderParameters.CustomTex = oldReference.mCustomTex; colliderParameters.IsCustomAtlasRegionUsed = oldReference.mIsCustomAtlasRegionUsed; colliderParameters.CustomAtlasFrameTitle = oldReference.mCustomAtlasFrameTitle; colliderParameters.CustomAtlasFramePositionInPixels = oldReference.mCustomAtlasFramePositionInPixels; colliderParameters.CustomAtlasFrameSizeInPixels = oldReference.mCustomAtlasFrameSizeInPixels; colliderParameters.CustomAtlasFrameRotation = oldReference.mCustomAtlasFrameRotation; colliderParameters.ApplySmoothMovesScaleAnim = oldReference.mApplySmoothMovesScaleAnim; oldReference.mCustomRotation = OLD_PARAMETERS_CONVERTED; }
//------------------------------------------------------------------------- public static void CalculateUnreducedOutlineForAllColliderRegions(ref ColliderRegionData[] colliderRegions, ref PolygonOutlineFromImageFrontend outlineAlgorithm, RegionIndependentParameters regionIndependentParameters, ColliderRegionParameters[] colliderRegionParameters, bool [,] binaryImage, bool ccwVertexOrder) { for (int count = 0; count < colliderRegions.Length; ++count) { if (colliderRegionParameters[count].EnableRegion) { // Calculate polygon bounds outlineAlgorithm.VertexReductionDistanceTolerance = regionIndependentParameters.VertexReductionDistanceTolerance; outlineAlgorithm.MaxPointCount = colliderRegionParameters[count].MaxPointCount; bool allRegionsConvex = regionIndependentParameters.Convex; outlineAlgorithm.Convex = allRegionsConvex ? true : colliderRegionParameters[count].Convex; //outlineAlgorithm.Convex = colliderRegionParameters[count].Convex; outlineAlgorithm.XOffsetNormalized = -0.5f;//-this.transform.localScale.x / 2.0f; outlineAlgorithm.YOffsetNormalized = -0.5f;//-this.transform.localScale.y / 2.0f; bool outputInNormalizedSpace = true; bool regionVertexOrder = ccwVertexOrder; if (!colliderRegions[count].mRegionIsIsland) { regionVertexOrder = !regionVertexOrder; } colliderRegions[count].mOutlineVertexOrderIsCCW = regionVertexOrder; outlineAlgorithm.UnreducedOutlineFromBinaryImage(out colliderRegions[count].mIntermediateOutlineVertices, binaryImage, colliderRegions[count].mDetectedRegion.mPointAtBorder, colliderRegions[count].mRegionIsIsland, outputInNormalizedSpace, regionVertexOrder); } else { colliderRegions[count].mIntermediateOutlineVertices = null; colliderRegions[count].mResultVertices = null; colliderRegions[count].mResultTriangleIndices = null; } } }
//------------------------------------------------------------------------- bool ReadUnity43SpriteAnimatorParams(UnityEngine.Animator unity43Animator, ref AnimatedColliderParameters animatedColliderParams, ref RegionIndependentParameters regionIndependentParams) { #if UNITY_5_AND_LATER UnityEditor.Animations.AnimatorController controller = (UnityEditor.Animations.AnimatorController) unity43Animator.runtimeAnimatorController; #else UnityEditorInternal.AnimatorController controller = (UnityEditorInternal.AnimatorController) unity43Animator.runtimeAnimatorController; #endif if (!controller) { regionIndependentParams.NumCollidersNeeded = 1; return false; } // Note: we have to maintain the order to keep the spriteRef and spriteID indices linked. // Thus we don't use a HashSet for duplicate prevention but a list.Contains() call. List<string> spriteIDs = new List<string>(); List<UnityEngine.Sprite> spriteFrames = new List<Sprite>(); AnimationClip[] clips = AnimationUtility.GetAnimationClips(this.gameObject); for (int index = 0; index < clips.Length; ++index) { AnimationClip clip = clips[index]; EditorCurveBinding[] bindings = AnimationUtility.GetObjectReferenceCurveBindings(clip); if (bindings != null) { for (int bindingIndex = 0; bindingIndex < bindings.Length; ++bindingIndex) { EditorCurveBinding binding = bindings[bindingIndex]; if (binding.isPPtrCurve) { ObjectReferenceKeyframe[] references = AnimationUtility.GetObjectReferenceCurve(clip, binding); for (int refIndex = 0; refIndex < references.Length; ++refIndex) { ObjectReferenceKeyframe reference = references[refIndex]; UnityEngine.Sprite spriteRef = (UnityEngine.Sprite) reference.value; if (spriteRef != null) { string spriteID = spriteRef.name; if (!spriteIDs.Contains(spriteID)) { spriteFrames.Add(spriteRef); spriteIDs.Add(spriteID); } } } } } } } animatedColliderParams.SpriteFrames = spriteFrames.ToArray(); animatedColliderParams.ColliderIDStrings = spriteIDs.ToArray(); regionIndependentParams.NumCollidersNeeded = animatedColliderParams.ColliderIDStrings.Length; return true; }