Exemple #1
0
    void Loaded()
    {
        Debug.Log("Loaded.");

        string[] classNames =
        {
            "rep_inf_ep2_rifleman",
            "rep_inf_ep2_rocketeer",
            "rep_inf_ep2_sniper",
            "rep_inf_ep2_engineer",
            "rep_inf_ep2_jettrooper",
            "rep_inf_ep3_rifleman",
            "rep_inf_ep3_rocketeer",
            "rep_inf_ep3_sniper",
            "rep_inf_ep3_sniper_felucia",
            "rep_inf_ep3_engineer",
            "rep_inf_ep3_officer",
            "rep_inf_ep3_jettrooper",
        };

        PhxRuntimeScene scene = PhxGameRuntime.GetScene();

        PhxClass[] classes = new PhxClass[classNames.Length];

        for (int i = 0; i < classes.Length; ++i)
        {
            classes[i] = scene.GetClass(classNames[i]);
            if (classes[i] == null)
            {
                Debug.LogError($"Cannot find class '{classNames[i]}'!");
                return;
            }
        }

        if (SpawnMobs)
        {
            Instances = new PhxSoldier[Width * Height];
            for (int x = 0; x < Width; ++x)
            {
                for (int y = 0; y < Height; ++y)
                {
                    Vector3 pos = new Vector3(x * -Padding, 0f, y * -Padding);
                    pos.x += Random.Range(-0.2f, 0.2f);
                    pos.z += Random.Range(-0.2f, 0.2f);

                    PhxClass spawnClass = classes[Random.Range(0, classes.Length)];

                    int idx = x + (Width * y);
                    Instances[idx] = MATCH.SpawnAI <PhxAnimTestController>(spawnClass, pos, Quaternion.identity);
                    Instances[idx].Fixate();
                }
            }
        }

        if (SpawnPlayer)
        {
            MATCH.SpawnPlayer(classes[5], transform.position, Quaternion.identity);
        }
    }
    void SetActive(PhxCharacterItem item, PhxClass cl, IPhxControlableInstance preview)
    {
        foreach (PhxCharacterItem it in Items)
        {
            it.SetActive(false);
        }
        item.SetActive(true);
        CurrentSelection = cl;

        foreach (PhxInstance inst in UnitPreviews)
        {
            inst.gameObject.SetActive(false);
        }
        preview.GetInstance().gameObject.SetActive(true);

        IPhxControlableInstance animPreview = preview as IPhxControlableInstance;

        if (animPreview != null)
        {
            animPreview.PlayIntroAnim();
        }
    }
    public void Add(PhxClass cl)
    {
        if (cl.ClassType != EEntityClassType.GameObjectClass)
        {
            Debug.LogError($"Cannot add odf class '{cl.Name}' as item to character selection!");
            return;
        }

        // CSP = Char Select Preview
        IPhxControlableInstance preview = RTS.CreateInstance(cl, cl.Name + "_CSP" + nameCounter++, Vector3.zero, Quaternion.identity, false, GAME.CharSelectTransform) as IPhxControlableInstance;

        preview.Fixate();
        UnitPreviews.Add(preview);

        PhxCharacterItem item = Instantiate(ItemPrefab, ListContents);

        item.OnClicked += () =>
        {
            SetActive(item, cl, preview);
        };

        item.SetHeaderText(cl.LocalizedName);

        string detailText = "";

        PhxSoldier.ClassProperties soldier = cl as PhxSoldier.ClassProperties;
        if (soldier != null)
        {
            foreach (Dictionary <string, IPhxPropRef> section in soldier.Weapons)
            {
                if (section.TryGetValue("WeaponName", out IPhxPropRef nameVal))
                {
                    PhxProp <string> weapName  = (PhxProp <string>)nameVal;
                    PhxClass         weapClass = RTS.GetClass(weapName);
                    if (weapClass != null)
                    {
                        PhxProp <int> medalProp = weapClass.P.Get <PhxProp <int> >("MedalsTypeToUnlock");
                        if (medalProp != null && medalProp != 0)
                        {
                            // Skip medal/award weapons for display
                            continue;
                        }
                        detailText += weapClass.LocalizedName + '\n';
                    }
                }
            }
            item.SetDetailText(detailText);
        }

        Items.Add(item);

        if (CurrentSelection == null)
        {
            SetActive(item, cl, preview);
        }
        else
        {
            item.SetActive(false);
            preview.GetInstance().gameObject.SetActive(false);
        }

        ReCalcItemSize();
    }