Esempio n. 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}");
            }
        }
Esempio n. 2
0
        public void Initialize(UnitModelInitializer initializer)
        {
            transform.SetParent(initializer.UnitRenderer.transform, false);
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;
            transform.localScale    = Vector3.one;

            Settings         = initializer.ModelSettings;
            Animator.enabled = true;

            if (initializer.UnitRenderer.Unit.IsDead)
            {
                animator.SetBool("IsDead", true);
                animator.Play("Death");
            }

            switch (initializer.ReplacementMode)
            {
            case UnitModelReplacementMode.ScopeIn:
                ToggleTransparentMode(true, 0.0f, 1.0f);
                break;

            case UnitModelReplacementMode.Transformation:
                if (initializer.PreviousModel != null && initializer.PreviousModel.CurrentAlpha < 1.0f)
                {
                    ToggleTransparentMode(true, initializer.PreviousModel.CurrentAlpha, initializer.PreviousModel.TargetAlpha);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(initializer.ReplacementMode), initializer.ReplacementMode, "Unhandled model replacement mode!");
            }

            HandleVisualEffects(initializer.UnitRenderer, false, true);
        }