오류 CS0433 'Task' 형식이 'Unity.Tasks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' 및 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'에 모두 있습니다.
[해결방법]
/Parse/Plugins 아래에서 안쓰는 버전의 Unity.Compat, Unity.Tasks 제거
(.NET 4.x 버전을 쓰고 있어서 .NET 3.5 버전 Unity.Compat, Unity.Tasks 제거함)
Unity 2020.3.21f1에서 Unity 2020.3.22f1으로 업데이트 하고나니 Android는 문제없는데, iOS에서 기존에 발생하지 않던 쉐이더 문제가 생겼다.
[증상] 기존에 검은 느낌이던 텍스쳐가 약간 회색빛이 나옴
그래서 Unity 2020.3.21f1으로 내리니 다시 정상동작 하는걸 확인했다.
링크 내용을 보니 iOS Dark Mode 관련 버그라고 한다.
현재 임시로 해결하는 방법은 iOS Info.plist에서 강제로 Dark Mode로 셋팅 하는 방법이 있다고 한다.
버그가 수정될 때까지 Dark Mode로 셋팅하거나, Unity 2020.3.21f1 이하 버전을 사용해야 될 것 같다.
[Unity 소스상에서 Info.plist 수정]
var projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
var plistPath = System.IO.Path.Combine(pathToBuiltProject, "Info.plist");
var plist = new PlistDocument();
plist.ReadFromFile(plistPath);
// [iOS15+Unity2020.3.22f1 이슈] Force Dark Mode(Automatic/Light/Dark) - Appearance
plist.root.SetString("UIUserInterfaceStyle", "Dark");
We may decide to execute a function not right now, but at a certain time later. That’s called “scheduling a call”. The Timers class helps you to do so with a clean and short syntax without having to worry about enumerators.
Install the latest stable release using the Unity Package Manager by adding the following line to yourmanifest.jsonfile located within your project's Packages directory, or by adding the Git URL to the Package Manager Window inside of Unity.
The module is availble on the OpenUPM package registry, you can install the latest stable release using the OpenUPM Package manager's Command Line Tool using the following command.
We may decide to execute a function not right now, but at a certain time later. That’s called “scheduling a call”. Note that the timers are using unscaled time.
There are two methods for it:
setTimeout allows to run a function once after the interval of time.
setInterval allows to run a function regularly with the interval between the runs.
Examples
public class MyClass {
private void Awake () {
Timers.SetTimeout(1000, () => {
Debug.Log("A second has passed!");
});
Timers.SetTimeout(1000, Notifiy);
Timers.SetInterval(2500, Notifiy);
}
private void Notify () {
Debug.Log("Notify!!");
}
}
This asset is a means to create bezier splines in editor and/or during runtime: splines can be created and edited visually in the editor, or by code during runtime. It is built uponCatlike Coding's spline tutorial:https://catlikecoding.com/unity/tutorials/curves-and-splines/
To create a new spline in the editor, clickGameObject - Bezier Spline.
Now you can select the end points of the spline in the Scene view and translate/rotate/scale or delete/duplicate them as you wish (each end point has 2 control points, which can also be translated):
The user interface for the spline editor should be pretty self-explanatory with most variables having explanatory tooltips.
WhenQuick Edit Modeis enabled, new points can quickly be added/inserted to the spline and the existing points can be dragged around/snapped to the scene geometry.
To reverse the order of the end points in a spline, you can right click the BezierSpline component and click theInvert Splinebutton.
You can tweak the Scene view gizmos viaProject Settings/yasirkula/Bezier Solutionpage (on older versions, this menu is located atPreferenceswindow).
CREATING & EDITING A NEW SPLINE BY CODE
Create a new bezier spline
Simply create a new GameObject, attach a BezierSpline component to it (BezierSpline usesBezierSolutionnamespace) and initialize the spline with a minimum of two end points:
BezierSpline spline = new GameObject().AddComponent<BezierSpline>(); spline.Initialize( 2 );
Populate the spline
BezierPoint InsertNewPointAt( int index ): adds a new end point to the spline and returns it
BezierPoint DuplicatePointAt( int index ): duplicates an existing end point and returns it
void RemovePointAt( int index ): removes an end point from the spline
void SwapPointsAt( int index1, int index2 ): swaps indices of two end points
void ChangePointIndex( int previousIndex, int newIndex ): changes an end point's index
Shape the spline
You can change the position, rotation, scale and normal values of the end points, as well as the positions of their control points to reshape the spline.
End points have the following properties to store their transformational data:position,localPosition,rotation,localRotation,eulerAngles,localEulerAngles,localScale,normalandautoCalculatedNormalAngleOffset.
Positions of control points can be tweaked using the following properties in BezierPoint:precedingControlPointPosition,precedingControlPointLocalPosition,followingControlPointPositionandfollowingControlPointLocalPosition. The local positions are relative to their corresponding end points.
End points also have read-onlysplineandindexproperties.
// Set first end point's (world) position to 2,3,5 spline[0].position = new Vector3( 2, 3, 5 ); // Set second end point's local position to 7,11,13 spline[1].localPosition = new Vector3( 7, 11, 13 ); // Set handle mode of first end point to Free to independently adjust each control point spline[0].handleMode = BezierPoint.HandleMode.Free; // Reposition the control points of the first end point spline[0].precedingControlPointLocalPosition = new Vector3( 0, 0, 1 ); spline[0].followingControlPointPosition = spline[1].position;
Auto construct the spline
If you don't want to position all the control points manually, but rather generate a nice-looking "continuous" spline that goes through the end points you have created, you can call eitherAutoConstructSpline()orAutoConstructSpline2(). These methods are implementations of some algorithms found on the internet (and credited in the source code). If you want these functions to be called automatically when spline's end points are modified, simply change the spline'sautoConstructModeproperty.
Convert spline to a linear path
If you want to create a linear path between the end points of the spline, you can call theConstructLinearPath()function. Or, if you want this function to be called automatically when spline's end points are modified, simply set the spline'sautoConstructModeproperty toSplineAutoConstructMode.Linear.
Auto calculate the normals
If you want to calculate the spline's normal vectors automatically, you can call theAutoCalculateNormals( float normalAngle = 0f, int smoothness = 10 )function (or, to call this function automatically when spline's end points are modified, simply change the spline'sautoCalculateNormalsandautoCalculatedNormalsAngleproperties). All resulting normal vectors will be rotated around their Z axis by "normalAngle" degrees. Additionally, each end point's normal vector will be rotated by that end point's "autoCalculatedNormalAngleOffset" degrees. "smoothness" determines how many intermediate steps are taken between each consecutive end point to calculate those end points' normal vectors. More intermediate steps is better but also slower to calculate.
If auto calculated normals don't look quite right despite modifying the "normalAngle" (Auto Calculated Normals Anglein the Inspector) and "autoCalculatedNormalAngleOffset" (Normal Anglein the Inspector) variables, you can either consider inserting new end points to the sections of the spline that normals don't behave correctly, or setting the normals manually.
Get notified when spline is modified
You can register to the spline'sonSplineChangedevent to get notified when some of its properties have changed. This event has the following signature:delegate void SplineChangeDelegate( BezierSpline spline, DirtyFlags dirtyFlags ).DirtyFlagsis an enum flag, meaning that it can have one or more of these values:SplineShapeChanged,NormalsChangedand/orExtraDataChanged.SplineShapeChangedflag means that either the spline's Transform values have changed or some of its end points' Transform values have changed (changing control points may also trigger this flag).NormalsChangedflag means that normals of some of the end points have changed andExtraDataChangedflag means that extraDatas of some of the end points have changed.
BezierSpline also has aversionproperty which is automatically increased whenever the spline's properties change.
NOTE:onSplineChanged event is usually invoked inLateUpdate. Before it is invoked,autoConstructModeandautoCalculateNormalsproperties' values are checked and the relevant auto construction/calculation functions are executed if necessary.
UTILITY FUNCTIONS
The framework comes with some utility functions. These functions are not necessarily perfect but most of the time, they get the job done. Though, if you want, you can use this framework to just create splines and then apply your own logic to them.
Vector3 GetPoint( float normalizedT )
A spline is essentially a mathematical formula with a [0,1] clamped input (usually calledt), which generates a point on the spline. As the name suggests, this function returns a point on the spline. Astgoes from 0 to 1, the point moves from the first end point to the last end point (or goes back to first end point, if spline is looping).
Vector3 GetTangent( float normalizedT )
Tangent is calculated using the first derivative of the spline formula and gives the direction of the movement at a given point on the spline. Can be used to determine which direction an object on the spline should look at at a given point.
Vector3 GetNormal( float normalizedT )
Interpolates between the end points' normal vectors. Note that this plugin doesn't store any intermediate data between end point pairs, so if two consecutive end points have almost the opposite tangents, then their interpolated normal vector may not be correct at some parts of the spline. Inserting a new end point between these two end points could resolve this issue. By default, all normal vectors have value (0,1,0).
Interpolates between the extra data provided at each end point. This data has 4 float components and can implicitly be converted to Vector2, Vector3, Vector4, Quaternion, Rect, Vector2Int, Vector3Int and RectInt.
Uses a custom function to interpolate between the end points' extra data. For example, BezierWalker components use this function to interpolate the extra data with Quaternion.Lerp.
Calculates the approximate length of a segment of the spline. To calculate the length, the spline is divided into "accuracy" points and the Euclidean distances between these points are summed up.
Food For Thought: BezierSpline has alengthproperty which is a shorthand forGetLengthApproximately( 0f, 1f ). Its value is cached and won't be recalculated unless the spline is modified.
Segment GetSegmentAt( float normalizedT )
Returns the two end points that are closest tonormalizedT. TheSegmentstruct also holds alocalTvalue in range [0,1], which can be used to interpolate between the properties of these two end points. You can also call theGetPoint(),GetTangent(),GetNormal()andGetExtraData()functions of this struct and the returned values will be calculated as if the spline consisted of only these two end points.
Vector3 FindNearestPointTo( Vector3 worldPos, out float normalizedT, float accuracy = 100f, int secondPassIterations = 7, float secondPassExtents = 0.025f )
Finds the nearest point on the spline to any given point in 3D space. The normalizedT parameter is optional and it returns the parametertcorresponding to the resulting point. To find the nearest point, the spline is divided into "accuracy" points and the nearest point is selected. Then, a binary search is performed in "secondPassIterations" steps in range[normalizedT-secondPassExtents, normalizedT+secondPassExtents]to fine-tune the result.
Vector3 FindNearestPointToLine( Vector3 lineStart, Vector3 lineEnd, out Vector3 pointOnLine, out float normalizedT, float accuracy = 100f, int secondPassIterations = 7, float secondPassExtents = 0.025f )
Finds the nearest point on the spline to the given line in 3D space. The pointOnLine and normalizedT parameters are optional.
Moves a point (normalizedT) on the spline deltaMovement units ahead and returns the resulting point. The normalizedT parameter is passed by reference to keep track of the newtparameter.
Finds uniformly distributed points along the spline and returns a lookup table. The lookup table isn't refreshed automatically, so it may be invalidated when the spline is modified. This function'sresolutionparameter determines approximately how many points will be calculated per each segment of the spline and accuracy determines how accurate the uniform spacing will be. The default values should work well in most cases.
Food For Thought: BezierSpline has anevenlySpacedPointsproperty which is a shorthand forCalculateEvenlySpacedPoints(). Its value is cached and won't be recalculated unless the spline is modified.
EvenlySpacedPointsHolderclass hasspline,splineLengthanduniformNormalizedTsvariables. In addition, it has the following convenience functions:
GetNormalizedTAtPercentage:converts a percentage to normalizedT value, i.e. if you enter 0.5f as parameter, it will return the normalizedT value of the spline that corresponds to its actual middle point.
GetNormalizedTAtDistance:finds the normalizedT value that is specified units away from the spline's starting point.
Returns a cache of data for uniformly distributed points along the spline. The cache isn't refreshed automatically, so it may be invalidated when the spline is modified. This function'sresolutionparameter determines how many uniformly distributed points the cache will have. To determine which data should be cached,cachedDataparameter is used.PointCacheFlagsis an enum flag, meaning that it can have one or more of these values:Positions,Normals,Tangents,Bitangentsand/orExtraDatas.lookupTableis an optional parameter and, by default, spline'sevenlySpacedPointsis used.extraDataLerpFunctionis also an optional parameter and is used only when PointCacheFlags.ExtraDatas is included in cachedData.
Food For Thought: BezierSpline has apointCacheproperty which is a shorthand forGeneratePointCache(). Its value is cached and won't be recalculated unless the spline is modified.
PointCacheclass haspositions,normals,tangents,bitangents,extraDatasandloopvariables (loop determines whether or not the spline had itsloopproperty set to true while calculating the cache). In addition, it has the following functions:GetPoint,GetNormal,GetTangent,GetBitangentandGetExtraData(if the required data for a function wasn't included in PointCacheFlags, then the function will throw an exception). If a spline is rarely modified at runtime, then point cache can be used to get points, tangents, normals, etc. along the spline in a cheaper and uniform way.
OTHER COMPONENTS
The plugin comes with some additional components that may help you move objects or particles along splines. These components are located in the Utilities folder.
BezierWalkerWithSpeed
Moves an object along a spline with constant speed. There are 3 travel modes: Once, Ping Pong and Loop. IfLook Atis Forward, the object will always face forwards (end points' normal vectors will be used as up vectors). If it is SplineExtraData, the extra data stored in the spline's end points is used to determine the rotation. You can modify this extra data from the points' Inspector. The smoothness of the rotation can be adjusted viaRotation Lerp Modifier.Normalized Tdetermines the starting point. Each time the object completes a lap, itsOn Path Completed ()event is invoked. To see this component in action without entering Play mode, click theSimulate In Editorbutton.
BezierWalkerWithTime
Travels a spline inTravel Timeseconds.Movement Lerp Modifierparameter defines the smoothness applied to the position of the object. IfHigh Qualityis enabled, the spline will be traversed with constant speed but the calculations can be more expensive.
BezierWalkerLocomotion
Allows you to move a number of objects together with this object on a spline. This component must be attached to an object with a BezierWalker component (tail objects don't need a BezierWalker, though).Look At,Movement Lerp ModifierandRotation Lerp Modifierparameters affect the tail objects. If tail objects jitter too much, enablingHigh Qualitymay help greatly but the calculations can be more expensive.
ParticlesFollowBezier
Moves particles of a Particle System in the direction of a spline. It is recommended to set theSimulation Spaceof the Particle System toLocalfor increased performance. This component affects particles in one of two ways:
Strict:particles will strictly follow the spline. They will always be aligned to the spline and will reach the end of the spline at the end of their lifetime. This mode performs slightly better than Relaxed mode
Relaxed:properties of the particle system like speed, Noise and Shape will affect the movement of the particles. Particles in this mode will usually look more interesting. If you want the particles to stick with the spline, though, set their speed to 0
Note that if theResimulatetick of the Particle System is selected, particles may move in a chaotic way for a short time while changing the properties of the particle system from the Inspector.
BezierAttachment
Snaps an object to the specified point of the spline. You can snap the object's position and/or rotation values, optionally with some offsets. Rotation can be snapped in one of two ways:
Use Spline Normals:spline's normal vectors will be used to determine the object's rotation
Use End Point Rotations:the Transform rotation values of the spline's end points will be used to determine the object's rotation
BezierLineRenderer
Automatically positions a Line Renderer's points so that its shape matches the target spline's shape. It is possible to match the shape of only a portion of the spline by tweaking theSpline Sample Rangeproperty. If Line Renderer'sUse World Spaceproperty is enabled, then its points will be placed at the spline's current position. Otherwise, the points will be placed relative to the Line Renderer's position and they will rotate/scale with the Line Renderer.
BendMeshAlongBezier
Modifies a MeshFilter's mesh to bend it in the direction of a spline. IfHigh Qualityis enabled, evenly spaced bezier points will be used so that the mesh bends uniformly but the calculations will be more expensive. IfAuto Refreshis enabled, the mesh will be refreshed automatically when the spline is modified (at runtime, this has the same effect with disabling the component but in edit mode, disabling the component will restore the original mesh instead). Mesh's normal and tangent vectors can optionally be recalculated in one of two ways:
Modify Originals:the original mesh's normal and tangent vectors will be rotated with the spline
Recalculate From Scratch:Unity'sRecalculateNormalsand/orRecalculateTangentsfunctions will be invoked to recalculate these vectors from scratch
Note that this component doesn't add new vertices to the original mesh, so if the original mesh doesn't have enough vertices in its bend axis, then the bent mesh will have jagged edges on complex splines.