示例#1
0
 public Hook UnhookWeightBlock(WeightBlock weightBlock)
 {
     _mainBalance.RemoveWeight(weightBlock.Mass * _hookCoefficient);
     _weightBlocks.Remove(weightBlock);
     UpdateWeightBlocksRotationInHook();
     return(null);
 }
示例#2
0
        public void CreateDefaultBlock(float weightValue, int unitValue, Vector3 weightBlockPosition)
        {
            GameController.Singleton.PlayClickSound();

            weightBlockPosition.z = 2.148f;

            var weightBlockPrefabIndex = 0;

            if (weightValue > 0)
            {
                if (weightValue <= 1)
                {
                    weightBlockPrefabIndex = 0;
                }
                else
                {
                    weightBlockPrefabIndex = Mathf.Min(3, (int)weightValue - 1);
                }
            }
            else
            {
                weightBlockPrefabIndex = 4;
            }

            WeightBlock newWeightBlock = Instantiate(_weightBlockPrefab[weightBlockPrefabIndex], weightBlockPosition, Quaternion.Euler(-6.378f, 0, 0)).GetComponent <WeightBlock>();

            _blocks.Add(newWeightBlock);
            newWeightBlock.SetBlock(weightValue, unitValue);
        }
示例#3
0
 public Hook HookWeightBlock(WeightBlock weightBlock)
 {
     _weightBlocks.Add(weightBlock);
     _mainBalance.AddWeight(weightBlock.Mass * _hookCoefficient);
     UpdateWeightBlocksRotationInHook();
     return(this);
 }
示例#4
0
        public void SumOfAbsoluteWeightsDefaultsToZero()
        {
            var reader = new BufferedReader(
                "= {}"
                );
            var weightBlock = new WeightBlock(reader);

            Assert.Equal((uint)0, weightBlock.SumOfAbsoluteWeights);
        }
示例#5
0
        public void GetMatchingObjectReturnsNullWhenObjectsMapIsEmpty()
        {
            var reader = new BufferedReader(
                "= {}"
                );
            var weightBlock = new WeightBlock(reader);

            Assert.Null(weightBlock.GetMatchingObject(0.345));
        }
示例#6
0
        public void GetMatchingObjectThrowsErrorOnArgumentGreaterThan1()
        {
            var reader = new BufferedReader(
                "= {\n" +
                "\t2 = female_hair_greek_2\n" +
                "}"
                );
            var weightBlock = new WeightBlock(reader);

            Assert.Throws <ArgumentOutOfRangeException>(() => weightBlock.GetMatchingObject(1.234));
        }
示例#7
0
        public void GetMatchingObjectThrowsErrorOnNegativeArgument()
        {
            var reader = new BufferedReader(
                "=\n" +
                "{\n" +
                "\t2 = female_hair_greek_2\n" +
                "}"
                );
            var weightBlock = new WeightBlock(reader);

            Assert.Throws <ArgumentOutOfRangeException>(() => weightBlock.GetMatchingObject(-0.5));
        }
示例#8
0
        public void ObjectsCanBeAddedByMethod()
        {
            var weightBlock = new WeightBlock();

            weightBlock.AddObject("new_object", 69);
            weightBlock.AddObject("new_object2", 5);
            Assert.Equal((uint)69, weightBlock.GetAbsoluteWeight("new_object"));
            Assert.Equal((uint)5, weightBlock.GetAbsoluteWeight("new_object2"));
            Assert.Equal((uint)74, weightBlock.SumOfAbsoluteWeights);

            Assert.Equal("new_object", weightBlock.GetMatchingObject(0));
            Assert.Equal("new_object2", weightBlock.GetMatchingObject(0.95));
        }
示例#9
0
        public void ObjectsCanBeAdded()
        {
            var reader = new BufferedReader(
                "= {\n" +
                "\t5 = female_hair_greek_1\n" +
                "\t2 = female_hair_greek_2\n" +
                "\t6 = female_hair_greek_3\n" +
                "}"
                );
            var weightBlock = new WeightBlock(reader);

            Assert.Equal((uint)5, weightBlock.GetAbsoluteWeight("female_hair_greek_1"));
            Assert.Equal((uint)2, weightBlock.GetAbsoluteWeight("female_hair_greek_2"));
            Assert.Equal((uint)6, weightBlock.GetAbsoluteWeight("female_hair_greek_3"));
            Assert.Equal((uint)13, weightBlock.SumOfAbsoluteWeights);

            Assert.Equal("female_hair_greek_1", weightBlock.GetMatchingObject(0.37234234));
            Assert.Equal("female_hair_greek_2", weightBlock.GetMatchingObject(0.52234234234));
            Assert.Equal("female_hair_greek_3", weightBlock.GetMatchingObject(1));
        }
示例#10
0
 public Hook CheckHookCollision(WeightBlock weightBlock)
 {
     if (weightBlock.Mass > 0)
     {
         for (int i = 0; i < _hooks.Length / 2; i++)
         {
             if (Vector3.Distance(_hooks[i].transform.position, weightBlock.transform.position) <= _minDistanceToHookCollision)
             {
                 return(_hooks[i].HookWeightBlock(weightBlock));
             }
         }
     }
     else
     {
         for (int i = _hooks.Length / 2; i < _hooks.Length; i++)
         {
             if (Vector3.Distance(_hooks[i].transform.position, weightBlock.transform.position) <= _minDistanceToHookCollision)
             {
                 return(_hooks[i].HookWeightBlock(weightBlock));
             }
         }
     }
     return(null);
 }
示例#11
0
 public void RemoveWeightBlockReferenceFromGame(WeightBlock weightBlock)
 {
     _blocks.Remove(weightBlock);
 }