示例#1
0
        protected override void EnableEditorInput()
        {
            if (!IsRootGameObject)
            {
                return;
            }

            Vio.isGrabbable = true;

            PlayerAppearance.InteractControllerAppearance grab =
                InputAdapter.Instance.PlayerAppearance.ControllerAppearance.GetFrom(GameObject)
                ?? InputAdapter.Instance.PlayerAppearance.ControllerAppearance.AddTo(GameObject);

            grab.HideControllerOnGrab = true;

            Vio.SwapControllersFlag = true;

            Vio.grabOverrideButton           = ControllerInput.ButtonAlias.GripPress;
            Vio.InteractableObjectGrabbed   += EditorGrabbed;
            Vio.InteractableObjectUngrabbed += EditorUngrabbed;

            JointBehaviour jointBehaviour = GameObject.GetComponent <JointBehaviour>();

            if (jointBehaviour != null)
            {
                _onEditorGrabStart += jointBehaviour.OnGrabStart;
                _onEditorGrabEnd   += jointBehaviour.OnGrabEnd;
            }
        }
示例#2
0
        public List <JointBehaviour> GetAllConnectedJoints(List <JointBehaviour> sender = null)
        {
            var result = sender ?? new List <JointBehaviour> {
                this
            };

            foreach (JointPoint jointPoint in JointPoints)
            {
                if (jointPoint.IsFree)
                {
                    continue;
                }

                JointBehaviour candidate = jointPoint.ConnectedJointPoint.JointBehaviour;

                if (result.Contains(candidate))
                {
                    continue;
                }

                result.Add(candidate);
                jointPoint.ConnectedJointPoint.JointBehaviour.GetAllConnectedJoints(result);
            }


            return(result);
        }
示例#3
0
        public JointData GetJointData()
        {
            JointData jointData;

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

            if (jointBehaviour == null)
            {
                return(null);
            }

            jointData = new JointData {
                JointConnetionsData = new Dictionary <int, JointConnetionsData>()
            };

            foreach (JointPoint jointPoint in jointBehaviour.JointPoints)
            {
                if (jointPoint.IsFree)
                {
                    continue;
                }

                var objectId = jointPoint.gameObject.GetComponent <ObjectId>();

                if (objectId == null)
                {
                    LogManager.GetCurrentClassLogger().Error($"Joint point {jointPoint.gameObject} have no object id");

                    continue;
                }

                var connectedJointPointObjectId = jointPoint.ConnectedJointPoint.gameObject.GetComponent <ObjectId>();

                if (connectedJointPointObjectId == null)
                {
                    LogManager.GetCurrentClassLogger()
                    .Error($"Connected joint point {jointPoint.ConnectedJointPoint.gameObject} have no object id");

                    continue;
                }

                int jointPointId = objectId.Id;
                int connectedObjectInstanceId   = jointPoint.ConnectedJointPoint.JointBehaviour.Wrapper.GetInstanceId();
                int connectedObjectJointPointId = connectedJointPointObjectId.Id;

                jointData.JointConnetionsData.Add(jointPointId,
                                                  new JointConnetionsData
                {
                    ConnectedObjectInstanceId   = connectedObjectInstanceId,
                    ConnectedObjectJointPointId = connectedObjectJointPointId,
                    ForceLocked = jointPoint.IsForceLocked
                });
            }

            return(jointData);
        }
示例#4
0
        public void Delete()
        {
            List <ObjectBehaviourWrapper> childrens =
                RootGameObject.GetComponentsInChildren <ObjectBehaviourWrapper>().ToList();

            childrens.Reverse();

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

            if (jointBehaviour != null)
            {
                jointBehaviour.UnLockAndDisconnectPoints();
            }


            foreach (var children in childrens)
            {
                ObjectController type = children.OwdObjectController;
                WrappersCollection.Remove(type.Id);

                foreach (ColliderController colliderController in type._colliderControllers)
                {
                    colliderController.Destroy();
                }

                foreach (InputController inputController in type._inputControllers.Values)
                {
                    inputController.Destroy();
                }

                type.OnDestroy?.Invoke();
                type.Entity?.Destroy();

                if (type.Uiid != null)
                {
                    Object.Destroy(type.Uiid.gameObject);
                }

                if (type.UiObject != null)
                {
                    Object.Destroy(type.UiObject.gameObject);
                }

                if (type.EntityParentLine != null)
                {
                    Object.Destroy(type.EntityParentLine.gameObject.Value);
                    type.EntityParentLine.Destroy();
                }

                type.RootGameObject.DestroyGameObject();
                type.Dispose();
            }

            ProjectData.ObjectsAreChanged = true;
        }
示例#5
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);
        }
示例#6
0
        private void AddJointBehaviour()
        {
            if (RootGameObject.GetComponent <JointBehaviour>() != null)
            {
                return;
            }

            _jointBehaviour = RootGameObject.AddComponent <JointBehaviour>();
            _jointBehaviour.Init();
            LogManager.GetCurrentClassLogger().Info("Added joint behaviour on " + RootGameObject.name);
        }
示例#7
0
        public void RemoveDisconnectedJoint(Wrapper wrapper, JointBehaviour jointBehaviour)
        {
            if (!_connectedWrappers.Contains(wrapper))
            {
                return;
            }

            _connectedWrappers.Remove(wrapper);
            _connectedJointBehaviours.Remove(jointBehaviour);
            Debug.Log($"Wrapper {wrapper} was disconnected! Connections count = {_connectedWrappers.Count}");
            SetDefaultHighLight();
            OnDisconnect?.Invoke();
        }
示例#8
0
        private void JointPointOnJointExit(JointPoint senderJoint, JointPoint nearJoint)
        {
            if (IsGrabbed)
            {
                return;
            }

            HideConnectionJoint();
            _senderJointPoint   = null;
            _nearJointBehaviour = null;
            _nearJointPoint     = null;
            Debug.Log($"Joint exit! {senderJoint} {nearJoint}");
        }
示例#9
0
        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;
            }
        }
示例#10
0
        private void JointPointOnJointEnter(JointPoint senderJoint, JointPoint nearJoint)
        {
            _senderJointPoint   = senderJoint;
            _nearJointPoint     = nearJoint;
            _nearJointBehaviour = nearJoint.JointBehaviour;

            if (!IsGrabbed || !senderJoint.IsFree || !nearJoint.IsFree)
            {
                return;
            }

            if (IsGrabbed && nearJoint.JointBehaviour.IsGrabbed)
            {
                //ToDo case 3 here
                return;
            }

            nearJoint.JointBehaviour.DrawConnectionJoint(nearJoint, senderJoint);
            Debug.Log($"Joint enter! {senderJoint} {nearJoint}");
        }
示例#11
0
        public List <JointBehaviour> GetAllConnectedJoints(JointPoint jointPoint, List <JointBehaviour> sender = null)
        {
            if (jointPoint == null)
            {
                return(null);
            }

            var result = sender ?? new List <JointBehaviour>()
            {
                this
            };

            if (jointPoint.IsFree)
            {
                return(result);
            }

            JointBehaviour candidate = jointPoint.ConnectedJointPoint.JointBehaviour;

            result.Add(candidate);
            jointPoint.ConnectedJointPoint.JointBehaviour.GetAllConnectedJoints(result);

            return(result);
        }
示例#12
0
 public void AddConnectedJoint(Wrapper wrapper, JointBehaviour jointBehaviour)
 {
     _connectedWrappers.Add(wrapper);
     _connectedJointBehaviours.Add(jointBehaviour);
     Debug.Log($"Wrapper {wrapper} was connected! Connections count = {_connectedWrappers.Count}");
 }