Пример #1
0
        public static void AutoSave(SpringManager springManager)
        {
            var autoSavePath = GetAutoSavePath(springManager.name);
            var sourceText   = SpringBoneSerialization.BuildDynamicsSetupString(springManager.gameObject);

            FileUtil.WriteAllText(autoSavePath, sourceText);
        }
Пример #2
0
        public static void UpdateSpringManagerFromBoneList(SpringManager springManager)
        {
            var rootObject            = springManager.gameObject;
            var designatedSpringBones = GetBonesDesignatedForDynamics(rootObject);
            var currentSpringBones    = rootObject.GetComponentsInChildren <SpringBone>(true);

            var skinBones            = GameObjectExtensions.GameObjectUtil.GetAllBones(rootObject);
            var springBonesToDestroy = currentSpringBones
                                       .Where(bone => !designatedSpringBones.Contains(bone.gameObject));

            foreach (var boneToDestroy in springBonesToDestroy)
            {
                var pivot = boneToDestroy.pivotNode;
                if (pivot != null &&
                    SpringBoneSetup.IsPivotProbablySafeToDestroy(pivot, skinBones))
                {
                    SpringBoneSetup.DestroyUnityObject(pivot.gameObject);
                }
                SpringBoneSetup.DestroyUnityObject(boneToDestroy);
            }

            var objectsToAddBonesTo = designatedSpringBones
                                      .Where(bone => bone.GetComponent <SpringBone>() == null);

            foreach (var newBoneOwner in objectsToAddBonesTo)
            {
                var newSpringBone = newBoneOwner.AddComponent <SpringBone>();
                SpringBoneSetup.CreateSpringPivotNode(newSpringBone);
            }
            SpringBoneSetup.FindAndAssignSpringBones(springManager, true);
        }
Пример #3
0
 // 全子供にSpringBoneを見つけて、springManagerに割り当てる
 public static void FindAndAssignSpringBones(SpringManager springManager, bool includeInactive = false)
 {
     if (springManager != null)
     {
         var sortedBones = GetSpringBonesSortedByDepth(springManager.gameObject, includeInactive);
         springManager.springBones = sortedBones.ToArray();
     }
 }
Пример #4
0
        public static void AutoLoad(SpringManager springManager)
        {
            var autoSavePath = GetAutoSavePath(springManager.name);

            if (System.IO.File.Exists(autoSavePath))
            {
                var sourceText = FileUtil.ReadAllText(autoSavePath);
                DynamicsSetup.BuildFromRecordText(springManager.gameObject, springManager.gameObject, sourceText);
            }
        }
 public void ApplyTo(SpringManager targetManager)
 {
     targetManager.automaticUpdates    = automaticUpdates;
     targetManager.simulationFrameRate = simulationFrameRate;
     targetManager.dynamicRatio        = dynamicRatio;
     targetManager.gravity             = gravity;
     targetManager.collideWithGround   = collideWithGround;
     targetManager.groundHeight        = groundHeight;
     targetManager.bounce   = bounce;
     targetManager.friction = friction;
 }
Пример #6
0
 private void OnDrawGizmos()
 {
     if (shouldDrawGizmosThisFrame || !SpringManager.onlyShowSelectedColliders)
     {
         if (manager == null)
         {
             manager = GetComponentInParent <SpringManager>();
         }
         DrawGizmos((enabled && manager != null) ? manager.colliderColor : Color.gray);
         shouldDrawGizmosThisFrame = false;
     }
 }
            public static PersistentSpringManagerProperties Create(SpringManager sourceManager)
            {
                if (sourceManager == null)
                {
                    return(null);
                }

                var properties = new PersistentSpringManagerProperties
                {
                    automaticUpdates    = sourceManager.automaticUpdates,
                    simulationFrameRate = sourceManager.simulationFrameRate,
                    dynamicRatio        = sourceManager.dynamicRatio,
                    gravity             = sourceManager.gravity,
                    collideWithGround   = sourceManager.collideWithGround,
                    groundHeight        = sourceManager.groundHeight,
                    bounce   = sourceManager.bounce,
                    friction = sourceManager.friction
                };

                return(properties);
            }
Пример #8
0
        // This should be called by the SpringManager in its Awake function before any updates
        public void Initialize(SpringManager owner)
        {
            manager = owner;

            var childPosition      = ComputeChildPosition();
            var localChildPosition = transform.InverseTransformPoint(childPosition);

            boneAxis = localChildPosition.normalized;

            initialLocalRotation = transform.localRotation;
            actualLocalRotation  = initialLocalRotation;

            sphereColliders  = sphereColliders.Where(item => item != null).ToArray();
            capsuleColliders = capsuleColliders.Where(item => item != null).ToArray();
            panelColliders   = panelColliders.Where(item => item != null).ToArray();

            lengthLimitTargets = (lengthLimitTargets != null)
                ? lengthLimitTargets.Where(target => target != null).ToArray()
                : new Transform[0];

            InitializeSpringLengthAndTipPosition();
        }
Пример #9
0
 private static void UpdateBoneList(SpringManager manager)
 {
     SpringBoneSetup.FindAndAssignSpringBones(manager, true);
 }
Пример #10
0
        private static void SelectAllBones(SpringManager manager)
        {
            var bones = manager.GetComponentsInChildren <SpringBone>(true);

            Selection.objects = bones.Select(item => item.gameObject).ToArray();
        }
Пример #11
0
 private static void ShowSpringWindow(SpringManager manager)
 {
     SpringBoneWindow.ShowWindow();
 }
 private static void UpdatePrivateForceProviderList(SpringManager manager)
 {
     Undo.RecordObject(manager, "Private ForceProviderを更新");
     manager.privateForceProviders.Clear();
     manager.privateForceProviders.AddRange(manager.transform.GetComponentsInChildren <ForceProvider>(true));
 }
 private static void UpdateBoneList(SpringManager manager)
 {
     Undo.RecordObject(manager, "SpringBoneリストを更新");
     SpringBoneSetup.FindAndAssignSpringBones(manager, true);
 }