Beispiel #1
0
        private void ReplaceModel(int modelId, UnitModelReplacementMode mode)
        {
            Assert.IsTrue(mode != UnitModelReplacementMode.ScopeOut);

            if (model != null && model.Settings.Id == modelId)
            {
                return;
            }

            if (rendering.Models.TryGetValue(modelId, out UnitModelSettings newModelSettings))
            {
                UnitModel newModel         = GameObjectPool.Take(newModelSettings.Prototype);
                var       modelInitializer = new UnitModelInitializer
                {
                    UnitRenderer    = this,
                    ModelSettings   = newModelSettings,
                    PreviousModel   = model,
                    ReplacementMode = mode
                };

                newModel.Initialize(modelInitializer);
                ReplaceModel(newModel);
            }
            else
            {
                Debug.LogError($"Missing model with id: {modelId}");
            }
        }
Beispiel #2
0
        private UnitModel ReplaceModel(UnitModel newModel = null, UnitModelReplacementMode mode = UnitModelReplacementMode.ScopeIn)
        {
            UnitModel oldModel = model;

            if (model != null && newModel != null)
            {
                model.TagContainer.TransferChildren(newModel.TagContainer);
            }

            model = newModel;
            UpdateAnimationState(canAnimate);
            soundController.HandleModelChange(model);

            if (oldModel != null)
            {
                EventHandler.ExecuteEvent(rendering, GameEvents.UnitModelAttached, oldModel, this, false);
            }

            if (newModel != null)
            {
                EventHandler.ExecuteEvent(rendering, GameEvents.UnitModelAttached, newModel, this, true);
            }

            if (oldModel != null && mode != UnitModelReplacementMode.ScopeOut)
            {
                oldModel.Deinitialize();
                oldModel = null;
            }

            return(oldModel);
        }
Beispiel #3
0
        public UnitModel Detach(UnitModelReplacementMode mode)
        {
            auraEffectController.HandleDetach();

            Unit.BoltEntity.RemoveEventListener(this);
            Unit.RemoveCallback(nameof(IUnitState.DeathState), OnDeathStateChanged);
            Unit.RemoveCallback(nameof(IUnitState.SpellCast), OnSpellCastChanged);
            Unit.RemoveCallback(nameof(IUnitState.EmoteType), OnEmoteTypeChanged);
            Unit.RemoveCallback(nameof(IUnitState.EmoteFrame), OnEmoteFrameChanged);
            EventHandler.UnregisterEvent(Unit, GameEvents.UnitModelChanged, OnModelChanged);
            EventHandler.UnregisterEvent(Unit, GameEvents.UnitScaleChanged, OnScaleChanged);
            EventHandler.UnregisterEvent(Unit, GameEvents.UnitVisualsChanged, OnVisualsChanged);

            CancelInvoke();
            Unit = null;

            return(ReplaceModel(mode: mode));
        }
Beispiel #4
0
        private UnitModel ReplaceModel(UnitModel newModel = null, UnitModelReplacementMode mode = UnitModelReplacementMode.ScopeIn)
        {
            UnitModel oldModel = model;

            if (oldModel != null && newModel != null)
            {
                model.TagContainer.TransferChildren(newModel.TagContainer);
            }

            model = newModel;
            UpdateAnimationState(canAnimate);
            soundController.HandleModelChange(model);

            if (oldModel != null && mode != UnitModelReplacementMode.ScopeOut)
            {
                oldModel.Deinitialize();
                oldModel = null;
            }

            return(oldModel);
        }