static void CreateSpline()
        {
            if (splineStoreData.Data.Count > 2 && splineStoreData.Data[0] && splineStoreData.Data[1] && splineStoreData.Data[2])
            {
                GameObject tangentCtrl = new GameObject(BoneCreation.GetUniqueBoneName("spline_Tangent"));
                Undo.RegisterCreatedObjectUndo(tangentCtrl, "Created splineTangent");
                splineStoreData.Data.Add(tangentCtrl.transform);
                tangentCtrl.transform.parent        = splineStoreData.Data[splineStoreData.Data.Count - 2].transform;
                tangentCtrl.transform.localPosition = Vector3.zero;


                splineStoreData.Data[1].position += splineStoreData.Data[0].position - splineStoreData.Data[2].position;

                splineStoreData.Data[splineStoreData.Data.Count - 1].position += splineStoreData.Data[splineStoreData.Data.Count - 2].position - splineStoreData.Data[splineStoreData.Data.Count - 3].position;

                Transform splineCtrlSwap = splineStoreData.Data[0];
                splineStoreData.Data[0] = splineStoreData.Data[1];
                splineStoreData.Data[1] = splineCtrlSwap;

                SplineControl spline = SplineCreationGroup.AddComponent <SplineControl>();

                spline._splineCTRLS.AddRange(splineStoreData.Data);
                spline.numberBones = Puppet3DEditor.numberSplineJoints;
                spline.Create();

                foreach (Transform ctrl in splineStoreData.Data)
                {
                    if (!ctrl.parent.parent)
                    {
                        ctrl.parent.parent = SplineCreationGroup.transform;
                    }
                }
                GameObject globalCtrl = CreateControls.CreateGlobalControl();
                globalCtrl.GetComponent <GlobalControl>()._SplineControls.Add(spline);
                SplineCreationGroup.transform.parent = globalCtrl.transform;

                globalCtrl.GetComponent <GlobalControl>().InitializeArrays();
                globalCtrl.GetComponent <GlobalControl>().Run();

                Undo.DestroyObjectImmediate(splineStoreData);

                splineStoreData.Data.Clear();



                Bone[] bones = GameObject.FindObjectsOfType <Bone>();
                foreach (Bone bone in bones)
                {
                    if (bone.transform.parent == null)
                    {
                        bone.transform.parent = globalCtrl.transform;
                    }
                }
            }
        }
Exemple #2
0
        public void TraverseHierarchy(Transform root)
        {
            Control globalControl = root.transform.GetComponent <Control>();

            _Controls.Add(globalControl);

            foreach (Transform child in root)
            {
                GameObject Go = child.gameObject;

                Control control = Go.transform.GetComponent <Control>();
                _Controls.Add(control);

                Bone bone = Go.transform.GetComponent <Bone>();
                _Bones.Add(bone);

                ParentControl newParentCtrl = Go.transform.GetComponent <ParentControl>();

                if (newParentCtrl)
                {
                    _ParentControls.Add(newParentCtrl);
                }
                IKControl newIKCtrl = Go.transform.GetComponent <IKControl>();
                if (newIKCtrl)
                {
                    _Ikhandles.Add(newIKCtrl);
                }


                SplineControl splineCtrl = Go.transform.GetComponent <SplineControl>();
                if (splineCtrl)
                {
                    _SplineControls.Add(splineCtrl);
                }

                IKFKBlend ikfkBlend = Go.transform.GetComponent <IKFKBlend>();
                if (ikfkBlend)
                {
                    _IKFKBlends.Add(ikfkBlend);
                }

                DrivenKey newDrivenKey = Go.transform.GetComponent <DrivenKey>();

                if (newDrivenKey)
                {
                    _DrivenKeys.Add(newDrivenKey);
                }

                TraverseHierarchy(child);
            }
        }