Пример #1
0
    // Use this for initialization
    void Start()
    {
        selectedGameObject.SubscribeToText(SelectedObjectText, go => go == null ? "No Object Selected" : go.name);
        selectedGameObject.SetValueAndForceNotify(null);


        TapStream().Subscribe(p =>
        {
            RaycastHit hit;
            GameObject go = null;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(p), out hit))
            {
                go = hit.collider.gameObject;
            }

            selectedGameObject.Value = go;
        });
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        LeftClicks().Subscribe(p =>
        {
            RaycastHit hit;
            GameObject go = null;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(p), out hit, unitLayer))
            {
                go = hit.collider.gameObject;
            }

            _selectedObject.Value = go ? go.GetComponent <Controllable>() : null;
        });


        // TODO, do i want to split this up into some wheres??
        RightClicks().Where(_ => _selectedObject.Value != null).Subscribe(p =>
        {
            RaycastHit hit;
            GameObject go = null;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(p), out hit))
            {
                go = hit.collider.gameObject;
                if (go.GetComponent <Targetable>())
                {
                    if (go != this.gameObject)
                    {
                        _selectedObject.Value.CommandStream.SetValueAndForceNotify(new AttackTargetCommand(go));
                    }
                    //what should we do when someone right clicks on themself?  Stop?
                }
                else
                {
                    _selectedObject.Value.CommandStream.SetValueAndForceNotify(new MoveToCommand(hit.point));
                }
            }
        });

        _selectedObject.SubscribeToText(selectedText, c => c ? c.name : "No Unit Selected");

        //selectedObject.Where(c => c != null && c.GetComponent<DamageManager>()).Select(c => c.GetComponent<DamageManager>()).Select(dm => dm.HitPointStream).SubscribeToText(selectedUnitHealthText, hp => "Health: " + hp);

        _selectedObject.Subscribe(c => SubscribeToSelectedObjectComponents(c));
    }