Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity生成播放器时出错,因为脚本有编译器错误_C#_Unity3d_Build_Compiler Errors_Scripting - Fatal编程技术网

C# Unity生成播放器时出错,因为脚本有编译器错误

C# Unity生成播放器时出错,因为脚本有编译器错误,c#,unity3d,build,compiler-errors,scripting,C#,Unity3d,Build,Compiler Errors,Scripting,我知道这是一个众所周知的问题。但我不知道该怎么办。 (在新选项卡中打开图像以提高清晰度) 该脚本FastIKFabric.cs工作正常(而且它来自资产存储),正如您在inspector中看到的,它没有任何使用UnityEdit的。第250行是该脚本的最后一行,}已正确关闭。正如我所说,脚本没有任何错误 我能做什么?提前感谢您的回答!:) 以下是脚本: #if UNITY_EDITOR #endif using UnityEngine; namespace DitzelGames.FastIK

我知道这是一个众所周知的问题。但我不知道该怎么办。

(在新选项卡中打开图像以提高清晰度)

该脚本FastIKFabric.cs工作正常(而且它来自资产存储),正如您在inspector中看到的,它没有任何使用UnityEdit的
。第250行是该脚本的最后一行,
}
已正确关闭。正如我所说,脚本没有任何错误

我能做什么?提前感谢您的回答!:)

以下是脚本:

#if UNITY_EDITOR
#endif
using UnityEngine;

namespace DitzelGames.FastIK
{
    /// <summary>
    /// Fabrik IK Solver
    /// </summary>
    public class FastIKFabric : MonoBehaviour
    {
        /// <summary>
        /// Chain length of bones
        /// </summary>
        public int ChainLength = 2;

        /// <summary>
        /// Target the chain should bent to
        /// </summary>
        public Transform Target;
        public Transform Pole;

        /// <summary>
        /// Solver iterations per update
        /// </summary>
        [Header("Solver Parameters")]
        public int Iterations = 10;

        /// <summary>
        /// Distance when the solver stops
        /// </summary>
        public float Delta = 0.001f;

        /// <summary>
        /// Strength of going back to the start position.
        /// </summary>
        [Range(0, 1)]
        public float SnapBackStrength = 1f;


        protected float[] BonesLength; //Target to Origin
        protected float CompleteLength;
        protected Transform[] Bones;
        protected Vector3[] Positions;
        protected Vector3[] StartDirectionSucc;
        protected Quaternion[] StartRotationBone;
        protected Quaternion StartRotationTarget;
        protected Transform Root;


        // Start is called before the first frame update
        void Awake()
        {
            Init();
        }

        void Init()
        {
            //initial array
            Bones = new Transform[ChainLength + 1];
            Positions = new Vector3[ChainLength + 1];
            BonesLength = new float[ChainLength];
            StartDirectionSucc = new Vector3[ChainLength + 1];
            StartRotationBone = new Quaternion[ChainLength + 1];

            //find root
            Root = transform;
            for (var i = 0; i <= ChainLength; i++)
            {
                if (Root == null)
                    throw new UnityException("The chain value is longer than the ancestor chain!");
                Root = Root.parent;
            }

            //init target
            if (Target == null)
            {
                Target = new GameObject(gameObject.name + " Target").transform;
                SetPositionRootSpace(Target, GetPositionRootSpace(transform));
            }
            StartRotationTarget = GetRotationRootSpace(Target);


            //init data
            var current = transform;
            CompleteLength = 0;
            for (var i = Bones.Length - 1; i >= 0; i--)
            {
                Bones[i] = current;
                StartRotationBone[i] = GetRotationRootSpace(current);

                if (i == Bones.Length - 1)
                {
                    //leaf
                    StartDirectionSucc[i] = GetPositionRootSpace(Target) - GetPositionRootSpace(current);
                }
                else
                {
                    //mid bone
                    StartDirectionSucc[i] = GetPositionRootSpace(Bones[i + 1]) - GetPositionRootSpace(current);
                    BonesLength[i] = StartDirectionSucc[i].magnitude;
                    CompleteLength += BonesLength[i];
                }

                current = current.parent;
            }



        }

        // Update is called once per frame
        void LateUpdate()
        {
            ResolveIK();
        }

        private void ResolveIK()
        {
            if (Target == null)
                return;

            if (BonesLength.Length != ChainLength)
                Init();

            //Fabric

            //  root
            //  (bone0) (bonelen 0) (bone1) (bonelen 1) (bone2)...
            //   x--------------------x--------------------x---...

            //get position
            for (int i = 0; i < Bones.Length; i++)
                Positions[i] = GetPositionRootSpace(Bones[i]);

            var targetPosition = GetPositionRootSpace(Target);
            var targetRotation = GetRotationRootSpace(Target);

            //1st is possible to reach?
            if ((targetPosition - GetPositionRootSpace(Bones[0])).sqrMagnitude >= CompleteLength * CompleteLength)
            {
                //just strech it
                var direction = (targetPosition - Positions[0]).normalized;
                //set everything after root
                for (int i = 1; i < Positions.Length; i++)
                    Positions[i] = Positions[i - 1] + direction * BonesLength[i - 1];
            }
            else
            {
                for (int i = 0; i < Positions.Length - 1; i++)
                    Positions[i + 1] = Vector3.Lerp(Positions[i + 1], Positions[i] + StartDirectionSucc[i], SnapBackStrength);

                for (int iteration = 0; iteration < Iterations; iteration++)
                {
                    //https://www.youtube.com/watch?v=UNoX65PRehA
                    //back
                    for (int i = Positions.Length - 1; i > 0; i--)
                    {
                        if (i == Positions.Length - 1)
                            Positions[i] = targetPosition; //set it to target
                        else
                            Positions[i] = Positions[i + 1] + (Positions[i] - Positions[i + 1]).normalized * BonesLength[i]; //set in line on distance
                    }

                    //forward
                    for (int i = 1; i < Positions.Length; i++)
                        Positions[i] = Positions[i - 1] + (Positions[i] - Positions[i - 1]).normalized * BonesLength[i - 1];

                    //close enough?
                    if ((Positions[Positions.Length - 1] - targetPosition).sqrMagnitude < Delta * Delta)
                        break;
                }
            }

            //move towards pole
            if (Pole != null)
            {
                var polePosition = GetPositionRootSpace(Pole);
                for (int i = 1; i < Positions.Length - 1; i++)
                {
                    var plane = new Plane(Positions[i + 1] - Positions[i - 1], Positions[i - 1]);
                    var projectedPole = plane.ClosestPointOnPlane(polePosition);
                    var projectedBone = plane.ClosestPointOnPlane(Positions[i]);
                    var angle = Vector3.SignedAngle(projectedBone - Positions[i - 1], projectedPole - Positions[i - 1], plane.normal);
                    Positions[i] = Quaternion.AngleAxis(angle, plane.normal) * (Positions[i] - Positions[i - 1]) + Positions[i - 1];
                }
            }

            //set position & rotation
            for (int i = 0; i < Positions.Length; i++)
            {
                if (i == Positions.Length - 1)
                    SetRotationRootSpace(Bones[i], Quaternion.Inverse(targetRotation) * StartRotationTarget * Quaternion.Inverse(StartRotationBone[i]));
                else
                    SetRotationRootSpace(Bones[i], Quaternion.FromToRotation(StartDirectionSucc[i], Positions[i + 1] - Positions[i]) * Quaternion.Inverse(StartRotationBone[i]));
                SetPositionRootSpace(Bones[i], Positions[i]);
            }
        }

        private Vector3 GetPositionRootSpace(Transform current)
        {
            if (Root == null)
                return current.position;
            else
                return Quaternion.Inverse(Root.rotation) * (current.position - Root.position);
        }

        private void SetPositionRootSpace(Transform current, Vector3 position)
        {
            if (Root == null)
                current.position = position;
            else
                current.position = Root.rotation * position + Root.position;
        }

        private Quaternion GetRotationRootSpace(Transform current)
        {
            //inverse(after) * before => rot: before -> after
            if (Root == null)
                return current.rotation;
            else
                return Quaternion.Inverse(current.rotation) * Root.rotation;
        }

        private void SetRotationRootSpace(Transform current, Quaternion rotation)
        {
            if (Root == null)
                current.rotation = rotation;
            else
                current.rotation = Root.rotation * rotation;
        }

        void OnDrawGizmos()
        {
#if UNITY_EDITOR
            var current = this.transform;
            for (int i = 0; i < ChainLength && current != null && current.parent != null; i++)
            {
                var scale = Vector3.Distance(current.position, current.parent.position) * 0.1f;
                //Handles.matrix = Matrix4x4.TRS(current.position, Quaternion.FromToRotation(Vector3.up, current.parent.position - current.position), new Vector3(scale, Vector3.Distance(current.parent.position, current.position), scale));
                //Handles.color = Color.green;
                //Handles.DrawWireCube(Vector3.up * 0.5f, Vector3.one);
                current = current.parent;
            }
        }
#endif

    }
}
\if UNITY\u编辑器
#恩迪夫
使用UnityEngine;
命名空间DitzelGames.FastIK
{
/// 
///法布里克IK解算器
/// 
公共类禁食面料:单一行为
{
/// 
///骨链长度
/// 
公共整数链长=2;
/// 
///链条应弯曲到目标位置
/// 
公共转型目标;
公共转换极;
/// 
///每次更新的解算器迭代次数
/// 
[标题(“解算器参数”)]
公共整数迭代次数=10;
/// 
///解算器停止时的距离
/// 
公共浮点数δ=0.001f;
/// 
///回到起始位置的力量。
/// 
[范围(0,1)]
公共浮力=1f;
受保护的浮点[]BonesLength;//目标到原点
保护浮子完整长度;
保护骨骼;
受保护向量3[]个位置;
受保护向量3[]开始方向UCC;
受保护的四元数[]StartRotationBone;
受保护的四元数StartRotationTarget;
保护变换根;
//在第一帧更新之前调用Start
无效唤醒()
{
Init();
}
void Init()
{
//初始数组
骨骼=新变换[链长+1];
位置=新矢量3[链长+1];
BonesLength=新浮动[链长];
StartDirectionSucc=新矢量3[链长+1];
StartRotationBone=新的四元数[链长+1];
//寻根
根=变换;
对于(变量i=0;i=0;i--)
{
骨[i]=电流;
StartRotationBone[i]=GetRotationRootSpace(当前);
if(i==Bones.Length-1)
{
//叶子
StartDirectionSucc[i]=GetPositionRootSpace(目标)-GetPositionRootSpace(当前);
}
其他的
{
//中骨
StartDirectionSucc[i]=GetPositionRootSpace(骨骼[i+1])-GetPositionRootSpace(当前);
BonesLength[i]=起始方向UCC[i]。震级;
完整长度+=骨长度[i];
}
current=current.parent;
}
}
//每帧调用一次更新
void LateUpdate()
{
ResolveIK();
}
私有void resolvik()
{
if(Target==null)
返回;
if(BonesLength.Length!=链长)
Init();
//织物
//根
//(bone0)(bonelen 0)(bone1)(bonelen 1)(bone2)。。。
//x------------------x------------------x--------。。。
//获得位置
for(int i=0;i=CompleteLength*CompleteLength)
{
//把它扔了
var方向=(targetPosition-位置[0])。标准化;
//把一切都放在根后面
对于(int i=1;i0;i--)
{
if(i==位置.长度-1)
Positions[i]=targetPosition;//将其设置为target
其他的
位置[i]=位置[i+1]+(位置[i]-位置[i+1])。标准化*骨骼长度[i];//在距离上设置为直线
}
//前进
对于(int i=1;i// previous code ...

        void OnDrawGizmos()
        {
#if UNITY_EDITOR
            var current = this.transform;
            for (int i = 0; i < ChainLength && current != null && current.parent != null; i++)
            {
                // ...code...
            }
        }
#endif

        // rest of the code ...
        private void LikeAnotherMethod() 
        {
            ....
        }
// previous code ...

        void OnDrawGizmos()
        {
            var current = this.transform;
            for (int i = 0; i < ChainLength && current != null && current.parent != null; i++)
            {
                // ...code...
            }
        }

        // rest of the code ...
        private void LikeAnotherMethod() 
        {
            ....
        }
// previous code ...

        void OnDrawGizmos()
        {
#if UNITY_EDITOR
// nope        var current = this.transform;
// nope        for (int i = 0; i < ChainLength && current != null && current.parent != null; i++)
// nope         {
// nope             // ...code...
// nope         }
// nope }
#endif

        // rest of the code ...
        private void LikeAnotherMethod() 
        {
            ....
        }
// previous code ...

        void OnDrawGizmos()
        {


        // rest of the code ...
        private void LikeAnotherMethod() 
        {
            ....
        }
// previous code ...

        void OnDrawGizmos()
        {
#if UNITY_EDITOR
            var current = this.transform;
            for (int i = 0; i < ChainLength && current != null && current.parent != null; i++)
            {
                // ...code...
            }
#endif
        }


        // rest of the code ...
        private void LikeAnotherMethod() 
        {
            ....
        }