Beispiel #1
0
    public MobileAgent CreateAgent(MObjects.AgentInfo mObject)
    {
        int         heroPrefab = heroes.FindIndex(x => x.name == mObject.clientPrefab);
        Transform   t          = Instantiate(heroes[heroPrefab]);
        MobileAgent ma         = t.gameObject.AddComponent <MobileAgent>();

        ma.id             = mObject.id;
        t.gameObject.name = ma.id.ToString();
        ma.clientPrefab   = mObject.clientPrefab;
        ma.alias          = mObject.alias;
        ma.team           = mObject.team;
        ma.isCreature     = (ma.team == 65535);

        ma.transform.position = (!ma.isCreature) ? CameraScript.sessionPosition - CameraScript.defaultOffsetToZero + new Vector3(0, 10, 0) : new Vector3(0, -5000, 0);

        ma.skills = mObject.skills;

        if (mObject.isController)
        {
            t.gameObject.AddComponent <AgentInput>();

            clientHeroId = heroPrefab;
            int cc = heroGrid.childCount;

            selectedHero.Find("selected").gameObject.SetActive(true);
            selectedHero.Find("Icon").GetComponent <Image>().sprite = heroGrid.Find(mObject.clientPrefab).Find("Icon").GetComponent <Image>().sprite;
            heroGrid.parent.gameObject.SetActive(false);

            for (int i = 0; i < cc; i++)
            {
                string sName = heroGrid.GetChild(i).name;
                heroGrid.GetChild(i).Find("selected").gameObject.SetActive(mObject.clientPrefab == sName);
            }

            heroKeyLine.currentStep = heroPrefab;
            heroKeyLine.Set();

            ma.isController  = true;
            MobileAgent.user = ma;
            panel_Loading.Open(false);

            // Clear skills panel
            int cCount = skillsHolder.childCount;
            for (int i = 0; i < cCount; i++)
            {
                Destroy(skillsHolder.GetChild(i).gameObject);
            }

            int sCount = ma.skills.Length;
            for (int i = 0; i < sCount; i++)
            {
                Transform s = Instantiate(skillItem, skillsHolder);
                s.name = i.ToString();
                s.Find("Icon").GetComponent <Image>().sprite = icons.Find(x => x.name == ma.skills[i]);

                if (KeyController.current.currentController != 3) // not for Touch
                {
                    KeyBinder kb = s.gameObject.AddComponent <KeyBinder>();
                    kb.targetPointer = s.gameObject;
                    kb.alwaysInit    = true;
                    kb.keyCodeOffset = new Vector3(-40, 0, 0);
                    kb.Init(KeyController.current.clientSkillKeys [i]);
                }
            }

            /*
             * THIS IS MY CONTROLLER LETS MAKE THIS FIRST AT MOBILE AGENT LIST
             * */

            MobileAgent.list.Insert(0, MobileAgent.list[MobileAgent.list.Count - 1]);
            MobileAgent.list.RemoveAt(MobileAgent.list.Count - 1);
        }

        /*
         * AGENT UI
         * */
        ma.panel = Instantiate((ma.isCreature) ? creatureCanvas : agentCanvas, canvas);
        ma.panel.SetSiblingIndex(0); // always behind from the main ui

        Color tColor = (ma.isCreature) ? creatureColor : teamColors[mObject.team];
        Text  alias  = ma.panel.Find("Text").GetComponent <Text>();

        alias.text  = mObject.alias;
        alias.color = tColor;

        ma.castingItem             = ma.panel.GetComponentInChildren <UICastingItem>(true);
        ma.castingItem.mobileAgent = ma;
        ma.health = ma.panel.GetComponentInChildren <Filler>(true);
        ma.health._image.color = tColor;

        ma.healthText = ma.panel.Find("healthText").GetComponent <Text>();

        ma.panel.GetComponent <UIFollowAgent>().target = t;
        ma.panel.GetComponent <UIVisibility>().Open();

        return(ma);
    }