Пример #1
0
        void Start()
        {
            EasyImageTargetBehaviour targetBehaviour;
            ImageTrackerBehaviour    tracker = null;

            foreach (var behaviour in FindObjectsOfType <ImageTrackerBehaviour>())
            {
                if (behaviour.name == "ImageTracker-3")
                {
                    tracker = behaviour;
                }
            }
            if (!tracker)
            {
                return;
            }
            tracker.SimultaneousNum = 2;

            // dynamically load from image (*.jpg, *.png)
            CreateTarget("argame01", out targetBehaviour);
            targetBehaviour.Bind(tracker);
            targetBehaviour.SetupWithImage("sightplus/argame01.jpg", StorageType.Assets, "argame01", new Vector2());
            GameObject duck02_1 = Instantiate(Resources.Load("duck02")) as GameObject;

            duck02_1.transform.parent = targetBehaviour.gameObject.transform;

            // dynamically load from json file
            CreateTarget("argame00", out targetBehaviour);
            targetBehaviour.Bind(tracker);
            targetBehaviour.SetupWithJsonFile("targets.json", StorageType.Assets, "argame");
            GameObject duck02_2 = Instantiate(Resources.Load("duck02")) as GameObject;

            duck02_2.transform.parent = targetBehaviour.gameObject.transform;

            // dynamically load from json string
            string jsonString = @"
{
  ""images"" :
  [
    {
      ""image"" : ""sightplus/argame02.jpg"",
      ""name"" : ""argame02""
    }
  ]
}
";

            CreateTarget("argame02", out targetBehaviour);
            targetBehaviour.Bind(tracker);
            targetBehaviour.SetupWithJsonString(jsonString, StorageType.Assets, "argame02");
            GameObject duck02_3 = Instantiate(Resources.Load("duck02")) as GameObject;

            duck02_3.transform.parent = targetBehaviour.gameObject.transform;

            // dynamically load all targets from json file
            var targetList = ImageTarget.LoadListFromJsonFile("targets2.json", StorageType.Assets);

            foreach (var target in targetList.Where(t => t.IsValid).OfType <ImageTarget>())
            {
                CreateTarget("argame03", out targetBehaviour);
                targetBehaviour.Bind(tracker);
                targetBehaviour.SetupWithTarget(target);
                GameObject duck03 = Instantiate(Resources.Load("duck03")) as GameObject;
                duck03.transform.parent = targetBehaviour.gameObject.transform;
            }

            targetBehaviour = null;
        }