Exemple #1
0
        public ViewObject CreateViewObject(ViewObjectCreateArgs args)
        {
            ViewObject viewObject = new ViewObject(args.LinkedGameObject.UniqueIdentifier, args.LinkedGameObject.ObjectType, args.LinkedGameObject.IsLocalPlayer, args.LinkedGameObject.PlayerLinkedId);

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

            foreach (var component in components)
            {
                DeusViewComponent tmpComponent = null;
                switch (component.ComponentType)
                {
                case EComponentType.HealthComponent:
                    tmpComponent = new HealthViewComponent(component, component.UniqueIdentifier, args.LinkedGameObject.UniqueIdentifier);
                    break;

                case EComponentType.PositionComponent:
                    break;

                default:
                    break;
                }
                if (tmpComponent != null)
                {
                    viewObject.AddComponent(tmpComponent);
                }
            }

            return(viewObject);
        }
Exemple #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);
    }