コード例 #1
0
        private IEnumerator RestoreJointsOnNextFrame(Dictionary <int, JointData> joints)
        {
            JointBehaviour.IsTempConnectionCreated = true;

            yield return(new WaitForEndOfFrame());

            Debug.Log("<Color=Olive>Restore joints started!</Color>");

            var jointsScene = FindObjectsOfType <JointBehaviour>();

            foreach (JointBehaviour joint in jointsScene)
            {
                joint.UnLockAndDisconnectPoints();
            }

            foreach (var joint in joints)
            {
                int              instanseId       = joint.Key;
                JointData        jointData        = joint.Value;
                ObjectController objectController = GameStateData.GetObjectInLocation(instanseId);

                if (objectController == null)
                {
                    continue;
                }

                JointBehaviour jointBehaviour = objectController.RootGameObject.GetComponent <JointBehaviour>();

                if (jointBehaviour == null)
                {
                    continue;
                }

                var jointPoints = Helper.GetJointPoints(objectController.RootGameObject);

                foreach (var jointConnectionsData in jointData.JointConnetionsData)
                {
                    int                 pointId               = jointConnectionsData.Key;
                    JointPoint          myJointPoint          = jointPoints[pointId];
                    JointConnetionsData connectionData        = jointConnectionsData.Value;
                    ObjectController    otherObjectController = GameStateData.GetObjectInLocation(connectionData.ConnectedObjectInstanceId);
                    var                 otherJointPoints      = Helper.GetJointPoints(otherObjectController.RootGameObject);
                    JointPoint          otherJointPoint       = otherJointPoints[connectionData.ConnectedObjectJointPointId];
                    jointBehaviour.ConnectToJointPoint(myJointPoint, otherJointPoint);
                    myJointPoint.IsForceLocked    = connectionData.ForceLocked;
                    otherJointPoint.IsForceLocked = connectionData.ForceLocked;
                }
            }

            yield return(new WaitForEndOfFrame());

            JointBehaviour.IsTempConnectionCreated = false;
            yield return(true);
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: RobboVariwn/VarBot
        public static void ReloadJointConnections(ObjectController objectController, JointData saveJointData)
        {
            JointBehaviour jointBehaviour = objectController.RootGameObject.GetComponent <JointBehaviour>();
            var            jointPoints    = GetJointPoints(objectController.RootGameObject);

            foreach (var jointConnectionsData in saveJointData.JointConnetionsData)
            {
                int                 pointId               = jointConnectionsData.Key;
                JointPoint          myJointPoint          = jointPoints[pointId];
                JointConnetionsData connectionData        = jointConnectionsData.Value;
                ObjectController    otherObjectController = GameStateData.GetObjectInLocation(connectionData.ConnectedObjectInstanceId);
                var                 otherJointPoints      = GetJointPoints(otherObjectController.RootGameObject);
                JointPoint          otherJointPoint       = otherJointPoints[connectionData.ConnectedObjectJointPointId];
                jointBehaviour.ConnectToJointPoint(myJointPoint, otherJointPoint);
                myJointPoint.IsForceLocked    = connectionData.ForceLocked;
                otherJointPoint.IsForceLocked = connectionData.ForceLocked;
            }
        }