Beispiel #1
0
    public void OnAgentInfo(NetworkMessage netMsg)
    {
        MObjects.AgentInfo mObject = netMsg.ReadMessage <MObjects.AgentInfo>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null) // Create the agent.
        {
            ma = CreateAgent(mObject);
        }
        else if (mObject.clientPrefab != ma.clientPrefab)
        {
            Destroy(ma.gameObject);
            ma = CreateAgent(mObject);
        }

        ma.moveSpeed = mObject.moveSpeed;
    }
Beispiel #2
0
    public void AgentInfo()
    {
        int sC = skills.Length;

        MObjects.AgentInfo mObject = new MObjects.AgentInfo();
        mObject.alias        = alias;
        mObject.clientPrefab = heroId;
        mObject.skills       = new string[sC];
        mObject.moveSpeed    = moveSpeed;

        for (int i = 0; i < sC; i++)
        {
            mObject.skills[i] = skills[i].clientPrefab;
        }

        mObject.id = (user != null) ? user.connectionId: customId;

        sC = session.users.Count;

        mObject.team = team;

        for (int i = 0; i < sC; i++)
        {
            if (NetworkServer.connections.Contains(session.users[i]))
            {
                mObject.isController = (session.users[i].connectionId == mObject.id);
                // send the mobject
                NetworkServer.SendToClient(session.users[i].connectionId, MTypes.AgentInfo, mObject);
            }
        }

        agentLevel.LevelInfo(); // Update user levels

        if (maxHealth == 0)     // health is not assigned yet
        {
            maxHealth = _hero.health;
            health    = maxHealth;
        }
        else
        {
            health = _health;  // Otherwise update user healths for other clients
        }
    }
Beispiel #3
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);
    }