Exemple #1
0
    /// <summary>
    /// クラッチをつなぎ,クラッチが離れている間の姿勢の変化によるフセット値を更新する.
    /// 成功した場合はtrueを返し,クラッチが離れていない場合は何もせずにfalseを返す.
    /// </summary>
    /// <returns>
    /// true: 成功
    /// false: 失敗
    /// </returns>
    public bool EngageClutch()
    {
        if (clutchEngaged)
        {
            return(false);
        }

        clutchedPositionOffset = clutchedPosition - rawPose.position;

        pose.position        = RotationOffset * (rawPose.position + clutchedPositionOffset) + PositionOffset;
        pose.rotation        = RotationOffset * rawPose.rotation;
        pose.velocity        = Vector3.zero;
        pose.angularVelocity = Vector3.zero;

        prevPose = pose;

        if (holdingObject != null)
        {
            Quaternion q = QuaternionUtility.Rotate(model.pointerOrigin.rotation, RotationOffset * clutchedRotation);
            model.pointerOrigin.rotation = Quaternion.Inverse(q) * pose.rotation;
        }
        clutchEngaged = true;

        return(true);
    }
Exemple #2
0
    //
    public Vector3 CalcTorque(Pose pointer, Rigidbody rigidbody)
    {
        Quaternion pointerRotation   = QuaternionUtility.Rotate(pointerOrigin.rotation, pointer.rotation);
        Quaternion rigidbodyRotation = QuaternionUtility.Rotate(rigidbodyOrigin.rotation, rigidbody.rotation);

        Quaternion qd;

        if (Quaternion.Dot(pointerRotation, rigidbodyRotation) > 0)
        {
            qd = QuaternionUtility.Subtract(pointerRotation, rigidbodyRotation);
        }
        else
        {
            qd = QuaternionUtility.Add(pointerRotation, rigidbodyRotation);
        }

        Quaternion conj = QuaternionUtility.Conjugated(pointerRotation);

        Quaternion temp = qd * conj;

        Vector3 angle = Vector3.zero;

        angle.x = temp.x * 2.0f;
        angle.y = temp.y * 2.0f;
        angle.z = temp.z * 2.0f;

        if (angle.x > Mathf.PI)
        {
            angle.x -= Mathf.PI * 2;
        }
        else if (angle.x < -Mathf.PI)
        {
            angle.x += Mathf.PI * 2;
        }

        if (angle.y > Mathf.PI)
        {
            angle.y -= Mathf.PI * 2;
        }
        else if (angle.y < -Mathf.PI)
        {
            angle.y += Mathf.PI * 2;
        }

        if (angle.z > Mathf.PI)
        {
            angle.z -= Mathf.PI * 2;
        }
        else if (angle.z < -Mathf.PI)
        {
            angle.z += Mathf.PI * 2;
        }

        Vector3 angularVelocity = pointer.angularVelocity - rigidbody.angularVelocity;

        return(SpringK * angle + DamperB * angularVelocity);
    }
Exemple #3
0
        private void PanCamera(float deltaX, float deltaY)
        {
            var cameraOrientation = QuaternionUtility.CreateFromYawPitchRoll_ZUp(
                _yaw,
                _pitch,
                0);

            _translation += Vector3.Transform(-Vector3.UnitX, cameraOrientation) * deltaX * PanSpeed;
            _translation += Vector3.Transform(Vector3.UnitZ, cameraOrientation) * deltaY * PanSpeed;
        }
    private void RotateHand()
    {
        handObject.transform.Rotate(new Vector3(mousePosition.y, 0, mousePosition.x));

        Vector3 clampedEulers = handObject.transform.eulerAngles;

        clampedEulers.x = QuaternionUtility.GetEulerByInspectorAngle(Mathf.Clamp(QuaternionUtility.GetInspectorAngleByEuler(handObject.transform.eulerAngles.x + mousePosition.y), minXAngle, maxXAngle));
        clampedEulers.y = 0f;
        clampedEulers.z = QuaternionUtility.GetEulerByInspectorAngle(Mathf.Clamp(QuaternionUtility.GetInspectorAngleByEuler(handObject.transform.eulerAngles.z + mousePosition.x), minZAngle, maxZAngle));
        handObject.transform.eulerAngles = clampedEulers;
    }
        public override void Update(double deltaTime)
        {
            var p = GeometryUtility.CalculateFrustumPlanes(GetComponent <Camera>());

            for (int i = 0; i < 6; i++)
            {
                // is broken maybe, furstum culling works but this doesnt make much sense
                //gos[i].transform.position = p[i].normal * p[i].distance;
                gos[i].transform.rotation = QuaternionUtility.LookRotation(p[i].normal);
            }
        }
Exemple #6
0
        public List <BoardCell> WithinCollider(Collider2D collider, Vector3 origin, Vector3 target)
        {
            collider.transform.position = origin;
            collider.transform.rotation = QuaternionUtility.LookRotation2D(target - origin);

            var colliders = new Collider2D[50];
            var overlaps  = Physics2D.OverlapCollider(collider, new ContactFilter2D(), colliders);

            collider.transform.position = new Vector3(-100, 0, 0);

            return(colliders.Take(overlaps).ToCellsPrecise().ToList());
        }
Exemple #7
0
        private void UpdateCamera()
        {
            var position = Vector3.Transform(
                -Vector3.UnitY,
                QuaternionUtility.CreateFromYawPitchRoll_ZUp(_yaw, _pitch, 0));

            position *= _zoom * _radius;
            position += _target;

            Entity.Transform.LocalPosition = position + _translation;
            Entity.Transform.LookAt(_target + _translation);
        }
    void Start()
    {
        //Movement
        maxZPosition = transform.position.z + maxZDistance;
        maxXPosition = transform.position.x + maxXDistance;
        minZPosition = transform.position.z;
        minXPosition = transform.position.x - maxXDistance;
        maxYPosition = transform.position.y + maxHeight;
        minYPosition = transform.position.y;

        //Rotation
        maxXAngle = QuaternionUtility.GetInspectorAngleByEuler(handObject.transform.eulerAngles.x) + maxXRotation;
        maxZAngle = QuaternionUtility.GetInspectorAngleByEuler(handObject.transform.eulerAngles.z) + maxZRotation;
        minXAngle = QuaternionUtility.GetInspectorAngleByEuler(handObject.transform.eulerAngles.x) - maxXRotation;
        minZAngle = QuaternionUtility.GetInspectorAngleByEuler(handObject.transform.eulerAngles.z) - maxZRotation;
    }
Exemple #9
0
        public void Draw(List <Vector3> points)
        {
            this.lineRenderer.positionCount = points.Count;
            this.lineRenderer.SetPositions(points.ToArray());

            if (points.Count < 2)
            {
                this.arrow.color = new Color(0, 0, 0, 0);
                return;
            }

            this.arrow.transform.position = points.Last();
            this.arrow.transform.rotation = QuaternionUtility.LookRotation2D(
                points[points.Count - 1] - points[points.Count - 2]);

            Drawn?.Invoke(points);
            AnyPathDrawn?.Invoke(points);
        }
Exemple #10
0
        private void PanCamera(float deltaX, float deltaY)
        {
            var cameraOrientation = QuaternionUtility.CreateFromYawPitchRoll_ZUp(
                _yaw,
                DefaultPitch,
                0);

            var panSpeed = PanSpeed * _zoom;

            var newTranslation = Vector3.Zero;

            newTranslation += Vector3.Transform(-Vector3.UnitX, cameraOrientation) * deltaX * panSpeed;
            newTranslation += Vector3.Transform(Vector3.UnitZ, cameraOrientation) * deltaY * panSpeed;

            newTranslation.Z = 0;

            _translation += newTranslation;
        }
Exemple #11
0
        public static void MoveCameraTo(ScriptExecutionContext context, [ScriptArgumentType(ScriptArgumentType.WaypointName)] string cameraName, float rawDuration, float shutter, float easeIn, float easeOut)
        {
            var camera = context.Scene.Cameras[cameraName];

            var targetPoint = camera.LookAtPoint;

            var duration = TimeSpan.FromSeconds(rawDuration);

            var animation = context.Scene.CameraController.StartAnimation(
                new[] { context.Scene.CameraController.TerrainPosition, targetPoint },
                context.UpdateTime.TotalTime,
                duration);

            var rotation   = QuaternionUtility.CreateFromYawPitchRoll_ZUp(camera.Yaw, 0, camera.Roll);
            var lookToward = Vector3.Transform(Vector3.UnitY, rotation);

            animation.SetFinalLookDirection(lookToward);

            animation.SetFinalPitchAngle(-camera.Pitch);

            animation.SetFinalZoom(camera.Zoom);

            animation.SetFinalFieldOfView(camera.FieldOfView);
        }
Exemple #12
0
        void Update(float deltaTime)
        {
            if (deltaTime > 1 / 30f)
            {
                deltaTime = 1 / 30f;
            }

            var rotation = Transform.Rotation;
            var position = Transform.Position;


            if (Debug.GetCVar("game / camera position 1 / save").EatBoolIfTrue())
            {
                savedPosition1 = position;
                savedRotation1 = rotation;
            }
            if (Debug.GetCVar("game / camera position 1 / load").EatBoolIfTrue())
            {
                position = Transform.Position = savedPosition1;
                rotation = Transform.Rotation = savedRotation1;
            }

            if (Debug.GetCVar("game / camera position 2 / save").EatBoolIfTrue())
            {
                savedPosition2 = position;
                savedRotation2 = rotation;
            }
            if (Debug.GetCVar("game / camera position 2 / load").EatBoolIfTrue())
            {
                position = Transform.Position = savedPosition2;
                rotation = Transform.Rotation = savedRotation2;
            }


            var planet = planets?.GetClosestPlanet(position);


            Debug.AddValue("camera / speed modifier", cameraSpeedModifier);
            Debug.AddValue("camera / position", position);

            var mouse = Mouse.GetState();

            var mouseDelta = new Point(mouse.X - lastMousePos.X, mouse.Y - lastMousePos.Y);

            lastMousePos = new Point(mouse.X, mouse.Y);

            int scrollWheelDelta = mouse.ScrollWheelValue - scrollWheelValue;

            scrollWheelValue = mouse.ScrollWheelValue;


            if (Input.GetKeyDown(Key.Escape))
            {
                if (Scene.Engine.WindowState == WindowState.Fullscreen)
                {
                    Scene.Engine.WindowState = WindowState.Normal;
                }
                else if (Input.LockCursor)
                {
                    Input.LockCursor    = false;
                    Input.CursorVisible = true;
                }
                else
                {
                    Scene.Engine.Exit();
                }
            }

            if (Input.GeMouseButtonDown(MouseButton.Left))
            {
                if (Input.LockCursor == false)
                {
                    Input.LockCursor    = true;
                    Input.CursorVisible = false;
                }
            }


            float planetSpeedModifier = 1;

            if (planet != null)
            {
                var planetLocalPosition          = planet.Transform.Position.Towards(position).ToVector3d();
                var sphericalPlanetLocalPosition = planet.CalestialToSpherical(planetLocalPosition);
                var onPlanetSurfaceHeight        = planet.GetSurfaceHeight(planetLocalPosition);
                var onPlanetDistanceToSurface    = sphericalPlanetLocalPosition.altitude - onPlanetSurfaceHeight;

                {
                    Debug.AddValue("camera / distance to surface", onPlanetDistanceToSurface);
                    {
                        var s = MyMath.SmoothStep(1, 30000, (float)onPlanetDistanceToSurface);
                        cam.NearClipPlane = 1000 * s + 0.5f;
                        cam.FarClipPlane  = 5000000 * s + 100000;
                    }
                }


                if (speedBasedOnDistanceToPlanet)
                {
                    var s = MyMath.Clamp(onPlanetDistanceToSurface, 1, 30000);
                    planetSpeedModifier = (1 + (float)s / 5.0f);
                }
            }

            if (Input.LockCursor)
            {
                if (scrollWheelDelta > 0)
                {
                    cameraSpeedModifier *= 1.3f;
                }
                if (scrollWheelDelta < 0)
                {
                    cameraSpeedModifier /= 1.3f;
                }
                cameraSpeedModifier = MyMath.Clamp(cameraSpeedModifier, 1, 100000);
                float currentSpeed = cameraSpeedModifier * planetSpeedModifier;



                if (Input.GetKey(Key.ShiftLeft))
                {
                    currentSpeed *= 5;
                }

                Debug.AddValue("camera / real speed", currentSpeed);

                var targetVelocity = Vector3.Zero;
                if (Input.GetKey(Key.W))
                {
                    targetVelocity += currentSpeed * Constants.Vector3Forward;
                }
                if (Input.GetKey(Key.S))
                {
                    targetVelocity -= currentSpeed * Constants.Vector3Forward;
                }
                if (Input.GetKey(Key.D))
                {
                    targetVelocity += currentSpeed * Constants.Vector3Right;
                }
                if (Input.GetKey(Key.A))
                {
                    targetVelocity -= currentSpeed * Constants.Vector3Right;
                }
                if (Input.GetKey(Key.Space))
                {
                    targetVelocity += currentSpeed * Constants.Vector3Up;
                }
                if (Input.GetKey(Key.ControlLeft))
                {
                    targetVelocity -= currentSpeed * Constants.Vector3Up;
                }

                //var pos = Matrix4.CreateTranslation(targetVelocity);


                float pitchDelta = 0;
                float yawDelta   = 0;
                float rollDelta  = 0;

                float c = mouseSensitivty * (float)deltaTime;
                yawDelta   += mouseDelta.X * c;
                pitchDelta += mouseDelta.Y * c;

                if (Input.GetKey(Key.Q))
                {
                    rollDelta -= c;
                }
                if (Input.GetKey(Key.E))
                {
                    rollDelta += c;
                }


                if (planet != null && Input.GetKeyDown(Key.C))
                {
                    rotation = position.Towards(planet.Transform.Position).ToVector3d().Normalized().ToVector3().LookRot();
                }

                if (planet != null && WalkOnPlanet.Bool)
                {
                    var up      = planet.Center.Towards(position).ToVector3().Normalized();
                    var forward = walkOnSphere_lastForward;

                    if (walkOnSphere_isFirstRun)
                    {
                        walkOnSphere_lastUp = up;

                        var pointOnPlanet = planet.Center.Towards(position).ToVector3d();
                        var s             = planet.CalestialToSpherical(pointOnPlanet);
                        //s.latitude += 0.1f;
                        //var forwardToPole = pointOnPlanet.Towards(planet.SphericalToCalestial(s)).Normalized().ToVector3().Normalized();
                        forward = Constants.Vector3Forward.RotateBy(rotation);
                    }
                    else
                    {
                        var upDeltaAngle = up.Angle(walkOnSphere_lastUp);
                        var upDeltaRot   = Quaternion.FromAxisAngle(up.Cross(walkOnSphere_lastUp), upDeltaAngle).Inverted();

                        forward = forward.RotateBy(upDeltaRot);
                    }


                    var left = up.Cross(forward);

                    var rotDelta =
                        Quaternion.FromAxisAngle(up, -yawDelta) *
                        Quaternion.FromAxisAngle(left, pitchDelta);


                    forward = forward.RotateBy(rotDelta);

                    {
                        // clamping up down rotation
                        var maxUpDownAngle = 80;
                        var minUp          = MyMath.ToRadians(90 - maxUpDownAngle);
                        var maxDown        = MyMath.ToRadians(90 + maxUpDownAngle);
                        var angle          = forward.Angle(up);
                        if (angle < minUp)
                        {
                            forward = up.RotateBy(Quaternion.FromAxisAngle(left, minUp));
                        }
                        else if (angle > maxDown)
                        {
                            forward = up.RotateBy(Quaternion.FromAxisAngle(left, maxDown));
                        }
                    }


                    forward.Normalize();

                    rotation = QuaternionUtility.LookRotation(forward, up);

                    walkOnSphere_lastForward = forward;
                    walkOnSphere_lastUp      = up;
                    walkOnSphere_isFirstRun  = false;
                }
                else
                {
                    var rotDelta =
                        Quaternion.FromAxisAngle(-Vector3.UnitX, pitchDelta) *
                        Quaternion.FromAxisAngle(-Vector3.UnitY, yawDelta) *
                        Quaternion.FromAxisAngle(-Vector3.UnitZ, rollDelta);

                    rotation = rotation * rotDelta;

                    walkOnSphere_isFirstRun = true;
                }



                Transform.Rotation = rotation;

                targetVelocity  = targetVelocity.RotateBy(rotation);
                currentVelocity = Vector3.Lerp(currentVelocity, targetVelocity, velocityChangeSpeed * (float)deltaTime);

                position += currentVelocity * (float)deltaTime;

                // make cam on top of the planet
                if (planet != null && collideWithPlanetSurface)
                {
                    var planetLocalPosition          = planet.Transform.Position.Towards(position).ToVector3d();
                    var sphericalPlanetLocalPosition = planet.CalestialToSpherical(planetLocalPosition);
                    var onPlanetSurfaceHeight        = planet.GetSurfaceHeight(planetLocalPosition);
                    var onPlanetDistanceToSurface    = sphericalPlanetLocalPosition.altitude - onPlanetSurfaceHeight;

                    var h = onPlanetSurfaceHeight + 2;
                    if (sphericalPlanetLocalPosition.altitude <= h || WalkOnPlanet.Bool)
                    {
                        sphericalPlanetLocalPosition.altitude = h;
                        position = planet.Transform.Position + planet.SphericalToCalestial(sphericalPlanetLocalPosition);
                    }
                }


                Transform.Position = position;                 // += Entity.Transform.Position.Towards(position).ToVector3d() * deltaTime * 10;

                //Log.Info(entity.transform.position);
            }
        }
Exemple #13
0
        internal void BuildRenderList(RenderList renderList, MeshComponent mesh)
        {
            if (Hidden)
            {
                return;
            }

            Matrix4x4 world;

            if (CameraOriented)
            {
                var localToWorldMatrix = mesh.Transform.LocalToWorldMatrix;

                var viewInverse    = Matrix4x4Utility.Invert(mesh.Game.Scene.Camera.View);
                var cameraPosition = viewInverse.Translation;

                var toCamera = Vector3.Normalize(Vector3.TransformNormal(
                                                     cameraPosition - mesh.Transform.WorldPosition,
                                                     mesh.Transform.WorldToLocalMatrix));

                toCamera.Z = 0;

                var cameraOrientedRotation = Matrix4x4.CreateFromQuaternion(QuaternionUtility.CreateRotation(Vector3.UnitX, toCamera));

                world = cameraOrientedRotation * localToWorldMatrix;
            }
            else
            {
                world = mesh.Transform.LocalToWorldMatrix;
            }

            ModelComponent modelComponent = null;

            if (Skinned)
            {
                modelComponent = mesh.Entity.GetComponent <ModelComponent>();
            }

            foreach (var materialPass in MaterialPasses)
            {
                foreach (var meshPart in materialPass.MeshParts)
                {
                    meshPart.Material.SetSkinningBuffer(modelComponent?.SkinningBuffer);

                    var renderQueue = meshPart.Material.PipelineState.BlendState.Enabled
                        ? renderList.Transparent
                        : renderList.Opaque;

                    renderQueue.AddRenderItemDrawIndexed(
                        meshPart.Material,
                        _vertexBuffer,
                        materialPass.TexCoordVertexBuffer,
                        CullFlags.None,
                        mesh,
                        world,
                        meshPart.StartIndex,
                        meshPart.IndexCount,
                        _indexBuffer);
                }
            }
        }
Exemple #14
0
 public static void LookAt2D(this Transform transform, Vector3 target)
 {
     transform.rotation = QuaternionUtility.LookRotation2D(target - transform.position);
 }
        public override void Update(double deltaTime)
        {
            var        ray = new Ray(this.transform.position, this.transform.forward);
            RaycastHit raycastHit;

            if (Physics.Raycast(ray, out raycastHit))
            {
                visualiseHitTarget.transform.position = raycastHit.point;
                visualiseHitTarget.transform.rotation = QuaternionUtility.LookRotation(raycastHit.normal);
                var legoPiece = raycastHit.collider.gameObject.GetComponent <LegoPiece>();
                if (legoPiece)
                {
                    if (legoPiece != lastLegoPiece)
                    {
                        if (lastLegoPiece)
                        {
                            lastLegoPiece.GetComponent <MeshRenderer>().material.albedo = lastAlbedo;
                        }
                        lastLegoPiece = legoPiece;

                        var m = lastLegoPiece.GetComponent <MeshRenderer>().material;
                        lastAlbedo = m.albedo;
                        const float T = 1.0f;
                        const float F = 0.3f;
                        if (clickedLegoPiece && clickedLegoPiece != lastLegoPiece)
                        {
                            m.albedo = new Vector4(F, T, F, 1);
                        }
                        else
                        {
                            m.albedo = new Vector4(T, F, F, 1);
                        }
                    }

                    if (clickedLegoPiece && lastLegoPiece && clickedLegoPiece != lastLegoPiece)
                    {
                        clickedLegoPiece.VizualizeConnectionTo(lastLegoPiece, visualiseHitTarget.transform.position);
                    }
                }
                else
                {
                    if (lastLegoPiece)
                    {
                        lastLegoPiece.GetComponent <MeshRenderer>().material.albedo = lastAlbedo;
                    }
                    lastLegoPiece = null;
                }
            }
            else
            {
                if (lastLegoPiece)
                {
                    lastLegoPiece.GetComponent <MeshRenderer>().material.albedo = lastAlbedo;
                }
                lastLegoPiece = null;
            }


            if (Input.GeMouseButtonDown(MouseButton.Left))
            {
                if (lastLegoPiece == null)
                {
                    if (clickedLegoPiece != null)
                    {
                        clickedLegoPiece.EndVisualise();
                        var p = visualiseHitTarget.transform.position - clickedLegoPiece.GetComponent <MeshRenderer>().mesh.bounds.center;
                        p.Y += 0.5f;
                        clickedLegoPiece.transform.position = p;
                        clickedLegoPiece.transform.rotation = visualiseHitTarget.transform.rotation;
                        clickedLegoPiece = null;
                    }
                }
                else
                {
                    if (clickedLegoPiece != null)
                    {
                        if (clickedLegoPiece != lastLegoPiece)
                        {
                            clickedLegoPiece.VizualizeConnectionTo(lastLegoPiece, visualiseHitTarget.transform.position);
                            clickedLegoPiece.ConnectTo(lastLegoPiece);
                            clickedLegoPiece = null;
                        }
                    }
                    else
                    {
                        clickedLegoPiece = lastLegoPiece;
                        clickedLegoPiece.StartVisualise();
                    }
                }
            }


            if (Input.GeMouseButton(MouseButton.Right))
            {
                if (lastLegoPiece)
                {
                    var rb = lastLegoPiece.GetComponent <Rigidbody>();
                    if (rb)
                    {
                        rb.AddForceAtPosition(transform.forward * 100, transform.position);
                    }
                }
            }

            if (Input.GetKeyDown(Key.L))
            {
                Debug.Info("a");
                Physics.IgnoreCollision(lastLegoPiece.GetComponent <Collider>(), clickedLegoPiece.GetComponent <Collider>(), true);
            }



            if (Input.GetKey(Key.AltLeft))
            {
                MyEngine.ParticleSimulation.Manager.instance.GenerateParticles(1000, visualiseHitTarget.transform.position, new Vector4(1, 1, 1, 1), new Vector4(1, 1, 1, 1), 1000, 1, 1);
            }
        }
Exemple #16
0
        public static bool StringToValueOfType(this string text, Type t, ref object result, bool errorMessages = false)
        {
            if (t == typeof(string))
            {
                result = text;
                return(true);
            }

            if (t == typeof(bool))
            {
                bool v;
                if (bool.TryParse(text, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to bool\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(int))
            {
                int v;
                if (Int32.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to integer\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(uint))
            {
                uint v;
                if (UInt32.TryParse(text, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to unsigned integer\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(long))
            {
                long v;
                if (long.TryParse(text, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to long integer\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(float))
            {
                float v;
                if (float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to float\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(Color))
            {
                var colorValue = Color.magenta;
                if (ColorUtility.TryParse(text, ref colorValue))
                {
                    result = colorValue;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to color\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(Vector3))
            {
                var vector3Value = new Vector3();
                if (VectorUtility.TryParseVector(text, ref vector3Value))
                {
                    result = vector3Value;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to vector3\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(Quaternion))
            {
                var quaternionValue = new Quaternion();
                if (QuaternionUtility.TryParseQuaternion(text, ref quaternionValue))
                {
                    result = quaternionValue;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to quaternion\n");
                    }
                    return(false);
                }
            }

            if (t.IsEnum)
            {
                // No TryParse until .NET 4...so we have to handle exceptions
                object value = null;
                var    valid = true;
                int    temp;
                if (Int32.TryParse(text, out temp))    // Check to see if it's just a number...then fail it.  (Enum.Parse allows it!)
                {
                    valid = false;
                }
                else
                {
                    try
                    {
                        value = Enum.Parse(t, text, true);
                    }
                    catch (Exception)
                    {
                        valid = false;
                    }
                }

                if (valid)
                {
                    result = value;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to the required enum.  Valid enum values are:\n");
                        foreach (var val in Enum.GetValues(t))
                        {
                            Debug.Log("   " + val);
                        }
                    }
                    return(false);
                }
            }

            Debug.LogError("Error:  Argument type not yet supported.  Assigning \"\"");

            result = "";
            return(true);
        }