/// <summary>
    /// Enable this search result for tracking
    ///
    /// Creates an ImageTarget for local detection and tracking of this target.
    /// If the given game object has no ImageTargetBehaviour, a new one will be created.
    /// Note that this call may result in an earlier ImageTarget that was enabled for
    /// tracking to be destroyed, including its ImageTargetBehaviour.
    /// Thus it is not advised to hold a pointer to an
    /// ealier created ImageTarget after calling enableTracking again. Returns
    /// NULL if the target failed to be enabled for tracking.
    /// </summary>
    public override ImageTargetBehaviour EnableTracking(TargetSearchResult result, GameObject gameObject)
    {
        // create a new trackable in native
        IntPtr imageTargetPtr    = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ImageTargetData)));
        int    newTrackableCount = QCARWrapper.Instance.TargetFinderEnableTracking(result.TargetSearchResultPtr, imageTargetPtr);

        ImageTargetData imageTargetData = (ImageTargetData)
                                          Marshal.PtrToStructure(imageTargetPtr, typeof(ImageTargetData));

        Marshal.FreeHGlobal(imageTargetPtr);

        StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();

        // if successful, create a new trackable here and add it to internal collection
        ImageTargetBehaviour imageTargetBehaviour = null;

        if (imageTargetData.id == -1)
        {
            Debug.LogError("TargetSearchResult " + result.TargetName + " could not be enabled for tracking.");
        }
        else
        {
            ImageTarget newImageTarget = new CloudRecoImageTargetImpl(result.TargetName, imageTargetData.id, imageTargetData.size);

            // Add newly created Image Target to dictionary.
            mImageTargets[imageTargetData.id] = newImageTarget;

            // Find or create ImageTargetBehaviour for this ImageTarget:
            imageTargetBehaviour = stateManager.FindOrCreateImageTargetBehaviourForTrackable(newImageTarget, gameObject);
        }

        // get a list of currently existing trackables
        IntPtr imageTargetIdArrayPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * newTrackableCount);

        QCARWrapper.Instance.TargetFinderGetImageTargets(imageTargetIdArrayPtr, newTrackableCount);

        List <int> targetIds = new List <int>();

        for (int i = 0; i < newTrackableCount; i++)
        {
            IntPtr targetIdPtr = new IntPtr(imageTargetIdArrayPtr.ToInt32() + i * Marshal.SizeOf(typeof(int)));
            int    targetID    = Marshal.ReadInt32(targetIdPtr);
            targetIds.Add(targetID);
        }

        Marshal.FreeHGlobal(imageTargetIdArrayPtr);

        // delete those targets that no longer exist
        foreach (ImageTarget imageTarget in mImageTargets.Values.ToArray())
        {
            if (!targetIds.Contains(imageTarget.ID))
            {
                stateManager.DestroyTrackableBehavioursForTrackable(imageTarget);
                mImageTargets.Remove(imageTarget.ID);
            }
        }


        return(imageTargetBehaviour);
    }
        /// <summary>
        /// Finds and creates a target from an ad sequencing source and a creative source.
        /// </summary>
        /// <param name="AdSource">Provides required target info</param>
        /// <param name="CreativeSource">Provides info about the actual creative that is to be placed.</param>
        /// <returns>And object representing the selected target of the creative</returns>
        public virtual IAdTarget FindTarget(IAdSource AdSource, ICreativeSource CreativeSource)
        {
            var target = GetAdTargets(AdSource, CreativeSource).FirstOrDefault();

            if (target == null && CreativeSource.Type != CreativeSourceType.Companion)
            {
                // assume VideoArea for linear and nonlinear ads
                target = new TargetSearchResult((IAdSequencingTarget) new VideoAreaTarget(CreativeSource), new List <IAdSequencingTarget>());
            }

            if (target != null)
            {
                var slResult = GetAdContainer(target.AdSequencingTarget);
#if !WINDOWS_PHONE && !OOB
                if (slResult == null && !Application.Current.IsRunningOutOfBrowser)
                {
                    var htmlResult = GetHtmlAdContainer(target.AdSequencingTarget);
                    if (htmlResult != null)
                    {
                        return(new HtmlElementAdTarget(htmlResult, target.AdSequencingTarget, target.DependencyTargets));
                    }
                }
                else
#endif
                {
                    return(CreateAdTarget(slResult, target.AdSequencingTarget, target.DependencyTargets));
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        //自动
        private HeroActionState AutoAction(List <BattleAction> heroActions)
        {
            //搜索敌人
            //如果存在可以攻击的目标
            //将会选定目标 以及 要移动到的位置(格子)
            TargetSearchResult searchResult = SearchTarget(heroActions);

            switch (searchResult)
            {
            //需要移动
            case TargetSearchResult.NeedMove:
                //先移动
                MoveToTargetGrid(heroActions, targetBattleUnit, targetGrid, toTargetPath.ToArray());
                //移动后判断是否可以攻击
                if (CheckUnderAttackRadius())
                {
                    UseSkill(heroActions, targetBattleUnit, 0);
                }
                break;

            //在攻击范围内
            case TargetSearchResult.InRange:
                UseSkill(heroActions, targetBattleUnit, 0);
                break;

            //战斗结束
            case TargetSearchResult.Inexistence:
                if (battleField.CheckBattleEnd())
                {
                    return(HeroActionState.BattleEnd);
                }
                else
                {
                    return(HeroActionState.Warn);
                }

            default:
                break;
            }

            if (battleField.CheckBattleEnd())
            {
                return(HeroActionState.BattleEnd);
            }
            else
            {
                return(HeroActionState.Normal);
            }
        }
Exemplo n.º 4
0
        public HeroActionState BattleAction(List <BattleAction> heroActions)
        {
            if (enemyTeam == null)
            {
                return(HeroActionState.Error);
            }

            if (heroActions != null)
            {
                heroActions.Clear();
            }

            //搜索敌人
            //如果存在可以攻击的目标
            //将会选定目标 以及 要移动到的位置(格子)
            TargetSearchResult searchResult = SearchTarget(heroActions);

            switch (searchResult)
            {
            //需要移动
            case TargetSearchResult.NeedMove:
                MoveToTargetGrid(heroActions);
                break;

            //在攻击范围内
            case TargetSearchResult.InRange:
                UseSkill(heroActions);
                break;

            //战斗结束
            case TargetSearchResult.Inexistence:
                //战斗结束
                if (CheckBattleEnd())
                {
                    return(HeroActionState.BattleEnd);
                }
                else
                {
                    return(HeroActionState.Warn);
                }

            default:
                break;
            }

            return(HeroActionState.Normal);
        }
    /// <summary>
    /// Enable this search result for tracking
    ///
    /// Creates an ImageTarget for local detection and tracking of this target
    /// and returns a new ImageTargetBehaviour attached to a new game object with the given name.
    /// Note that this call may result in an earlier ImageTarget that was enabled for
    /// tracking to be destroyed, including its ImageTargetBehaviour.
    /// Thus it is not advised to hold a pointer to an
    /// ealier created ImageTarget after calling enableTracking again. Returns
    /// NULL if the target failed to be enabled for tracking.
    /// </summary>
    public override ImageTargetBehaviour EnableTracking(TargetSearchResult result, string gameObjectName)
    {
        GameObject gameObject = new GameObject(gameObjectName);

        return(EnableTracking(result, gameObject));
    }
 /// <summary>
 /// Enable this search result for tracking
 ///
 /// Creates an ImageTarget for local detection and tracking of this target.
 /// If the given game object has no ImageTargetBehaviour, a new one will be created.
 /// Note that this call may result in an earlier ImageTarget that was enabled for
 /// tracking to be destroyed, including its ImageTargetBehaviour. 
 /// Thus it is not advised to hold a pointer to an
 /// ealier created ImageTarget after calling enableTracking again. Returns
 /// NULL if the target failed to be enabled for tracking.
 /// </summary>
 public abstract ImageTargetBehaviour EnableTracking(TargetSearchResult result, GameObject gameObject);
Exemplo n.º 7
0
        //搜索目标
        private TargetSearchResult SearchTarget(List <BattleAction> actions)
        {
            //按照距离排序敌人
            UtilityObjs.battleUnits.Clear();
            //只考虑可以行动的
            for (int i = 0; i < enemyTeam.battleUnits.Count; ++i)
            {
                if (enemyTeam.battleUnits[i].CanAction)
                {
                    UtilityObjs.battleUnits.Add(enemyTeam.battleUnits[i]);
                }
            }

            //天下无敌了,还有谁??
            if (UtilityObjs.battleUnits.Count == 0)
            {
                return(TargetSearchResult.Inexistence);
            }

            //结果类型
            TargetSearchResult searchResult = TargetSearchResult.InRange;

            //按照距离排序
            UtilityObjs.battleUnits.Sort(delegate(BattleUnit b1, BattleUnit b2)
            {
                return(mapGrid.Distance(b1.mapGrid) - mapGrid.Distance(b2.mapGrid));
            });

            //暂时不添加复杂的逻辑,只选择直线距离最近的
            BattleUnit newTarget     = null;
            GridUnit   newTargetGrid = null;

            for (int i = 0; i < UtilityObjs.battleUnits.Count; ++i)
            {
                //如果当前目标就在范围内
                if (mapGrid.Distance(UtilityObjs.battleUnits[i].mapGrid) <= 1)
                {
                    //设置目标,但是不需要移动
                    newTarget = UtilityObjs.battleUnits[i];
                    toTargetPath.Clear();
                    targetGrid   = null;
                    searchResult = TargetSearchResult.InRange;
                    break;
                }

                //目标不在周围需要移动
                newTargetGrid = battleField.battleMap.GetEmptyGrid(mapGrid, UtilityObjs.battleUnits[i].mapGrid, toTargetPath, mobility);
                if (newTargetGrid == null)
                {
                    //UtilityHelper.LogWarning(battleUnitID + "找不到空格子了,看看下一个吧");
                    continue;
                }
                else
                {
                    newTarget    = UtilityObjs.battleUnits[i];
                    searchResult = TargetSearchResult.NeedMove;
                    break;
                }
            }

            if (newTarget == null)
            {
                UtilityHelper.LogWarning("确实找不到了");
                targetBattleUnit = null;
                targetGrid       = null;
                toTargetPath.Clear();
                if (actions != null)
                {
                    //创建一个warning
                    BattleHeroWarningAction action = new BattleHeroWarningAction(this, "No target:" + battleUnitID);
                    actions.Add(action);
                }
                return(TargetSearchResult.Inexistence);
            }

            //目标不一致,切换目标
            if (targetBattleUnit != newTarget)
            {
                //切换目标
                BattleHeroChangeTargetAction action = new BattleHeroChangeTargetAction(this);
                action.lastTargetUnit = targetBattleUnit;
                action.newTargetUnit  = newTarget;

                //设置当前目标以及格子
                targetBattleUnit = newTarget;
                actions.Add(action);
            }

            //移动的格子重新设置
            targetGrid = newTargetGrid;

            return(searchResult);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Enable this search result for tracking
 ///
 /// Creates an ImageTarget for local detection and tracking of this target.
 /// If the given game object has no ImageTargetBehaviour, a new one will be created.
 /// Note that this call may result in an earlier ImageTarget that was enabled for
 /// tracking to be destroyed, including its ImageTargetBehaviour.
 /// Thus it is not advised to hold a pointer to an
 /// ealier created ImageTarget after calling enableTracking again. Returns
 /// NULL if the target failed to be enabled for tracking.
 /// </summary>
 public abstract ImageTargetBehaviour EnableTracking(TargetSearchResult result, GameObject gameObject);
Exemplo n.º 9
0
 /// <summary>
 /// Enable this search result for tracking
 ///
 /// Creates an ImageTarget for local detection and tracking of this target
 /// and returns a new ImageTargetBehaviour attached to a new game object with the given name.
 /// Note that this call may result in an earlier ImageTarget that was enabled for
 /// tracking to be destroyed, including its ImageTargetBehaviour. 
 /// Thus it is not advised to hold a pointer to an
 /// ealier created ImageTarget after calling enableTracking again. Returns
 /// NULL if the target failed to be enabled for tracking.
 /// </summary>
 public override ImageTargetBehaviour EnableTracking(TargetSearchResult result, string gameObjectName)
 {
     GameObject gameObject = new GameObject(gameObjectName);
     return EnableTracking(result, gameObject);
 }
Exemplo n.º 10
0
    /// <summary>
    /// Enable this search result for tracking
    ///
    /// Creates an ImageTarget for local detection and tracking of this target.
    /// If the given game object has no ImageTargetBehaviour, a new one will be created.
    /// Note that this call may result in an earlier ImageTarget that was enabled for
    /// tracking to be destroyed, including its ImageTargetBehaviour. 
    /// Thus it is not advised to hold a pointer to an
    /// ealier created ImageTarget after calling enableTracking again. Returns
    /// NULL if the target failed to be enabled for tracking.
    /// </summary>
    public override ImageTargetBehaviour EnableTracking(TargetSearchResult result, GameObject gameObject)
    {
        // create a new trackable in native
        IntPtr imageTargetPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ImageTargetData)));
        int newTrackableCount = QCARWrapper.Instance.TargetFinderEnableTracking(result.TargetSearchResultPtr, imageTargetPtr);

        ImageTargetData imageTargetData = (ImageTargetData)
                Marshal.PtrToStructure(imageTargetPtr, typeof(ImageTargetData));
        Marshal.FreeHGlobal(imageTargetPtr);

        StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();

        // if successful, create a new trackable here and add it to internal collection
        ImageTargetBehaviour imageTargetBehaviour = null;
        if (imageTargetData.id == -1)
        {
            Debug.LogError("TargetSearchResult " + result.TargetName + " could not be enabled for tracking.");
        }
        else
        {
            ImageTarget newImageTarget = new CloudRecoImageTargetImpl(result.TargetName, imageTargetData.id, imageTargetData.size);

            // Add newly created Image Target to dictionary.
            mImageTargets[imageTargetData.id] = newImageTarget;

            // Find or create ImageTargetBehaviour for this ImageTarget:
            imageTargetBehaviour = stateManager.FindOrCreateImageTargetBehaviourForTrackable(newImageTarget, gameObject);
        }

        // get a list of currently existing trackables
        IntPtr imageTargetIdArrayPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * newTrackableCount);
        QCARWrapper.Instance.TargetFinderGetImageTargets(imageTargetIdArrayPtr, newTrackableCount);

        List<int> targetIds = new List<int>();
        for (int i = 0; i < newTrackableCount; i++)
        {
            IntPtr targetIdPtr = new IntPtr(imageTargetIdArrayPtr.ToInt32() + i * Marshal.SizeOf(typeof(int)));
            int targetID = Marshal.ReadInt32(targetIdPtr);
            targetIds.Add(targetID);
        }

        Marshal.FreeHGlobal(imageTargetIdArrayPtr);

        // delete those targets that no longer exist
        foreach (ImageTarget imageTarget in mImageTargets.Values.ToArray())
        {
            if (!targetIds.Contains(imageTarget.ID))
            {
                stateManager.DestroyTrackableBehavioursForTrackable(imageTarget);
                mImageTargets.Remove(imageTarget.ID);
            }
        }

        return imageTargetBehaviour;
    }
        /// <summary>
        /// Finds and creates a target from an ad sequencing source and a creative source.
        /// </summary>
        /// <param name="AdSource">Provides required target info</param>
        /// <param name="CreativeSource">Provides info about the actual creative that is to be placed.</param>
        /// <returns>And object representing the selected target of the creative</returns>
        public virtual IAdTarget FindTarget(IAdSource AdSource, ICreativeSource CreativeSource)
        {
            var target = GetAdTargets(AdSource, CreativeSource).FirstOrDefault();
            if (target == null && CreativeSource.Type != CreativeSourceType.Companion)
            {
                // assume VideoArea for linear and nonlinear ads
                target = new TargetSearchResult((IAdSequencingTarget)new VideoAreaTarget(CreativeSource), new List<IAdSequencingTarget>());
            }

            if (target != null)
            {
                var slResult = GetAdContainer(target.AdSequencingTarget);
#if !WINDOWS_PHONE && !OOB
                if (slResult == null && !Application.Current.IsRunningOutOfBrowser)
                {
                    var htmlResult = GetHtmlAdContainer(target.AdSequencingTarget);
                    if (htmlResult != null)
                    {
                        return new HtmlElementAdTarget(htmlResult, target.AdSequencingTarget, target.DependencyTargets);
                    }
                }
                else
#endif
                {
                    return CreateAdTarget(slResult, target.AdSequencingTarget, target.DependencyTargets);
                }
            }

            return null;
        }
Exemplo n.º 12
0
 public abstract ImageTargetAbstractBehaviour EnableTracking(TargetSearchResult result, string gameObjectName);