Exemplo n.º 1
0
    public SpriteCollection(Sprite[] sprites, Camera camera, AbstractTouchSensor sensor)
    {
        this.sprites = sprites;
        this.camera = camera;
        this.sensor = sensor;

        lastTouchedTimes = new float[sprites.Length];
    }
Exemplo n.º 2
0
    public SpriteCollection(Sprite[] sprites, Camera camera, AbstractTouchSensor sensor)
    {
        this.sprites = sprites;
        this.camera  = camera;
        this.sensor  = sensor;

        lastTouchedTimes = new float[sprites.Length];
    }
Exemplo n.º 3
0
 private GameObject detectObjectInteraction(AbstractTouchSensor sensor, Dictionary <GameObject, ActionResponsePair[]> interactions)
 {
     foreach (var gameObject in interactions.Keys
              .Where((gameObject) => gameObject != null))
     {
         if (sensor.insideSprite(Camera.main, gameObject.GetComponent <Sprite>(), new[] { TouchPhase.Began }))
         {
             return(gameObject);
         }
     }
     return(null);
 }
    // Cycles through displaying a sequence of action-response pairs for each object that is touched.
    // Calls onComplete when it reaches the end of a cycle with the object for which the sequence was completed.
    public void hintWhenTouched(Action<GameObject> onComplete, AbstractTouchSensor sensor, float currentTime, Dictionary<GameObject, ActionResponsePair[]> interactions)
    {
        //if (!sensor.hasTaps()) return; // only act on touches

        // if there was an interaction but a dialog has not shown yet...
        if (currentTime <= actionPrintedAt + promptTime && touchedObject != null) {
            // ignore a tap if it's been at least a half second since prompting
            if (sensor.hasTaps() && currentTime > actionPrintedAt + 0.5f) {
                return;
            }
            // ignore touches of the same object before the first dialog is shown
            if (touchedObject != null && sensor.insideSprite(Camera.main, touchedObject.GetComponent<Sprite>(), TouchSensor.allPhases)) {
                return;
            }
        }

        // if a dialog was just shown, let it sit there for a moment
        if (currentTime <= actionPrintedAt + promptTime + 0.5f) {
            return;
        }

        // cycle through remaining dialogs
        if (remainingMessages.Count > 0) {
            if (sensor.hasTaps()) {
                messageBox.setMessage(remainingMessages[0]);
                remainingMessages.RemoveAt(0);
                actionPrintedAt = currentTime - promptTime;
            }
            return;
        }

        // start an action-dialog sequence if they touched an interactive object

        touchedObject = detectObjectInteraction(sensor, interactions);

        if (touchedObject == null) return;

        var message = interactions[touchedObject][0];
        var action = message.action;
        var responses = message.responses;
        actionPrintedAt = currentTime;
        print(action, responses[0]);

        var restOfresponses = new List<string>(responses).Skip(1).ToList();
        hint(action, restOfresponses);

        if (interactions[touchedObject].Length > 1) {
            interactions[touchedObject] = interactions[touchedObject].Skip(1).ToArray();
        } else {
            target = touchedObject;
            this.onComplete = onComplete;
        }
    }
Exemplo n.º 5
0
 public static bool belowFinger(this Sprite obj, AbstractTouchSensor sensor)
 {
     return(sensor.insideSprite(Camera.main, obj, new[] { TouchPhase.Began, TouchPhase.Moved, TouchPhase.Stationary }));
 }
Exemplo n.º 6
0
    // Cycles through displaying a sequence of action-response pairs for each object that is touched.
    // Calls onComplete when it reaches the end of a cycle with the object for which the sequence was completed.
    public void hintWhenTouched(Action <GameObject> onComplete, AbstractTouchSensor sensor, float currentTime, Dictionary <GameObject, ActionResponsePair[]> interactions)
    {
        //if (!sensor.hasTaps()) return; // only act on touches

        // if there was an interaction but a dialog has not shown yet...
        if (currentTime <= actionPrintedAt + promptTime && touchedObject != null)
        {
            // ignore a tap if it's been at least a half second since prompting
            if (sensor.hasTaps() && currentTime > actionPrintedAt + 0.5f)
            {
                return;
            }
            // ignore touches of the same object before the first dialog is shown
            if (touchedObject != null && sensor.insideSprite(Camera.main, touchedObject.GetComponent <Sprite>(), TouchSensor.allPhases))
            {
                return;
            }
        }

        // if a dialog was just shown, let it sit there for a moment
        if (currentTime <= actionPrintedAt + promptTime + 0.5f)
        {
            return;
        }

        // cycle through remaining dialogs
        if (remainingMessages.Count > 0)
        {
            if (sensor.hasTaps())
            {
                messageBox.setMessage(remainingMessages[0]);
                remainingMessages.RemoveAt(0);
                actionPrintedAt = currentTime - promptTime;
            }
            return;
        }

        // start an action-dialog sequence if they touched an interactive object

        touchedObject = detectObjectInteraction(sensor, interactions);

        if (touchedObject == null)
        {
            return;
        }

        var message   = interactions[touchedObject][0];
        var action    = message.action;
        var responses = message.responses;

        actionPrintedAt = currentTime;
        print(action, responses[0]);

        var restOfresponses = new List <string>(responses).Skip(1).ToList();

        hint(action, restOfresponses);

        if (interactions[touchedObject].Length > 1)
        {
            interactions[touchedObject] = interactions[touchedObject].Skip(1).ToArray();
        }
        else
        {
            target          = touchedObject;
            this.onComplete = onComplete;
        }
    }
 private GameObject detectObjectInteraction(AbstractTouchSensor sensor, Dictionary<GameObject, ActionResponsePair[]> interactions)
 {
     foreach (var gameObject in interactions.Keys
             .Where((gameObject) => gameObject != null)) {
         if (sensor.insideSprite(Camera.main, gameObject.GetComponent<Sprite>(), new[] {TouchPhase.Began})) {
             return gameObject;
         }
     }
     return null;
 }
 public static bool belowFinger(this Sprite obj, AbstractTouchSensor sensor)
 {
     return sensor.insideSprite(Camera.main, obj, new[] {TouchPhase.Began, TouchPhase.Moved, TouchPhase.Stationary});
 }