Ejemplo n.º 1
0
        public void RangeTest(string rangeStr, int testValue, bool expectedResult)
        {
            var range  = DetectionRange.Parse(rangeStr);
            var result = range.IsInRange(testValue);

            Debug.Assert(result == expectedResult);
        }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        eventDispatcher = EventDispatcher.Instance;

        BeatEvent = new UnityEvent();
        BeatEvent.AddListener(OnBeat);
        eventDispatcher.RegisterBeatListener(ref BeatEvent);


        detect1 = transform.FindChild("Detect1");
        detect2 = transform.FindChild("Detect2");
        detect3 = transform.FindChild("Detect3");

        detect1Ren = detect1.GetComponent <Renderer>();
        detect2Ren = detect2.GetComponent <Renderer>();
        detect3Ren = detect3.GetComponent <Renderer>();

        detect1Script = detect1.GetComponent <DetectionRange>();
        detect2Script = detect2.GetComponent <DetectionRange>();
        detect3Script = detect3.GetComponent <DetectionRange>();

        spriteRenderer = GetComponent <SpriteRenderer>();

        transform.rotation = new Quaternion(0, 0, 0, 0);
    }
Ejemplo n.º 3
0
    public static void CreateNPCPrefab()
    {
        UnityEngine.Object[] selectedObjects = Selection.objects;
        if (selectedObjects.Length > 0)
        {
            foreach (UnityEngine.Object obj in selectedObjects)
            {
                if (obj is Texture2D)
                {
                    Texture2D texture = obj as Texture2D;
                    if (Resources.Load("Assets/Resources/PreFabs/NPC/" + texture.name) == false)
                    {
                        GameObject newPrefab = PrefabUtility.CreatePrefab("Assets/Resources/PreFabs/NPC/" + texture.name + ".prefab", new GameObject());
                        newPrefab.AddComponent <NPC>();
                        newPrefab.layer = LayerMask.NameToLayer("NPC");

                        NPC npc = newPrefab.GetComponent <NPC>();
                        npc.isPickupable = false;

                        Rigidbody2D rb = newPrefab.GetComponent <Rigidbody2D>();
                        rb.interpolation          = RigidbodyInterpolation2D.Extrapolate;
                        rb.collisionDetectionMode = CollisionDetectionMode2D.Continuous;

                        BoxCollider2D coll = newPrefab.GetComponent <BoxCollider2D>();
                        coll.size = new Vector2(1, 1);

                        DetectionRange detector = newPrefab.GetComponent <DetectionRange>();
                        detector.TargetMask   = (1 << LayerMask.NameToLayer("Foreground")) | (1 << LayerMask.NameToLayer("Player")) | (1 << LayerMask.NameToLayer("NPC"));
                        detector.ObstacleMask = (1 << LayerMask.NameToLayer("BoundaryTiles"));

                        Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Art/" + texture.name + ".png");
                        newPrefab.GetComponent <SpriteRenderer>().sprite = sprite;

                        Selection.activeObject = newPrefab;
                        Debug.Log("NPC " + texture.name + " Created!");
                    }
                }
            }
        }
        else
        {
            GameObject newPrefab = PrefabUtility.CreatePrefab("Assets/Resources/PreFabs/NPC/NewNPC.prefab", new GameObject());
            newPrefab.AddComponent <NPC>();
            newPrefab.layer = LayerMask.NameToLayer("NPC");

            NPC npc = newPrefab.GetComponent <NPC>();
            npc.isPickupable = false;

            Rigidbody2D rb = newPrefab.GetComponent <Rigidbody2D>();
            rb.interpolation          = RigidbodyInterpolation2D.Extrapolate;
            rb.collisionDetectionMode = CollisionDetectionMode2D.Continuous;

            BoxCollider2D coll = newPrefab.GetComponent <BoxCollider2D>();
            coll.size = new Vector2(1, 1);

            Selection.activeObject = newPrefab;
            Debug.Log("NewNPC Created!");
        }
    }
Ejemplo n.º 4
0
    void Start() {

        target = GameObject.FindGameObjectWithTag("Player");
        rendererMat = gameObject.GetComponent<Renderer>().material;
        hpMax = hp;
        AllPlatform = new GameObject[] { spawnBoss, platform1, platform2, platform3, platform4 };
        detectArea = GetComponentInChildren<DetectionRange>();
    }
        public async void Container_Should_TriggerOnCount_With_Count()
        {
            var calculator = new StandardDeviationCalculator(3);
            var trigger    = new TriggerSettings(2, 202);
            var range      = new DetectionRange <double>(300, 800, 1000, 1200, 1700);
            var container  = new ValueContainer <double>(calculator, trigger, range);

            var    anomalyLowTriggeredCounter   = 0;
            var    anomalyHighTriggeredCounter  = 0;
            var    valueChangedTriggeredCounter = 0;
            double value        = 0;
            var    triggerValue = Trigger.None;

            container.AnomalyEvent += (object _, AnomalyEventArgs <double> e) =>
            {
                if (e.Anomaly == Anomaly.Low)
                {
                    anomalyLowTriggeredCounter++;
                }
                else if (e.Anomaly == Anomaly.High)
                {
                    anomalyHighTriggeredCounter++;
                }
            };

            container.ValueChangedEvent += (object _, ValueChangedEventArgs <double> e) =>
            {
                valueChangedTriggeredCounter++;
                value        = e.Value;
                triggerValue = e.Trigger;
            };

            for (var i = 700; i <= 900; i++)
            {
                await container.AddAsync(i).ConfigureAwait(false);
            }

            anomalyLowTriggeredCounter.Should().Be(0);
            anomalyHighTriggeredCounter.Should().Be(0);
            valueChangedTriggeredCounter.Should().Be(0);

            await container.AddAsync(800).ConfigureAwait(false);

            anomalyLowTriggeredCounter.Should().Be(0);
            anomalyHighTriggeredCounter.Should().Be(0);
            valueChangedTriggeredCounter.Should().Be(1);
            value.Should().Be(800);
            triggerValue.Should().Be(Trigger.Count);

            await container.AddAsync(800).ConfigureAwait(false);

            await container.AddAsync(900).ConfigureAwait(false);

            valueChangedTriggeredCounter.Should().Be(2);
            value.Should().Be(850);
            triggerValue.Should().Be(Trigger.Count);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Set the sensor detection range.
        /// </summary>
        /// <param name="detectionRange">Detection range of the sensor</param>
        /// <exception cref="System.IO.IOException">Communication with sensor failed</exception>
        public void SetSensorDetectionRange(DetectionRange detectionRange)
        {
            var request = CreateRequest(Command.DetectionRangeSetting);

            // set detection range in request, c. f. datasheet rev. 1.0, pg. 8 for details
            request[(int)MessageFormat.DataHighRequest] = (byte)((int)detectionRange / 256);
            request[(int)MessageFormat.DataLowRequest]  = (byte)((int)detectionRange % 256);

            SendRequest(request);
        }
        public void Constructor_Should_CreateValidModel_With_Double(
            double maxDetectionLow, double low, double normal, double high, double maxDetectionHigh)
        {
            var actual = new DetectionRange <double>(maxDetectionLow, low, normal, high, maxDetectionHigh);

            actual.MaxDetectionLow.Should().Be(maxDetectionLow);
            actual.Low.Should().Be(low);
            actual.Normal.Should().Be(normal);
            actual.High.Should().Be(high);
            actual.MaxDetectionHigh.Should().Be(maxDetectionHigh);
        }
        public void Constructor_Should_CreateValidModel_With_DateTime(
            int maxDetectionLow, int low, int normal, int high, int maxDetectionHigh)
        {
            var referenceDate = DateTimeOffset.Now;

            var maxDetectionLowDate  = referenceDate.AddTicks(maxDetectionLow);
            var lowDate              = referenceDate.AddTicks(low);
            var normalDate           = referenceDate.AddTicks(normal);
            var highDate             = referenceDate.AddTicks(high);
            var maxDetectionHighDate = referenceDate.AddTicks(maxDetectionHigh);

            var actual = new DetectionRange <DateTimeOffset>(maxDetectionLowDate, lowDate, normalDate, highDate, maxDetectionHighDate);

            actual.MaxDetectionLow.Should().Be(maxDetectionLowDate);
            actual.Low.Should().Be(lowDate);
            actual.Normal.Should().Be(normalDate);
            actual.High.Should().Be(highDate);
            actual.MaxDetectionHigh.Should().Be(maxDetectionHighDate);
        }
Ejemplo n.º 9
0
        protected override IEnumerable <Control> GetControls()
        {
            yield return(new InputBox("Width (mm)",
                                      () => GetCurrent().Width.ToString(),
                                      (o) => ModifyCurrent(id => id.Width = ToFloat(o))
                                      ));

            yield return(new InputBox("Height (mm)",
                                      () => GetCurrent().Height.ToString(),
                                      (o) => ModifyCurrent(id => id.Height = ToFloat(o))
                                      ));

            yield return(new InputBox("Max X (px)",
                                      () => GetCurrent().MaxX.ToString(),
                                      (o) => ModifyCurrent(id => id.MaxX = ToFloat(o))
                                      ));

            yield return(new InputBox("Max Y (px)",
                                      () => GetCurrent().MaxY.ToString(),
                                      (o) => ModifyCurrent(id => id.MaxY = ToFloat(o))
                                      ));

            yield return(new InputBox("Max Pressure",
                                      () => GetCurrent().MaxPressure.ToString(),
                                      (o) => ModifyCurrent(id => id.MaxPressure = ToUInt(o))
                                      ));

            yield return(new InputBox("Active Report ID",
                                      () => GetCurrent().ActiveReportID?.ToString() ?? new DetectionRange().ToString(),
                                      (o) => ModifyCurrent(id => id.ActiveReportID = DetectionRange.Parse(o))
                                      ));

            foreach (var control in base.GetControls())
            {
                yield return(control);
            }
        }
Ejemplo n.º 10
0
 public void updateEmbarrassment(DetectionRange detectionRange)
 {
     if (detectionRange == DetectionRange.greenZone/* || (this.foundShirt && this.foundShirt && this.foundShoes)*/)
     {
         if (this.embarrassment > this.embarrassmentMeter.getMinimumEmbarrassmentValue())
         {
             this.embarrassment -= this.cooldownEmbarrassmentDecrement;
         }
         else
         {
             this.embarrassment = (int)this.embarrassmentMeter.getMinimumEmbarrassmentValue();
         }
     }
     else if (detectionRange == DetectionRange.redZone && !this.hidden && !this.isFullyClothed)
     {
         this.insideEnemyFieldOfView = true;
         if (this.embarrassment < this.embarrassmentMeter.getMaximumEmbarrassmentValue())
         {
             this.embarrassment += this.redZoneEmbarrassmentIncrement - this.absoluteReduction;
             ewwManager.Play();
         }
         else
         {
             this.embarrassment = (int)this.embarrassmentMeter.getMaximumEmbarrassmentValue();
         }
     }
     else if (detectionRange == DetectionRange.yellowZone && !this.hidden && !this.isFullyClothed)
     {
         this.insideEnemyFieldOfView = true;
         if (this.embarrassment < this.embarrassmentMeter.getMaximumEmbarrassmentValue())
         {
             this.embarrassment += this.yellowZoneEmbarrassmentIncrement - this.absoluteReduction;
             ewwManager.Play();
         }
         else
         {
             this.embarrassment = (int)this.embarrassmentMeter.getMaximumEmbarrassmentValue();
         }
     }
 }
Ejemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     Base   = transform.position;
     Vision = gameObject.GetComponent <DetectionRange>();
     smelly = Resources.Load <Descriptor>("Descriptors/Smelly");
 }