diff --git a/Assets/RapidIcon/Exports.meta b/Assets/RapidIcon/Exports.meta new file mode 100644 index 000000000..927c66cb2 --- /dev/null +++ b/Assets/RapidIcon/Exports.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f81249cd36222584abd0759a96c54ca4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RapidIcon/Exports/c_hook_20789.png b/Assets/RapidIcon/Exports/c_hook_20789.png new file mode 100644 index 000000000..d5ea2b66e Binary files /dev/null and b/Assets/RapidIcon/Exports/c_hook_20789.png differ diff --git a/Assets/RapidIcon/Exports/c_hook_20789.png.meta b/Assets/RapidIcon/Exports/c_hook_20789.png.meta new file mode 100644 index 000000000..29cd7c0b5 --- /dev/null +++ b/Assets/RapidIcon/Exports/c_hook_20789.png.meta @@ -0,0 +1,117 @@ +fileFormatVersion: 2 +guid: afc5808f3fe379248a9ac9a4ff85ec4a +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 13 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 4 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + customData: + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spriteCustomMetadata: + entries: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RapidIcon/Exports/c_hook_20790.png b/Assets/RapidIcon/Exports/c_hook_20790.png new file mode 100644 index 000000000..7b88448f0 Binary files /dev/null and b/Assets/RapidIcon/Exports/c_hook_20790.png differ diff --git a/Assets/RapidIcon/Exports/c_hook_20790.png.meta b/Assets/RapidIcon/Exports/c_hook_20790.png.meta new file mode 100644 index 000000000..460beb1a1 --- /dev/null +++ b/Assets/RapidIcon/Exports/c_hook_20790.png.meta @@ -0,0 +1,117 @@ +fileFormatVersion: 2 +guid: 24f1f6d6c75330443b604c7d62e8889d +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 13 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 4 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + customData: + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spriteCustomMetadata: + entries: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Fgui/Common/Common_atlas0.png b/Assets/Resources/Fgui/Common/Common_atlas0.png index e8d7095ad..009a54930 100644 Binary files a/Assets/Resources/Fgui/Common/Common_atlas0.png and b/Assets/Resources/Fgui/Common/Common_atlas0.png differ diff --git a/Assets/Resources/Fgui/Common/Common_fui.bytes b/Assets/Resources/Fgui/Common/Common_fui.bytes index 7ee7d27c1..d3be8a09f 100644 Binary files a/Assets/Resources/Fgui/Common/Common_fui.bytes and b/Assets/Resources/Fgui/Common/Common_fui.bytes differ diff --git a/Assets/Resources/Fgui/Fishing/Fishing_fui.bytes b/Assets/Resources/Fgui/Fishing/Fishing_fui.bytes index 846c6341a..6ee987960 100644 Binary files a/Assets/Resources/Fgui/Fishing/Fishing_fui.bytes and b/Assets/Resources/Fgui/Fishing/Fishing_fui.bytes differ diff --git a/Assets/Resources/Fgui/Shop.meta b/Assets/Resources/Fgui/Shop.meta new file mode 100644 index 000000000..25a0c4b97 --- /dev/null +++ b/Assets/Resources/Fgui/Shop.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1bec4163aaf7d4b4198d279c801609e0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Fgui/Shop/Shop_fui.bytes b/Assets/Resources/Fgui/Shop/Shop_fui.bytes new file mode 100644 index 000000000..fdbe405ea Binary files /dev/null and b/Assets/Resources/Fgui/Shop/Shop_fui.bytes differ diff --git a/Assets/Resources/Fgui/Shop/Shop_fui.bytes.meta b/Assets/Resources/Fgui/Shop/Shop_fui.bytes.meta new file mode 100644 index 000000000..feebdaee7 --- /dev/null +++ b/Assets/Resources/Fgui/Shop/Shop_fui.bytes.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7fd0585f74b572c4ca830b37141de9b3 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Def/GameDef.cs b/Assets/Scripts/Def/GameDef.cs index 87229e9b1..b0ff0b000 100644 --- a/Assets/Scripts/Def/GameDef.cs +++ b/Assets/Scripts/Def/GameDef.cs @@ -48,7 +48,7 @@ namespace NBF { Type = UIDef.InteractiveType.Oven, Name = "烤箱", - Icon = "op-use", + Icon = "op-oven", Use1 = "1,1", Use1Title = "使用" }, @@ -114,7 +114,7 @@ namespace NBF { Type = UIDef.InteractiveType.VendingMachine, Name = "自动贩卖机", - Icon = "op-use", + Icon = "op-vending", Use1 = "1,1", Use1Title = "进入", }, @@ -122,7 +122,7 @@ namespace NBF { Type = UIDef.InteractiveType.Wharf, Name = "码头", - Icon = "op-use", + Icon = "op-wharf", Use1 = "1,1", Use1Title = "进入", }, diff --git a/Assets/Scripts/PhysicsTools.meta b/Assets/Scripts/PhysicsTools.meta new file mode 100644 index 000000000..58c1e59c0 --- /dev/null +++ b/Assets/Scripts/PhysicsTools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8ce6ddcc06025e84c8f118c9af703263 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools.zip b/Assets/Scripts/PhysicsTools.zip new file mode 100644 index 000000000..29fb9c40a Binary files /dev/null and b/Assets/Scripts/PhysicsTools.zip differ diff --git a/Assets/Scripts/PhysicsTools.zip.meta b/Assets/Scripts/PhysicsTools.zip.meta new file mode 100644 index 000000000..12eb22b90 --- /dev/null +++ b/Assets/Scripts/PhysicsTools.zip.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2684716fa91d0e444a710242e2db2f9b +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/Bezier.cs b/Assets/Scripts/PhysicsTools/Bezier.cs new file mode 100644 index 000000000..88050ac5c --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Bezier.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace PhysicsTools +{ + public class Bezier + { + private Vector3[] knots; + + private Vector3[] firstControlPts; + + private Vector3[] secondControlPts; + + private int lastIndex = 1; + + private float lengthCovered; + + private float indexedLength; + + private float totalLength; + + public Bezier(List points) + { + Vector3[] array = new Vector3[points.Count]; + for (int i = 0; i < points.Count; i++) + { + array[i] = points[i].pos; + } + + init(array); + } + + public Bezier(Vector3[] points) + { + init(points); + } + + private void init(Vector3[] points) + { + knots = new Vector3[points.Length]; + for (int i = 0; i < points.Length; i++) + { + knots[i] = points[i]; + if (i != 0) + { + totalLength += (knots[i] - knots[i - 1]).magnitude; + } + } + + GetCurveControlPoints(knots, out firstControlPts, out secondControlPts); + indexedLength = (knots[1] - knots[0]).magnitude; + } + + public float TotalLength() + { + return totalLength; + } + + public PosOri getNext(float deltaLen) + { + return new PosOri(getNextPos(deltaLen), Quaternion.identity); + } + + public Vector3 getNextPos(float deltaLen) + { + bool flag = false; + float num = indexedLength; + float num2 = indexedLength; + while (!flag) + { + num = indexedLength; + num2 = indexedLength - (knots[lastIndex] - knots[lastIndex - 1]).magnitude; + if (lengthCovered + deltaLen > num) + { + lastIndex++; + if (lastIndex == knots.Length) + { + flag = true; + deltaLen = num - lengthCovered; + lastIndex = knots.Length - 1; + } + else + { + indexedLength += (knots[lastIndex] - knots[lastIndex - 1]).magnitude; + } + + continue; + } + + break; + } + + float num3 = (lengthCovered + deltaLen - num2) / (num - num2); + Vector3 result = (float)Math.Pow(1f - num3, 3.0) * knots[lastIndex - 1] + + 3f * (float)Math.Pow(1f - num3, 2.0) * num3 * firstControlPts[lastIndex - 1] + + 3f * (1f - num3) * num3 * num3 * secondControlPts[lastIndex - 1] + + num3 * num3 * num3 * knots[lastIndex]; + lengthCovered += deltaLen; + return result; + } + + private void GetCurveControlPoints(Vector3[] knots, out Vector3[] firstControlPoints, + out Vector3[] secondControlPoints) + { + if (knots == null) + { + throw new ArgumentNullException(nameof(knots)); + } + + int num = knots.Length - 1; + if (num < 1) + { + throw new ArgumentException("至少需要两个结点", nameof(knots)); + } + + if (num == 1) + { + firstControlPoints = new Vector3[1]; + firstControlPoints[0].x = (2f * knots[0].x + knots[1].x) / 3f; + firstControlPoints[0].y = (2f * knots[0].y + knots[1].y) / 3f; + firstControlPoints[0].z = (2f * knots[0].z + knots[1].z) / 3f; + secondControlPoints = new Vector3[1]; + secondControlPoints[0].x = 2f * firstControlPoints[0].x - knots[0].x; + secondControlPoints[0].y = 2f * firstControlPoints[0].y - knots[0].y; + secondControlPoints[0].z = 2f * firstControlPoints[0].z - knots[0].z; + return; + } + + float[] array = new float[num]; + for (int i = 1; i < num - 1; i++) + { + array[i] = 4f * knots[i].x + 2f * knots[i + 1].x; + } + + array[0] = knots[0].x + 2f * knots[1].x; + array[num - 1] = (8f * knots[num - 1].x + knots[num].x) / 2f; + float[] firstControlPoints2 = GetFirstControlPoints(array); + for (int j = 1; j < num - 1; j++) + { + array[j] = 4f * knots[j].y + 2f * knots[j + 1].y; + } + + array[0] = knots[0].y + 2f * knots[1].y; + array[num - 1] = (8f * knots[num - 1].y + knots[num].y) / 2f; + float[] firstControlPoints3 = GetFirstControlPoints(array); + for (int k = 1; k < num - 1; k++) + { + array[k] = 4f * knots[k].z + 2f * knots[k + 1].z; + } + + array[0] = knots[0].z + 2f * knots[1].z; + array[num - 1] = (8f * knots[num - 1].z + knots[num].z) / 2f; + float[] firstControlPoints4 = GetFirstControlPoints(array); + firstControlPoints = new Vector3[num]; + secondControlPoints = new Vector3[num]; + for (int l = 0; l < num; l++) + { + firstControlPoints[l] = + new Vector3(firstControlPoints2[l], firstControlPoints3[l], firstControlPoints4[l]); + if (l < num - 1) + { + secondControlPoints[l] = new Vector3(2f * knots[l + 1].x - firstControlPoints2[l + 1], + 2f * knots[l + 1].y - firstControlPoints3[l + 1], + 2f * knots[l + 1].z - firstControlPoints4[l + 1]); + } + else + { + secondControlPoints[l] = new Vector3((knots[num].x + firstControlPoints2[num - 1]) / 2f, + (knots[num].y + firstControlPoints3[num - 1]) / 2f, + (knots[num].z + firstControlPoints4[num - 1]) / 2f); + } + } + } + + private float[] GetFirstControlPoints(float[] rhs) + { + int num = rhs.Length; + float[] array = new float[num]; + float[] array2 = new float[num]; + float num2 = 2f; + array[0] = rhs[0] / num2; + for (int i = 1; i < num; i++) + { + array2[i] = 1f / num2; + num2 = ((i >= num - 1) ? 3.5f : 4f) - array2[i]; + array[i] = (rhs[i] - array[i - 1]) / num2; + } + + for (int j = 1; j < num; j++) + { + array[num - j - 1] -= array2[num - j] * array[num - j]; + } + + return array; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/PhysicsTools/Bezier.cs.meta b/Assets/Scripts/PhysicsTools/Bezier.cs.meta new file mode 100644 index 000000000..d9018985f --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Bezier.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0cc4d18ef4a8ff6439959ca335b42593 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/ControlPoint.cs b/Assets/Scripts/PhysicsTools/ControlPoint.cs new file mode 100644 index 000000000..acfdc67ab --- /dev/null +++ b/Assets/Scripts/PhysicsTools/ControlPoint.cs @@ -0,0 +1,62 @@ +using System; +using UnityEngine; + +namespace PhysicsTools +{ + [Serializable] + public class ControlPoint + { + [Tooltip("Optional: Object")] + public GameObject obj; + + [Tooltip("Position through which rope will pass... If Object is specified then it is the local to the object otherwise it is global position")] + public Vector3 localPos; + + [Range(1f, 5f)] + [Tooltip("SlackFraction: How much of the rope length should be created between two control points... If it is more than 1 then a catenary is formed between the control points")] + public float slackFraction; + + [Tooltip("Specify whether it is attached to the control point or not")] + public bool attached; + + public ControlPoint() + { + obj = null; + slackFraction = 1f; + attached = true; + } + + public override string ToString() + { + return ((!(obj != null)) ? "Object: null" : ("Object:" + obj.ToString())) + ", Position: " + localPos.ToString() + ", SlackFraction: " + slackFraction + ", Attached: " + attached; + } + + public bool compare(ControlPoint rhs) + { + if (obj != rhs.obj || localPos != rhs.localPos || slackFraction != rhs.slackFraction || attached != rhs.attached) + { + return false; + } + return true; + } + + public ControlPoint clone() + { + ControlPoint controlPoint = new ControlPoint(); + controlPoint.obj = obj; + controlPoint.localPos = localPos; + controlPoint.slackFraction = slackFraction; + controlPoint.attached = attached; + return controlPoint; + } + + public Vector3 globalPos(Rope rope) + { + if (obj != null) + { + return obj.transform.TransformPoint(localPos); + } + return rope.transform.TransformPoint(localPos); + } + } +} diff --git a/Assets/Scripts/PhysicsTools/ControlPoint.cs.meta b/Assets/Scripts/PhysicsTools/ControlPoint.cs.meta new file mode 100644 index 000000000..2aace74af --- /dev/null +++ b/Assets/Scripts/PhysicsTools/ControlPoint.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 4c3919bd67247ecf47ac8b5970b70372 +timeCreated: 1747788126 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/Joint.cs b/Assets/Scripts/PhysicsTools/Joint.cs new file mode 100644 index 000000000..dc79dc696 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Joint.cs @@ -0,0 +1,152 @@ +using UnityEngine; + +namespace PhysicsTools +{ + public class Joint + { + public UnityEngine.Joint joint; + + public Joint(Segment seg1, Segment seg2, JointProperties prop, SegmentPropertiesBase segProperties, + Quaternion twistOffset) + { + if (seg2 == null) + { + } + + seg2.seg.transform.rotation *= twistOffset; + switch (prop.type) + { + case JointProperties.Type.HINGE_JOINT: + { + HingeJoint hingeJoint = seg1.seg.AddComponent(); + hingeJoint.autoConfigureConnectedAnchor = false; + joint = hingeJoint; + JointLimits limits = new JointLimits + { + min = 0f - prop.swingLimitDeg, + max = prop.swingLimitDeg + }; + joint.axis = new Vector3(0f, 0f, 1f); + hingeJoint.limits = limits; + break; + } + case JointProperties.Type.CONFIGURABLE_JOINT: + { + ConfigurableJoint configurableJoint = seg1.seg.AddComponent(); + configurableJoint.enableCollision = false; + configurableJoint.xMotion = ConfigurableJointMotion.Locked; + configurableJoint.yMotion = ConfigurableJointMotion.Locked; + configurableJoint.zMotion = ConfigurableJointMotion.Locked; + configurableJoint.angularXMotion = ConfigurableJointMotion.Limited; + configurableJoint.angularYMotion = ConfigurableJointMotion.Limited; + configurableJoint.angularZMotion = ConfigurableJointMotion.Limited; + configurableJoint.autoConfigureConnectedAnchor = false; + configurableJoint.lowAngularXLimit = new SoftJointLimit + { + limit = 0f - prop.twistLimitDeg + }; + configurableJoint.highAngularXLimit = new SoftJointLimit + { + limit = prop.twistLimitDeg + }; + configurableJoint.projectionMode = JointProjectionMode.PositionAndRotation; + configurableJoint.projectionDistance = prop.projectionDistance; + SoftJointLimit softJointLimit = new SoftJointLimit + { + limit = prop.swingLimitDeg + }; + configurableJoint.angularYLimit = softJointLimit; + configurableJoint.angularZLimit = softJointLimit; + joint = configurableJoint; + joint.axis = new Vector3(0f, 1f, 0f); + if (prop.breakingForce != 0f) + { + configurableJoint.breakForce = prop.breakingForce; + } + + configurableJoint.enablePreprocessing = false; + break; + } + } + + if (segProperties is SegmentPropertiesCylinder) + { + joint.anchor = new Vector3(0f, 1f - prop.offsetScale, 0f); + joint.connectedAnchor = new Vector3(0f, -1f + prop.offsetScale, 0f); + } + else + { + joint.anchor = new Vector3(0f, (1f - prop.offsetScale) / 2f, 0f); + joint.connectedAnchor = new Vector3(0f, (-1f + prop.offsetScale) / 2f, 0f); + } + + joint.connectedBody = seg2.seg.GetComponent(); + } + + public Joint(GameObject seg1, GameObject seg2, Vector3 vGlobalAnchor, Vector3 vGlobalAxis, JointProperties prop, + Rope r, int jtPos) + { + ConfigurableJoint configurableJoint = seg1.AddComponent(); + configurableJoint.enableCollision = false; + configurableJoint.xMotion = ConfigurableJointMotion.Limited; + configurableJoint.yMotion = ConfigurableJointMotion.Limited; + configurableJoint.zMotion = ConfigurableJointMotion.Limited; + configurableJoint.angularXMotion = ConfigurableJointMotion.Limited; + configurableJoint.angularYMotion = ConfigurableJointMotion.Free; + configurableJoint.angularZMotion = ConfigurableJointMotion.Free; + configurableJoint.anchor = seg1.transform.InverseTransformPoint(vGlobalAnchor); + configurableJoint.axis = seg1.transform.InverseTransformDirection(vGlobalAxis); + if (seg2 != null) + { + configurableJoint.connectedBody = seg2.GetComponent(); + } + + SoftJointLimit linearLimit = new SoftJointLimit + { + limit = 0.01f + }; + SoftJointLimitSpring linearLimitSpring = default(SoftJointLimitSpring); + switch (jtPos) + { + case 0: + linearLimitSpring = r.getStartJtSpring(); + break; + case 1: + linearLimitSpring = r.getEndJtSpring(); + break; + default: + { + float damper = (linearLimitSpring.spring = 0f); + linearLimitSpring.damper = damper; + break; + } + } + + if (linearLimitSpring.spring == 0f) + { + linearLimit.limit = 0f; + } + + configurableJoint.linearLimitSpring = linearLimitSpring; + configurableJoint.linearLimit = linearLimit; + configurableJoint.projectionMode = JointProjectionMode.PositionAndRotation; + configurableJoint.projectionDistance = prop.projectionDistanceFirst; + configurableJoint.lowAngularXLimit = new SoftJointLimit + { + limit = 0f - prop.twistLimitDeg + }; + configurableJoint.highAngularXLimit = new SoftJointLimit + { + limit = prop.twistLimitDeg + }; + if (prop.breakingForce != 0f) + { + configurableJoint.breakForce = prop.breakingForce; + } + + joint = configurableJoint; + configurableJoint.autoConfigureConnectedAnchor = false; + configurableJoint.enablePreprocessing = false; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/PhysicsTools/Joint.cs.meta b/Assets/Scripts/PhysicsTools/Joint.cs.meta new file mode 100644 index 000000000..3a5ec9fcb --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Joint.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 3e680fa725d3066a2472a42dc6f1ba88 +timeCreated: 1747788127 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/JointProperties.cs b/Assets/Scripts/PhysicsTools/JointProperties.cs new file mode 100644 index 000000000..4d7e2124b --- /dev/null +++ b/Assets/Scripts/PhysicsTools/JointProperties.cs @@ -0,0 +1,48 @@ +using System; +using UnityEngine; + +namespace PhysicsTools +{ + [Serializable] + public class JointProperties + { + [Serializable] + public enum Type + { + CONFIGURABLE_JOINT = 0, + HINGE_JOINT = 1 + } + + public Type type; + + [Range(0f, 180f)] + public float twistLimitDeg; + + [Range(0f, 180f)] + public float swingLimitDeg; + + [Range(0f, 0.5f)] + public float offsetScale; + + [Range(0f, 90f)] + public float twistOffsetDeg; + + public float breakingForce; + + public float projectionDistance; + + public float projectionDistanceFirst; + + public JointProperties() + { + type = Type.CONFIGURABLE_JOINT; + twistLimitDeg = 10f; + swingLimitDeg = 50f; + offsetScale = 0f; + twistOffsetDeg = 0f; + breakingForce = 0f; + projectionDistance = 0.1f; + projectionDistanceFirst = 0.001f; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/JointProperties.cs.meta b/Assets/Scripts/PhysicsTools/JointProperties.cs.meta new file mode 100644 index 000000000..418ef8093 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/JointProperties.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 09ae8cd9a6c1c324b8c2a2a78ac60d7d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/LinkMesh.cs b/Assets/Scripts/PhysicsTools/LinkMesh.cs new file mode 100644 index 000000000..dab64351a --- /dev/null +++ b/Assets/Scripts/PhysicsTools/LinkMesh.cs @@ -0,0 +1,89 @@ +using System; +using UnityEngine; + +namespace PhysicsTools +{ + [Serializable] + public class LinkMesh + { + [HideInInspector] + public Mesh modifiedMesh; + + [HideInInspector] + public Matrix4x4 transform; + + [HideInInspector] + public Mesh defaultMesh; + + [HideInInspector] + public Material defaultMeshMaterial; + + [HideInInspector] + public Matrix4x4 defaultTransform; + + public Mesh mesh; + + public Material meshMaterial; + + public Vector3 position; + + public Vector3 rotation; + + public Vector3 scale; + + public LinkMesh() + { + mesh = null; + position = new Vector3(0f, 0f, 0f); + rotation = new Vector3(0f, 0f, 0f); + scale = new Vector3(1f, 1f, 1f); + defaultTransform = default(Matrix4x4); + defaultTransform.SetTRS(position, Quaternion.Euler(rotation), scale); + transform = default(Matrix4x4); + transform.SetTRS(position, Quaternion.Euler(rotation), scale); + } + + public void update() + { + if (mesh == null) + { + mesh = defaultMesh; + transform = defaultTransform; + Quaternion rot; + Utility.MatrixToTRS(transform, out position, out rot, out scale); + rotation = rot.eulerAngles; + } + if (mesh != null) + { + modifiedMesh = UnityEngine.Object.Instantiate(mesh); + } + if (modifiedMesh != null) + { + transform.SetTRS(position, Quaternion.Euler(rotation), scale); + ScaleMesh(); + } + } + + public void ScaleMesh() + { + Vector3[] vertices = modifiedMesh.vertices; + for (int i = 0; i < vertices.Length; i++) + { + Vector3 point = vertices[i]; + point = transform.MultiplyPoint(point); + vertices[i] = point; + } + modifiedMesh.vertices = vertices; + } + + public Mesh getMesh() + { + return modifiedMesh; + } + + public Material getMaterial() + { + return null; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/LinkMesh.cs.meta b/Assets/Scripts/PhysicsTools/LinkMesh.cs.meta new file mode 100644 index 000000000..5a4347280 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/LinkMesh.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 88218b6dac3a1d87d3867523046c804d +timeCreated: 1747788125 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/PosOri.cs b/Assets/Scripts/PhysicsTools/PosOri.cs new file mode 100644 index 000000000..76c910095 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/PosOri.cs @@ -0,0 +1,19 @@ +using System; +using UnityEngine; + +namespace PhysicsTools +{ + [Serializable] + public class PosOri + { + public Vector3 pos; + + public Quaternion rot; + + public PosOri(Vector3 p, Quaternion q) + { + pos = p; + rot = q; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/PosOri.cs.meta b/Assets/Scripts/PhysicsTools/PosOri.cs.meta new file mode 100644 index 000000000..0214032f6 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/PosOri.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3b2e47173d3a5c346a9528bef13473eb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/Rope.cs b/Assets/Scripts/PhysicsTools/Rope.cs new file mode 100644 index 000000000..120c3400a --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Rope.cs @@ -0,0 +1,1502 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +namespace PhysicsTools +{ + [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] + public class Rope : MonoBehaviour + { + public enum RopeGameplayType + { + NORMAL = 0, + ICE = 1, + FLOAT = 2 + } + + [Serializable] + public enum LOGGING + { + NONE = 0, + INFO = 1, + DEBUG = 2 + } + + [Serializable] + public enum RopeType + { + Procedural = 0, + FromBones = 1 + } + + [Serializable] + public enum RendererType + { + None = 0, + Continuous = 1, + Segment = 2 + } + + public delegate void BrokenHandler(object sender); + + public delegate void CreateHandler(object sender); + + public delegate void DeleteHandler(object sender); + + public RopeGameplayType ropeGameplayType; + + private List prevControlPoints = new List(); + + private bool prevKinematic = true; + + private bool prevHideChildren = true; + + private RendererType prevRendererType = RendererType.Continuous; + + public bool startJointSpringy; + + public SerializedSoftJointLimitSpring startJtSpring; + + public bool endJointSpringy; + + public SerializedSoftJointLimitSpring endJtSpring; + + private string prevStrStaticBones; + + public string strStaticBones; + + private HashSet staticBones = new HashSet(); + + public PhysicsMaterial ropeMaterial; + + private GameObject springHolder; + + private Joint springJoint; + + [HideInInspector] public List lstComponentsCreated = new List(); + + public bool HideChildren = true; + + public LOGGING loggingType = LOGGING.INFO; + + public RopeType ropeType; + + public int numControlPoints = 2; + + public List controlPoints = new List(); + + public Transform startPosition; + + public float rate; + + [Range(0f, 10f)] public float gravity = 1f; + + public bool kinematic = true; + + private GameObject prevFirstBone; + + private GameObject prevLastBone; + + public GameObject firstBone; + + public GameObject lastBone; + + public bool sendRopeEvents; + + public RendererType rendererType = RendererType.Continuous; + + public LinkMesh linkMesh = new LinkMesh(); + + public Material continuousMaterial; + + public MeshRenderer meshRenderer; + + public MeshFilter meshFilter; + + public bool useColliders = true; + + public float radiusFactor = 1f; + + public float segmentBordersScaleFactor = 1f; + + public bool useSegmentBordersOffset; + + public SegmentProperties.Type segPropertyType; + + public SegmentPropertiesBox segPropertiesBox = new SegmentPropertiesBox(); + + public SegmentPropertiesCylinder segPropertiesCylinder = new SegmentPropertiesCylinder(); + + public JointProperties jointProp = new JointProperties(); + + private int initialNumSegemnts; + + public List lstSegments = new List(); + + private Mesh mesh; + + private Vector3[] vertexBuffer; + + private Vector2[] uv; + + private int[] indexBuffer; + + private Vector4[] tangents; + + public float totalLengthGet; + + public float tensionGet; + + public float totalLength; + + public float totalLengthColliders; + + public float ropeStretchThreshold = -1f; + + public float textureLength = 0.33f; + + private int numCirclePt = 3; + + public event BrokenHandler Broken; + + public event CreateHandler Created; + + public event DeleteHandler Deleted; + + public void setStartJointSpring(SoftJointLimitSpring sp) + { + startJtSpring = (SerializedSoftJointLimitSpring)sp; + if (springJoint != null) + { + ConfigurableJoint configurableJoint = (ConfigurableJoint)springJoint.joint; + if (configurableJoint != null) + { + configurableJoint.linearLimitSpring = getStartJtSpring(); + SoftJointLimit linearLimit = default(SoftJointLimit); + linearLimit.limit = 0.01f; + configurableJoint.linearLimit = linearLimit; + } + } + } + + public void setEndJointSpring(SoftJointLimitSpring sp) + { + endJtSpring = (SerializedSoftJointLimitSpring)sp; + if (lstSegments.Count != 0) + { + ConfigurableJoint configurableJoint = ((lstSegments[lstSegments.Count - 1].next == null) + ? null + : ((ConfigurableJoint)lstSegments[lstSegments.Count - 1].next.joint)); + if (configurableJoint != null) + { + configurableJoint.linearLimitSpring = getEndJtSpring(); + SoftJointLimit linearLimit = default(SoftJointLimit); + linearLimit.limit = 0.01f; + configurableJoint.linearLimit = linearLimit; + } + } + } + + public SegmentPropertiesBase getSegmentProperties() + { + switch (segPropertyType) + { + case SegmentProperties.Type.BOX: + return segPropertiesBox; + case SegmentProperties.Type.CYLINDER: + return segPropertiesCylinder; + default: + return segPropertiesCylinder; + } + } + + public void setPhysicsMaterial(PhysicsMaterial mat) + { + foreach (Segment lstSegment in lstSegments) + { + lstSegment.capsuleCollider.sharedMaterial = mat; + } + } + + private void Debug(string msg, LOGGING type) + { + if (type <= loggingType) + { + UnityEngine.Debug.Log(msg, this); + } + } + + private void OnJointBreak(float breakForce) + { + if (sendRopeEvents && this.Broken != null) + { + this.Broken(this); + } + } + + public void setContinuousMaterialMapping(float f) + { + textureLength = f; + } + + public void setFirstBone(GameObject bone) + { + firstBone = bone; + } + + public void setLastBone(GameObject bone) + { + lastBone = bone; + } + + public List getSegments() + { + return lstSegments; + } + + public void setStaticBoneList(string str) + { + staticBones.Clear(); + str.Trim(); + if (str != string.Empty) + { + string[] array = str.Split(','); + string[] array2 = array; + foreach (string text in array2) + { + string[] array3 = text.Split('-'); + if (array3.Length == 1) + { + staticBones.Add(int.Parse(array3[0])); + } + else if (array3.Length == 2) + { + int num = int.Parse(array3[0]); + int num2 = int.Parse(array3[1]); + for (int j = num; j <= num2; j++) + { + staticBones.Add(j); + } + } + } + } + + strStaticBones = str; + prevStrStaticBones = str; + } + + public bool setControlPoints(List lstControlPoints) + { + if (numControlPoints < 2 && ropeType == RopeType.Procedural) + { + throw new ArgumentException("Control points should be more than 1"); + } + + bool flag = false; + if (numControlPoints != lstControlPoints.Count) + { + while (lstControlPoints.Count < numControlPoints) + { + lstControlPoints.Add(new ControlPoint()); + } + + while (lstControlPoints.Count > numControlPoints) + { + lstControlPoints.RemoveAt(lstControlPoints.Count - 1); + } + + flag = true; + } + + for (int i = 0; i < lstControlPoints.Count; i++) + { + if (i < prevControlPoints.Count && !lstControlPoints[i].compare(prevControlPoints[i])) + { + flag = true; + break; + } + } + + prevControlPoints.Clear(); + for (int j = 0; j < lstControlPoints.Count; j++) + { + prevControlPoints.Add(lstControlPoints[j].clone()); + } + + if (flag) + { + controlPoints.Clear(); + for (int k = 0; k < prevControlPoints.Count; k++) + { + controlPoints.Add(prevControlPoints[k].clone()); + } + } + + numControlPoints = lstControlPoints.Count; + return flag; + } + + public SoftJointLimitSpring getStartJtSpring() + { + SoftJointLimitSpring result = default(SoftJointLimitSpring); + if (startJointSpringy) + { + result.spring = startJtSpring.spring; + result.damper = startJtSpring.damper; + } + else + { + float spring = (result.damper = 0f); + result.spring = spring; + } + + return result; + } + + public SoftJointLimitSpring getEndJtSpring() + { + SoftJointLimitSpring result = default(SoftJointLimitSpring); + if (endJointSpringy) + { + result.spring = endJtSpring.spring; + result.damper = endJtSpring.damper; + } + else + { + float spring = (result.damper = 0f); + result.spring = spring; + } + + return result; + } + + public void RefreshJointSpring() + { + setStartJointSpring(startJtSpring); + setEndJointSpring(endJtSpring); + } + + public void RefreshProperties(bool bForce) + { + Debug("Refreshing Properties Force = " + bForce, LOGGING.INFO); + bool flag = bForce; + if (numControlPoints < 2) + { + numControlPoints = 2; + } + + bool flag2 = setControlPoints(controlPoints); + flag = flag || flag2; + if (prevStrStaticBones != strStaticBones) + { + setStaticBoneList(strStaticBones); + flag = true; + } + + if (flag) + { + regenerateRope(true); + } + + if (prevHideChildren != HideChildren) + { + HideChildrenObjects(HideChildren); + } + + if (prevKinematic != kinematic) + { + changeToKinematic(kinematic); + } + + if (prevRendererType != rendererType) + { + setRendererType(rendererType); + } + + linkMesh.update(); + setLinkMesh(linkMesh); + if (rendererType == RendererType.Continuous) + { + generateOverallMesh(); + } + + Debug("Refreshing Properties Done", LOGGING.INFO); + } + + public void setBreakingForce(float force) + { + Debug("Setting breaking force to " + force, LOGGING.INFO); + foreach (Segment lstSegment in lstSegments) + { + if (lstSegment.next != null) + { + if (force != 0f) + { + lstSegment.next.joint.breakForce = force; + } + else + { + lstSegment.next.joint.breakForce = 1E+10f; + } + } + } + + jointProp.breakingForce = force; + Debug("Setting breaking force done", LOGGING.INFO); + } + + public void setRendererType(RendererType rType) + { + Debug("Setting Renderer Type to " + rType, LOGGING.INFO); + switch (rType) + { + case RendererType.Continuous: + enableRendering(true); + enableSegmentRendering(false); + break; + case RendererType.Segment: + enableRendering(false); + enableSegmentRendering(true); + break; + case RendererType.None: + enableRendering(false); + enableSegmentRendering(false); + break; + } + + rendererType = rType; + prevRendererType = rType; + } + + public void setLinkMesh(LinkMesh lMesh) + { + if (lMesh != null && lMesh.getMesh() != null) + { + foreach (Segment lstSegment in lstSegments) + { + lstSegment.meshFilter.sharedMesh = lMesh.getMesh(); + lstSegment.meshRenderer.sharedMaterial = lMesh.meshMaterial; + } + } + + linkMesh = lMesh; + } + + public void applyGravity(float f) + { + if (f == -1f) + { + return; + } + + foreach (Segment lstSegment in lstSegments) + { + lstSegment.body.AddForce((0f - (1f - f)) * lstSegment.body.mass * Physics.gravity); + } + } + + public void updateMass(float m) + { + getSegmentProperties().massPerUnitLength = m; + float mass = getSegmentProperties().massPerUnitLength * getSegmentProperties().length; + foreach (Segment lstSegment in lstSegments) + { + lstSegment.body.mass = mass; + } + } + + private void HideChildrenObjects(bool bHide) + { + foreach (Segment lstSegment in lstSegments) + { + if (bHide) + { + lstSegment.seg.hideFlags = HideFlags.HideInHierarchy; + } + else + { + lstSegment.seg.hideFlags = HideFlags.None; + } + } + + prevHideChildren = bHide; + } + + public List> getTrajectory() + { + List> list = new List>(); + float num = segmentBordersScaleFactor; + float num2 = ((!useSegmentBordersOffset || lstSegments.Count <= 0) + ? 0f + : lstSegments[0].capsuleCollider.radius); + num2 *= num; + float num3 = 1f; + int num4 = lstSegments.Count; + // if (num4 > 30 && GameController.Instance.useFastRopeDraw) + // { + // num4 = 30; + // } + + List list2 = new List(); + int num5 = 0; + if (lstSegments.Count > 0) + { + foreach (Segment lstSegment in lstSegments) + { + if (list2.Count == 0) + { + PosOri posOri = + new PosOri( + lstSegment.seg.transform.TransformPoint(new Vector3(0f, + 0f - getSegmentProperties().length - num2, 0f)), lstSegment.seg.transform.rotation); + posOri.pos = startPosition.position; + list2.Add(posOri); + } + + PosOri item = new PosOri(lstSegment.seg.transform.position, lstSegment.seg.transform.rotation); + list2.Add(item); + if (lstSegment.next == null && num5 < num4 - 1) + { + PosOri item2 = + new PosOri( + lstSegment.seg.transform.TransformPoint(new Vector3(0f, + getSegmentProperties().length * num3, 0f)), lstSegment.seg.transform.rotation); + list2.Add(item2); + list.Add(list2); + list2 = new List(); + } + + num5++; + if (num5 > num4) + { + break; + } + } + + PosOri item3 = + new PosOri( + lstSegments[Mathf.Min(num4, lstSegments.Count) - 1].seg.transform + .TransformPoint(new Vector3(0f, getSegmentProperties().length + num2, 0f)), + lstSegments[0].seg.transform.rotation); + list2.Add(item3); + } + + list.Add(list2); + return list; + } + + private void generateMeshForTrajectory(List trajectory, Bezier interpolator, float totalLen, + ref float lengthCovered, ref int lastVertId, ref int lastIndexID) + { + float num = ((segPropertyType != 0) ? segPropertiesBox.width : segPropertiesCylinder.radius); + num *= radiusFactor; + float num2 = 6.28318f / (float)numCirclePt; + Vector3[] array = new Vector3[numCirclePt]; + Vector3[] array2 = new Vector3[numCirclePt]; + for (int i = 0; i < numCirclePt; i++) + { + array[i] = new Vector3((float)((double)num * Math.Cos((float)i * num2)), 0f, + (float)((double)num * Math.Sin((float)i * num2))); + array2[i] = new Vector3((float)((double)(0f - num) * Math.Sin((float)i * num2)), 0f, + (float)((double)num * Math.Cos((float)i * num2))); + array2[i].Normalize(); + } + + int num3 = lastVertId; + Vector3 v = new Vector3(0f, 0f, 1f); + Vector3 vector = new Vector3(1f, 1f, 1f); + Vector3 vector2 = new Vector3(0.3f, 1f, 0.3f); + Vector3 s = new Vector3(0.2f, 1f, 0.2f); + float num4 = 0f; + Vector3 vector3 = trajectory[0].pos; + int num5 = trajectory.Count * 4; + float deltaLen = totalLen / (float)(num5 - 1); + for (int j = 0; j < num5; j++) + { + Vector3 vector4 = ((j != 0) ? interpolator.getNext(deltaLen).pos : trajectory[0].pos); + if (j != 0) + { + v = vector4 - vector3; + v.Normalize(); + } + else if (j == 0 && trajectory.Count > 1) + { + v = trajectory[1].pos - vector4; + v.Normalize(); + } + + Vector3 vector5 = vector4 - vector3; + vector3 = vector4; + Matrix4x4 matrix4x = default(Matrix4x4); + for (int k = 0; k < numCirclePt; k++) + { + Quaternion q = Utility.createOrientation(v); + // if (GameController.Instance.fishingPlayer.currentHands.fishingLine.lineType == + // FishingLine.LineType.FLY && j >= num5 - 8) + // { + // matrix4x.SetTRS(vector4, q, s); + // } + // else + { + matrix4x.SetTRS(vector4, q, (!(vector4.y < 0f)) ? vector : vector2); + } + + vertexBuffer[num3] = base.transform.InverseTransformPoint(matrix4x.MultiplyPoint(array[k])); + if (j == 0) + { + } + + Vector3 vector6 = base.transform.InverseTransformDirection(matrix4x.MultiplyVector(array2[k])); + tangents[num3] = new Vector4(vector6.x, vector6.y, vector6.z, -1f); + if (j == 1) + { + } + + uv[num3] = new Vector2((float)k * 1f / (float)numCirclePt, (totalLen - num4) / textureLength); + num3++; + } + + num4 += vector5.magnitude; + } + + if (true) + { + int num6 = lastIndexID; + for (int l = 0; l < num5 - 1; l++) + { + for (int m = 0; m < numCirclePt; m++) + { + int num7 = l + lastVertId / numCirclePt; + indexBuffer[num6++] = num7 * numCirclePt + m; + indexBuffer[num6++] = (num7 + 1) * numCirclePt + m; + indexBuffer[num6++] = num7 * numCirclePt + (m + 1) % numCirclePt; + indexBuffer[num6++] = num7 * numCirclePt + (m + 1) % numCirclePt; + indexBuffer[num6++] = (num7 + 1) * numCirclePt + m; + indexBuffer[num6++] = (num7 + 1) * numCirclePt + (m + 1) % numCirclePt; + } + } + + lastIndexID = num6; + } + + lengthCovered += num4; + lastVertId = num3; + } + + public void generateOverallMesh() + { + // if ((bool)GameController.Instance.fishingPlayer && GameController.Instance.optimalRopeGenerator && + // ((GameController.Instance.fishingPlayer.currentHands.fakeStraightLine.enabled && + // ropeGameplayType != RopeGameplayType.FLOAT) || + // GameController.Instance.fishingPlayer.underwaterCamera.isTurnedOn)) + // { + // return; + // } + + List> trajectory = getTrajectory(); + if (trajectory[0].Count <= 0) + { + return; + } + + int num = 0; + int num2 = 0; + bool flag = false; + foreach (List item in trajectory) + { + int num3 = item.Count * 4; + num += num3; + num2 += (num3 - 1) * (numCirclePt * 2); + } + + int num4 = numCirclePt * num; + if (vertexBuffer == null || num4 != vertexBuffer.Length) + { + flag = vertexBuffer == null || num4 > vertexBuffer.Length; + vertexBuffer = new Vector3[num4]; + tangents = new Vector4[num4]; + uv = new Vector2[num4]; + } + + if (indexBuffer == null || num2 * 3 != indexBuffer.Length) + { + indexBuffer = new int[num2 * 3]; + } + + int lastVertId = 0; + int lastIndexID = 0; + List list = new List(); + float num5 = 0f; + foreach (List item2 in trajectory) + { + list.Add(new Bezier(item2)); + num5 += list[list.Count - 1].TotalLength(); + } + + float lengthCovered = 0f; + for (int i = 0; i < trajectory.Count; i++) + { + generateMeshForTrajectory(trajectory[i], list[i], num5, ref lengthCovered, ref lastVertId, + ref lastIndexID); + } + + if (mesh == null) + { + mesh = new Mesh(); + } + + if (flag) + { + mesh.vertices = vertexBuffer; + mesh.triangles = indexBuffer; + } + else + { + mesh.triangles = indexBuffer; + mesh.vertices = vertexBuffer; + } + + mesh.uv = uv; + mesh.RecalculateNormals(); + mesh.tangents = tangents; + meshFilter.sharedMesh = mesh; + meshRenderer.sharedMaterial = continuousMaterial; + mesh.bounds = new Bounds(base.transform.position, new Vector3(10000f, 10000f, 10000f)); + } + + public void regenerateRope(bool bDestroyImmediate) + { + deleteRope(bDestroyImmediate); + generateCatnaryRope(controlPoints.ToArray()); + setLinkMesh(linkMesh); + initialNumSegemnts = lstSegments.Count; + } + + public void generateRope(ControlPoint[] arrPoints) + { + bool flag = false; + List list = new List(arrPoints.Length); + for (int i = 0; i < arrPoints.Length; i++) + { + list.Add(arrPoints[i].localPos); + if (arrPoints[i].obj != null) + { + list[i] = arrPoints[i].obj.transform.TransformPoint(arrPoints[i].localPos); + } + else + { + list[i] = ((!flag) + ? base.gameObject.transform.TransformPoint(arrPoints[i].localPos) + : arrPoints[i].localPos); + } + } + + SCapsulePos sCapsulePos = new SCapsulePos(); + bool flag2 = false; + int last = 0; + bool flag3 = false; + Segment segment = null; + Quaternion quaternion = Quaternion.identity; + Quaternion quaternion2 = Quaternion.AngleAxis(jointProp.twistOffsetDeg, new Vector3(0f, 1f, 0f)); + totalLength = 0f; + Vector3 vector = list[0]; + int num = 0; + while (!flag2) + { + int num2 = last; + flag2 = getNextCapsulePos(sCapsulePos, list, ref last, getSegmentProperties(), jointProp, false); + Segment segment2 = null; + if (sCapsulePos.fLen > 0f) + { + segment2 = createSegment(sCapsulePos.fLen, sCapsulePos.vPos, sCapsulePos.vDir); + if (useColliders && num >= 0) + { + if ((bool)segment2.capsuleCollider) + { + segment2.capsuleCollider.enabled = true; + } + + num = 0; + } + else + { + if ((bool)segment2.capsuleCollider) + { + segment2.capsuleCollider.enabled = false; + } + + num++; + } + + lstSegments.Add(segment2); + if (segment != null) + { + totalLength += (sCapsulePos.vPos - vector).magnitude; + vector = sCapsulePos.vPos; + segment.next = createSegmentJoint(segment, segment2, quaternion); + segment2.prev = segment.next; + } + + GameObject gameObject = null; + Vector3 vector2 = new Vector3(0f, 0f, 0f); + bool flag4 = false; + if (!flag3 && num2 == 0) + { + if (arrPoints[num2].attached) + { + gameObject = arrPoints[num2].obj; + vector2 = arrPoints[num2].localPos; + flag4 = true; + } + } + else if (num2 != last && last < arrPoints.Length && arrPoints[last].attached) + { + gameObject = arrPoints[last].obj; + vector2 = arrPoints[last].localPos; + flag4 = true; + } + + if (flag4) + { + vector2 = ((gameObject != null) + ? gameObject.transform.TransformPoint(vector2) + : ((!flag) ? base.gameObject.transform.TransformPoint(vector2) : vector2)); + int jtPos = -1; + Joint prev = new Joint(segment2.seg, gameObject, vector2, + segment2.seg.transform.TransformDirection(0f, 1f, 0f), jointProp, this, jtPos); + if (num2 == 0) + { + segment2.prev = prev; + } + + flag3 = true; + } + + segment = segment2; + quaternion = quaternion2 * quaternion; + } + else + { + flag2 = true; + } + } + + if (lstSegments.Count == 1) + { + GameObject obj = arrPoints[last].obj; + Vector3 localPos = arrPoints[last].localPos; + int jtPos2 = -1; + Segment segment3 = lstSegments[0]; + Joint prev2 = new Joint(segment3.seg, obj, localPos, + segment3.seg.transform.TransformDirection(0f, 1f, 0f), jointProp, this, jtPos2); + segment3.prev = prev2; + } + + if (lstSegments.Count > 0 && !lstSegments[lstSegments.Count - 1].seg.GetComponent()) + { + GameObject obj2 = arrPoints[last].obj; + Vector3 localPos2 = arrPoints[last].localPos; + int jtPos3 = -1; + Segment segment4 = lstSegments[lstSegments.Count - 1]; + Joint joint = new Joint(segment4.seg, obj2, localPos2, + segment4.seg.transform.TransformDirection(0f, 1f, 0f), jointProp, this, jtPos3); + } + + if (sendRopeEvents && this.Created != null) + { + this.Created(this); + } + } + + public void generateCatnaryRope(ControlPoint[] arrPoints) + { + Debug("Generating Catenary Rope " + arrPoints.ToString(), LOGGING.INFO); + if (arrPoints.Length < 2) + { + return; + } + + List list = new List(); + Vector3 vector = ((!(arrPoints[0].obj != null)) + ? arrPoints[0].localPos + : arrPoints[0].obj.transform.TransformPoint(arrPoints[0].localPos)); + list.Add(arrPoints[0]); + for (int i = 1; i < arrPoints.Length; i++) + { + Vector3 vector2 = ((!(arrPoints[i].obj != null)) + ? arrPoints[i].localPos + : arrPoints[i].obj.transform.TransformPoint(arrPoints[i].localPos)); + ControlPoint controlPoint = arrPoints[i - 1]; + if (controlPoint.slackFraction > 1f) + { + float magnitude = (vector2 - vector).magnitude; + SegmentPropertiesBase segmentProperties = getSegmentProperties(); + List catenaryPts = Utility.getCatenaryPts(vector, vector2, + magnitude * controlPoint.slackFraction, (int)(magnitude / segmentProperties.length)); + for (int j = 1; j < catenaryPts.Count; j++) + { + ControlPoint controlPoint2 = new ControlPoint(); + controlPoint2.attached = false; + controlPoint2.obj = null; + controlPoint2.localPos = catenaryPts[j]; + if (j == catenaryPts.Count - 1) + { + controlPoint2.attached = arrPoints[i].attached; + controlPoint2.obj = arrPoints[i].obj; + controlPoint2.localPos = ((!(controlPoint2.obj != null)) + ? controlPoint2.localPos + : controlPoint2.obj.transform.InverseTransformPoint(controlPoint2.localPos)); + } + + list.Add(controlPoint2); + } + } + else + { + list.Add(arrPoints[i]); + } + + vector = vector2; + } + + generateRope(list.ToArray()); + Debug("Generating Catenary Rope done", LOGGING.INFO); + } + + public void deleteRope(bool bDestroyImmediate) + { + if (lstSegments != null) + { + foreach (Segment lstSegment in lstSegments) + { + if (bDestroyImmediate) + { + UnityEngine.Object.DestroyImmediate(lstSegment.seg); + } + else + { + UnityEngine.Object.Destroy(lstSegment.seg); + } + } + + lstSegments.Clear(); + } + + if (springJoint != null) + { + UnityEngine.Object.Destroy(springJoint.joint); + } + + if (springHolder != null) + { + UnityEngine.Object.Destroy(springHolder); + } + + if (bDestroyImmediate) + { + clearOrphan(); + } + + if (sendRopeEvents && this.Deleted != null) + { + this.Deleted(this); + } + } + + public float getLength() + { + return totalLength; + } + + public float getLengthColliders() + { + return totalLengthColliders; + } + + public float getTension() + { + if (springJoint != null && springJoint.joint != null) + { + ConfigurableJoint configurableJoint = (ConfigurableJoint)springJoint.joint; + Vector3 vector = configurableJoint.connectedAnchor; + Rigidbody connectedBody = configurableJoint.connectedBody; + Vector3 vector2 = configurableJoint.anchor; + Rigidbody body = lstSegments[0].body; + if (connectedBody != null) + { + vector = connectedBody.transform.TransformPoint(vector); + } + + if (body != null) + { + vector2 = body.transform.TransformPoint(vector2); + } + + float num = (vector - vector2).magnitude - 0.01f; + return num * configurableJoint.linearLimitSpring.spring; + } + + if (lstSegments.Count > 0 && lstSegments[0].prev != null) + { + UnityEngine.Joint joint = lstSegments[0].prev.joint; + Vector3 vector3 = joint.connectedAnchor; + Rigidbody connectedBody2 = joint.connectedBody; + Vector3 vector4 = joint.anchor; + Rigidbody body2 = lstSegments[0].body; + if (connectedBody2 != null) + { + vector3 = connectedBody2.transform.TransformPoint(vector3); + } + + if (body2 != null) + { + vector4 = body2.transform.TransformPoint(vector4); + } + + float num2 = (vector3 - vector4).magnitude - 0.01f; + return num2 * ((ConfigurableJoint)joint).linearLimitSpring.spring; + } + + return 0f; + } + + public void breakRope(float fraction) + { + Debug("Breaking Rope from Fraction: " + fraction, LOGGING.INFO); + int num = (int)((float)lstSegments.Count * fraction); + if (num < lstSegments.Count - 1 && num >= 0) + { + Debug("Breaking Rope from segment: " + num, LOGGING.DEBUG); + if (lstSegments[num].next != null) + { + UnityEngine.Object.Destroy(lstSegments[num].next.joint); + lstSegments[num].next = null; + lstSegments[num + 1].prev = null; + } + } + + Debug("Breaking Rope done", LOGGING.INFO); + } + + public void setLength(float newLength) + { + newLength -= getLength(); + changeLength(newLength); + } + + public void changeLength(float deltaLen) + { + if (lstSegments.Count < 1 || deltaLen == 0f) + { + CalculateTotalLength(); + return; + } + + deltaLen *= 0.5f; + int num = 0; + Segment segment = lstSegments[num]; + SegmentPropertiesBase segmentProperties = getSegmentProperties(); + Vector3 localScale = segment.seg.transform.localScale; + if (localScale.y > 0f) + { + localScale.y += deltaLen; + } + + if (localScale.y < 0.01f) + { + localScale.y = 0.01f; + } + + float num2 = 0.5f; + float num3 = 1f; + float num4 = 0f; + float num5 = 0f; + float num6 = segmentProperties.length * num2; + num5 = ((SegmentPropertiesCylinder)segmentProperties).radius * 2f; + if (localScale.y > (segmentProperties.length + num5) * num2) + { + Vector3 localScale2 = segment.seg.transform.localScale; + localScale2.y = num6; + segment.seg.transform.localScale = localScale2; + float num7 = 0f; + for (deltaLen = 0f - segmentProperties.length + localScale.y / num2; deltaLen > 0f; deltaLen -= num7) + { + num7 = Mathf.Clamp(deltaLen, 0.01f, num6); + segment.seg.transform.position += segment.seg.transform.TransformDirection(0f, 1f, 0f) * num7; + if (segment.next != null) + { + if (segment.next.joint.connectedBody != segment.body) + { + segment.next.joint.anchor = new Vector3(0f, (1f - jointProp.offsetScale) * num3, 0f); + } + else + { + segment.next.joint.connectedAnchor = + new Vector3(0f, (1f - jointProp.offsetScale) * num3, 0f); + } + } + + Vector3 pos = segment.seg.transform.position - + segment.seg.transform.TransformDirection(0f, 1f, 0f) * + (num7 + segmentProperties.length / 2f); + Segment segment2 = createSegment(num7 * 2f, pos, + segment.seg.transform.TransformDirection(0f, 1f, 0f)); + float num8 = jointProp.twistOffsetDeg * (float)(-1 + (initialNumSegemnts - lstSegments.Count)); + num8 = (num8 + 36000f) % 360f; + Quaternion quaternion = Quaternion.AngleAxis(num8, new Vector3(0f, 1f, 0f)); + segment2.seg.transform.rotation = segment2.seg.transform.rotation * quaternion; + Rigidbody connectedBody = segment.prev.joint.connectedBody; + Vector3 connectedAnchor = segment.prev.joint.connectedAnchor; + Vector3 vGlobalAnchor = ((!connectedBody) + ? connectedAnchor + : connectedBody.transform.TransformPoint(connectedAnchor)); + Joint prev = new Joint(segment2.seg, (!connectedBody) ? null : connectedBody.gameObject, + vGlobalAnchor, segment2.seg.transform.TransformDirection(0f, 1f, 0f), jointProp, this, -1); + segment2.prev = prev; + Joint prev2 = (segment2.next = new Joint(segment2, segment, jointProp, getSegmentProperties(), + Quaternion.identity)); + Joint prev3 = segment.prev; + segment.prev = prev2; + lstSegments.Insert(0, segment2); + UnityEngine.Object.Destroy(prev3.joint); + FixAnchors(segment2, num3); + segment = segment2; + } + + CalculateTotalLength(); + } + else if (localScale.y < num5 * num2) + { + while (deltaLen < 0f) + { + if (lstSegments.Count < num + 1 + 1) + { + UnityEngine.Debug.LogError("!!! changeLength lstSegments size error index !!!: " + num); + // if (GameController.Instance.fishingPlayer.currentState == FishingPlayer.PlayerState.FISHING || + // GameController.Instance.fishingPlayer.currentState == FishingPlayer.PlayerState.ICE_FISHING) + // { + // GameController.Instance.fishingPlayer.LineBreak( + // Utilities.GetTranslation("HUD_MESSAGE/LINE_BROKE_TENSION"), 0f); + // } + + return; + } + + Segment segment3 = lstSegments[num + 1]; + Vector3 localScale3 = segment3.seg.transform.localScale; + localScale3.y = num6; + segment3.seg.transform.localScale = localScale3; + segment.seg.transform.position += + segment.seg.transform.TransformDirection(0f, -1f, 0f) * localScale.y / num2; + Vector3 connectedAnchor2 = segment.prev.joint.connectedAnchor; + Rigidbody connectedBody2 = segment.prev.joint.connectedBody; + Vector3 vGlobalAnchor2 = ((!connectedBody2) + ? connectedAnchor2 + : connectedBody2.transform.TransformPoint(connectedAnchor2)); + Joint prev4 = new Joint(segment3.seg, (!connectedBody2) ? null : connectedBody2.gameObject, + vGlobalAnchor2, segment3.seg.transform.TransformDirection(0f, 1f, 0f), jointProp, this, -1); + segment3.prev = prev4; + deltaLen += segment.seg.transform.localScale.y; + lstSegments.Remove(segment); + UnityEngine.Object.Destroy(segment.seg); + FixAnchors(segment3, num3); + segment = segment3; + if (!(deltaLen < 0f)) + { + } + } + + CalculateTotalLength(); + } + else + { + segment.seg.transform.localScale = localScale; + FixAnchors(segment, num3); + CalculateTotalLength(); + } + } + + public void FixAnchors(Segment seg, float anchorMult) + { + Joint prev = seg.prev; + Joint next = seg.next; + if (prev != null) + { + if (prev.joint.connectedBody != seg.body) + { + prev.joint.anchor = new Vector3(0f, (-1f + jointProp.offsetScale) * anchorMult, 0f); + } + else + { + prev.joint.connectedAnchor = new Vector3(0f, (-1f + jointProp.offsetScale) * anchorMult, 0f); + } + } + + if (next != null) + { + if (next.joint.connectedBody != seg.body) + { + next.joint.anchor = new Vector3(0f, (1f - jointProp.offsetScale) * anchorMult, 0f); + } + else + { + next.joint.connectedAnchor = new Vector3(0f, (1f - jointProp.offsetScale) * anchorMult, 0f); + } + } + } + + private void clearOrphan() + { + Debug("Clear Orphan", LOGGING.INFO); + if (lstComponentsCreated != null) + { + foreach (UnityEngine.Object item in lstComponentsCreated) + { + UnityEngine.Object.DestroyImmediate(item); + } + + lstComponentsCreated.Clear(); + } + + Debug("Clear Orphan done", LOGGING.INFO); + } + + private void OnEnable() + { + } + + private void Awake() + { + meshRenderer = GetComponent(); + meshFilter = GetComponent(); + if (startPosition == null && (bool)controlPoints[0].obj) + { + startPosition = controlPoints[0].obj.transform; + } + + List list = new List(); + for (int i = 0; i < base.transform.childCount; i++) + { + if (base.transform.GetChild(i).name.Contains("__rope__")) + { + list.Add(base.transform.GetChild(i).gameObject); + } + } + + foreach (GameObject item in list) + { + UnityEngine.Object.Destroy(item); + } + + lstSegments = new List(); + if (ropeType == RopeType.FromBones) + { + rendererType = RendererType.None; + } + + regenerateRope(true); + setRendererType(rendererType); + } + + private void Start() + { + } + + private void FixedUpdate() + { + changeLength(rate); + if (gravity != -1f) + { + applyGravity(gravity); + } + } + + private void LateUpdate() + { + generateOverallMesh(); + } + + private void checkBrokenJoints() + { + foreach (Segment lstSegment in lstSegments) + { + if (lstSegment.prev != null && lstSegment.prev.joint == null) + { + lstSegment.prev = null; + } + + if (lstSegment.next != null && lstSegment.next.joint == null) + { + lstSegment.next = null; + } + } + } + + private void checkStabilization() + { + foreach (Segment lstSegment in lstSegments) + { + float num = lstSegment.body.linearVelocity.sqrMagnitude * lstSegment.body.mass + + lstSegment.body.inertiaTensor.magnitude * lstSegment.body.angularVelocity.sqrMagnitude; + if (num > lstSegment.body.mass * 25f) + { + lstSegment.body.linearVelocity = new Vector3(0f, 0f, 0f); + lstSegment.body.angularVelocity = new Vector3(0f, 0f, 0f); + } + } + } + + public void changeToKinematic(bool b) + { + int num = 0; + foreach (Segment lstSegment in lstSegments) + { + if (ropeType == RopeType.Procedural || (ropeType == RopeType.FromBones && !staticBones.Contains(num))) + { + lstSegment.body.isKinematic = b; + } + + num++; + } + + kinematic = b; + prevKinematic = b; + } + + private void enableRendering(bool b) + { + Debug("Enable Rendering " + b, LOGGING.INFO); + meshRenderer.enabled = b; + Debug("Enable Rendering done", LOGGING.INFO); + } + + private void enableSegmentRendering(bool b) + { + Debug("Enable Segment Rendering " + b, LOGGING.INFO); + foreach (Segment lstSegment in lstSegments) + { + lstSegment.meshRenderer.enabled = b; + } + + Debug("Enable Segment Rendering done", LOGGING.INFO); + } + + private bool getNextCapsulePos(SCapsulePos capPose, List vecPts, ref int last, + SegmentPropertiesBase segProp, JointProperties jointProp, bool bExtraSegPosAtStart) + { + capPose.vPrevPos = capPose.vPos; + capPose.vPrevDir = capPose.vDir; + if (bExtraSegPosAtStart) + { + capPose.vPos += capPose.vDir * capPose.fLen * (1f - jointProp.offsetScale); + capPose.vDir *= -1f; + } + + bool result = false; + if (capPose.vDir.magnitude != 0f) + { + Vector3 vDir = capPose.vDir; + capPose.vPos += vDir * capPose.fLen * (1f - jointProp.offsetScale); + } + else + { + capPose.vPos = vecPts[last]; + } + + int num = last + 1; + if (num < vecPts.Count && num >= 0) + { + Vector3 vDir2 = vecPts[num] - capPose.vPos; + float magnitude = vDir2.magnitude; + vDir2.Normalize(); + float length = segProp.length; + capPose.fLen = length; + capPose.vDir = vDir2; + if (magnitude < segProp.length) + { + last = num; + num = last + 1; + if (last == 0 || last == vecPts.Count - 1) + { + capPose.fLen = magnitude; + result = true; + } + } + } + + if (bExtraSegPosAtStart) + { + capPose.vPos += capPose.vDir * capPose.fLen; + capPose.vDir *= -1f; + } + + return result; + } + + private Segment createSegment(float len, Vector3 pos, Vector3 dir) + { + Quaternion q = Utility.createOrientation(dir); + Segment segment = new Segment("segment-" + lstSegments.Count + "__rope__", len, pos + dir * len / 2f, q, + getSegmentProperties(), this); + segment.seg.transform.parent = base.gameObject.transform; + // if ((bool)GameController.Instance) + { + segment.meshRenderer.enabled = true; + // segment.meshRenderer.material = GameController.Instance.waterInteractiveMaterial; + segment.meshRenderer.shadowCastingMode = ShadowCastingMode.Off; + } + // else + // { + // segment.meshRenderer.enabled = false; + // } + if (totalLength <= 105f) + { + // segment.waterInteractive = segment.seg.AddComponent(); + // segment.waterInteractive.Multiplier = 1.5f; + } + + return segment; + } + + private Joint createSegmentJoint(Segment seg1, Segment seg2, Quaternion twistOffset) + { + return new Joint(seg1, seg2, jointProp, getSegmentProperties(), twistOffset); + } + + public void CalculateTotalLength() + { + totalLength = 0f; + totalLengthColliders = 0f; + for (int i = 0; i < lstSegments.Count; i++) + { + totalLengthColliders += + lstSegments[i].seg.transform.localScale.y * lstSegments[i].capsuleCollider.height; + if (i == 0) + { + totalLength += (lstSegments[i].seg.transform.position - controlPoints[0].obj.transform.position) + .magnitude; + } + + if (i == lstSegments.Count - 1) + { + totalLength += (lstSegments[i].seg.transform.position - controlPoints[1].obj.transform.position) + .magnitude; + } + + if (i > 0) + { + totalLength += (lstSegments[i].seg.transform.position - lstSegments[i - 1].seg.transform.position) + .magnitude; + } + } + + + if (ropeStretchThreshold > 0f && totalLength - totalLengthColliders > ropeStretchThreshold) + { + regenerateRope(true); + UnityEngine.Debug.LogError("Rope stretch regenerate"); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/PhysicsTools/Rope.cs.meta b/Assets/Scripts/PhysicsTools/Rope.cs.meta new file mode 100644 index 000000000..2d948fc3e --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Rope.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 8d8b3d7293da4ed8736330164944ddd3 +timeCreated: 1747788125 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/SCapsulePos.cs b/Assets/Scripts/PhysicsTools/SCapsulePos.cs new file mode 100644 index 000000000..b6153e9f1 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SCapsulePos.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace PhysicsTools +{ + internal class SCapsulePos + { + public Vector3 vPos; + + public Vector3 vDir; + + public Vector3 vPrevPos; + + public Vector3 vPrevDir; + + public float fLen; + + public SCapsulePos() + { + vPos = new Vector3(0f, 0f, 0f); + vDir = new Vector3(0f, 0f, 0f); + vPrevPos = new Vector3(0f, 0f, 0f); + vPrevDir = new Vector3(0f, 0f, 0f); + fLen = 0f; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/SCapsulePos.cs.meta b/Assets/Scripts/PhysicsTools/SCapsulePos.cs.meta new file mode 100644 index 000000000..63e36c32b --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SCapsulePos.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 089e242339d5f784baf45339b1f072ed +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/Segment.cs b/Assets/Scripts/PhysicsTools/Segment.cs new file mode 100644 index 000000000..2451ee1c0 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Segment.cs @@ -0,0 +1,57 @@ +using UnityEngine; + +namespace PhysicsTools +{ + public class Segment + { + public GameObject seg; + + public Rigidbody body; + + public Joint prev; + + public Joint next; + + public CapsuleCollider capsuleCollider; + + public MeshFilter meshFilter; + + public MeshRenderer meshRenderer; + + // public WaterInteractive waterInteractive; + + public Segment(string name, float len, Vector3 pos, Quaternion q, SegmentPropertiesBase segProperties, Rope r) + { + SegmentPropertiesCylinder segmentPropertiesCylinder = (SegmentPropertiesCylinder)segProperties; + float radius = segmentPropertiesCylinder.radius; + seg = GameObject.CreatePrimitive(PrimitiveType.Cylinder); + capsuleCollider = seg.GetComponent(); + meshFilter = seg.GetComponent(); + meshRenderer = seg.GetComponent(); + body = seg.AddComponent(); + capsuleCollider.sharedMaterial = r.ropeMaterial; + capsuleCollider.enabled = r.useColliders; + r.lstComponentsCreated.Add(seg); + seg.hideFlags = (r.HideChildren ? HideFlags.HideInHierarchy : HideFlags.None); + meshRenderer.enabled = true; + r.linkMesh.defaultMesh = meshFilter.sharedMesh; + r.linkMesh.defaultMeshMaterial = meshRenderer.sharedMaterial; + r.linkMesh.defaultTransform = Matrix4x4.identity; + if (r.linkMesh.getMesh() != null) + { + meshFilter.sharedMesh = r.linkMesh.getMesh(); + meshRenderer.sharedMaterial = r.linkMesh.meshMaterial; + } + seg.name = name; + seg.transform.localScale = new Vector3(radius * 2f, len / 2f, radius * 2f); + seg.transform.localPosition = pos; + seg.transform.localRotation = q; + body.maxAngularVelocity = 1f; + body.angularDamping = segmentPropertiesCylinder.angularDamping; + body.linearDamping = segmentPropertiesCylinder.linearDamping; + body.mass = segmentPropertiesCylinder.massPerUnitLength * segmentPropertiesCylinder.length; + body.solverIterations = segmentPropertiesCylinder.solverCount; + body.isKinematic = r.kinematic; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/Segment.cs.meta b/Assets/Scripts/PhysicsTools/Segment.cs.meta new file mode 100644 index 000000000..9f128f1e4 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Segment.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b876b665f2164469858aa78787017d4d +timeCreated: 1747788127 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/SegmentProperties.cs b/Assets/Scripts/PhysicsTools/SegmentProperties.cs new file mode 100644 index 000000000..c2661eb68 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentProperties.cs @@ -0,0 +1,39 @@ +using System; + +namespace PhysicsTools +{ + [Serializable] + public class SegmentProperties + { + [Serializable] + public enum Type + { + CYLINDER = 0, + BOX = 1 + } + + public Type type; + + public SegmentPropertiesBase properties; + + public SegmentProperties() + { + properties = new SegmentPropertiesCylinder(); + type = Type.CYLINDER; + } + + public void setType(Type t) + { + switch (t) + { + case Type.BOX: + properties = new SegmentPropertiesBox(); + break; + case Type.CYLINDER: + properties = new SegmentPropertiesCylinder(); + break; + } + type = t; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/SegmentProperties.cs.meta b/Assets/Scripts/PhysicsTools/SegmentProperties.cs.meta new file mode 100644 index 000000000..88f340744 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentProperties.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4bbc2d7df2b1ead41bf1846c6e06b77d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/SegmentPropertiesBase.cs b/Assets/Scripts/PhysicsTools/SegmentPropertiesBase.cs new file mode 100644 index 000000000..621c13a0b --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentPropertiesBase.cs @@ -0,0 +1,27 @@ +using System; + +namespace PhysicsTools +{ + [Serializable] + public class SegmentPropertiesBase + { + public float massPerUnitLength; + + public int solverCount; + + public float length; + + public float linearDamping; + + public float angularDamping; + + public SegmentPropertiesBase() + { + massPerUnitLength = 10f; + solverCount = 255; + length = 1f; + linearDamping = 0.01f; + angularDamping = 0.01f; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/SegmentPropertiesBase.cs.meta b/Assets/Scripts/PhysicsTools/SegmentPropertiesBase.cs.meta new file mode 100644 index 000000000..464c46453 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentPropertiesBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9090fbf5485508f41b83439d2c44e9b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/SegmentPropertiesBox.cs b/Assets/Scripts/PhysicsTools/SegmentPropertiesBox.cs new file mode 100644 index 000000000..1a03d069d --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentPropertiesBox.cs @@ -0,0 +1,19 @@ +using System; + +namespace PhysicsTools +{ + [Serializable] + public class SegmentPropertiesBox : SegmentPropertiesBase + { + public float width; + + public float height; + + public SegmentPropertiesBox() + { + length = 1f; + width = 0.05f; + height = 0.2f; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/SegmentPropertiesBox.cs.meta b/Assets/Scripts/PhysicsTools/SegmentPropertiesBox.cs.meta new file mode 100644 index 000000000..0bab88874 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentPropertiesBox.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dd4b78dfa69ad534c94ee6f13133b5e0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/SegmentPropertiesCylinder.cs b/Assets/Scripts/PhysicsTools/SegmentPropertiesCylinder.cs new file mode 100644 index 000000000..17acf3661 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentPropertiesCylinder.cs @@ -0,0 +1,16 @@ +using System; + +namespace PhysicsTools +{ + [Serializable] + public class SegmentPropertiesCylinder : SegmentPropertiesBase + { + public float radius; + + public SegmentPropertiesCylinder() + { + length = 1f; + radius = 0.1f; + } + } +} diff --git a/Assets/Scripts/PhysicsTools/SegmentPropertiesCylinder.cs.meta b/Assets/Scripts/PhysicsTools/SegmentPropertiesCylinder.cs.meta new file mode 100644 index 000000000..4416a4fe7 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SegmentPropertiesCylinder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c06432f1a93c1694e97f31bf3112ceb0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/SerializedSoftJointLimitSpring.cs b/Assets/Scripts/PhysicsTools/SerializedSoftJointLimitSpring.cs new file mode 100644 index 000000000..634bd0938 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SerializedSoftJointLimitSpring.cs @@ -0,0 +1,38 @@ +using System; +using UnityEngine; + +namespace PhysicsTools +{ + [Serializable] + public class SerializedSoftJointLimitSpring + { + public float spring = 30000f; + + public float damper = 30000f; + + public SerializedSoftJointLimitSpring() + { + spring = 30000f; + damper = 30000f; + } + + private SerializedSoftJointLimitSpring(SoftJointLimitSpring c) + { + damper = c.damper; + spring = c.spring; + } + + public static implicit operator SoftJointLimitSpring(SerializedSoftJointLimitSpring c) + { + SoftJointLimitSpring result = default(SoftJointLimitSpring); + result.spring = c.spring; + result.damper = c.damper; + return result; + } + + public static explicit operator SerializedSoftJointLimitSpring(SoftJointLimitSpring c) + { + return new SerializedSoftJointLimitSpring(c); + } + } +} diff --git a/Assets/Scripts/PhysicsTools/SerializedSoftJointLimitSpring.cs.meta b/Assets/Scripts/PhysicsTools/SerializedSoftJointLimitSpring.cs.meta new file mode 100644 index 000000000..91feae635 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/SerializedSoftJointLimitSpring.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: e9f687b18e562c31f90c28822c0f641d +timeCreated: 1747788125 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/Utility.cs b/Assets/Scripts/PhysicsTools/Utility.cs new file mode 100644 index 000000000..f3d6ad76c --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Utility.cs @@ -0,0 +1,270 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using UnityEngine; + +namespace PhysicsTools +{ + public class Utility + { + public class Calc + { + private float r_length; + + private float h; + + private float d; + + public Calc(float r_, float h_, float d_) + { + r_length = r_; + h = h_; + d = d_; + } + + public float g(float s) + { + return (float)(2.0 * Math.Sinh(s * d / 2f) / s - Math.Sqrt(r_length * r_length - h * h)); + } + + public float dg(float s) + { + return (float)(2.0 * Math.Cosh(s * d / 2f) * d / (2f * s) - 2.0 * Math.Sinh(s * d / 2f) / (s * s)); + } + } + + private const float DEG_2_RAD = 0.017453277f; + + private const float RAD_2_DEG = 57.29583f; + + public static void MatrixToTRS(Matrix4x4 mat, out Vector3 pos, out Quaternion rot, out Vector3 scale) + { + pos = mat.GetColumn(3); + rot = Quaternion.LookRotation(mat.GetColumn(2), mat.GetColumn(1)); + scale = new Vector3(mat.GetColumn(0).magnitude, mat.GetColumn(1).magnitude, mat.GetColumn(2).magnitude); + } + + private static void Swap(ref T lhs, ref T rhs) + { + (lhs, rhs) = (rhs, lhs); + } + + public static List getCatenaryPts(Vector3 vStart, Vector3 vEnd, float r_length, int N) + { + bool flag = false; + int num = 100; + float num2 = 1E-10f; + float num3 = 1E-08f; + float num4 = 0.5f; + float num5 = 1E-09f; + float num6 = 0.001f; + if (vStart.y > vEnd.y) + { + Swap(ref vStart, ref vEnd); + flag = true; + } + Vector3 vector = vEnd - vStart; + float y = vector.y; + vector.y = 0f; + Vector3 vector2 = vector / (N - 1); + float magnitude = vector.magnitude; + vector.Normalize(); + float num7 = ((magnitude == 0f) ? 1f : (1f / magnitude)); + List list = new List(new Vector3[N]); + if (Math.Abs(magnitude) < num6) + { + Vector3 vector3 = new Vector3((vStart.x + vEnd.x) / 2f, 0f, (vStart.z + vEnd.z) / 2f); + if (r_length < Math.Abs(y)) + { + for (int i = 0; i < N; i++) + { + list[i] = vector3 + new Vector3(0f, vStart.y + y * (i * 1f / (N - 1)), 0f); + } + } + else + { + num7 = (r_length - Math.Abs(y)) / 2f; + int num8 = (int)Math.Ceiling(N * num7 / r_length); + float num9 = Math.Max(vStart.y, vEnd.y); + float num10 = Math.Min(vStart.y, vEnd.y); + for (int j = 0; j < N; j++) + { + if (j < N - num8) + { + float num11 = num10 - num7 - num9; + float num12 = num11 * (j * 1f / (N - num8 - 1f)); + list[j] = vector3 + new Vector3(0f, num9 + num12, 0f); + } + else + { + float num13 = num7; + float num14 = num13 * (j * 1f / (num8 - 1f)); + vector3 = (list[j] = vector3 + new Vector3(0f, num10 - num7 + num14, 0f)); + } + } + } + } + else if (r_length <= Math.Sqrt(magnitude * magnitude + y * y)) + { + for (int k = 0; k < N; k++) + { + Vector3 value = vStart + k * vector2; + float num15 = k * (vEnd.y - vStart.y) / (N - 1); + value.y = vStart.y + num15; + list[k] = value; + } + } + else + { + Calc calc = new Calc(r_length, y, magnitude); + for (int l = 0; l < num; l++) + { + float value2 = calc.g(num7); + float value3 = calc.dg(num7); + if (Math.Abs(value2) < num3 || Math.Abs(value3) < num2) + { + break; + } + float num16 = (0f - calc.g(num7)) / calc.dg(num7); + float num17 = 1f; + float num18 = num7 + num17 * num16; + while (num18 < 0f || Math.Abs(calc.g(num18)) > Math.Abs(value2)) + { + num17 = num4 * num17; + if (num17 < num5) + { + break; + } + num18 = num7 + num17 * num16; + } + num7 = num18; + } + float num19 = (float)(0.5 * (Math.Log((r_length + y) / (r_length - y)) / num7 - magnitude)); + vector.y = 0f; + vector.Normalize(); + Vector3 vector5 = vStart - num19 * vector; + vector5.y = 0f; + float num20 = (float)(vStart.y - Math.Cosh(num19 * num7) / num7); + for (int m = 0; m < N; m++) + { + Vector3 vector6 = vStart + m * vector2; + Vector3 vector7 = vector6; + vector6.y = 0f; + vector6.y = (float)(Math.Cosh((vector6 - vector5).magnitude * num7) / num7 + num20); + list[m] = vector6; + } + } + if (flag) + { + list.Reverse(); + } + return list; + } + + public static Quaternion createOrientation(Vector3 v) + { + if (v.x == 0f && v.y == 0f && v.z == 0f) + { + return Quaternion.identity; + } + Vector3 vector = new Vector3(0f, 1f, 0f); + Vector3 vector2 = Vector3.Cross(v, vector); + vector2.Normalize(); + float num = Vector3.Dot(vector, v); + if (num > 1f) + { + num = 1f; + } + else if (num < -1f) + { + num = -1f; + } + float num2 = (float)Math.Acos(num); + return Quaternion.AngleAxis(num2 * 180f / 3.14159f, -vector2); + } + + public static T DeepClone(T a) + { + using (MemoryStream memoryStream = new MemoryStream()) + { + BinaryFormatter binaryFormatter = new BinaryFormatter(); + binaryFormatter.Serialize(memoryStream, a); + memoryStream.Position = 0L; + return (T)binaryFormatter.Deserialize(memoryStream); + } + } + + private static Dictionary> buildMapOfJoints() + { + Dictionary> dictionary = new Dictionary>(); + UnityEngine.Joint[] array = UnityEngine.Object.FindObjectsOfType(); + UnityEngine.Joint[] array2 = array; + foreach (UnityEngine.Joint joint in array2) + { + Rigidbody component = joint.gameObject.GetComponent(); + if (component != null) + { + if (!dictionary.ContainsKey(component)) + { + dictionary.Add(component, new List()); + } + dictionary[component].Add(joint); + } + Rigidbody connectedBody = joint.connectedBody; + if (connectedBody != null) + { + if (!dictionary.ContainsKey(connectedBody)) + { + dictionary.Add(connectedBody, new List()); + } + dictionary[connectedBody].Add(joint); + } + } + return dictionary; + } + + private static void getConnectedBodies(ref Dictionary> dic, Rigidbody body, ref HashSet bodies) + { + bodies.Add(body); + if (!dic.ContainsKey(body)) + { + return; + } + List list = dic[body]; + foreach (UnityEngine.Joint item in list) + { + if (item.connectedBody != null && !bodies.Contains(item.connectedBody)) + { + getConnectedBodies(ref dic, item.connectedBody, ref bodies); + } + Rigidbody component = item.gameObject.GetComponent(); + if (component != null && !bodies.Contains(component)) + { + getConnectedBodies(ref dic, component, ref bodies); + } + } + } + + public static void moveConnectedBodies(Rigidbody start, Matrix4x4 newPose) + { + Dictionary> dic = buildMapOfJoints(); + HashSet bodies = new HashSet(); + getConnectedBodies(ref dic, start, ref bodies); + Matrix4x4 matrix4x = Matrix4x4.TRS(start.transform.position, start.transform.rotation, new Vector3(1f, 1f, 1f)); + foreach (Rigidbody item in bodies) + { + Matrix4x4 matrix4x2 = Matrix4x4.TRS(item.transform.position, item.transform.rotation, new Vector3(1f, 1f, 1f)); + Matrix4x4 inverse = matrix4x.inverse; + matrix4x2 = inverse * matrix4x2; + matrix4x2 = newPose * matrix4x2; + Vector3 pos; + Quaternion rot; + Vector3 scale; + MatrixToTRS(matrix4x2, out pos, out rot, out scale); + item.transform.position = pos; + item.transform.rotation = rot; + } + } + } +} diff --git a/Assets/Scripts/PhysicsTools/Utility.cs.meta b/Assets/Scripts/PhysicsTools/Utility.cs.meta new file mode 100644 index 000000000..17119b852 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Utility.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 93c19397aa18981aebed2e7aba8ca270 +timeCreated: 1747788122 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PhysicsTools/Winch.cs b/Assets/Scripts/PhysicsTools/Winch.cs new file mode 100644 index 000000000..9eefaf374 --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Winch.cs @@ -0,0 +1,107 @@ +using System; +using UnityEngine; + +namespace PhysicsTools +{ + public class Winch : MonoBehaviour + { + public float brakeForce; + + public float heaveTorque; + + public float tensionTorque; + + public float radius; + + public float length; + + public float inertia; + + public float maxRopeLength; + + public float minRopeLength; + + public float rpm; + + public float maxRPM; + + private float omega; + + public Rope rope; + + public Winch() + { + radius = 1f; + length = 1f; + maxRPM = 1f; + omega = 0f; + } + + private void FixedUpdate() + { + float fixedDeltaTime = Time.fixedDeltaTime; + float num = tensionTorqueValue() - heaveTorque; + float num2 = num / inertia; + float num3 = brakeForce * radius / inertia; + float num4 = omega + num2 * fixedDeltaTime; + if ((num2 < 0f && rope.getLength() > minRopeLength) || + (num2 > 0f && num2 > num3 && rope.getLength() < maxRopeLength)) + { + if (num4 > 0f && num4 - num3 * fixedDeltaTime < 0f) + { + num4 = 0f; + } + else if (num4 < 0f && num4 + num3 * fixedDeltaTime > 0f) + { + num4 = 0f; + } + else if (num4 > 0f) + { + num4 -= num3 * fixedDeltaTime; + } + else if (num4 < 0f) + { + num4 += num3 * fixedDeltaTime; + } + + omega = num4; + rope.changeLength(getLinearSpeed() * fixedDeltaTime); + } + else + { + omega = 0f; + } + + rpm = omega / 6.28318f * 60f; + if (Math.Abs(rpm) > maxRPM) + { + if (rpm < 0f) + { + rpm = 0f - maxRPM; + } + else + { + rpm = maxRPM; + } + } + + omega = rpm / 60f * 6.28318f; + } + + private float tensionTorqueValue() + { + tensionTorque = radius * getTension(); + return tensionTorque; + } + + private float getLinearSpeed() + { + return omega * radius; + } + + private float getTension() + { + return rope.getTension(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/PhysicsTools/Winch.cs.meta b/Assets/Scripts/PhysicsTools/Winch.cs.meta new file mode 100644 index 000000000..7e30353ba --- /dev/null +++ b/Assets/Scripts/PhysicsTools/Winch.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: fac89f9401be21c56be128e602bbd1cd +timeCreated: 1747788127 +licenseType: Free +MonoImporter: + serializedVersion: 2 + name: + externalObjects: {} + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/Binders/Binder.cs b/Assets/Scripts/UI/Binders/Binder.cs index b1f7bb041..8029a2c7f 100644 --- a/Assets/Scripts/UI/Binders/Binder.cs +++ b/Assets/Scripts/UI/Binders/Binder.cs @@ -8,6 +8,7 @@ CommonBinder.BindAll(); FishingBinder.BindAll(); MainBinder.BindAll(); + ShopBinder.BindAll(); } } } \ No newline at end of file diff --git a/Assets/Scripts/UI/Binders/ShopBinder.cs b/Assets/Scripts/UI/Binders/ShopBinder.cs new file mode 100644 index 000000000..e76fbeb9a --- /dev/null +++ b/Assets/Scripts/UI/Binders/ShopBinder.cs @@ -0,0 +1,13 @@ +/**注册组件绑定关系。本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/ + +using FairyGUI; + +namespace NBF +{ + public class ShopBinder + { + public static void BindAll() + { + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/UI/Binders/ShopBinder.cs.meta b/Assets/Scripts/UI/Binders/ShopBinder.cs.meta new file mode 100644 index 000000000..35756b57c --- /dev/null +++ b/Assets/Scripts/UI/Binders/ShopBinder.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f579b85674067d740ba424bcc5da406d \ No newline at end of file diff --git a/Assets/Scripts/UI/Fishing/InteractiveTag.cs b/Assets/Scripts/UI/Fishing/InteractiveTag.cs index 1016ef817..39f616c23 100644 --- a/Assets/Scripts/UI/Fishing/InteractiveTag.cs +++ b/Assets/Scripts/UI/Fishing/InteractiveTag.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using UnityEngine; using FairyGUI; +using NBC; namespace NBF { @@ -48,11 +49,14 @@ namespace NBF public void Use1() { if (string.IsNullOrEmpty(_interactiveData.Use1)) return; + Debug.Log(_interactiveData.Use1); + UI.Inst.OpenUI(); } public void Use2() { if (string.IsNullOrEmpty(_interactiveData.Use2)) return; + Debug.Log(_interactiveData.Use2); } } } \ No newline at end of file diff --git a/Assets/Scripts/UI/Shops.meta b/Assets/Scripts/UI/Shops.meta new file mode 100644 index 000000000..2832ed464 --- /dev/null +++ b/Assets/Scripts/UI/Shops.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2bcd18877a1d471b97572c04d7e5e02a +timeCreated: 1747753015 \ No newline at end of file diff --git a/Assets/Scripts/UI/Shops/FishingShop.Designer.cs b/Assets/Scripts/UI/Shops/FishingShop.Designer.cs new file mode 100644 index 000000000..930d313b5 --- /dev/null +++ b/Assets/Scripts/UI/Shops/FishingShop.Designer.cs @@ -0,0 +1,22 @@ +/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/ + +using FairyGUI; +using FairyGUI.Utils; +using NBC; +using System.Collections.Generic; + +namespace NBF +{ + /// + public partial class FishingShop + { + public GObject this[string aKey] => ContentPane.GetChild(aKey); + [AutoFind(Name = "Banner")] + public GLabel Banner; + [AutoFind(Name = "BtnClose")] + public GButton BtnClose; + public override string[] GetDependPackages(){ return new string[] {"Common"}; } + + + } +} \ No newline at end of file diff --git a/Assets/Scripts/UI/Shops/FishingShop.Designer.cs.meta b/Assets/Scripts/UI/Shops/FishingShop.Designer.cs.meta new file mode 100644 index 000000000..f8ee69e5f --- /dev/null +++ b/Assets/Scripts/UI/Shops/FishingShop.Designer.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 77b9a0646693d344b8dd031f4537c3c8 \ No newline at end of file diff --git a/Assets/Scripts/UI/Shops/FishingShop.cs b/Assets/Scripts/UI/Shops/FishingShop.cs new file mode 100644 index 000000000..63a0537a2 --- /dev/null +++ b/Assets/Scripts/UI/Shops/FishingShop.cs @@ -0,0 +1,44 @@ +// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 + +using FairyGUI; +using UnityEngine; +using NBC; +using UIPanel = NBC.UIPanel; + +namespace NBF +{ + public partial class FishingShop : UIPanel + { + public override string UIPackName => "Shop"; + public override string UIResName => "FishingShop"; + + protected override void OnInit() + { + base.OnInit(); + this.AutoAddClick(OnClick); + } + + protected override void OnShow() + { + base.OnShow(); + } + + private void OnClick(GComponent btn) + { + if (btn == BtnClose) + { + Hide(); + } + } + + protected override void OnHide() + { + base.OnHide(); + } + + protected override void OnDestroy() + { + base.OnDestroy(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/UI/Shops/FishingShop.cs.meta b/Assets/Scripts/UI/Shops/FishingShop.cs.meta new file mode 100644 index 000000000..ac9a2fa8d --- /dev/null +++ b/Assets/Scripts/UI/Shops/FishingShop.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b9c7e605b14059445a8598c3cc8d3997 \ No newline at end of file diff --git a/FGUIProject/assets/Common/Com/Buttons/BtnClose.xml b/FGUIProject/assets/Common/Com/Buttons/BtnClose.xml new file mode 100644 index 000000000..96a0326a4 --- /dev/null +++ b/FGUIProject/assets/Common/Com/Buttons/BtnClose.xml @@ -0,0 +1,9 @@ + + + + + + + +