예제 #1
0
파일: DragThrow.cs 프로젝트: kwmcc/Hoarder
    IEnumerator DragObject( float distance  )
    {
        float oldDrag = springJoint.connectedBody.drag;
        float oldAngularDrag = springJoint.connectedBody.angularDrag;
        springJoint.connectedBody.drag = drag;
        springJoint.connectedBody.angularDrag = angularDrag;
        Camera mainCamera = FindCamera();
        while (Input.GetMouseButton (0))
        {
            Ray ray= mainCamera.ScreenPointToRay (new Vector3(mainCamera.pixelWidth/2, mainCamera.pixelHeight/2, 0));
            springJoint.transform.position = ray.GetPoint(distance);
            springJoint.transform.rotation = player.transform.rotation;
            yield return 0;

            if (Input.GetMouseButton (1)){
                springJoint.connectedBody.AddExplosionForce(throwForce,mainCamera.transform.position,throwRange);
                springJoint.connectedBody.drag = oldDrag;
                springJoint.connectedBody.angularDrag = oldAngularDrag;
                springJoint.connectedBody = null;
            }
        }
        if (springJoint.connectedBody)
        {
            springJoint.connectedBody.drag = oldDrag;
            springJoint.connectedBody.angularDrag = oldAngularDrag;
            springJoint.connectedBody = null;
            _hoverObjectValuable.setGrab(false);
            _hoverObjectValuable = null;
        }
    }
예제 #2
0
 void Update()
 {
     // If user clicks the left mouse button and has any valuables to shoot
     if (playerManager.HoldingValuables() && Input.GetMouseButtonDown(0))
     {
         Valuable valuable = playerManager.GetNextValuable();
         Shoot(valuable);
     }
 }
        public void ReflectionSyncTest_TargetValueBecomesEqualToSource()
        {
            var source = new Valuable <string>(string.Empty);
            var target = new Valuable <string>("initialValue");

            _synchronizer.Sync(source, target, _propertyName);
            source.Value = "newValue";

            Assert.That(target.Value, Is.EqualTo(source.Value));
        }
        public void DelegateSyncTest_TargetValueBecomesEqualToSource()
        {
            var source        = new Valuable <string>(string.Empty);
            var sourceContext = new DelegateSyncContext <Valuable <string>, string>(source, _propertyName);
            var target        = new Valuable <string>("initialValue");
            var targetContext = new DelegateSyncContext <Valuable <string>, string>(target, _propertyName);

            _synchronizer.Sync(sourceContext, targetContext);
            source.Value = "newValue";

            Assert.That(target.Value, Is.EqualTo(source.Value));
        }
        // Not part of the engine because it doesn't know if we want a tree, list, etc.
        private List <Valuable> CreateRandomValuables()
        {
            var random   = new Random();
            var toReturn = new List <Valuable>();

            while (toReturn.Count < SOLUTION_LIST_SIZE)
            {
                var next = new Valuable(random.Next(100), random.Next(20));
                toReturn.Add(next);
            }
            return(toReturn);
        }
        public void OneWayToSourceSyncTest_SourceValueBecomesEqualToTargetButNotViceVersa()
        {
            var source = new Valuable <string>(string.Empty);
            var target = new Valuable <string>("initialValue");

            _synchronizer.Sync(source, target, _propertyName, SyncMode.OneWayToSource);

            source.Value = "syncValue";
            Assert.That(target.Value, Is.EqualTo("initialValue"));

            target.Value = "newTargetValue";
            Assert.That(source.Value, Is.EqualTo("newTargetValue"));
        }
예제 #7
0
파일: MouseLook.cs 프로젝트: kwmcc/Hoarder
    void Update()
    {
        if(Time.timeScale != 0){
            // Testing to see if objects are within range of throwing
            RaycastHit hit;
            Vector3 target = new Vector3 (Camera.main.pixelWidth / 2, Camera.main.pixelHeight / 2, 0);
            Ray ray = Camera.main.ScreenPointToRay(target);
            Physics.Raycast (ray, out hit, 3);
            // We need to hit a rigidbody that is not kinematic
            if (!hit.rigidbody || hit.rigidbody.isKinematic){
                crosshairTexture = crosshairTextureRed;
                if(_hoverObjectValuable != null){
                    _hoverObjectValuable.highlightItem(false);
                    _hoverObjectValuable = null;
                }
            }else{
                crosshairTexture = crosshairTextureGreen;
                GameObject _hoverObject = hit.collider.gameObject;
                if(_hoverObjectValuable != null && _hoverObject != _lastHoverObject ){
                    _hoverObjectValuable.highlightItem(false);
                    _hoverObjectValuable = null;
                }
                if(_hoverObjectValuable = hit.collider.gameObject.GetComponent<Valuable>()){
                    _lastHoverObject = hit.collider.gameObject;
                    _hoverObjectValuable.highlightItem(true);
                }
            }

            if (axes == RotationAxes.MouseXAndY)
            {
                float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;

                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
                rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

                transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
            }
            else if (axes == RotationAxes.MouseX)
            {
                transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
            }
            else
            {
                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
                rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

                transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
            }
        }
    }
        public void SyncDisposingTest_NoValueSynchronizationAfterDisposing()
        {
            var source = new Valuable <string>(string.Empty);
            var target = new Valuable <string>("initialValue");

            using (_synchronizer.Sync(source, target, nameof(Valuable <string> .Value)))
            {
                source.Value = "syncValue";
            }

            source.Value = "desyncValue";

            Assert.That(target.Value, Is.EqualTo("syncValue"));
        }
        public void TestSpaceNotAvailableForValuable()
        {
            Ship     ship  = new Ship(2, 2);
            Valuable value = new Valuable {
                ContainerWeight = 20000, Type = ContainerType.Valuable
            };
            List <IContainer> containers = new List <IContainer>()
            {
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Cooled {
                    ContainerWeight = 30000, Type = ContainerType.Cooled
                },
                new Valuable {
                    ContainerWeight = 20000, Type = ContainerType.Valuable
                },
                new Valuable {
                    ContainerWeight = 20000, Type = ContainerType.Valuable
                }
            };

            ship.PlaceAllContainers(containers);
            Assert.IsNull(value.SearchSpace(ship.Columns.ToList()));
        }
예제 #10
0
 public Valuable GetNextValuable()
 {
     // Sanity check to see if list of held valuables is not empty
     if (HoldingValuables())
     {
         // Retrieve and remove valuable from list of held valuables
         Valuable shotVal = heldValuables[0];
         RemoveValuable(shotVal);
         return(shotVal);
     }
     else
     {
         Debug.LogError("Asked for a valuable when holding none! Check HoldingValuables() first!");
         return(null);
     }
 }
예제 #11
0
    void Shoot(Valuable valuable)
    {
        // throwAudio.Play();
        //shotParticles.Stop ();
        //shotParticles.Play ();

        // re-enable valuable physics before spawning it + reset parent
        valuable.gameObject.tag   = Constants.TAG_UNTAGGED;
        valuable.gameObject.layer = LayerMask.NameToLayer(Constants.LAYER_PROJECTILE);
        valuable.ResetParent();
        valuable.EnablePhysics();

        // Spawns valuable in front of player
        GameObject shotVal = Instantiate(valuable.gameObject, shootFrom.position, transform.rotation);

        // Destroy valuable that was on player now that we no longer need it
        Destroy(valuable.gameObject);

        // Add force to valuable to be thrown in direction of player
        shotVal.GetComponent <Rigidbody>().AddForce(transform.forward * shootSpeed);
    }
예제 #12
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag(Constants.TAG_VALUABLE))
        {
            Valuable   valuable   = collision.gameObject.GetComponent <Valuable>();
            Rigidbody  rb         = collision.gameObject.GetComponent <Rigidbody>();
            MeshFilter meshFilter = collision.gameObject.GetComponent <MeshFilter>();
            if (!valuable)
            {
                Debug.LogError("No Valuable!");
                return;
            }
            if (!rb)
            {
                Debug.LogError("No Rigidbody!");
                return;
            }
            if (!meshFilter)
            {
                Debug.LogError("No MeshFilter!");
                return;
            }

            // update internal list
            AddValuable(valuable);

            // set the parent of the object to be the player now (moves with player now)
            valuable.SetParent(transform);

            // freeze pos and rot, and stop collision (no weird, rigidbody physics + no more colliding with magnetic cone)
            valuable.DisablePhysics();

            // push player back based on the mesh size
            // we only push back the player if they sucked the object to them, otherwise it just sticks
            if (magneticRange.magnetismActive)
            {
                playerRb.AddForce((transform.position - collision.transform.position).normalized * Vector3.Scale(collision.transform.localScale, meshFilter.mesh.bounds.size).magnitude *blowBackForce, ForceMode.Impulse);
            }
        }
    }
예제 #13
0
 private void OnTriggerExit(Collider other)
 {
     if (other.CompareTag(Constants.TAG_VALUABLE))
     {
         Valuable valuable = other.GetComponent<Valuable>();
         if (!valuable)
         {
             Debug.LogError($"{other.name}: Object with Valuable tag but no component!");
         }
         else
         {
             Debug.Log($"Removing valuable with value of {valuable.price}...");
             if (valuablesInRange.Contains(valuable))
             {
                 valuablesInRange.Remove(valuable);
             } else
             {
                 Debug.LogError($"Almost tried to remove valuable {other.name} but was not in HashSet!");
             }
         }
     }
 }
        public void FacilityMap_Valuables_AreCorrect()
        {
            _map.Add(_sampleLayer);
            var value1 = new ValuableFacilityObject {
                Type = "Painting", ObjectLayer = ObjectLayer.UpperObject
            };
            var container = new ValuablesContainer {
                Type = "Table", ObjectLayer = ObjectLayer.LowerObject
            };
            var value2 = new Valuable {
                Type = "Diamond"
            };

            container.Put(value2);
            _map[5, 5, 0].Put(value1);
            _map[7, 8, 0].Put(container);

            var valuables = _map.SpatialValuables.ToList();

            Assert.AreEqual(2, valuables.Count);
            Assert.IsTrue(valuables.Any(x => x.Obj.Type.Equals("Painting")));
            Assert.IsTrue(valuables.Any(x => x.Obj.Type.Equals("Diamond")));
        }
예제 #15
0
파일: DragThrow.cs 프로젝트: kwmcc/Hoarder
    void Update()
    {
        //toggle between holding and not

        // Make sure the user pressed the mouse down
        if (!Input.GetMouseButtonDown (0))
            return;

        Camera mainCamera = FindCamera();

        // We need to actually hit an object
        RaycastHit hit;
        Ray ray= mainCamera.ScreenPointToRay(new Vector3(mainCamera.pixelWidth/2, mainCamera.pixelHeight/2, 0));
        if (!Physics.Raycast(ray, out hit, range))
            return;
        // We need to hit a rigidbody that is not kinematic
        if (!hit.rigidbody || hit.rigidbody.isKinematic)
            return;

        if (!springJoint)
        {
            GameObject go = new GameObject("Rigidbody dragger");
            Rigidbody body = go.AddComponent ("Rigidbody") as Rigidbody;
            springJoint = (SpringJoint) go.AddComponent ("SpringJoint");
            body.isKinematic = true;
        }

        if(_hoverObjectValuable = hit.collider.gameObject.GetComponent<Valuable>()){
            _hoverObjectValuable.setGrab(true);
        }

        springJoint.transform.position = hit.point;
        if (attachToCenterOfMass)
        {
            Vector3 anchor= transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
            anchor = springJoint.transform.InverseTransformPoint(anchor);
            springJoint.anchor = anchor;
        }
        else
        {
            springJoint.anchor = Vector3.zero;
        }

        springJoint.spring = spring;
        springJoint.damper = damper;
        springJoint.maxDistance = distance;
        springJoint.connectedBody = hit.rigidbody;

        StartCoroutine ("DragObject", hit.distance);
    }
예제 #16
0
 void RemoveValuable(Valuable valuable)
 {
     heldValuables.Remove(valuable);
 }
예제 #17
0
 // Add valuable to the list of held items
 private void AddValuable(Valuable valuable)
 {
     heldValuables.Add(valuable);
 }
예제 #18
0
 public void UpdateValuables(Valuable valueable)
 {
     if (valueable.type == ValuableType.gemstone)
         gemstones++;
 }