using System.Collections.Generic; using UnityEngine; public static class RopePersistManager { private class RopeData { public class TransformInfo { public GameObject goObject; public string strObjectName; public Transform tfParent; public Vector3 v3LocalPosition; public Quaternion qLocalOrientation; public Vector3 v3LocalScale; public bool bLinkMarkedKinematic; public bool bExtensibleKinematic; } public UltimateRope m_rope; public bool m_bDeleted; public Dictionary m_hashFieldName2Value; public bool m_bSkin; public Vector3[] m_av3SkinVertices; public Vector2[] m_av2SkinMapping; public Vector4[] m_av4SkinTangents; public BoneWeight[] m_aSkinBoneWeights; public int[] m_anSkinTrianglesRope; public int[] m_anSkinTrianglesSections; public Matrix4x4[] m_amtxSkinBindPoses; public TransformInfo m_transformInfoRope; public TransformInfo[] m_aLinkTransformInfo; public TransformInfo m_transformInfoStart; public TransformInfo[] m_transformInfoSegments; public bool[][] m_aaJointsProcessed; public bool[][] m_aaJointsBroken; public RopeData(UltimateRope rope) { m_rope = rope; m_hashFieldName2Value = new Dictionary(); m_aLinkTransformInfo = new TransformInfo[rope.TotalLinks]; m_transformInfoSegments = new TransformInfo[rope.RopeNodes.Count]; m_bSkin = rope.GetComponent() != null; if (m_bSkin) { SkinnedMeshRenderer component = rope.GetComponent(); Mesh sharedMesh = component.sharedMesh; int vertexCount = component.sharedMesh.vertexCount; int num = component.sharedMesh.GetTriangles(0).Length; int num2 = component.sharedMesh.GetTriangles(1).Length; m_av3SkinVertices = new Vector3[vertexCount]; m_av2SkinMapping = new Vector2[vertexCount]; m_av4SkinTangents = ((sharedMesh.tangents == null) ? null : new Vector4[sharedMesh.tangents.Length]); m_aSkinBoneWeights = new BoneWeight[vertexCount]; m_anSkinTrianglesRope = new int[num]; m_anSkinTrianglesSections = new int[num2]; m_amtxSkinBindPoses = new Matrix4x4[component.sharedMesh.bindposes.Length]; MakeSkinDeepCopy(sharedMesh.vertices, sharedMesh.uv, sharedMesh.tangents, sharedMesh.boneWeights, sharedMesh.GetTriangles(0), sharedMesh.GetTriangles(1), sharedMesh.bindposes, m_av3SkinVertices, m_av2SkinMapping, m_av4SkinTangents, m_aSkinBoneWeights, m_anSkinTrianglesRope, m_anSkinTrianglesSections, m_amtxSkinBindPoses); } } public static void MakeSkinDeepCopy(Vector3[] av3VerticesSource, Vector2[] av2MappingSource, Vector4[] av4TangentsSource, BoneWeight[] aBoneWeightsSource, int[] anTrianglesRopeSource, int[] anTrianglesSectionsSource, Matrix4x4[] aBindPosesSource, Vector3[] av3VerticesDestiny, Vector2[] av2MappingDestiny, Vector4[] av4TangentsDestiny, BoneWeight[] aBoneWeightsDestiny, int[] anTrianglesRopeDestiny, int[] anTrianglesSectionsDestiny, Matrix4x4[] aBindPosesDestiny) { int num = av3VerticesSource.Length; for (int i = 0; i < num; i++) { av3VerticesDestiny[i] = av3VerticesSource[i]; av2MappingDestiny[i] = av2MappingSource[i]; if (av4TangentsDestiny != null && av4TangentsSource != null && av4TangentsDestiny.Length == num && av4TangentsSource.Length == num) { av4TangentsDestiny[i] = av4TangentsSource[i]; } aBoneWeightsDestiny[i] = aBoneWeightsSource[i]; } for (int j = 0; j < anTrianglesRopeDestiny.Length; j++) { anTrianglesRopeDestiny[j] = anTrianglesRopeSource[j]; } for (int k = 0; k < anTrianglesSectionsDestiny.Length; k++) { anTrianglesSectionsDestiny[k] = anTrianglesSectionsSource[k]; } for (int l = 0; l < aBindPosesSource.Length; l++) { aBindPosesDestiny[l] = aBindPosesSource[l]; } } } private static Dictionary s_hashInstanceID2RopeData; static RopePersistManager() { s_hashInstanceID2RopeData = new Dictionary(); } private static RopeData.TransformInfo ComputeTransformInfo(UltimateRope rope, GameObject node, GameObject parent) { RopeData.TransformInfo transformInfo = new RopeData.TransformInfo(); transformInfo.goObject = node; transformInfo.strObjectName = node.name; transformInfo.tfParent = ((!(parent == null)) ? parent.transform : null); if (transformInfo.tfParent != null) { transformInfo.v3LocalPosition = transformInfo.tfParent.InverseTransformPoint(node.transform.position); transformInfo.qLocalOrientation = Quaternion.Inverse(transformInfo.tfParent.rotation) * node.transform.rotation; } else { transformInfo.v3LocalPosition = node.transform.position; transformInfo.qLocalOrientation = node.transform.rotation; } transformInfo.v3LocalScale = node.transform.localScale; UltimateRopeLink component = node.GetComponent(); if (component != null) { transformInfo.bExtensibleKinematic = component.ExtensibleKinematic; transformInfo.bLinkMarkedKinematic = node.GetComponent() != null && node.GetComponent().isKinematic; } else { transformInfo.bExtensibleKinematic = false; transformInfo.bLinkMarkedKinematic = false; } return transformInfo; } private static void SetTransformInfo(RopeData.TransformInfo transformInfo, GameObject node) { if (transformInfo.tfParent != null) { node.transform.position = transformInfo.tfParent.TransformPoint(transformInfo.v3LocalPosition); node.transform.rotation = transformInfo.tfParent.rotation * transformInfo.qLocalOrientation; } else { node.transform.position = transformInfo.v3LocalPosition; node.transform.rotation = transformInfo.qLocalOrientation; } node.transform.localScale = transformInfo.v3LocalScale; } }