示例#1
0
    static void AddTwistChain(Twist.TwistChain twistChain)
    {
        if (!twistChain.HasValidData())
        {
            return;
        }

        GameDebug.Assert(s_SourceJoints.length < k_MaxSetups, "You are trying to add more twist joint chains then there is allocated space for.");
        GameDebug.Assert(s_TwistJoints.length + twistChain.twistJoints.Count <= k_MaxTwistJoints, "You are trying to add more twist joint then there is allocated space for.");

        s_SourceJoints.Add(twistChain.driver);
        s_SourceData[s_SetupIndex] = new SourceData
        {
            bindpose = twistChain.bindpose
        };

        for (var j = 0; j < twistChain.twistJoints.Count; j++)
        {
            if (twistChain.twistJoints[j].joint != null)
            {
                s_TwistJoints.Add(twistChain.twistJoints[j].joint);
                s_TargetData[s_TwistIndex] = new TargetData
                {
                    sourceIndex = s_SetupIndex,
                    twistFactor = twistChain.twistJoints[j].factor
                };
                s_TwistIndex++;
            }
        }

        s_SetupIndex++;
    }
示例#2
0
    static void AddTwistComponents(GameObject root, List <TwistConfig> twistConfigs)
    {
        if (twistConfigs.Count == 0)
        {
            return;
        }

        var twistComponent = root.AddComponent <Twist>();

        for (var i = 0; i < twistConfigs.Count; i++)
        {
            var twistConfig = twistConfigs[i];
            var twistChain  = new Twist.TwistChain();
            twistChain.driver = FindInChildren(root.transform, twistConfig.driver);

            if (!twistChain.driver)
            {
                continue;
            }

            // TODO: Support variable axis
//            switch (twistConfig.aimAxis)
//            {
//                case "X":
//                    twistComponent.aimAxis = Twist.AimAxis.X;
//                    break;
//                case "Y":
//                    twistComponent.aimAxis = Twist.AimAxis.Y;
//                    break;
//                case "Z":
//                    twistComponent.aimAxis = Twist.AimAxis.Z;
//                    break;
//                default:
//                    twistComponent.aimAxis = Twist.AimAxis.X;
//                    break;
//            }

            twistChain.twistJoints = new List <Twist.TwistJoint>();
            for (var j = 0; j < twistConfig.twistJoints.Count; j++)
            {
                var twistJoint = new Twist.TwistJoint();
                twistJoint.joint  = FindInChildren(root.transform, twistConfig.twistJoints[j]);
                twistJoint.factor = twistConfig.twistFactors[j];
                twistChain.twistJoints.Add(twistJoint);
            }

            if (twistChain.HasValidData())
            {
                twistComponent.twistChains.Add(twistChain);
            }
        }

        twistComponent.SetBindpose();
    }