/*
         * Based on Polymorph.TryReplaceView. Replaces view, only used when changing view through UI
         * When id is null or "", rebuilds original view
         */
        public static void ReplaceView(UnitEntityData unit, string id)
        {
            var original = unit.View;

            foreach (Buff buff in unit.Buffs)
            {
                buff.ClearParticleEffect();
            }
            UnitEntityView template = GetView(id);

            if (template == null)
            {
                template = unit.Blueprint.Prefab.Load();
            }
            var instance = UnityEngine.Object.Instantiate(template).GetComponent <UnitEntityView>();

            instance.UniqueId = unit.UniqueId;
            instance.transform.SetParent(original.transform.parent);
            instance.transform.position = original.transform.position;
            instance.transform.rotation = original.transform.rotation;
            if (!string.IsNullOrEmpty(id))
            {
                instance.DisableSizeScaling = true;
                //Prevent halflings from running too fast
                Traverse.Create(instance).Field("m_IgnoreRaceAnimationSettings").SetValue(true);
            }
            instance.Blueprint = unit.Blueprint;
            unit.AttachToViewOnLoad(instance);
            unit.Commands.InterruptAll((UnitCommand cmd) => !(cmd is UnitMoveTo));
            SelectionManagerBase selectionManager = Game.Instance.UI.SelectionManager; // SelectionManager to SelectionManagerBase

            if (selectionManager != null)
            {
                selectionManager.ForceCreateMarks();
            }
            UnityEngine.Object.Destroy(original.gameObject);
            if (string.IsNullOrEmpty(id))
            {
                CharacterManager.RebuildCharacter(unit);
            }
        }
Exemple #2
0
            private static void TrySetIdx(int nIdx)
            {
                SelectionManagerBase sm = Game.Instance.UI.SelectionManager;

                if (Settings.EnableAllSelectedCharacters)
                {
                    foreach (Kingmaker.EntitySystem.Entities.UnitEntityData unit in sm.SelectedUnits)
                    {
                        unit.Body.CurrentHandEquipmentSetIndex = nIdx;
                    }

                    return;
                }

                if (sm.SelectedUnits.Count != 1)
                {
                    return;
                }

                sm.SelectedUnits[0].Body.CurrentHandEquipmentSetIndex = nIdx;
            }