NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using UnityEngine;
using System.Collections;
using com.boombitgames.Gameplay;
using com.boombitgames.Shared;
using Extensions;
using Sirenix.OdinInspector;
using UI;

public class ButtonObserver : MonoBehaviour
{
public bool IsCurrentlyAnyButtonInButtonDownButtonUpStayState
{
get { return objectTappedOnMouseDown != null; }

}

[ShowInInspector, ReadOnly] private string _lastTouchedCollider = "";

public int allowedLayer;
private bool isObserverBlocked = false;

public Camera curCamera;
private GameObject objectTappedOnMouseDown = null;

private AudioSource audioSource;

private static ButtonObserver instance;
public static ButtonObserver Instance {
get {
if (instance == null) {
instance = Refs.ButtonObserver;
if (instance == null) {
Debug.LogError ("ButtonObserver does not exist!!!" );
return null;
}
}
return instance;
}
}

void Start ()
{
//--- set up click ---//
audioSource = this.gameObject.AddComponent<AudioSource>();
AudioClip clickClip = Resources.Load("Sounds/click")as AudioClip;
audioSource.clip = clickClip;
//--- --- --- --- ---//

PluginManagerFacade.Instance.EnableAllTouchesEvent += HandleEnableAllTouchesEvent;
PluginManagerFacade.Instance.DisableAllTouchesEvent += HandleDisableAllTouchesEvent;
}

void PlayClickSound ()
{
if(GameplayAudioSystem.isSoundOn)
audioSource.Play();
}

void HandleDisableAllTouchesEvent ()
{
isObserverBlocked = true;
}

void HandleEnableAllTouchesEvent ()
{
isObserverBlocked = false;
}

public bool IsPadUsed { get { return (_isPadButtonDown || _isPadButtonUp); } }

public bool IsPadButtonDown { get {return _isPadButtonDown; } }
public bool IsPadButtonUp { get { return _isPadButtonUp; } }
public bool IsPadButtonHold { get { return _isPadButtonHold; } }

private bool _isPadButtonDown = false;
private bool _isPadButtonUp = false;
private bool _isPadButtonHold = false;

void Update ()
{
#if CHEATS_ENABLED
if (Opencoding.Console.DebugConsole.IsVisible)
{
return;
}
#endif

if(isObserverBlocked)
return;

if (Input.touchCount > 1)
return;

bool inputControllerExists = Systems.Exists<InputController>();

_isPadButtonDown = inputControllerExists && InputController.Instance.GetButtonDownForCurrentController(KeyFunction.Select);
_isPadButtonUp = inputControllerExists &&InputController.Instance.GetButtonUpForCurrentController(KeyFunction.Select);


bool isMouseButtonDown = Input.GetMouseButtonDown(0);
bool isMouseButtonHold = Input.GetMouseButton(0);
bool isMouseButtonUp = Input.GetMouseButtonUp (0);


if (isMouseButtonDown || isMouseButtonUp )
{
InputController.LastInputType = IsPadUsed ? InputType.Gamepad : Input.touchCount == 0 ? InputType.Mouse : InputType.Touch;

Vector2 mPos = Input.mousePosition;

Vector2 mousePosition = IsPadUsed ? inputControllerExists ? InputController.Instance.LastPointerPos : Vector2.zero : mPos;
RaycastHit hit;
Ray ray = curCamera.ScreenPointToRay (mousePosition);
if (Physics.Raycast (ray))
{
RaycastHit[] rayHits = Physics.RaycastAll (ray);
if (rayHits.Length == 0)
{
if(objectTappedOnMouseDown != null)
{
var touchInputHandler = objectTappedOnMouseDown.GetComponent<ITouchInputHandler>();
if(touchInputHandler != null)
touchInputHandler.OnTouchUpOutside ();
objectTappedOnMouseDown = null;
}
return;
}

RaycastHit closest = rayHits [0];
foreach (RaycastHit hittt in rayHits)
{
// if (hittt.collider.transform.position.z < closest.collider.transform.position.z)
if (hittt.point.z < closest.point.z)
closest = hittt;
}

hit = closest;

#if UNITY_EDITOR
_lastTouchedCollider = hit.collider.gameObject.GetFullName();
#endif
if (hit.collider.gameObject.layer == allowedLayer)
{
if(isMouseButtonDown)
{
objectTappedOnMouseDown = hit.collider.gameObject;
var touchInputHandler = hit.collider.GetComponent<ITouchInputHandler>();
if(touchInputHandler!=null)
touchInputHandler.OnTouchUpOutside ();
}
if(isMouseButtonUp)
{
if(objectTappedOnMouseDown != null && objectTappedOnMouseDown == hit.collider.gameObject)
{
var touchInputHandler = hit.collider.GetComponent<ITouchInputHandler>();
if(touchInputHandler != null)
{
PlayClickSound();
touchInputHandler.OnTouchUpInside ();
}
}
else
{
ITouchInputHandler touchInputHandler = null;
if(objectTappedOnMouseDown != null)
touchInputHandler = objectTappedOnMouseDown.GetComponent<ITouchInputHandler>();
if(touchInputHandler!=null)
touchInputHandler.OnTouchUpOutside ();
}
objectTappedOnMouseDown = null;
}
//added to disable button tapped if mouse during whole action goes out of the button
if(isMouseButtonHold)
{
if(objectTappedOnMouseDown != hit.collider.gameObject)
{
ITouchInputHandler touchInputHandler = null;
if(objectTappedOnMouseDown != null)
touchInputHandler = objectTappedOnMouseDown.GetComponent<ITouchInputHandler>();
if(touchInputHandler!=null)
touchInputHandler.OnTouchUpOutside ();
objectTappedOnMouseDown = null;
}
}
}
else
{
ITouchInputHandler touchInputHandler = null;
if(objectTappedOnMouseDown != null)
touchInputHandler = objectTappedOnMouseDown.GetComponent<ITouchInputHandler>();
if(touchInputHandler!=null)
touchInputHandler.OnTouchUpOutside ();
}
}
else
{
if(objectTappedOnMouseDown != null)
{
var touchInputHandler = objectTappedOnMouseDown.GetComponent<ITouchInputHandler>();
if(touchInputHandler != null)
touchInputHandler.OnTouchUpOutside ();
objectTappedOnMouseDown = null;
}
}
}

}

void OnDestry()
{
if(!PluginManagerFacade.IsNull)
{
PluginManagerFacade.Instance.EnableAllTouchesEvent -= HandleEnableAllTouchesEvent;
PluginManagerFacade.Instance.DisableAllTouchesEvent -= HandleDisableAllTouchesEvent;
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.