Exemple #1
0
    public void AddMarker(string markerName, TrackableEventHandler trackableEvent)
    {
        var m = Configuration.ConfigMaganer.Instance.Get(markerName);

        if (m != null)
        {
            trackableEvent.marker = m;
            _markers.Add(trackableEvent, m);
            var texture = new Texture2D(128, 128, TextureFormat.RGB565, false);

            var path = m.Icon.StartsWith("/") ? m.Icon : Path.Combine(Application.persistentDataPath, m.Icon);
            if (texture.LoadImage(File.ReadAllBytes(path)))
            {
                _icons.Add(markerName, texture);
            }
            else
            {
                Debug.LogWarning("Icon not found " + markerName + " by key " + m.Icon);
            }
        }
        else
        {
            Debug.LogWarning(markerName + " has been not found in data file");
        }
    }
Exemple #2
0
 public void StartMove(Vector3 directon, Collider deadCollider, TrackableEventHandler target)
 {
     _direction          = directon;
     DeadCollider        = deadCollider;
     Target              = target;
     Target.TargetEvent += DestroyOnTargetLost;
     IsMoving            = true;
 }
 void onClick(GameObject btnObj)
 {
     if (TrackableEventHandler.IfFound() && !InstantiateHandler.Instance.IsPlaying() && btnObj != null)
     {
         InstantiateHandler.Instance.StartInstantiate();
         FindObjectOfType <DrumVBHandler>().SetStartTrue();
         aud.Play();
         Destroy(btnObj);
     }
 }
    public void StopPlayerOnLost(bool condition, TrackableEventHandler sender)
    {
        var player  = sender.GetComponentInChildren <VideoPlayer>();
        var preview = player.transform.Find("PreviewImage").gameObject;

        if (!condition && !_isInFullScreenMod)
        {
            player.Stop();
            preview.SetActive(true);
            if (player == _trackedVideoPlayer)
            {
                _playButtonImage.overrideSprite = PlaySprite;
            }
        }
    }
Exemple #5
0
    public static string GetGameojectNameWithMaxIndex()
    {
        System.UInt64 max             = 0;
        string        goTrackableName = "";

        foreach (GameObject go in instance.goDictionary.Values)
        {
            TrackableEventHandler dt = go.GetComponent <TrackableEventHandler> ();
            if (dt.modelIndex > max)
            {
                max             = dt.modelIndex;
                goTrackableName = dt.trackableName;
            }
        }
        return(goTrackableName);
    }
Exemple #6
0
    //每次found方法执行的时候都会执行这个方法
    public static void UpdateModelIndex(string trackName)
    {
        currentModelIndex++;
        GameObject thisGO;

        if (instance.goDictionary.TryGetValue(trackName, out thisGO))
        {
            TrackableEventHandler dt = thisGO.GetComponent <TrackableEventHandler> ();
            dt.modelIndex = currentModelIndex;
            Debug.Log("this model's index is updated to :" + currentModelIndex);
        }
        else
        {
            //如果走了这里,肯定有模型漏掉了,代码逻辑一定有问题
            Debug.Log("Utility error,there is a gameobject has not save to dic ---" + trackName);
        }
    }
    public void Start()
    {
        imageTarget = GameObject.Find("ImageTarget");
        Debug.Log("################################### found imagetarget");
        arCam = GameObject.Find("ARCamera");
        Debug.Log("################################### found arcam");
        trackableEventHandler = imageTarget.GetComponent<TrackableEventHandler>();
        Debug.Log("################################### found trackableEventHandler");

        //Get VirtualButton
        //IVirtualButtonEventHandler?
        VirtualButtonBehaviour[] vbs = imageTarget.GetComponentsInChildren<VirtualButtonBehaviour>();
        mVirtualButton1 = vbs[0];

        //GameObject virtualButton1 = GameObject.Find("VirtualButton1");
        //mVirtualButton1 = virtualButton1.GetComponent<VirtualButtonBehaviour>();
        Debug.Log("################################### found mVirtualButton1");
    }
    private void GetTrackedTarget(bool condition, TrackableEventHandler sender)
    {
        var target = sender.GetComponent <TargetTrack>();

        if (condition)
        {
            //if(!_videoTargetContainer.Exists(x => x.DublicatedTarget == target))
            //    _videoTargetContainer.Add(target);

            Debug.Log(sender.gameObject.name + " is tracked");
            //+ " on " + _trackedVideoPlayerTargets.IndexOf(target) + " index");
            if (_trackedVideoPlayer == null || //TODO: check
                _trackedVideoPlayer == sender.GetComponentInChildren <VideoPlayer>())
            {
                RendVideoScreen(true, target);
            }
            if (_videoTargetContainer.Count > 1 && !_isInFullScreenMod)
            {
                ShowSwitchButtons(true);
            }
            if (!_isInFullScreenMod)
            {
                FullScreenPreview.SetActive(true);
            }
        }
        else
        {
            //_videoTargetContainer.Remove(target);
            Debug.Log(sender.gameObject.name + " has lost");
            RendVideoScreen(false, target);
            if (!_isInFullScreenMod)
            {
                if (_videoTargetContainer.Count == 0)
                {
                    _trackedVideoPlayer = null;
                }
                if (_videoTargetContainer.Count == 1)
                {
                    ShowSwitchButtons(false);
                }
            }
        }
    }
    private void RendNextVideoScreenIfTracked(bool condition, TrackableEventHandler sender)
    {
        var temp = sender.GetComponentInChildren <VideoPlayer>();

        if (!condition && _trackedVideoPlayer == temp &&
            _videoTargetContainer.Count > 0 && !_isInFullScreenMod)
        {
            _trackedVideoPlayer.loopPointReached -= EndPlayer;
            _trackedVideoPlayer.prepareCompleted -= EndLoadingAnimation;
            while (_targetIndex < 0)
            {
                _targetIndex += _videoTargetContainer.Count;
            }
            while (_targetIndex >= _videoTargetContainer.Count)
            {
                _targetIndex -= _videoTargetContainer.Count;
            }
            //RendVideoScreen(true, _videoTargetContainer[_targetIndex]);
        }
    }
Exemple #10
0
    public static void RemoveGoFromMemoryManager()
    {
        string goName = instance.GetGameojectNameWithMinIndex();

        if (goName.Equals(""))
        {
            Debug.LogError("delete go fail,because the gameobjectName is nil");
            return;
        }

        GameObject thisGameObject;

        if (memoryManager == null)
        {
            return;
        }
        if (instance.goDictionary.TryGetValue(goName, out thisGameObject))
        {
            Debug.Log("from dic found track object:" + thisGameObject.name);
            TrackableEventHandler dt = thisGameObject.GetComponent <TrackableEventHandler> ();
            if (dt != null)
            {
                Debug.Log("this gameobject has the defaulttrak.. scripts:");
                for (int i = 0; i < thisGameObject.transform.childCount; i++)
                {
                    Destroy(thisGameObject.transform.GetChild(i).gameObject);
                    Debug.Log("delete success");
                }
                //isModelLoaded置false,这样下次再found的时候就会从内存去加载。
                dt.isModelLoaded = false;
            }
            else
            {
                Debug.LogError("there isn't a defaultRrackableEventHandler in this gameobject");
            }
        }
    }
Exemple #11
0
    //在加载的所有模型中,找到一个index最小的。如果有相同的最小的index,取第一次获取到的index的模型作为当前要取的gameobject
    private string GetGameojectNameWithMinIndex()
    {
        System.UInt64 min             = 0;
        string        goTrackableName = "";
        int           i = 0;

        foreach (GameObject go in goDictionary.Values)
        {
            TrackableEventHandler dt = go.GetComponent <TrackableEventHandler> ();
            if (min == 0 && i == 0)
            {
                goTrackableName = dt.trackableName;
                min             = dt.modelIndex;
                i++;                //保证这里只执行一次
                continue;
            }
            if (dt.modelIndex < min)
            {
                min             = dt.modelIndex;
                goTrackableName = dt.trackableName;
            }
        }
        return(goTrackableName);
    }
 private void NewMethod(bool arg1, TrackableEventHandler arg2)
 {
     Debug.LogErrorFormat("[C] {0} is tracked with result {2}", arg2.name, arg1);
 }
    public void TargetTrackeStateChanged(bool condition, TrackableEventHandler sender)
    {
        if (condition)
        {
            Debug.LogWarningFormat("{0} has catched", sender.gameObject.name);

            var existCondition = _trackedTargets.Exists(item => item.DublicatedTargets.FirstOrDefault(dublicate => dublicate == sender));
            Debug.LogWarningFormat("_trackedTarges.Exist {0} with result {1}", sender.name, existCondition);
            if (!existCondition)
            {
                if (TrackedTarget != sender) // TO DO: подумать про костыль
                {
                    _trackedTargets.Add(sender);
                    Debug.LogWarningFormat("{0} added with index {1}, summary {2}", sender.name, _trackedTargets.IndexOf(sender), _trackedTargets.Count);
                }
                else
                {
                    Debug.LogErrorFormat("{0} already exist, but woulde be rendered", sender.name);
                }

                if (TrackedTarget == sender)
                {
                    RenderTrackedTarget(true);
                }
                PlayerButtonsSetActive(true);

                if (_trackedTargets.Count > 1 && !_isFullScreen)
                {
                    SwitchButtons.SetActive(true);
                }
            }
            else
            {
                Debug.LogErrorFormat("Nope, {0} already exist", sender.name);
            }
        }
        else
        {
            Debug.LogWarningFormat("{0} has lost", sender.gameObject.name);
            if (TrackedTarget == sender)
            {
                RenderTrackedTarget(false);
            }

            if (_isFullScreen)
            {
                if (TrackedTarget != sender)
                {
                    _trackedTargets.Remove(sender);
                    Debug.LogWarningFormat("{0} removed", sender.name);
                }
            }
            else
            {
                _trackedTargets.Remove(sender);
                Debug.LogWarningFormat("{0} removed", sender.name);
            }

            if (_trackedTargets.Count > 0)
            {
                RenderTrackedTarget(true);
            }

            if (!_isFullScreen && !TrackedTarget)
            {
                PlayerButtonsSetActive(false);
            }

            if (_trackedTargets.Count <= 1)
            {
                SwitchButtons.SetActive(false);
            }
        }
    }