public void setSelectedZone(MotionMapZone zone) { if (zone == selectedZone) { return; } if (selectedZone != null) { if (autoDeselectOnNewSelection) { selectedZone.setSelected(false); } } selectedZone = zone; if (selectedZone != null) { selectedZone.setSelected(true); } OSCMessage m = new OSCMessage("/lastSelectedZone"); m.Append(selectedZone.id); OSCMaster.sendMessage(m); }
private static void AddInteractionZone() { GameObject zonePrefab = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Lib/MotionMap/Prefabs/Zone.prefab"); if (zonePrefab == null) { Debug.LogWarning("Zone prefab was not found"); return; } GameObject zone = (GameObject)PrefabUtility.InstantiatePrefab(zonePrefab); GameObject container = GameObject.Find("MotionMapRig/InteractiveZones"); GameObject sceneContainer = GameObject.Find("MotionMapRig/Scene"); if (container != null) { zone.transform.parent = container.transform; zone.layer = container.layer; MotionMapZone z = zone.GetComponent <MotionMapZone>(); GameObject[] objects = Selection.gameObjects; List <GameObject> objectsToAdd = new List <GameObject>(); Bounds bounds = new Bounds(); z.objects = new GameObject[objects.Length]; for (int i = 0; i < objects.Length; i++) { z.objects[i] = objects[i]; if (bounds.size == Vector3.zero) { bounds = GetMaxBounds(objects[i]); } else { bounds.Encapsulate(GetMaxBounds(objects[i])); } } z.transform.position = bounds.center; z.transform.localScale = bounds.size * 1.2f; } else { Debug.Log("InteractiveZones container not found"); } Selection.activeObject = zone; Undo.RegisterCreatedObjectUndo(zone, "Create Interactive Zone"); }
void Update() { foreach (MotionMapZone z in zones) { z.isOverInThisFrame = false; } foreach (MotionMapCursor mmc in clustersToRemove) { removeCursorForCluster(mmc); } foreach (Cluster c in clustersToAdd) { addCursorForCluster(c); } clustersToAdd.Clear(); clustersToRemove.Clear(); for (int i = 0; i < cursors.Count; i++) { Vector3 targetPos = Vector3.zero; Vector3 targetRot = Vector3.up; RaycastHit hit; if (Physics.Raycast(cursors[i].clusterCenter, cursors[i].clusterOrientation, out hit, 100, sceneLayer)) { MotionMapZone z = hit.collider.GetComponent <MotionMapZone>(); if (z != null) { z.isOverInThisFrame = true; } targetPos = new Vector3(hit.transform.position.x, 0.01f, hit.transform.position.z); targetRot = Vector3.up; } else if (Physics.Raycast(cursors[i].clusterCenter, cursors[i].clusterOrientation, out hit, 100.0f, plateauLayer)) { targetPos = hit.point + hit.normal * 0.01f; targetRot = hit.normal; } cursors[i].transform.DOLocalMove(targetPos, cursorSmoothing); //decal a bit to avoid mesh overlap cursors[i].transform.DOLocalRotate(targetRot, cursorSmoothing); } foreach (MotionMapZone z in zones) { z.setOver(z.isOverInThisFrame); if (z.over) { float curSelectTime = (Time.time - z.overStartTime) / selectionTime; z.setSelectionProgression(curSelectTime); if (curSelectTime >= 1) { setSelectedZone(z); } } else { z.setSelectionProgression(z.selectionProgression - Time.deltaTime / progressionDecayTime); } } if (Input.GetKeyDown(KeyCode.C)) { canvas.SetActive(!canvas.activeInHierarchy); } }