示例#1
0
    private static UnitAI MakeAI(ScriptableUnitConfig data, int group, GameObject base_unit, Unit m_unit)
    {
        UnitAI ai = m_unit.gameObject.AddComponent <UnitAI>();

        ai.group_id = group;

        return(ai);
    }
示例#2
0
    public static void GiveWeapon(ScriptableUnitConfig data, GameObject unit_mesh, UnitInventory inventory)
    {
        Weapon weapon = SpawnWeaponToUnit(unit_mesh, data.Weapon);


        weapon.transform.SetParent(unit_mesh.transform);

        inventory.AddItem(weapon, 1);
    }
示例#3
0
    static UnitStats MakeStats(GameObject target, ScriptableUnitConfig conf, Unit_EffectManager effects, M_Math.R_Range range)
    {
        UnitStats stats = target.AddComponent <UnitStats>();

        conf.BaseStats.StartTurnTime = range;

        stats.Init(StatsHelper.GetStatListForInit(conf.BaseStats), effects);

        return(stats);
    }
示例#4
0
    private static UnitInventory MakeInventory(ScriptableUnitConfig data, GameObject base_unit, UnitStats stats)
    {
        UnitInventory inventory = base_unit.AddComponent <UnitInventory>();

        inventory.Init(stats, data.BaseStats);



        return(inventory);
    }
示例#5
0
    private static void GetName(ScriptableUnitConfig data, GameObject base_unit)
    {
        string name = data.MeshConfig.Names.GetName();

        if (string.IsNullOrEmpty(name))
        {
            name = "UNKOWN " + Random.Range(0, 100);
        }

        base_unit.name = name;
    }
示例#6
0
    public void SpawnUnit(ScriptableUnitConfig unit_config, M_Math.R_Range range, int group, bool hide_player)
    {
        Unit u = UnitFactory.CreateUnit(unit_config, group, range, hide_player);

        if (u != null)
        {
            UnitFactory.SpawnUnit(u, GetComponent <Tile>());
        }
        else
        {
            Debug.LogWarning("Could not spawn unit");
        }
    }
示例#7
0
    void OnUpdate(List <TieredUnit> selected)
    {
        for (int i = 0; i < getHighestSlotCount(); i++)
        {
            ScriptableUnitConfig unit = null;

            if (i < selected.Count)
            {
                unit = TieredUnit.Unlocks(selected[i].Tiers, PlayerLevel.Instance).GetHighestUnlocked().Config;
            }
            Slots[i].SetUnit(unit);
        }
        UpdateTF();
    }
示例#8
0
    public void Init(Unit _target, ScriptableUnitConfig config)
    {
        target = _target;

        Behavior = config.BlipBehavior;
        Blip     = Resources.Load("Units/unit_blip").Instantiate(this.transform, true);

        Blip.SetActive(Behavior == BlipBehaviour.always);

        if (Behavior == BlipBehaviour.on_action)
        {
            target.Actions.OnActionStarted  += CheckTurn;
            target.Actions.OnActionComplete += CheckTurn;
        }

        target.OnIdentify += OnIdentify;
    }
示例#9
0
    private static GameObject MakeMesh(ScriptableUnitConfig data, Unit base_unit)
    {
        GameObject mesh = Instantiate(Resources.Load("Units/playermodel")) as GameObject;

        HeadData head = data.MeshConfig.HeadConfig.GetHead();

        base_unit.SetSprite(head.UI_Texture, data.UnidentfiedSprite);

        SpawnSkinnedMeshToUnit(mesh, head.Mesh, data.MeshConfig.Suit);

        mesh.transform.SetParent(base_unit.transform, false);
        mesh.transform.localPosition = Vector3.zero;
        mesh.transform.localScale    = Vector3.one;
        mesh.name = "playermodel";


        return(mesh);
    }
示例#10
0
    private static void InitIdentified(ScriptableUnitConfig data, Unit unit, bool hide_player)
    {
        if (data.Owner == 0 && !hide_player)
        {
            unit.Identify(null);
        }
        else
        {
            GameObject trigger = Instantiate(Resources.Load("unit_trigger")) as GameObject;

            trigger.transform.SetParent(unit.transform, true);
            trigger.transform.localPosition = Vector3.zero;

            trigger.GetComponent <UnitTrigger>().SetTarget(unit);
            trigger.GetComponent <BoxCollider>().size = new Vector3(1 + 2 * data.TriggerRange, 1 + 2 * data.TriggerRange, 1 + 2 * data.TriggerRange);

            unit.gameObject.AddComponent <UnitShowBlip>().Init(unit, data);
        }
    }
示例#11
0
    public void ShowUnit(ScriptableUnitConfig conf)
    {
        if (m_config != null && conf == m_config)
        {
            InfoPopup.SetActive(false);
            m_config = null;
            return;
        }

        m_config = conf;
        InfoPopup.SetActive(true);
        Portrait.sprite = conf.MeshConfig.HeadConfig.Heads[0].UI_Texture;
        Name.text       = conf.ID;

        ATK1.SetAttack(conf.Weapon.Behaviors[0]);

        if (conf.Weapon.Behaviors.Count > 1)
        {
            ATK2.gameObject.SetActive(true);
            ATK2.SetAttack(conf.Weapon.Behaviors[1]);
        }
        else
        {
            ATK2.gameObject.SetActive(false);
        }

        if (conf.Weapon.Behaviors.Count > 2)
        {
            ATK3.gameObject.SetActive(true);
            ATK3.SetAttack(conf.Weapon.Behaviors[2]);
        }
        else
        {
            ATK3.gameObject.SetActive(false);
        }
    }
示例#12
0
 public void Set(ScriptableUnitConfig c)
 {
     TF.text         = c.ID;
     Portrait.sprite = c.MeshConfig.HeadConfig.Heads[0].UI_Texture;
 }
示例#13
0
 public void SetUnit(ScriptableUnitConfig unit)
 {
     m_config = unit;
     setState();
 }
示例#14
0
    UI_UnitMiniView MakeView(ScriptableUnitConfig config, Transform target)
    {
        UI_UnitMiniView view = UI_UnitMiniView.MakeView(config, FrameColor, target);

        return(view);
    }
示例#15
0
 private static ActionManager MakeActions(ScriptableUnitConfig data, GameObject base_unit)
 {
     UnitActionBase[] Actions = M_Math.SpawnFromList(data.Actions.ToList()).ToArray();
     M_Math.SetListAsChild(Actions.ToList(), base_unit.transform);
     return(base_unit.AddComponent <ActionManager>());
 }
示例#16
0
    /// <summary>
    /// Returns the instance of a unit
    /// </summary>
    /// <param name="data">Unit Config to determine unit type, stats, actions</param>
    /// <returns></returns>
    public static Unit CreateUnit(ScriptableUnitConfig data, int group, M_Math.R_Range initiative_range, bool hide_player)
    {
        if (data == null)
        {
            Debug.LogWarning("cant create unit, data == null");
            return(null);
        }
        MDebug.Log("^unitCreating Unit " + data.ID);
        GameObject         base_unit      = Instantiate(Resources.Load("base_unit")) as GameObject;
        SpawnLootOnDeath   loot           = base_unit.AddComponent <SpawnLootOnDeath>();
        Unit_EffectManager effect_manager = base_unit.AddComponent <Unit_EffectManager>();
        UnitStats          stats          = MakeStats(base_unit, data, effect_manager, initiative_range);
        UnitInventory      inventory      = MakeInventory(data, base_unit, stats);
        ActionManager      actions        = MakeActions(data, base_unit);


        UnitAdrenalineRushParticleManager adr_particles = base_unit.GetComponent <UnitAdrenalineRushParticleManager>();

        Unit                    m_unit          = base_unit.AddComponent <Unit>();
        GameObject              mesh            = MakeMesh(data, m_unit);
        Unit_UnitDeath          unit_death      = base_unit.AddComponent <Unit_UnitDeath>();
        Unit_UnitEvacuation     unit_evac       = base_unit.AddComponent <Unit_UnitEvacuation>();
        UnitAnimationController animations      = mesh.AddComponent <UnitAnimationController>();
        Unit_SoundController    sound           = base_unit.AddComponent <Unit_SoundController>();
        UnitRotationController  rotator         = base_unit.AddComponent <UnitRotationController>();
        SpeechManager_Unit      speech_mananger = base_unit.AddComponent <SpeechManager_Unit>();

        m_unit.OwnerID = data.Owner;
        m_unit.Config  = data;

        UI_Unit.CreateUnitUI(m_unit);


        sound.Init(m_unit);
        unit_evac.Init(m_unit);
        adr_particles.Init(stats);
        AddActiveTurnIndicator(m_unit, data.Owner == 0);
        GetName(data, base_unit);
        GiveWeapon(data, mesh, inventory);


        loot.Init(m_unit, data.LootCategory);
        effect_manager.SetUnit(m_unit);
        animations.Init(m_unit, mesh);



        speech_mananger.Init(data.SpeechConfig, m_unit);


        if (data.Owner == 1)
        {
            UnitAI ai = MakeAI(data, group, base_unit, m_unit);
            rotator.Init(m_unit.GetComponent <WaypointMover>(), ai.GetLookRotation);

            ai.OnPreferredTargetChange += unit => new TurnEventQueue.AIAggroEvent(ai, unit);
        }
        else
        {
            rotator.Init(m_unit.GetComponent <WaypointMover>(), delegate     { return(m_unit.transform.position + m_unit.transform.forward); });
        }
        //set mesh inactive
        mesh.gameObject.GetComponentsInChildren <Renderer>().ToList().ForEach(rend => rend.enabled = false);
        //and then identify
        InitIdentified(data, m_unit, hide_player);


        return(m_unit);
    }