示例#1
0
        public override void InitComponent(WGMObject obj)
        {
            base.InitComponent(obj);

            _util = new Util(gameObject);
            // tap handler
            _handlers[GType.Tap] = () => {
                _gesture.SetTappable();
                _gesture.OnTapListeners += pos => TryBroadcastEvent(_evTap);
            };
            // drag handler
            // TODO: might want to revamp the events e.g. send the cur pos too ?
            _handlers[GType.Drag] = () => {
                _gesture.SetDraggable();
                _gesture.OnStartSwipeListeners += ed => TryBroadcastEvent(_evStartDrag);
                _gesture.OnSwipingListeners    += ed => {
                    _util.SetFromScreenPos(ed.Pos);
                    TryBroadcastEvent(_evDragging);
                };
                _gesture.OnEndSwipeListeners += ed => TryBroadcastEvent(_evEndDrag);
            };
            // init the gesture handler
            _gesture = new CGestureHandler(gameObject);
            // iterate over the given types and attach the gesture handler accordingly.
            _gestureTypes.ForEach(g => {
                if (_handlers.ContainsKey(g))
                {
                    _handlers[g]();
                    // make sure gesture type only be added once for each of them.
                    _handlers.Remove(g);
                }
            });
        }
示例#2
0
        public override void InitComponent(WGMObject obj)
        {
            base.InitComponent(obj);

            Object.Observable.Subscribe(ev => {
                ReceiverEv r;
                if (ev.Matches(this, _triggers, out r))
                {
                    TryBroadcastEvent(r.data);
                }
            });
        }
示例#3
0
        public override void InitComponent(WGMObject obj)
        {
            base.InitComponent(obj);

            _handlers[Show]   = g => true;
            _handlers[Hide]   = g => false;
            _handlers[Toggle] = g => !g.activeSelf;

            obj.Observable.Subscribe(ev => {
                ReceiverEv ae = null;
                if (ev.Matches(this, _triggers, out ae))
                {
                    bool visible;
                    if (ProcessData(ae.data, out visible))
                    {
                        gameObject.SetActive(visible);
                        // broadcast the visibility state.
                        // indicating that the event given has been triggered
                        TryBroadcastEvent(visible ? Show : Hide);
                    }
                }
            });
        }
示例#4
0
 public virtual void InitComponent(WGMObject obj)
 {
     Object = obj;
 }
示例#5
0
        public override void InitComponent(WGMObject obj)
        {
            base.InitComponent(obj);

            // iterate over the children...
            // dont include the children that have another WGMTween too.
            List <GameObject> children = new List <GameObject>();

            gameObject.IterateSelfAndChildren(go => {
                bool stopIteration = !go.Same(gameObject) && go.HasComponent <WGMTween>();
                if (stopIteration)
                {
                    return(false);
                }

                children.Add(go);
                return(true);
            });
            // add the children object that has tweens to our container
            _tweener = new CTweenChainer();
            _tweener.Add(children.ToArray());
            // cache the sfx manager
            _sfx = obj.Engine.GetSystem <AudioSystem>().GetManager <SfxManager>();

            obj.Observable.Subscribe(ev => {
                TweenEv te;
                if (ev.Matches(this, _triggers, out te))
                {
                    TryPlaySound(te.startSound);
                    TryBroadcastEvent(te.startEv);

                    _tweener.FastForward();

                    if (te.stop)
                    {
                        // when data is empty, stop all
                        // otherwise iterate over the list data and stop them
                        if (te.data.IsEmpty())
                        {
                            _tweener.Stop();
                        }
                        else
                        {
                            te.data.ForEach(d => {
                                _tweener.StopTween(d);
                            });
                        }
                    }
                    else
                    {
                        // stop first if still playing;
                        if (_tweener.IsPlaying)
                        {
                            _tweener.Stop();
                        }

                        _tweener.PlayExistingTween(
                            te.data,
                            () => {
                            TryPlaySound(te.doneSound);
                            TryBroadcastEvent(te.doneEv);
                        }
                            );
                    }
                }
            });
        }