Exemple #1
0
        public PointerAction(ObjectController objectController, GameObject gameObject, ObjectInteraction.InteractObject vio) : base(objectController, gameObject, vio)
        {
            _gameObject   = gameObject;
            _pointerClick = _gameObject.GetComponents <IPointerClickAware>().ToList();

            if (_pointerClick.Count > 0)
            {
                AddPointerClickAction();
            }

            _pointerIn = _gameObject.GetComponents <IPointerInAware>().ToList();

            if (_pointerIn.Count > 0)
            {
                AddPointerInAction();
            }

            _pointerOut = _gameObject.GetComponents <IPointerOutAware>().ToList();

            if (_pointerOut.Count > 0)
            {
                AddPointerOutAction();
            }

            if (_pointerClick.Count > 0 || _pointerIn.Count > 0 || _pointerOut.Count > 0)
            {
                AddPointerBehaviour();
            }
        }
Exemple #2
0
        /// <summary>
        /// Get wrapper of parent object
        /// </summary>
        /// <param name="target">Target wrapper</param>
        /// <returns></returns>
        public Wrapper GetParent(Wrapper target)
        {
            GameObject       gameObject       = target.GetGameObject();
            ObjectController objectController = gameObject.GetComponent <ObjectBehaviourWrapper>().OwdObjectController;

            return(objectController.Parent?.Entity.wrapper.Value);
        }
Exemple #3
0
        public GrabAction(
            ObjectController objectController,
            GameObject gameObject,
            ObjectInteraction.InteractObject vio) : base(objectController, gameObject, vio)
        {
            _grabStartList = GameObject.GetComponents <IGrabStartAware>().ToList();

            if (_grabStartList.Count > 0)
            {
                AddGrabStartBehaviour();
            }

            _grabEndList = GameObject.GetComponents <IGrabEndAware>().ToList();

            if (_grabEndList.Count > 0)
            {
                AddGrabEndBehaviour();
            }

            _grabPoint  = GameObject.GetComponent <IGrabPointAware>();
            _gameObject = gameObject;

            _onEditorGrabStart += OnGrabInit;
            _onEditorGrabEnd   += OnUngrabInit;
        }
        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;
        }
Exemple #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);
        }
Exemple #6
0
 public void Invoke(ObjectController newParent)
 {
     switch (ParentCommand)
     {
     case ParentCommand.SetThis:
         SetParentCommand command = new SetParentCommand(_selectedObjectController, newParent);
         ((ICommand)command).Execute();
         ParentCommand = ParentCommand.None;
         break;
     }
 }
Exemple #7
0
        private void OnGrabInit()
        {
            _saveTransform = GameObject.transform.ToTransformDT();

            _onInitTransform = ObjectController.gameObject.transform.ToTransformDT();

            if (ObjectController != null)
            {
                _saveJointData = ObjectController.GetJointData();
            }
        }
Exemple #8
0
        /// <summary>
        /// Get wrapper of ancestry object
        /// </summary>
        /// <param name="target">Target wrapper</param>
        /// <returns></returns>
        public List <Wrapper> GetAncestry(Wrapper target)
        {
            List <Wrapper>   result           = new List <Wrapper>();
            GameObject       gameObject       = target.GetGameObject();
            ObjectController objectController = gameObject.GetComponent <ObjectBehaviourWrapper>().OwdObjectController;
            ObjectController parent           = objectController.Parent;

            while (parent != null)
            {
                result.Add(parent.Entity.wrapper.Value);
                parent = parent.Parent;
            }

            return(result);
        }
Exemple #9
0
        public static void Dispose(this ObjectController self)
        {
            if (ObjectsIds.ContainsKey(self))
            {
                ObjectsIds.Remove(self);
                ObjectsCollectionChanged?.Invoke();
            }

            if (ObjectTypeEntities.ContainsKey(self.Id))
            {
                ObjectTypeEntities.Remove(self.Id);
            }

            GC.Collect();
        }
Exemple #10
0
        public TouchAction(ObjectController objectController, GameObject gameObject, ObjectInteraction.InteractObject vio) : base(objectController, gameObject, vio)
        {
            _touchStartList = GameObject.GetComponents <ITouchStartAware>().ToList();

            if (_touchStartList.Count > 0)
            {
                AddTouchStartAction();
            }

            _touchEndList = GameObject.GetComponents <ITouchEndAware>().ToList();

            if (_touchEndList.Count > 0)
            {
                AddTouchEndAction();
            }
        }
Exemple #11
0
        public UseAction(ObjectController objectController, GameObject gameObject, ObjectInteraction.InteractObject vio) :
            base(objectController, gameObject, vio)
        {
            _useStartList = GameObject.GetComponents <IUseStartAware>().ToList();

            if (_useStartList.Count > 0)
            {
                AddUseStartBehaviour();
            }

            _useEndList = GameObject.GetComponents <IUseEndAware>().ToList();

            if (_useEndList.Count > 0)
            {
                AddUseEndBehaviour();
            }
        }
Exemple #12
0
        /// <summary>
        ///     Initialize object in platform
        /// </summary>
        /// <param name="idObject">Object type id. Used for save.</param>
        /// <param name="spawnInitParams">Parameters for spawn</param>
        /// <param name="spawnedGameObject">Game object for init</param>
        public static void InitObject(int idObject, SpawnInitParams spawnInitParams, GameObject spawnedGameObject, Config config)
        {
            //var photonView = AddPhoton(spawnedGameObject, spawnInitParams.spawnAsset.IdPhoton);
            PhotonView photonView     = AddPhoton(spawnedGameObject, 0);
            GameObject gameObjectLink = spawnedGameObject;
            int        idLocation     = spawnInitParams.IdLocation;
            int        idServer       = spawnInitParams.IdServer;
            int        idInstance     = spawnInitParams.IdInstance;
            bool       embedded       = spawnInitParams.Embedded;
            string     name           = spawnInitParams.Name;
            var        parentId       = spawnInitParams.ParentId;

            ObjectController parent = null;

            if (parentId != null)
            {
                parent = GameStateData.GetObjectInLocation(parentId.Value);
            }

            WrappersCollection wrappersCollection = null;

            if (idLocation != 0)
            {
                wrappersCollection = GameStateData.GetWrapperCollection();
            }

            InitObjectParams initObjectParams = new InitObjectParams
            {
                Id                 = idInstance,
                IdObject           = idObject,
                IdLocation         = idLocation,
                IdServer           = idServer,
                Asset              = gameObjectLink,
                Name               = name,
                Photonview         = photonView,
                RootGameObject     = spawnedGameObject,
                WrappersCollection = wrappersCollection,
                Parent             = parent,
                Embedded           = embedded,
                Config             = config
            };

            var newController = new ObjectController(initObjectParams);

            ObjectControllerCreated?.Invoke(newController);
        }
Exemple #13
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;
            }
        }
Exemple #14
0
        public InputController(
            ObjectController objectController,
            GameObject gameObject,
            PhotonView photonView,
            bool isRoot = false)
        {
            _objectController = objectController;
            _gameObject       = gameObject;
            _photonView       = photonView;

            _vio = InputAdapter.Instance.ObjectInteraction.Object.AddTo(_gameObject);

            _isRoot = isRoot;
            Init();
            EnableMultiplayer();

            _vio.InteractableObjectGrabbed   += OnAnyGrabStart;
            _vio.InteractableObjectUngrabbed += OnAnyGrabEnd;
        }
Exemple #15
0
        public static void RegisterMeInLocation(this ObjectController self, ref int instanceId)
        {
            if (instanceId == 0)
            {
                int newId;

                if (ObjectsIds.Count == 0)
                {
                    newId = 1;
                }
                else
                {
                    newId = ObjectsIds.Values.ToList().Max() + 1;
                }

                instanceId = newId;
                self.SetName(instanceId.ToString());
            }

            ObjectsIds.Add(self, instanceId);
            ObjectTypeEntities.Add(instanceId, self.Entity);
            ObjectsCollectionChanged?.Invoke();
        }
Exemple #16
0
        public static IEnumerator DeleteAllChildren(ObjectController objectController, ObjectBehaviourWrapper[] wrappers = null)
        {
            if (wrappers == null)
            {
                wrappers = objectController.RootGameObject.GetComponentsInChildren <ObjectBehaviourWrapper>();
            }

            List <bool> canDelete = new List <bool>();

            foreach (ObjectBehaviourWrapper wrapper in wrappers)
            {
                if (wrapper.OwdObjectController.IdServer != 0)
                {
                    var request = new RequestApi(string.Format(ApiRoutes.CanDeleteObjectRequest, wrapper.OwdObjectController.IdServer));
                    request.OnFinish += response =>
                    {
                        ResponseApi jsend = (ResponseApi)response;
                        if (jsend.Data == null || (bool)jsend.Data)
                        {
                            canDelete.Add(true);
                        }
                        else
                        {
                            canDelete.Add(false);
                        }
                    };
                    request.OnError += s =>
                    {
                        VRErrorManager.Instance.Show("!!!");
                    };
                }
                else
                {
                    canDelete.Add(true);
                }
            }

            while (canDelete.Count != wrappers.Length)
            {
                yield return(null);
            }

            bool ok = true;

            foreach (bool can in canDelete)
            {
                if (!can)
                {
                    ok = false;
                    break;
                }
            }

            if (!ok)
            {
                LogManager.GetCurrentClassLogger()
                .Info($"Can not delete object IdServer = {objectController.IdServer}");
                VRErrorManager.Instance.Show(
                    ErrorHelper.GetErrorDescByCode(Varwin.Errors.ErrorCode.CannotDeleteObjectLogic));
                ObjectCannotDelete?.Invoke();
            }
            else
            {
                DeleteCommand(objectController);
            }

            yield return(true);
        }
Exemple #17
0
 public void SetSelectedBaseType(ObjectController selected)
 {
     _selectedObjectController = selected;
 }
        private void SetParent(ObjectController value)
        {
            _parent = value;
            Vector3 scale = RootGameObject.transform.localScale;

            if (value != null)
            {
                _parentId = value.Id;
                Entity.ReplaceIdParent(_parentId);

                if (EntityParentLine == null)
                {
                    EntityParentLine = _context.game.CreateEntity();
                    GameObject go = new GameObject("LineToParent");
                    EntityParentLine.AddGameObject(go);
                    LineRenderer lineRenderer = Helper.CreateLineRenderer(go);

                    if (lineRenderer != null)
                    {
                        EntityParentLine.AddLineRenderer(lineRenderer);

                        EntityParentLine.AddChildrenParentTransform(RootGameObject.transform,
                                                                    value.RootGameObject.transform);
                    }
                }
                else
                {
                    EntityParentLine.ReplaceChildrenParentTransform(RootGameObject.transform,
                                                                    value.RootGameObject.transform);
                }

                RootGameObject.transform.SetParent(value.RootGameObject.transform, true);

                LogManager.GetCurrentClassLogger()
                .Info($"New parent {value.RootGameObject.name} was set to {RootGameObject.name}");
            }
            else
            {
                _parentId = 0;
                RootGameObject.transform.SetParent(null, true);

                if (Entity.hasIdParent)
                {
                    Entity.RemoveIdParent();
                }

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

                    EntityParentLine.Destroy();
                    EntityParentLine = null;
                }

                LogManager.GetCurrentClassLogger().Info($"Parent was remove to {RootGameObject.name}");
            }

            RootGameObject.transform.ExtSetGlobalScale(scale);
        }
Exemple #19
0
        public static void DeleteCommand(ObjectController objectController)
        {
            ICommand command = new DeleteCommand(objectController);

            command.Execute();
        }
Exemple #20
0
 protected InputAction(ObjectController objectController, GameObject gameObject, ObjectInteraction.InteractObject vio)
 {
     ObjectController = objectController;
     GameObject       = gameObject;
     Vio = vio;
 }