コード例 #1
0
    private void ManageViewObjectUpdate(PacketUpdateViewObject packet)
    {
        GameObject objectToUpdate = m_viewObjects.FirstOrDefault(vo => vo.GetComponent <DeusObjectLinker>() && vo.GetComponent <DeusObjectLinker>().GetDeusObjectId() == packet.ObjectId);

        if (objectToUpdate)
        {
            DeusComponentLinker component = objectToUpdate.GetComponents <DeusComponentLinker>().FirstOrDefault(dcl => dcl.GetComponentId() == packet.ComponentId);
            if (component)
            {
                component.UpdateViewValue(packet.NewValue);
            }
        }
    }
コード例 #2
0
    public static GameObject CreateViewObject(ViewObjectCreateArgs args)
    {
        GameObject viewObj = null;

        /////////////////////////////////////////////////////////////
        // Instantiate the good prefab if needed
        switch (args.LinkedGameObject.ObjectType)
        {
        case EObjectType.Player:
            viewObj = Instantiate(instance.playerPrefab);
            viewObj.transform.parent = GameManager.GameObjectContainer.transform;

            if (args.LinkedGameObject.PlayerLinkedId > 0)
            {
                string      playerName = GameManager.PlayerInfos?.FirstOrDefault(pi => pi.Key == args.LinkedGameObject.PlayerLinkedId).Value ?? "";
                TextMeshPro text       = viewObj.transform.GetChild(0).GetChild(0).GetChild(1).GetComponent <TextMeshPro>();
                if (text)
                {
                    text.text = playerName;
                }
            }
            break;

        default:
            break;
        }

        /////////////////////////////////////////////////////////////
        // always create deusobjectlinker
        DeusObjectLinker goLinker = viewObj.AddComponent <DeusObjectLinker>();

        goLinker.Init(args.LinkedGameObject.UniqueIdentifier, args.LinkedGameObject.IsLocalPlayer);
        /////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////
        // Manage components
        List <IViewableComponent> components = args.LinkedGameObject.GetViewableGameComponents().ToList();

        uint idComponentPosition = 0;

        foreach (var component in components)
        {
            DeusComponentLinker linker = null;
            switch (component.ComponentType)
            {
            case EComponentType.HealthComponent:
                linker = viewObj.AddComponent <HealthComponentView>();
                linker.Init(component);
                break;

            case EComponentType.PositionComponent:
                linker = viewObj.AddComponent <PositionComponentView>();
                linker.Init(component);
                idComponentPosition = component.UniqueIdentifier;
                break;

            case EComponentType.SkillComponent:
                linker = viewObj.AddComponent <SkillComponentView>();
                linker.Init(component);
                break;

            default:
                throw new DeusException("Unknown component type. Did you forget to update your ViewObjectFactory ?");
            }
        }
        /////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////
        // Specific behavior if this is the local player
        if (goLinker.IsLocalPlayer())
        {
            PlayerInputHandler handlerInput = viewObj.AddComponent <PlayerInputHandler>();
            handlerInput.ObjectId            = goLinker.GetDeusObjectId();
            handlerInput.PositionComponentId = idComponentPosition;

            Renderer rend = viewObj.GetComponentInChildren <Renderer>();
            if (rend)
            {
                rend.material.color = Color.red;
            }

            Camera playerCam = viewObj.transform.GetChild(1).GetComponentInChildren <Camera>(true);
            if (playerCam)
            {
                playerCam.gameObject.SetActive(true);
                GameManager.EnableCamera(false);
                GameManager.SetPlayerCam(playerCam);
            }
        }
        /////////////////////////////////////////////////////////////

        return(viewObj);
    }