Beispiel #1
0
    static void AddTranslateScaleChains(TranslateScale.TranslateScaleChain translateScaleChain)
    {
        if (!translateScaleChain.HasValidData())
        {
            return;
        }

        GameDebug.Assert(s_SourceJoints.length < k_MaxDrivers, "You are trying to add more translate scale chains then there is allocated space for.");
        GameDebug.Assert(s_DrivenJoints.length + translateScaleChain.drivenJoints.Count <= k_MaxDrivenJoints, "You are trying to add more driven joint then there is allocated space for.");

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

        for (var j = 0; j < translateScaleChain.drivenJoints.Count; j++)
        {
            if (translateScaleChain.drivenJoints[j].joint != null)
            {
                s_DrivenJoints.Add(translateScaleChain.drivenJoints[j].joint);
                s_TargetData[s_DrivenIndex] = new TargetData
                {
                    sourceIndex   = s_DriverIndex,
                    bindpose      = translateScaleChain.drivenJoints[j].bindpose,
                    stretchFactor = translateScaleChain.drivenJoints[j].strectchFactor,
                    scaleFactor   = translateScaleChain.drivenJoints[j].scaleFactor
                };
                s_DrivenIndex++;
            }
        }

        s_DriverIndex++;
    }
Beispiel #2
0
    static void AddTranslateScaleComponents(GameObject root, List <TranslateScaleConfig> translateScaleConfigs)
    {
        if (translateScaleConfigs.Count == 0)
        {
            return;
        }

        var component = root.AddComponent <TranslateScale>();

        for (var i = 0; i < translateScaleConfigs.Count; i++)
        {
            var config = translateScaleConfigs[i];
            var chain  = new TranslateScale.TranslateScaleChain();
            chain.driver = FindInChildren(root.transform, config.driver);

            if (!chain.driver)
            {
                continue;
            }

            chain.drivenJoints = new List <TranslateScale.Driven>();
            for (var j = 0; j < config.stretchBones.Count; j++)
            {
                var driven = new TranslateScale.Driven();
                driven.joint          = FindInChildren(root.transform, config.stretchBones[j]);
                driven.scaleFactor    = config.scaleFactors[j];
                driven.strectchFactor = config.stretchFactors[j];
                chain.drivenJoints.Add(driven);
            }

            if (chain.HasValidData())
            {
                component.chains.Add(chain);
            }
        }

        component.SetBindpose();
    }