Пример #1
0
        public ObjectController(InitObjectParams initObjectParams)
        {
            _context = Contexts.sharedInstance;
            Entity   = _context.game.CreateEntity();
            _config  = initObjectParams.Config;

            RootGameObject     = initObjectParams.RootGameObject;
            gameObject         = initObjectParams.Asset;
            Id                 = initObjectParams.Id;
            IdObject           = initObjectParams.IdObject;
            IdLocation         = initObjectParams.IdLocation;
            IdServer           = initObjectParams.IdServer;
            Name               = initObjectParams.Name;
            WrappersCollection = initObjectParams.WrappersCollection;

            int instanceId = Id;

            this.RegisterMeInLocation(ref instanceId);
            Id = instanceId;
            SetName(Name);

            if (initObjectParams.Parent != null)
            {
                SetParent(initObjectParams.Parent);
            }

            RootGameObject.AddComponent <ObjectBehaviourWrapper>().OwdObjectController = this;

            AddBehaviours();
            AddWrapper();
            SaveKinematics();

            Entity.AddId(Id);
            Entity.AddIdServer(IdServer);
            Entity.AddIdObject(IdObject);
            Entity.AddRootGameObject(RootGameObject);
            Entity.AddGameObject(gameObject);

            Rigidbody rigidbody = gameObject.GetComponent <Rigidbody>();

            if (rigidbody != null)
            {
                Entity.AddRigidbody(rigidbody);
            }

            Collider collider = gameObject.GetComponentInChildren <Collider>();

            if (collider)
            {
                Entity.AddCollider(collider);
            }

            ApplyGameMode(WorldData.GameMode, WorldData.GameMode);
            RequestManager.Instance.StartCoroutine(ExecuteSwitchGameModeDelayedCoroutine());

            Create();
        }
Пример #2
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);
        }