Exemple #1
0
    void UpdateUnit(Unit unit)
    {
        List <UnitQuirk> quirks = unit.parts.quirks;

        for (int i = 0; i < quirks.Count; i++)
        {
            UnitQuirk quirk = quirks[i];
            quirk.DoUpdate();
        }

        UpdateMovement(unit);
        UpdatePathing(unit);
        UpdateWeapon(unit);
    }
Exemple #2
0
    public void GetQuirks <T>(List <T> results) where T : UnitQuirk
    {
        for (int i = 0; i < allUnits.Count; i++)
        {
            Unit unit = allUnits[i];

            if (!unit.isActiveAndEnabled)
            {
                continue;
            }

            for (int z = 0; z < unit.parts.quirks.Count; z++)
            {
                UnitQuirk quirk = unit.parts.quirks[z];
                if (quirk.GetType() == typeof(T))
                {
                    results.Add((T)quirk);
                }
            }
        }
    }
    void RegisterInternal(Unit unit)
    {
        if (IsRegistered(unit))
        {
            return;
        }

        int id = ++idCounter;

        allUnits.Add(unit);
        idToUnit[id] = unit;

        unit.state.persistent.Reset();

        // TODO
        unit.GetComponents <UnitQuirk>(results: unit.parts.quirks);

        for (int i = 0; i < unit.parts.quirks.Count; ++i)
        {
            UnitQuirk quirk = unit.parts.quirks[i];
            quirk.Setup(unit);
        }
    }
    void UnregisterInternal(Unit unit)
    {
        if (!IsRegistered(unit))
        {
            return;
        }

        if (instance.onUnitWillUnregister != null)
        {
            instance.onUnitWillUnregister(unit);
        }

        AtWillUnregister(unit);

        // TODO
        for (int i = 0; i < unit.parts.quirks.Count; ++i)
        {
            UnitQuirk quirk = unit.parts.quirks[i];
            quirk.Shutdown();
        }

        allUnits.Remove(unit);
        idToUnit.Remove(unit.manState.id);
    }