コード例 #1
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);
        }
コード例 #2
0
 public void Invoke(ObjectController newParent)
 {
     switch (ParentCommand)
     {
     case ParentCommand.SetThis:
         ParentCommand = ParentCommand.None;
         break;
     }
 }
コード例 #3
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();
        }
コード例 #4
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);
        }
コード例 #5
0
        public InputController(ObjectController objectController, GameObject gameObject,
                               bool isRoot = false, bool isObject = false)
        {
            _objectController = objectController;
            _gameObject       = gameObject;
            _vio               = _gameObject.AddComponent <VRTK_InteractableObject>();
            _isRoot            = isRoot;
            _isObject          = isObject;
            OnEditorGrabStart += OnGrabInit;
            OnEditorGrabEnd   += OnUngrabInit;
            Init();

            _ioBehavior = gameObject.GetComponent <InteractableObjectBehaviour>();

            _vio.InteractableObjectGrabbed   += OnAnyGrabStart;
            _vio.InteractableObjectUngrabbed += OnAnyGrabEnd;
        }
コード例 #6
0
        public static int SetIdInLocation(this ObjectController self, int id)
        {
            if (!ObjectsIds.ContainsKey(self))
            {
                ObjectsIds.Add(self, id);
                ObjectsCollectionChanged?.Invoke();
            }

            if (!ObjectTypeEntities.ContainsKey(id))
            {
                ObjectTypeEntities.Add(id, self.Entity);
            }
            else
            {
                ObjectTypeEntities[id] = self.Entity;
            }

            return(ObjectsIds[self]);
        }
コード例 #7
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);
            GameObject gameObjectLink = spawnedGameObject;
            int        idLocation     = spawnInitParams.IdLocation;
            int        idServer       = spawnInitParams.IdServer;
            int        idInstance     = spawnInitParams.IdInstance;
            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,
                RootGameObject     = spawnedGameObject,
                WrappersCollection = wrappersCollection,
                Parent             = parent,
                Config             = config
            };

            var newController = new ObjectController(initObjectParams);

            ObjectControllerCreated?.Invoke(newController);
        }
コード例 #8
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();
        }
コード例 #9
0
        public void Delete()
        {
            List <ObjectBehaviourWrapper> childrens =
                RootGameObject.GetComponentsInChildren <ObjectBehaviourWrapper>().ToList();

            childrens.Reverse();

            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.EntityParentLine != null)
                {
                    Object.Destroy(type.EntityParentLine.gameObject.Value);
                    type.EntityParentLine.Destroy();
                }

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

            WorldData.ObjectsAreChanged = true;
        }
コード例 #10
0
 public void SetSelectedBaseType(ObjectController selected)
 {
     _selectedObjectController = selected;
 }
コード例 #11
0
        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.SetGlobalScale(scale);
        }