コード例 #1
0
    void Awake()
    {
        TestClass tc = new TestClass(1);

        HolderClass hc = new HolderClass(tc);

        tc.value = 2;

        Debug.Log(tc.value);

        Debug.Log(hc.testClass.value);


        hc.testClass.value = 3;

        Debug.Log(tc.value);

        Debug.Log(hc.testClass.value);
    }
コード例 #2
0
        public void CollectionWithAbstractItems()
        {
            HolderClass testObject = new HolderClass();

            testObject.TestMember        = new ContentSubClass("First One");
            testObject.AnotherTestMember = new Dictionary <int, IList <ContentBaseClass> >();
            testObject.AnotherTestMember.Add(1, new List <ContentBaseClass>());
            testObject.AnotherTestMember[1].Add(new ContentSubClass("Second One"));
            testObject.AThirdTestMember = new ContentSubClass("Third One");


            JsonSerializer serializingTester = new JsonSerializer();

            serializingTester.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            StringWriter sw = new StringWriter();

            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.Indented;
                serializingTester.TypeNameHandling = TypeNameHandling.Auto;
                serializingTester.Serialize(jsonWriter, testObject);
            }

            string json = sw.ToString();

            string contentSubClassRef = ReflectionUtils.GetTypeName(typeof(ContentSubClass), FormatterAssemblyStyle.Simple);
            string dictionaryRef      = ReflectionUtils.GetTypeName(typeof(Dictionary <int, IList <ContentBaseClass> >), FormatterAssemblyStyle.Simple);
            string listRef            = ReflectionUtils.GetTypeName(typeof(List <ContentBaseClass>), FormatterAssemblyStyle.Simple);


            Assert.AreEqual(@"{
  ""TestMember"": {
    ""$type"": """ + contentSubClassRef + @""",
    ""SomeString"": ""First One""
  },
  ""AnotherTestMember"": {
    ""$type"": """ + dictionaryRef + @""",
    ""1"": {
      ""$type"": """ + listRef + @""",
      ""$values"": [
        {
          ""$type"": """ + contentSubClassRef + @""",
          ""SomeString"": ""Second One""
        }
      ]
    }
  },
  ""AThirdTestMember"": {
    ""$type"": """ + contentSubClassRef + @""",
    ""SomeString"": ""Third One""
  }
}", json);
            Console.WriteLine(json);

            StringReader sr = new StringReader(json);

            JsonSerializer deserializingTester = new JsonSerializer();

            HolderClass anotherTestObject;

            using (JsonTextReader jsonReader = new JsonTextReader(sr))
            {
                deserializingTester.TypeNameHandling = TypeNameHandling.Auto;

                anotherTestObject = deserializingTester.Deserialize <HolderClass>(jsonReader);
            }

            Assert.IsNotNull(anotherTestObject);
            CustomAssert.IsInstanceOfType(typeof(ContentSubClass), anotherTestObject.TestMember);
            CustomAssert.IsInstanceOfType(typeof(Dictionary <int, IList <ContentBaseClass> >), anotherTestObject.AnotherTestMember);
            Assert.AreEqual(1, anotherTestObject.AnotherTestMember.Count);

            IList <ContentBaseClass> list = anotherTestObject.AnotherTestMember[1];

            CustomAssert.IsInstanceOfType(typeof(List <ContentBaseClass>), list);
            Assert.AreEqual(1, list.Count);
            CustomAssert.IsInstanceOfType(typeof(ContentSubClass), list[0]);
        }
コード例 #3
0
ファイル: WhiskerAllocator.cs プロジェクト: BrettHewitt/ARWT
        public Dictionary <IWhiskerSegment, ITrackSingleWhisker> AllocateWhiskers(int frameNumber, IEnumerable <ITrackSingleWhisker> singleWhiskers, IEnumerable <IWhiskerSegment> currentWhiskers, PointF nosePoint, PointF midPoint)
        {
            List <ITrackSingleWhisker> whiskers = singleWhiskers.ToList();
            List <HolderClass>         holders  = new List <HolderClass>();
            Vector forwardVec      = new Vector(nosePoint.X - midPoint.X, nosePoint.Y - midPoint.Y);
            double extensionFactor = 10;
            double forwardX        = nosePoint.X + (forwardVec.X * extensionFactor);
            double forwardY        = nosePoint.Y + (forwardVec.Y * extensionFactor);
            double rearX           = midPoint.X - (forwardVec.X * extensionFactor);
            double rearY           = midPoint.Y - (forwardVec.Y * extensionFactor);

            System.Windows.Point newForwardPoint = new System.Windows.Point(forwardX, forwardY);
            System.Windows.Point newRearPoint    = new System.Windows.Point(rearX, rearY);
            foreach (IWhiskerSegment foundWhisker in currentWhiskers)
            {
                //Find most likely tracked whisker
                foreach (ITrackSingleWhisker tWhisker in whiskers)
                {
                    double dist  = tWhisker.CurrentWhisker.Distance(foundWhisker);
                    double angle = tWhisker.CurrentWhisker.DeltaAngle(foundWhisker);

                    if (dist < (6 * tWhisker.MissingFrameCount) && angle < (20 * tWhisker.MissingFrameCount))
                    {
                        HolderClass holder = new HolderClass();
                        holder.Whisker        = foundWhisker;
                        holder.TrackedWhisker = tWhisker;
                        holder.Score          = dist;
                        holder.PotentialTracks.Add(tWhisker, dist);

                        System.Windows.Point centerPoint = GetCenterPoint(foundWhisker.Line);
                        System.Windows.Point linePoint;
                        MathExtension.FindDistanceToSegmentSquared(centerPoint, newForwardPoint, newRearPoint, out linePoint);

                        double forwardVecDist = linePoint.DistanceSquared(nosePoint);

                        holder.DistanceFromNose = forwardVecDist;

                        holders.Add(holder);
                    }
                }
            }

            //We now have every whisker associated with a tracked whisker, need to find lowest values
            //HolderClass[] newHolders = holders.OrderBy(x => x.Score).ThenBy(x => x.DistanceFromNose).ToArray();


            List <ITrackSingleWhisker> usedTrackedWhiskers = new List <ITrackSingleWhisker>();
            List <IWhiskerSegment>     usedWhiskers        = new List <IWhiskerSegment>();
            Dictionary <IWhiskerSegment, ITrackSingleWhisker> finalWhiskers = new Dictionary <IWhiskerSegment, ITrackSingleWhisker>();


            int    maxPos = singleWhiskers.Select(x => x.PositionId).Max();
            double currentDistFromNose = 0;

            for (int currentPos = 0; currentPos <= maxPos; currentPos++)
            {
                //Get holders for position index
                IEnumerable <HolderClass> bestHolders = holders.Where(x => x.TrackedWhisker.PositionId == currentPos && x.DistanceFromNose > currentDistFromNose).OrderBy(x => x.Score);

                if (!bestHolders.Any())
                {
                    continue;
                }

                HolderClass bestHolder = bestHolders.First();

                currentDistFromNose = bestHolder.DistanceFromNose;

                ITrackSingleWhisker tSingle  = bestHolder.TrackedWhisker;
                IWhiskerSegment     tWhisker = bestHolder.Whisker;

                if (usedTrackedWhiskers.Contains(tSingle))
                {
                    continue;
                }

                if (usedWhiskers.Contains(tWhisker))
                {
                    continue;
                }

                finalWhiskers.Add(tWhisker, tSingle);
                tWhisker.Color = tSingle.Color;
                usedTrackedWhiskers.Add(tSingle);
                usedWhiskers.Add(tWhisker);
                tSingle.MissingFrameCount = 1;
            }

            //for (int i = 0; i < newHolders.Length; i++)
            //{
            //    HolderClass cHolder = newHolders[i];
            //    ITrackSingleWhisker tSingle = cHolder.TrackedWhisker;

            //    IWhiskerSegment tWhisker = cHolder.Whisker;
            //    if (usedTrackedWhiskers.Contains(tSingle))
            //    {
            //        continue;
            //    }

            //    if (usedWhiskers.Contains(tWhisker))
            //    {
            //        continue;
            //    }

            //    finalWhiskers.Add(tWhisker, tSingle);
            //    tWhisker.Color = tSingle.Color;
            //    usedTrackedWhiskers.Add(tSingle);
            //    usedWhiskers.Add(tWhisker);
            //    tSingle.MissingFrameCount = 1;
            //}

            foreach (ITrackSingleWhisker tWhisker in whiskers)
            {
                if (!usedTrackedWhiskers.Contains(tWhisker))
                {
                    tWhisker.MissingFrameCount++;
                }
            }

            return(finalWhiskers);
        }