/// <summary> /// Override OnCursorState change to set the correct object state for the cursor /// </summary> public override void OnCursorStateChange(CursorStateEnum state) { base.OnCursorStateChange(state); if (state != CursorStateEnum.Contextual) { //// First, try to find a cursor for the current state var newActive = new ObjectCursorDatum(); bool newStateCursorFound = cursorStatesDict.TryGetValue(state, out newActive); // if not found, just show the last active cursor object if (!newStateCursorFound) { return; } // hide the last active cursor if (lastActiveCursorObj != null) { lastActiveCursorObj.SetActive(false); } lastActiveCursorObj = newActive.CursorObject; newActive.CursorObject.SetActive(true); // cursorstate does NOT change if going from building => map (still observeHover) // targeted object is NOT updated until the state changes => use GazeManager.HitObject if (isDrawing) { GameObject hitObject = GazeManager.Instance.HitObject; if (hitObject != null) { if (hitObject.name == GameObjectNamesHolder.NAME_MAP_COLLIDER) { if (newActive.CursorState == CursorStateEnum.ObserveHover) { newActive.CursorObject.SetActive(false); } ShowPointCursor(); return; // note that this is return } else if (hitObject.name.Contains("Point")) { //This is for the first-drawn-point object HidePointCursor(); if (newActive.CursorState == CursorStateEnum.ObserveHover) { newActive.CursorObject.SetActive(false); } return; } } HidePointCursor(); } } }
/// <summary> /// Override OnCursorState change to set the correct animation /// state for the cursor /// </summary> /// <param name="state"></param> public override void OnCursorStateChange(CursorStateEnum state) { base.OnCursorStateChange(state); if (state != CursorStateEnum.Contextual) { // First, try to find a cursor for the current state var newActive = new ObjectCursorDatum(); for (int cursorIndex = 0; cursorIndex < CursorStateData.Length; cursorIndex++) { ObjectCursorDatum cursor = CursorStateData[cursorIndex]; if (cursor.CursorState == state) { newActive = cursor; break; } } // If no cursor for current state is found, let the last active cursor be // (any cursor is better than an invisible cursor) if (newActive.Name == null) { //return; } // If we come here, there is a cursor for the new state, // so de-activate a possible earlier active cursor for (int cursorIndex = 0; cursorIndex < CursorStateData.Length; cursorIndex++) { ObjectCursorDatum cursor = CursorStateData[cursorIndex]; if (cursor.CursorObject.activeSelf) { cursor.CursorObject.SetActive(false); break; } } // ... and set the cursor for the new state active. newActive.CursorObject.SetActive(true); } }
private void SetCursorWithName(string name) { var currentStateCursor = new ObjectCursorDatum(); foreach (var cursor in CursorStateData) { if (cursor.Name == name) { currentStateCursor = cursor; break; } } if (currentStateCursor.Name == null) { currentStateCursor = CursorStateData.FirstOrDefault(); if (default(ObjectCursorDatum).Equals(currentStateCursor)) { return; } } // De-activate all of base class cursor states. foreach (var cursor in CursorStateData) { if (cursor.CursorObject && cursor.CursorObject.activeSelf) { cursor.CursorObject.SetActive(false); break; } } // Activate newer cursor. currentStateCursor.CursorObject.SetActive(true); }