public void EnableBend() { GenerateShaderPropertyIDs(); previousBentType = bendType; previousID = bendID; UpdateShaderdata(); }
void CheckBendChanging() { if (previousBentType != bendType || previousID != bendID) { DisableBend(); previousBentType = bendType; if (bendID < 1) { bendID = 1; } previousID = bendID; GenerateShaderPropertyIDs(); } }
void Update() { if (bendType_Current != projectBendType) { bendType_Current = projectBendType; //Disable all for (int i = 0; i < bendTemplates.Length; i++) { bendTemplates[i].SetActive(false); bendTemplates[i].hideFlags = HideFlags.HideInHierarchy; } //Enable if (projectBendType != BEND_TYPE.Unknown) { bendTemplates[(int)projectBendType].SetActive(true); bendTemplates[(int)projectBendType].hideFlags = HideFlags.None; } } }
static Vector3 TransformPosition(Vector3 vertex, BEND_TYPE bendType, Vector3 pivotPoint, Vector2 bendSize, Vector2 bendOffset) { switch (bendType) { case BEND_TYPE.ClassicRunner_X_Positive: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Max(0.0f, newPoint.x - bendOffset.x); float yOff = Mathf.Max(0.0f, newPoint.x - bendOffset.y); newPoint = new Vector3(0.0f, bendSize.x * xOff * xOff, -bendSize.y * yOff * yOff) * 0.001f; return(vertex + newPoint); } case BEND_TYPE.ClassicRunner_X_Negative: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Min(0.0f, newPoint.x + bendOffset.x); float yOff = Mathf.Min(0.0f, newPoint.x + bendOffset.y); newPoint = new Vector3(0.0f, bendSize.x * xOff * xOff, bendSize.y * yOff * yOff) * 0.001f; return(vertex + newPoint); } case BEND_TYPE.ClassicRunner_Z_Positive: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Max(0.0f, newPoint.z - bendOffset.x); float yOff = Mathf.Max(0.0f, newPoint.z - bendOffset.y); newPoint = new Vector3(bendSize.y * yOff * yOff, bendSize.x * xOff * xOff, 0.0f) * 0.001f; return(vertex + newPoint); } case BEND_TYPE.ClassicRunner_Z_Negative: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Min(0.0f, newPoint.z + bendOffset.x); float yOff = Mathf.Min(0.0f, newPoint.z + bendOffset.y); newPoint = new Vector3(-bendSize.y * yOff * yOff, bendSize.x * xOff * xOff, 0.0f) * 0.001f; return(vertex + newPoint); } default: return(vertex); } }
static Vector3 TransformPosition(Vector3 vertex, BEND_TYPE bendType, Vector3 pivotPoint, Vector3 rotationAxis, Vector3 bendSize, Vector3 bendOffset) { switch (bendType) { case BEND_TYPE.TwistedSpiral_X_Positive: { Vector3 positionWS = vertex; positionWS -= pivotPoint; float d = Mathf.Max(0, positionWS.x - bendOffset.x); d = SmoothTwistedPositive(d, 100); float angle = bendSize.x * d; RotateVertex(ref positionWS, pivotPoint + new Vector3(bendOffset.x, 0, 0), rotationAxis, angle); float yOff = Mathf.Max(0, positionWS.x - bendOffset.y); float zOff = Mathf.Max(0, positionWS.x - bendOffset.z); positionWS += new Vector3(0.0f, bendSize.y * yOff * yOff, -bendSize.z * zOff * zOff) * 0.001f; positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.TwistedSpiral_X_Negative: { Vector3 positionWS = vertex; positionWS -= pivotPoint; float d = Mathf.Min(0, positionWS.x + bendOffset.x); d = SmoothTwistedNegative(d, -100); float angle = bendSize.x * d; RotateVertex(ref positionWS, pivotPoint - new Vector3(bendOffset.x, 0, 0), rotationAxis, angle); float yOff = Mathf.Min(0, positionWS.x + bendOffset.y); float zOff = Mathf.Min(0, positionWS.x + bendOffset.z); positionWS += new Vector3(0.0f, bendSize.y * yOff * yOff, bendSize.z * zOff * zOff) * 0.001f; positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.TwistedSpiral_Z_Positive: { Vector3 positionWS = vertex; positionWS -= pivotPoint; float d = Mathf.Max(0, positionWS.z - bendOffset.x); d = SmoothTwistedPositive(d, 100); float angle = bendSize.x * d; RotateVertex(ref positionWS, pivotPoint + new Vector3(0, 0, bendOffset.x), rotationAxis, angle); float xOff = Mathf.Max(0, positionWS.z - bendOffset.z); float yOff = Mathf.Max(0, positionWS.z - bendOffset.y); positionWS += new Vector3(bendSize.z * xOff * xOff, bendSize.y * yOff * yOff, 0.0f) * 0.001f; positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.TwistedSpiral_Z_Negative: { Vector3 positionWS = vertex; positionWS -= pivotPoint; float d = Mathf.Min(0, positionWS.z + bendOffset.x); d = SmoothTwistedNegative(d, -100); float angle = bendSize.x * d; RotateVertex(ref positionWS, pivotPoint - new Vector3(0, 0, bendOffset.x), rotationAxis, angle); float xOff = Mathf.Min(0, positionWS.z + bendOffset.z); float yOff = Mathf.Min(0, positionWS.z + bendOffset.y); positionWS += new Vector3(-bendSize.z * xOff * xOff, bendSize.y * yOff * yOff, 0.0f) * 0.001f; positionWS += pivotPoint; return(positionWS); } default: return(vertex); } }
static Vector3 TransformPosition(Vector3 vertex, BEND_TYPE bendType, Vector3 pivotPoint, Vector3 rotationCenter, float bendAngle, float bendMinimumRadius, float bendRolloff) { switch (bendType) { case BEND_TYPE.SpiralHorizontalRolloff_X: { if (vertex.x < rotationCenter.x - bendRolloff) { rotationCenter.x -= bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_X_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else if (vertex.x > rotationCenter.x + bendRolloff) { rotationCenter.x += bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_X_Positive, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else { return(vertex); } } case BEND_TYPE.SpiralHorizontalRolloff_Z: { if (vertex.z > rotationCenter.z + bendRolloff) { rotationCenter.z += bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_Z_Positive, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else if (vertex.z < rotationCenter.z - bendRolloff) { rotationCenter.z -= bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_Z_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else { return(vertex); } } case BEND_TYPE.SpiralVerticalRolloff_X: { if (vertex.x < rotationCenter.x - bendRolloff) { rotationCenter.x -= bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_X_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else if (vertex.x > rotationCenter.x + bendRolloff) { rotationCenter.x += bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_X_Positive, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else { return(vertex); } } case BEND_TYPE.SpiralVerticalRolloff_Z: { if (vertex.z > rotationCenter.z + bendRolloff) { rotationCenter.z += bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_Z_Positive, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else if (vertex.z < rotationCenter.z - bendRolloff) { rotationCenter.z -= bendRolloff; return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_Z_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else { return(vertex); } } default: return(vertex); } }
static Vector3 TransformPosition(Vector3 vertex, BEND_TYPE bendType, Vector3 pivotPoint, Vector3 rotationCenter, Vector3 rotationCenter2, float bendAngle, float bendMinimumRadius, float bendAngle2, float bendMinimumRadius2) { switch (bendType) { case BEND_TYPE.SpiralHorizontalDouble_X: { Vector3 positionWS = vertex; if (positionWS.x < pivotPoint.x) { return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_X_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else if (positionWS.x > pivotPoint.x) { return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_X_Positive, pivotPoint, rotationCenter2, bendAngle2, bendMinimumRadius2)); } else { return(vertex); } } case BEND_TYPE.SpiralHorizontalDouble_Z: { Vector3 positionWS = vertex; if (positionWS.z > pivotPoint.z) { return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_Z_Positive, pivotPoint, rotationCenter2, bendAngle2, bendMinimumRadius2)); } else if (positionWS.z < pivotPoint.z) { return(TransformPosition(vertex, BEND_TYPE.SpiralHorizontal_Z_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else { return(vertex); } } case BEND_TYPE.SpiralVerticalDouble_X: { Vector3 positionWS = vertex; if (positionWS.x < pivotPoint.x) { return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_X_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else if (positionWS.x > pivotPoint.x) { return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_X_Positive, pivotPoint, rotationCenter2, bendAngle2, bendMinimumRadius2)); } else { return(vertex); } } case BEND_TYPE.SpiralVerticalDouble_Z: { Vector3 positionWS = vertex; if (positionWS.z > pivotPoint.z) { return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_Z_Positive, pivotPoint, rotationCenter2, bendAngle2, bendMinimumRadius2)); } else if (positionWS.z < pivotPoint.z) { return(TransformPosition(vertex, BEND_TYPE.SpiralVertical_Z_Negative, pivotPoint, rotationCenter, bendAngle, bendMinimumRadius)); } else { return(vertex); } } default: return(vertex); } }
static Vector3 TransformPosition(Vector3 vertex, BEND_TYPE bendType, Vector3 pivotPoint, Vector3 rotationCenter, float bendAngle, float bendMinimumRadius) { switch (bendType) { case BEND_TYPE.SpiralHorizontal_X_Positive: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.x > rotationCenter.x) { rotationCenter.z = Mathf.Abs(rotationCenter.z) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.z) : rotationCenter.z; float radius = rotationCenter.z; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absX = Mathf.Abs(rotationCenter.x - positionWS.x) / l; float smoothAbsX = Smooth(absX); Spiral_H_Rotate_X_Negative(ref positionWS, rotationCenter, absX, smoothAbsX, l, angle); } positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.SpiralHorizontal_X_Negative: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.x < rotationCenter.x) { rotationCenter.z = Mathf.Abs(rotationCenter.z) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.z) : rotationCenter.z; float radius = rotationCenter.z; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absX = Mathf.Abs(rotationCenter.x - positionWS.x) / l; float smoothAbsX = Smooth(absX); Spiral_H_Rotate_X_Positive(ref positionWS, rotationCenter, absX, smoothAbsX, l, angle); } positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.SpiralHorizontal_Z_Positive: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.z > rotationCenter.z) { rotationCenter.x = Mathf.Abs(rotationCenter.x) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.x) : rotationCenter.x; float radius = rotationCenter.x; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absZ = Mathf.Abs(rotationCenter.z - positionWS.z) / l; float smoothAbsZ = Smooth(absZ); Spiral_H_Rotate_Z_Positive(ref positionWS, rotationCenter, absZ, smoothAbsZ, l, angle); } positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.SpiralHorizontal_Z_Negative: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.z < rotationCenter.z) { rotationCenter.x = Mathf.Abs(rotationCenter.x) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.x) : rotationCenter.x; float radius = rotationCenter.x; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absZ = Mathf.Abs(rotationCenter.z - positionWS.z) / l; float smoothAbsZ = Smooth(absZ); Spiral_H_Rotate_Z_Negative(ref positionWS, rotationCenter, absZ, smoothAbsZ, l, angle); } positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.SpiralVertical_X_Positive: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.x > rotationCenter.x) { rotationCenter.y = Mathf.Abs(rotationCenter.y) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.y) : rotationCenter.y; float radius = rotationCenter.y; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absX = Mathf.Abs(rotationCenter.x - positionWS.x) / l; float smoothAbsX = Smooth(absX); Spiral_V_Rotate_X_Negative(ref positionWS, rotationCenter, absX, smoothAbsX, l, angle); } positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.SpiralVertical_X_Negative: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.x < rotationCenter.x) { rotationCenter.y = Mathf.Abs(rotationCenter.y) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.y) : rotationCenter.y; float radius = rotationCenter.y; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absX = Mathf.Abs(rotationCenter.x - positionWS.x) / l; float smoothAbsX = Smooth(absX); Spiral_V_Rotate_X_Positive(ref positionWS, rotationCenter, absX, smoothAbsX, l, angle); } positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.SpiralVertical_Z_Positive: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.z > rotationCenter.z) { rotationCenter.y = Mathf.Abs(rotationCenter.y) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.y) : rotationCenter.y; float radius = rotationCenter.y; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absZ = Mathf.Abs(rotationCenter.z - positionWS.z) / l; float smoothAbsZ = Smooth(absZ); Spiral_V_Rotate_Z_Positive(ref positionWS, rotationCenter, absZ, smoothAbsZ, l, angle); } positionWS += pivotPoint; return(positionWS); } case BEND_TYPE.SpiralVertical_Z_Negative: { Vector3 positionWS = vertex; positionWS -= pivotPoint; rotationCenter -= pivotPoint; if (positionWS.z < rotationCenter.z) { rotationCenter.y = Mathf.Abs(rotationCenter.y) < bendMinimumRadius?bendMinimumRadius *Sign(rotationCenter.y) : rotationCenter.y; float radius = rotationCenter.y; float angle = bendAngle * Sign(radius); float l = 6.28318530717f * radius * (angle / 360); float absZ = Mathf.Abs(rotationCenter.z - positionWS.z) / l; float smoothAbsZ = Smooth(absZ); Spiral_V_Rotate_Z_Negative(ref positionWS, rotationCenter, absZ, smoothAbsZ, l, angle); } positionWS += pivotPoint; return(positionWS); } default: return(vertex); } }
static Vector3 TransformPosition(Vector3 vertex, BEND_TYPE bendType, Vector3 pivotPoint, float bendSize, float bendOffset) { switch (bendType) { case BEND_TYPE.LittlePlanet_X: { Vector3 newPoint = vertex - pivotPoint; float yOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.y) - (bendOffset < 0 ? 0 : bendOffset)) * (newPoint.y < 0.0f ? -1.0f : 1.0f); float zOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.z) - (bendOffset < 0 ? 0 : bendOffset)) * (newPoint.z < 0.0f ? -1.0f : 1.0f); newPoint = new Vector3(-(bendSize * yOff * yOff + bendSize * zOff * zOff) * 0.001f, 0.0f, 0.0f); return(vertex + newPoint); } case BEND_TYPE.LittlePlanet_Y: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.x) - (bendOffset < 0 ? 0 : bendOffset)) * (newPoint.x < 0.0f ? -1.0f : 1.0f); float zOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.z) - (bendOffset < 0 ? 0 : bendOffset)) * (newPoint.z < 0.0f ? -1.0f : 1.0f); newPoint = new Vector3(0.0f, -(bendSize * zOff * zOff + bendSize * xOff * xOff) * 0.001f, 0.0f); return(vertex + newPoint); } case BEND_TYPE.LittlePlanet_Z: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.x) - (bendOffset < 0 ? 0 : bendOffset)) * (newPoint.x < 0.0f ? -1.0f : 1.0f); float yOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.y) - (bendOffset < 0 ? 0 : bendOffset)) * (newPoint.y < 0.0f ? -1.0f : 1.0f); newPoint = new Vector3(0.0f, 0.0f, -(bendSize * xOff * xOff + bendSize * yOff * yOff) * 0.001f); return(vertex + newPoint); } case BEND_TYPE.CylindricalTower_X: { Vector3 newPoint = vertex - pivotPoint; float zOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.x) - bendOffset) * (newPoint.x < 0.0f ? -1.0f : 1.0f); newPoint = new Vector3(0.0f, 0.0f, bendSize * zOff * zOff * 0.001f); return(vertex + newPoint); } case BEND_TYPE.CylindricalTower_Z: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.z) - bendOffset) * (newPoint.z < 0.0f ? -1.0f : 1.0f); newPoint = new Vector3(bendSize * xOff * xOff * 0.001f, 0.0f, 0.0f); return(vertex + newPoint); } case BEND_TYPE.CylindricalRolloff_X: { Vector3 newPoint = vertex - pivotPoint; float yOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.x) - bendOffset) * (newPoint.x < 0.0f ? -1.0f : 1.0f); newPoint = new Vector3(0.0f, -bendSize * yOff * yOff * 0.001f, 0.0f); return(vertex + newPoint); } case BEND_TYPE.CylindricalRolloff_Z: { Vector3 newPoint = vertex - pivotPoint; float xOff = Mathf.Max(0.0f, Mathf.Abs(newPoint.z) - bendOffset) * (newPoint.z < 0.0f ? -1.0f : 1.0f); newPoint = new Vector3(0.0f, -bendSize * xOff * xOff * 0.001f, 0.0f); return(vertex + newPoint); } default: return(vertex); } }