public override void SetupUsingApi(GameObject _interaction) { // Get the data and cast it string objectToGazeGUID = creationData[0].ToString(); bool gazeIn = (bool)creationData[1]; Gaze_GazeConstraints gazeConstraints = (Gaze_GazeConstraints)creationData[2]; // Get the conditions obj Gaze_Conditions conditions = _interaction.GetComponent <Gaze_Conditions>(); // Set al the necessary parameters conditions.gazeEnabled = true; conditions.gazeIn = gazeIn; constraints = gazeConstraints; conditions.gazeConstraintsIndex = (int)gazeConstraints; conditions.gazeStateIndex = gazeIn ? (int)Gaze_HoverStates.IN : (int)Gaze_HoverStates.OUT; if (gazeConstraints == Gaze_GazeConstraints.OBJECT) { Gaze_InteractiveObject io = SpatialStoriesAPI.GetInteractiveObjectWithGUID(objectToGazeGUID); conditions.gazeColliderIO = io; // Setup the gaze collider Setup(io.GetComponentInChildren <Gaze_Gaze>().GetComponent <Collider>()); } else { // Setup the gaze collider conditions.gazeColliderIO = conditions.RootIO; Setup(conditions.RootIO.GetComponentInChildren <Gaze_Gaze>().GetComponent <Collider>()); } }
public void AddProximityEntryToGroup(Gaze_InteractiveObject dependentObject) { Gaze_ProximityEntry p = new Gaze_ProximityEntry(); p.dependentGameObject = dependentObject; proximityEntries.Add(p); }
public void AddCollidingObject(Gaze_InteractiveObject g) { if (!collidingObjects.Contains(g)) { collidingObjects.Add(g); } }
void OnEnable() { rootIO = GetComponentInParent <Gaze_InteractiveObject>(); root = rootIO.gameObject; if (Application.isPlaying) { ActivateOnDependencyMap.OnEnable(this); DeactivateOnDependencyMap.OnEnable(this); foreach (Gaze_AbstractCondition conditions in allConditions) { conditions.Enable(); } Gaze_EventManager.OnTriggerStateEvent += OnTriggerStateEvent; Gaze_EventManager.OnTriggerEvent += OnTriggerEvent; Gaze_EventManager.OnCustomConditionEvent += OnCustomConditionEvent; Gaze_EventManager.OnIODestroyed += OnIODestroyed; if (customConditionsDico.Count != customConditions.Count) { foreach (Gaze_AbstractConditions condition in customConditions) { customConditionsDico.Add(condition.GetInstanceID(), false); } } } }
/// <summary> /// Check if both colliding objects are in the list. /// </summary> /// <returns>The colliding's (_other) index within list. /// If one of the object is not in the list, return -1</returns> /// <param name="_other">Other.</param> /// <param name="_sender">Sender.</param> private int IsCollidingObjectsInList(Gaze_InteractiveObject _other, Gaze_InteractiveObject _sender) { int found = 0; int foundSameGroup = 0; int otherIndex = -1; int tmpIndex = -1; int entryInGroupIndex = -1; // if there is EntryGroups in the ProximityMap if (gazeConditionsScript.proximityMap.proximityEntryGroupList.Count > 0) { // then we iterate through each one of them for (int i = 0; i < gazeConditionsScript.proximityMap.proximityEntryGroupList.Count; i++) { List <Gaze_ProximityEntry> groupList = gazeConditionsScript.proximityMap.proximityEntryGroupList[i].proximityEntries; for (int j = 0; j < groupList.Count; j++) { if (groupList[j].dependentGameObject.Equals(_other)) { // TODO : check if assigning tmpIndex to the index of the group is ok entryInGroupIndex = j; tmpIndex = -i - 2; found++; foundSameGroup++; } if (groupList[j].dependentGameObject.Equals(_sender)) { found++; foundSameGroup++; } // if sender and other are in the same group, invalidate the collision if (foundSameGroup == 2) { return(-1); } } } } for (int i = 0; i < gazeConditionsScript.proximityMap.proximityEntryList.Count; i++) { if (gazeConditionsScript.proximityMap.proximityEntryList[i].dependentGameObject.Equals(_other)) { tmpIndex = i; found++; } if (gazeConditionsScript.proximityMap.proximityEntryList[i].dependentGameObject.Equals(_sender)) { found++; } if (found == 2) { otherIndex = tmpIndex; this.entryInGroupIndex = entryInGroupIndex; break; } } return(otherIndex); }
public override void SetupUsingApi(GameObject _interaction) { // Get the data and cast it bool touchIO = (bool)creationData[1]; string touchObjGUID = string.Empty; if (touchIO) { touchObjGUID = creationData[0].ToString(); } // Get the conditions obj Gaze_Conditions conditions = _interaction.GetComponent <Gaze_Conditions>(); // Enable touch for the conditions conditions.arkitTouchEnabled = true; Gaze_InteractiveObject io = null; if (touchIO) { io = SpatialStoriesAPI.GetInteractiveObjectWithGUID(touchObjGUID); } // this condition has the touch options on the gaze conditions script some we need to set it there too conditions.arkitTouchOption = touchIO ? Gaze_Conditions.ARKIT_TOUCH_OPTIONS.Object : Gaze_Conditions.ARKIT_TOUCH_OPTIONS.Anywhere; // Setup the touch condition Setup(conditions, io, touchIO); }
public static void AddRigidBodyToIO(Gaze_InteractiveObject _IO) { if (_IO.GetComponent <Rigidbody>() == null) { _IO.gameObject.AddComponent <Rigidbody>(); SetGravity(_IO, true); } }
public void RemoveCollidingObjectToEntry(Gaze_ProximityEntry _entry, Gaze_InteractiveObject _collidingObject, bool displayCollidingObjects = false) { _entry.RemoveCollidingObject(_collidingObject); if (displayCollidingObjects) { _entry.DisplayCollidingObjects(); } }
private void GazeInputManagerOnOnObjectTouchUp(Gaze_InteractiveObject _io) { if (_io != IO) { return; } IsValid = false; }
private void GazeInputManagerOnOnObjectTouchedDown(Gaze_InteractiveObject _io) { if (_io != IO) { return; } IsValid = true; }
/// <summary> /// Gets the root IO of GazeActions /// </summary> /// <returns></returns> public Gaze_InteractiveObject GetIO() { Gaze_InteractiveObject io = GetComponentInParent <Gaze_InteractiveObject>(); if (io == null) { Debug.LogWarning("Interactive object could not be found"); } return(io); }
private void InitMembers() { gaze_InteractiveObjectScript = (Gaze_InteractiveObject)target; logo = (Texture)Resources.Load("SpatialStorires_Logo_256", typeof(Texture)); logoRect = new Rect(); logoRect.x = 10; logoRect.y = 10; dnd_dropTargetsNames = new List <string>(); dnd_targetMaterial = Resources.Load("DnD_TargetMaterial", typeof(Material)) as Material; }
public override void OnEnable() { base.OnEnable(); IO = GetIO(); visualsScript = IO.GetComponentInChildren <Gaze_InteractiveObjectVisuals>(); //Gaze_EventManager.OnGazeEvent += OnGazeEvent; if (loopAudio.Length < 5) { loopAudio = new LOOP_MODES[5]; } }
private static void ReturnToDefaultState(Gaze_InteractiveObject _IO) { if (_IO.IsGravityLocked()) { if (SHOW_GRAVITY_WARNINGS) { Debug.LogWarning(string.Format("GravityManager -> Interactive object: {0} has ben requested to change its gravity but the object is LOCKED", _IO.name)); } return; } else { _IO.ReturnToInitialGravityState(); } }
/// <summary> /// Sets the gravity of a game object and attach to it. /// </summary> /// <param name="_IO">The io where the changed where be performed</param> /// <param name="_hasGravity">True = Gravity and not kinematic, False = No Gravity and kinematic</param> private static void SetGravityAndAttachIO(Gaze_InteractiveObject _IO, bool _hasGravity) { if (_IO) { if (_IO.IsGravityLocked()) { if (SHOW_GRAVITY_WARNINGS) { Debug.LogWarning(string.Format("GravityManager -> Interactive object: {0} has ben requested to change its gravity but the object is LOCKED", _IO.name)); } return; } _IO.SetGravityAndAttach(_hasGravity); } }
public void Setup(Gaze_Conditions _gazeConditionsScript, Gaze_InteractiveObject _IO, bool _touchIO) { gazeConditionsScript = _gazeConditionsScript; touchIO = _touchIO; IO = _IO; if (touchIO) { Gaze_InputManager.OnObjectTouchedDown += GazeInputManagerOnOnObjectTouchedDown; Gaze_InputManager.OnObjectTouchUp += GazeInputManagerOnOnObjectTouchUp; } else { Gaze_InputManager.OnScreenTouched += OnScreenTouched; } }
private void CheckRaycastedObjects() { if (OnObjectTouchedDown == null) { return; } m_Touch.position = GetTouchPosition(); var screenPosition = S_ArUtilitiesManager.SelectedCamera.ScreenToViewportPoint(m_Touch.position); Ray ray = S_ArUtilitiesManager.SelectedCamera.ViewportPointToRay(screenPosition); // Raycast against the IOs layer LayerMask lm = 1 << 8; RaycastHit[] hits = Physics.RaycastAll(ray); foreach (RaycastHit hit in hits) { Gaze_InteractiveObject collider = hit.collider.GetComponentInParent <Gaze_InteractiveObject>(); if (collider != null) { // All the raycasted ios goes here m_CurrentRaycastedObjects.Add(collider); // The new ones are computed here (Those will be notified) if (!m_RaycastedGameobjects.Contains(collider)) { OnObjectTouchedDown(collider); } } } // We need to compute also the ones that are no longer raycasted Gaze_InteractiveObject io; for (int i = m_RaycastedGameobjects.Count - 1; i >= 0; --i) { io = m_RaycastedGameobjects[i]; if (!m_CurrentRaycastedObjects.Contains(io)) { OnObjectTouchUp(io); m_RaycastedGameobjects.RemoveAt(i); } } m_RaycastedGameobjects = new List <Gaze_InteractiveObject>(m_CurrentRaycastedObjects); m_CurrentRaycastedObjects.Clear(); }
/// <summary> /// Enables or disables visuals according with the user preferences. /// </summary> private void HandleColliders() { if (ActionColliders == ACTIVABLE_OPTION.NOTHING) { return; } Gaze_InteractiveObject io = GetIO(); Collider[] AllColliders = io.GetComponentsInChildren <Collider>(); bool isEnabled = ActionColliders == ACTIVABLE_OPTION.ACTIVATE; foreach (Collider collider in AllColliders) { collider.enabled = isEnabled; } }
/// <summary> /// Shows the alter gravity option and warns the user if he desn't have a rigidbody /// </summary> private void ShowGravityOption() { actionsScript.ActionGravity = (Gaze_Actions.ACTIVABLE_OPTION)EditorGUILayout.EnumPopup("Gravity:", actionsScript.ActionGravity); // Warn the user if he is trying to change the gravity of an IO that does not have a rigibody on the root if (actionsScript.ActionGravity != Gaze_Actions.ACTIVABLE_OPTION.NOTHING) { Gaze_InteractiveObject IO = actionsScript.GetIO(); if (IO.GetComponentInParent <Rigidbody>() == null) { if (GUILayout.Button("+ Add Rigidbody")) { Gaze_GravityManager.AddRigidBodyToIO(IO); } EditorGUILayout.HelpBox("No rigidbody found on " + IO.name, MessageType.Error); } } }
public static void ChangeGravityState(Gaze_InteractiveObject _IO, Gaze_GravityRequestType operation) { switch (operation) { case Gaze_GravityRequestType.ACTIVATE: SetGravity(_IO, true); break; case Gaze_GravityRequestType.DEACTIVATE: SetGravity(_IO, false); break; case Gaze_GravityRequestType.DEACTIVATE_AND_ATTACH: SetGravityAndAttachIO(_IO, false); break; case Gaze_GravityRequestType.ACTIVATE_AND_DETACH: SetGravityAndAttachIO(_IO, true); break; case Gaze_GravityRequestType.LOCK: _IO.LockGravity(); break; case Gaze_GravityRequestType.UNLOCK: _IO.UnlockGravity(); break; case Gaze_GravityRequestType.RETURN_TO_DEFAULT: ReturnToDefaultState(_IO); break; case Gaze_GravityRequestType.SET_AS_DEFAULT: SetActualGravityStateAsDefault(_IO); break; } }
private void Awake() { io = GetComponentInParent <Gaze_InteractiveObject>(); }
/// <summary> /// Checks the proximities conditions validity. /// </summary> /// <returns><c>true</c>, if proximities was checked, <c>false</c> otherwise.</returns> /// <param name="e">E.</param> private bool HandleProximity(Gaze_ProximityEventArgs e) { // get colliding objects Gaze_InteractiveObject sender = ((Gaze_InteractiveObject)e.Sender).GetComponentInChildren <Gaze_Proximity>().IOScript; Gaze_InteractiveObject other = ((Gaze_InteractiveObject)e.Other).GetComponentInChildren <Gaze_Proximity>().IOScript; // make sure the collision concerns two objects in the list of proximities (-1 if NOT) int otherIndex = IsCollidingObjectsInList(other, sender); // Debug.Log ("otherIndex = " + otherIndex); if (otherIndex != -1) { // OnEnter and tested only if validation is not already true (to avoid multiple collision to toggle the proximitiesValidated flag if (e.IsInProximity && !IsValid) { // update number of collision in the list occuring collisionsOccuringCount++; // if the sender is normal entry, add colliding object to it if (otherIndex > -1) { gazeConditionsScript.proximityMap.AddCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryList[otherIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } // if the sender is an entryGroup (then otherIndex starts at -2 and goes down instead of going up), add colliding object to the entry of the group that triggered the event else { gazeConditionsScript.proximityMap.AddCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryGroupList[-otherIndex - 2].proximityEntries[entryInGroupIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } if (gazeConditionsScript.proximityMap.proximityStateIndex.Equals((int)ProximityEventsAndStates.OnEnter) || gazeConditionsScript.proximityMap.proximityStateIndex.Equals((int)ProximityEventsAndStates.OnStay)) { // get number of valid entries int validatedEntriesCount = gazeConditionsScript.proximityMap.GetValidatedEntriesCount(); // OnEnter + RequireAll if (gazeConditionsScript.requireAllProximities) { return(validatedEntriesCount == gazeConditionsScript.proximityMap.proximityEntryList.Count + gazeConditionsScript.proximityMap.proximityEntryGroupList.Count); } // OnEnter + NOT RequireAll if (!gazeConditionsScript.requireAllProximities) { return(validatedEntriesCount >= 2); } } } // OnExit else if (!e.IsInProximity) { // update number of collision in the list occuring collisionsOccuringCount--; // update everyoneIsColliding tag before removing an element gazeConditionsScript.proximityMap.UpdateEveryoneColliding(); if (otherIndex > -1) { // // if the sender is normal entry, remove colliding object to it gazeConditionsScript.proximityMap.RemoveCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryList[otherIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } else { // if the sender is an entryGroup (then otherIndex starts at -2 and goes down instead of going up), remove colliding object to the entry of the group that triggered the event gazeConditionsScript.proximityMap.RemoveCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryGroupList[-otherIndex - 2].proximityEntries[entryInGroupIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } // if proximity condition is EXIT if (gazeConditionsScript.proximityMap.proximityStateIndex.Equals((int)ProximityEventsAndStates.OnExit)) { if (gazeConditionsScript.requireAllProximities) { // every entry was colliding before the exit if (gazeConditionsScript.proximityMap.IsEveryoneColliding) { IsValid = true; } else { IsValid = false; } // OnExit + NOT RequireAll } else { gazeConditionsScript.proximityMap.ResetEveryoneColliding(); IsValid = true; } // if proximity condition is ENTER } else { // if proximities was validated if (IsValid) { // and if require all if (gazeConditionsScript.requireAllProximities) { return(false); } else { // check there's a valid collision left in the list... if (collisionsOccuringCount > 0) { IsValid = true; } else { IsValid = false; } } } } } } return(IsValid); }
public void RemoveCollidingObject(Gaze_InteractiveObject g) { collidingObjects.Remove(g); }
private void UpdateProximitiesList(GameObject g) { Gaze_InteractiveObject proximity = g.GetComponentInChildrenBFS <Gaze_Proximity>().GetComponentInParent <Gaze_InteractiveObject>(); hierarchyProximities.Add(proximity); }
/// <summary> /// Initializes a new instance of the <see cref="Gaze_ProximityEventArgs"/> class. /// </summary> /// <param name="_sender">The GameObject that fires the event. The Interactive Object (Root)</param> /// <param name="_other">The colliding GameObject</param> /// <param name="_isInProximity">true means the camera entered the proximity zone, false means exits the zone</param> public Gaze_ProximityEventArgs(object _sender, Gaze_InteractiveObject _other, bool _isInProximity) { sender = _sender; other = _other; isInProximity = _isInProximity; }
private void Awake() { // otherwise the event is fired too early IOScript = GetComponentInParent <Gaze_InteractiveObject>(); }
/// <summary> /// Initializes a new instance of the <see cref="Gaze.Gaze_HandleEventArgs"/> class. /// </summary> /// <param name="_sender">Sender.</param> /// <param name="_isColliding">If set to <c>true</c> is colliding.</param> public Gaze_IODestroyEventArgs(object _sender, Gaze_InteractiveObject io) { Sender = _sender; IO = io; }
public Gaze_ARKitScreenTouchCondition(Gaze_Conditions _gazeConditionsScript, Gaze_InteractiveObject _IO, bool _touchIO) : base(_gazeConditionsScript) { Setup(_gazeConditionsScript, _IO, _touchIO); }