예제 #1
0
    protected void OnDestroy()
    {
        foreach (var es in m_weaponEffects)
        {
            es.Value.Clear();
        }
        m_weaponEffects.Clear();

        m_weaponInfo    = null;
        m_offWeaponInfo = null;
        m_weapons       = null;
        m_mainWeapons   = null;
        m_offWeapons    = null;
        m_creature      = null;
        m_weaponEffects = null;

        m_normalDamageTrans?.Clear();
        m_buffDamageTrans?.Clear();

        m_normalDamageTrans = null;
        m_buffDamageTrans   = null;

        if (m_renderGuardMesh)
        {
            Destroy(m_renderGuardMesh);
        }
        m_renderGuardMesh = null;
    }
예제 #2
0
    private void UpdateWeaponEffects(GameObject w, WeaponInfo.Weapon wi, WeaponInfo.SingleWeapon sw)
    {
        var effs = m_weaponEffects.GetDefault(w.GetInstanceID());
        var es   = Util.ParseString <string>(sw.effects);

        foreach (var e in es)
        {
            var eff = Level.GetPreloadObjectFromPool(e);
            if (!eff)
            {
                Logger.LogError("Could not load weapon effect [{0}] in weapon [{1}:{2}]", e, wi.weaponID, sw.index);
            }
            else
            {
                var i = eff.GetComponent <EffectInvertHelper>();
                if (!i)
                {
                    Logger.LogError("Invalid weapon effect [{0}] in weapon [{1}:{2}]", e, wi.weaponID, sw.index);
                    Level.BackEffect(eff);
                    continue;
                }

                eff.name = e;
                eff.SetActive(true);

                var ad = GetComponent <AutoDestroy>();
                if (ad)
                {
                    ad.enabled = false;
                }

                effs.Add(i);
                Util.AddChild(w.transform, eff.transform);
            }
        }
    }
예제 #3
0
    private bool UpdateWeaponModel(bool off)
    {
        var weaponID = off ? m_creature.offWeaponID : m_creature.weaponID;
        var itemId   = off ? m_creature.offWeaponItemID : m_creature.weaponItemID;

        var weapon = WeaponInfo.GetWeapon(weaponID, itemId);

        if (!off && weapon.isEmpty && weaponID < Creature.MAX_WEAPON_ID) // Only main weapon need error log
        {
            Logger.LogError("Could not find weapon config [{0}:{1}]", weaponID, itemId);
            return(false);
        }

        if (off)
        {
            m_offWeaponInfo = weapon;
        }
        else
        {
            m_weaponInfo = weapon;
        }

        var ws = off ? m_offWeapons : m_mainWeapons;

        foreach (var w in ws)
        {
            w.Value?.transform.SetParent(m_weapon, false);
            m_weapons.Remove(w.Value);
        }
        ws.Clear();

        Util.DisableAllChildren(m_weapon);

        var sws = weapon.singleWeapons;

        if (sws.Length < 1)
        {
            return(true);
        }

        var visible = !m_creature.currentState || !off || m_creature.currentState.showOffWeapon;

        foreach (var sw in sws)
        {
            if (string.IsNullOrEmpty(sw.model))
            {
                Logger.LogError("Invalid weapon config [weapon:{0}, itemID:{1}, index:{2}, name:{3}]", weapon.weaponID, weapon.weaponItemId, sw.index, weapon.name);
                continue;
            }

            var t = m_weapon.Find(sw.model);
            var w = t?.gameObject;

            if (!w)
            {
                w = Level.GetPreloadObject(sw.model);
                if (!w)
                {
                    Logger.LogError("Could not load weapon model [{0}]", sw.model);
                }
                else
                {
                    w.name = sw.model;
                    UpdateWeaponEffects(w, weapon, sw);
                }
            }

            if (w)
            {
                w.SetActive(visible);
                Util.AddChild(m_weapon, w.transform);

                ws.Set(sw.index, w);
                m_weapons.Add(w);
            }
        }

        if (off)
        {
            var sm = ConfigManager.Get <StateMachineInfoOff>(1);
            if (sm)
            {
                SetWeaponBind(sm.defaultWeaponBinds, true);
            }
        }
        else if (m_creature.currentState)
        {
            SetWeaponBind(m_creature.currentState.bindInfo);
        }

        Logger.LogInfo("{2}eapon changed to [{0}: {3}:{1}]", weapon.weaponID, weapon.weaponItemId, off ? "Off W" : "W", weapon.name);

        return(true);
    }