Esempio n. 1
0
 void Reset()
 {
     startTouch        = swipeDelta = Vector2.zero;
     dragStartSelected = null;
     isDraging         = false;
     isMultiTouching   = false;
 }
Esempio n. 2
0
    void RayCheck(Ray ray)
    {
        RaycastHit hit;

        // Create a particle if hit
        if (Physics.Raycast(ray, out hit, 50f, layerMask))
        {
            Debug.Log("Hit");
            AnchorAsset targetAnchor = hit.transform.gameObject.GetComponentInParent <AnchorAsset>();
            Debug.Log(targetAnchor);
            if (targetAnchor != null)
            {
                Debug.Log("Touched anchor asset");
                if (lastSelected != null)
                {
                    lastSelected.ExitSelection();
                    _uiManager.ExitSelectionMode();
                }
                if (lastSelected != targetAnchor)
                {
                    targetAnchor.EnterSelection();
                    _uiManager.EnterSelectionMode(targetAnchor.GetAsset());
                    lastSelected = targetAnchor;
                }
                else
                {
                    lastSelected = null;
                }
            }
        }
    }
Esempio n. 3
0
 public void DeleteCurrentAsset()
 {
     if (lastSelected != null)
     {
         lastSelected.Delete();
         lastSelected = null;
         Reset();
     }
 }
    private void DrawAnchorTrack(AnchorTrack track, int idx)
    {
        var          clips = track.GetClips();
        TimelineClip clip  = clips.FirstOrDefault();

        if (clip != null && clip.asset != null)
        {
            AnchorAsset asset = clip.asset as AnchorAsset;
            DrawAnchorAsset(asset, clip.start, clip.end, idx);
        }
    }
 private void DrawAnchorAsset(AnchorAsset asset, double start, double end, int idx)
 {
     FetchKeys(asset, start, end);
     if (sample_vtx != null)
     {
         Handles.color = gizColors[idx % 3];
         for (int i = 0; i < sample_cnt - 1; i++)
         {
             Handles.DrawLine(sample_vtx[i], sample_vtx[i + 1]);
         }
     }
 }
Esempio n. 6
0
    void RayCheck(Ray ray)
    {
        RaycastHit hit;

        // Create a particle if hit
        if (Physics.Raycast(ray, out hit, 50f, layerMask))
        {
            AnchorAsset targetAnchor = hit.transform.gameObject.GetComponentInParent <AnchorAsset>();
            if (targetAnchor != null)
            {
                targetAnchor.HandleClick();
            }
        }
    }
    private void FetchKeys(AnchorAsset asset, double start, double end)
    {
        double dur   = end - start;
        double delta = dur / sample_cnt;

        if (asset.IsValid())
        {
            for (int i = 0; i < sample_cnt; i++)
            {
                float time = (float)(start + delta * i);
                float x    = asset.clip_pos[0].Evaluate(time);
                float y    = asset.clip_pos[1].Evaluate(time);
                float z    = asset.clip_pos[2].Evaluate(time);
                sample_vtx[i] = new Vector3(x, y, z);
            }
        }
    }
Esempio n. 8
0
    public async Task <bool> SaveAnchors()
    {
        AnchorAsset[] anchorAssets = FindObjectsOfType <AnchorAsset>();
        Debug.Log("Found " + anchorAssets.Length + " anchors");
        List <Anchor> anchors = new List <Anchor>();

        for (int i = 0; i < anchorAssets.Length; i++)
        {
            AnchorAsset anchorAsset = anchorAssets[i];
            if (anchorAsset != null && anchorAsset.GetAnchor() != null)
            {
                try {
                    anchors.Add(new Anchor {
                        assetId = anchorAsset.GetAsset().assetId, anchorId = anchorAsset.GetAnchor().trackableId.ToString(), scale = anchorAsset.transform.localScale.x
                    });
                } catch (System.Exception) {
                    Debug.Log("ERROR IN ANCHOR SAVE");
                }
            }
        }
        AnchorPost anchorPost = new AnchorPost {
            anchors = anchors.ToArray()
        };
        string jsonPost = JsonUtility.ToJson(anchorPost);

        Debug.Log(jsonPost);
        using (UnityWebRequest req = new UnityWebRequest($"{Configuration.SERVER_URL}/api/anchors", "POST"))
        {
            byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonPost);
            req.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
            req.SetRequestHeader("Content-Type", "application/json");
            req.SendWebRequest();
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error} : {req.downloadHandler.text}");
                return(false);
            }

            while (!req.isDone)
            {
                await Task.Delay(100);
            }
            return(true);
        }
    }
Esempio n. 9
0
        public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
        {
            AnchorAsset asset = clip.asset as AnchorAsset;
            Rect        rect  = region.position;
            TrackAsset  track = clip.parentTrack;

            target = track as AnchorTrack;
            if (target != null)
            {
                target.RebuildClip();
            }
            if (asset != null)
            {
                var quantizedRect       = new Rect(Mathf.Ceil(rect.x), Mathf.Ceil(rect.y), Mathf.Ceil(rect.width), Mathf.Ceil(rect.height));
                AnimationCurve[] curves = asset.clip_pos;
                DrawCurve(rect, curves);
            }
        }
    private void DrawAnchors()
    {
        AnchorAsset asset = target as AnchorAsset;

        if (director == null)
        {
            director = GameObject.FindObjectOfType <PlayableDirector>();
        }
        var list = director.playableAsset.outputs;
        int idx  = 0;

        foreach (PlayableBinding pb in list)
        {
            if (pb.sourceObject is AnchorTrack)
            {
                AnchorTrack tack = pb.sourceObject as AnchorTrack;
                DrawAnchorTrack(tack, idx++);
            }
        }
    }
Esempio n. 11
0
    private void CreateClips()
    {
        if (signals != null && signals.Count > 0)
        {
            ClearCurves(ref m_curves_pos);
            ClearCurves(ref m_curves_rot);
            for (int i = 0; i < signals.Count; i++)
            {
                AnchorSignalEmitter sign = signals[i];
                float time = (float)sign.time;
                m_curves_pos[0].AddKey(time, sign.position.x);
                m_curves_pos[1].AddKey(time, sign.position.y);
                m_curves_pos[2].AddKey(time, sign.position.z);

                m_curves_rot[0].AddKey(time, sign.rotation.x);
                m_curves_rot[1].AddKey(time, sign.rotation.y);
                m_curves_rot[2].AddKey(time, sign.rotation.z);
            }
            var clips = GetClips();
            if (clips != null)
            {
                TimelineClip xclip = clips.FirstOrDefault();
                if (xclip == null)
                {
                    Debug.LogWarning("transform clip con't be null");
                }
                else
                {
                    AnchorAsset asset = xclip.asset as AnchorAsset;
                    asset.clip_pos = m_curves_pos;
                    asset.clip_rot = m_curves_rot;
                    BindObj(asset);
                }
            }
        }
    }
Esempio n. 12
0
    void CheckTouch()
    {
        if (Input.touchCount != 0)
        {
            if (Input.touchCount == 1)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    isDraging  = true;
                    startTouch = Input.GetTouch(0).position;

                    RaycastHit hit;
                    Ray        ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
                    if (Physics.Raycast(ray, out hit, 50f, layerMask))
                    {
                        AnchorAsset targetAnchor = hit.transform.gameObject.GetComponentInParent <AnchorAsset>();
                        if (targetAnchor != null)
                        {
                            dragStartSelected = targetAnchor;
                        }
                    }
                }
                else if (Input.GetTouch(0).phase == TouchPhase.Moved)
                {
                    if (!isMultiTouching && isDraging && lastSelected != null)
                    {
                        if (_raycastManager.Raycast(Input.GetTouch(0).position, s_Hits, TrackableType.PlaneEstimated))
                        {
                            Pose    hitPose     = s_Hits[0].pose;
                            Vector3 hitPosition = hitPose.position;

                            if (dragStartSelected == lastSelected)
                            {
                                dragStartSelected.transform.position = hitPosition;
                            }
                        }
                    }
                }
                else if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled)
                {
                    swipeDelta = Input.GetTouch(0).position - startTouch;
                    if (swipeDelta.magnitude > 25)
                    {
                        // swipe
                    }
                    else
                    {
                        if (!isMultiTouching)
                        {
                            Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
                            RayCheck(ray);
                        }
                    }

                    Reset();
                }
            }
            else if (Input.touchCount == 2)
            {
                isMultiTouching = true;
                // Store both touches.
                Touch touchZero = Input.GetTouch(0);
                Touch touchOne  = Input.GetTouch(1);

                // Find the position in the previous frame of each touch.
                Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

                // Find the magnitude of the vector (the distance) between the touches in each frame.
                float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

                // Find the difference in the distances between each frame.
                float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

                if (lastSelected != null)
                {
                    float min = 0.5f;
                    float max = 2.5f;

                    Vector3 newScale = lastSelected.transform.localScale + Vector3.one * -deltaMagnitudeDiff * 0.001f;
                    if (newScale.x > min && newScale.x < max)
                    {
                        lastSelected.transform.localScale = newScale;
                    }
                }

                Vector2 prevDir   = (touchZeroPrevPos - touchOnePrevPos).normalized;
                Vector2 latestDir = (touchZero.position - touchOne.position).normalized;

                float angle = Vector2.SignedAngle(prevDir, latestDir);

                if (lastSelected != null)
                {
                    lastSelected.transform.Rotate(Vector3.up, -angle * 0.5f);
                }
            }
        }
        swipeDelta = Vector2.zero;
    }
Esempio n. 13
0
    private void BindObj(AnchorAsset asset)
    {
        var track = parent as TrackAsset;

        asset.track = track;
    }