public override bool Equals(MergeableObject obj)
        {
            if (!(obj is SettingsBase))
            throw new ArgumentException("Object must be an instance of the SettingsBase class.", "obj");

              SettingsBase settings = (SettingsBase)obj;

              return Parameters.Equals(settings.Parameters) && DataSources.Equals(settings.DataSources);
        }
        public override bool Equals(MergeableObject obj)
        {
            if (!(obj is Parameter))
            throw new ArgumentException("Object must be an instance of the SettingsParameter class.", "obj");

              Parameter parameter = (Parameter)obj;

              return (parameter != null) ? (parameter.Name == Name && parameter.Value == Value) : false;
        }
        public override void Merge(MergeableObject obj)
        {
            if (!(obj is SettingsBase))
            throw new ArgumentException("Object must be an instance of the SettingsBase class.", "obj");

              SettingsBase settings = (SettingsBase)obj;

              Parameters.Merge(settings.Parameters);
              DataSources.Merge(settings.DataSources);

              OnMerged();
        }
        public override void Merge(MergeableObject obj)
        {
            if (!(obj is Parameter))
            throw new ArgumentException("Object must be an instance of the SettingsParameter class.", "obj");

              Parameter parameter = (Parameter)obj;

              Name = parameter.Name;
              Value = parameter.Value;

              OnMerged();
        }
        public override void Merge(MergeableObject obj)
        {
            if (!(obj is Source))
            throw new ArgumentException("Object must be an instance of the Source class.", "obj");

              Source source = (Source)obj;

              Interval = source.Interval;
              Url = source.Url;
              Name = source.Name;

              OnMerged();
        }
示例#6
0
    private void DetectObjectCollision()
    {
        var collisions = Physics.OverlapSphere(transform.position, 1.5f, grabbiesLayerMask);

        DebugExtensions.DebugWireSphere(transform.position, Color.black, 1.5f, 2f);

        if (collisions.Length == 0)
        {
            return;
        }

        var mergeableObject = collisions[0].GetComponentInParent <MergeableObject>();

        if (currentMergeableObject == null)
        {
            currentMergeableObject = mergeableObject;
            mergeableObject.transform.SetParent(grabbyPoint);
            mergeableObject.transform.localPosition = Vector3.zero;
            mergeableObject.transform.localRotation = Quaternion.identity;
            mergeableObject.transform.localScale    = Vector3.one;
            collisions[0].enabled = false;
            mergeableObject.GetComponent <FakeGravity>().enabled = false;

            AudioManager.Instance.PlayCombineSuccess();
            //Close hands
        }
        else
        {
            if (currentMergeableObject.UpgradeObjectByAddition(mergeableObject.VectorMaterial))
            {
                AudioManager.Instance.PlayCombineSuccess();
                Destroy(mergeableObject.gameObject);
            }
            else
            {
                AudioManager.Instance.PlayCombineFail();
            }
        }
    }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        if (GameFlowManager.Instance.GameOver)
        {
            return;
        }

#if !KEYBOARD_MODE
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            Joycon j = joycons[jc_ind];

            // GetButtonDown checks if a button has been pressed (not held)
            //if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
            //{
            //    Debug.Log("Shoulder button 2 pressed");
            //    // GetStick returns a 2-element vector with x/y joystick components
            //    Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

            //    // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
            //    j.Recenter();
            //}

            //if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            //{
            //    Debug.Log("Rumble");

            //    // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
            //    // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

            //    j.SetRumble(160, 320, 0.6f, 200);

            //    // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
            //    // (Useful for dynamically changing rumble values.)
            //    // Then call SetRumble(0,0,0) when you want to turn it off.
            //}

            //if (j.GetButtonDown(Joycon.Button.DPAD_LEFT))
            //{
            //    Debug.Log("Rumble");

            //    // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
            //    // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

            //    int low_freq = Random.Range(100, 150);
            //    int high_freq = Random.Range(320, 500);
            //    float amp = Random.Range(0.5f, 1f);
            //    int time = Random.Range(100, 500);
            //    j.SetRumble(low_freq, high_freq, amp, time);

            //    // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
            //    // (Useful for dynamically changing rumble values.)
            //    // Then call SetRumble(0,0,0) when you want to turn it off.
            //}

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            oldAccel = accel;
            accel    = j.GetAccel();

            orientation = j.GetVector();
            var   position    = transform.position;
            float sensitivity = this.sensitivity / 1000;
            position.x += stick[0] * sensitivity;
            position.z += stick[1] * sensitivity;

            ClampPosition(ref position);

            hover1.UpdateRotation = false;
            hover2.UpdateRotation = false;

            if (handState == HandState.Idle)
            {
                if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
                {
                    holdingButton  = Joycon.Button.SHOULDER_2;
                    startPressTime = Time.time;
                }
                else if (j.GetButtonDown(Joycon.Button.STICK))
                {
                    holdingButton  = Joycon.Button.STICK;
                    startPressTime = Time.time;
                }
                else if (holdingButton != Joycon.Button.CAPTURE)
                {
                    if (j.GetButtonUp(holdingButton))
                    {
                        holdingButton  = Joycon.Button.CAPTURE;
                        handState      = HandState.GoingDown;
                        startPressTime = 0;
                    }
                    else if (holdingSomethingYeetable && Time.time - startPressTime > holdDurationRequirement)
                    {
                        handState      = HandState.ChargingYeet;
                        startPressTime = 0;
                    }
                }
                //if (j.GetButton(Joycon.Button.SHOULDER_1))
                //{
                //    handState = HandState.GoingDown;
                //}
                //else if (holdingSomethingYeetable && j.GetButton(Joycon.Button.SHOULDER_2))
                //{
                //    handState = HandState.ChargingYeet;
                //}
            }

            if (handState == HandState.ChargingYeet)
            {
                if (j.GetButton(holdingButton))
                {
                    yeetingPower += (oldAccel - accel).magnitude;
                    yeetingPower  = Mathf.Clamp(yeetingPower, 0, MAX_YEETING_POWER);

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);
                    j.SetRumble(yoteMin, yoteMax, 0.6f);
                }
                else if (j.GetButtonUp(holdingButton))
                {
                    holdingButton = Joycon.Button.CAPTURE;

                    //Debug.LogFormat("Yoting {0}", yeetingPower);
                    handState = HandState.Yeeting;

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);
                    j.SetRumble(yoteMin, yoteMax, 0.6f, 200);

                    var direction = ourPosition.position.x <= opponentPosition.position.x;
                    if (yeetDirection != direction)
                    {
                        yeetRotMin *= -1;
                        yeetRotMax *= -1;
                    }
                    yeetDirection = direction;
                }
            }

            if (handState == HandState.GoingDown)
            {
                position.y -= descentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y    -= descentSpeed * grabbySpeedIncrement * Time.deltaTime;
                grabbyPoint.localPosition = grabbyPointPosition;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingDown: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y <= MaxDescentPosition)
                {
                    position.y = MaxDescentPosition;
                    DetectObjectCollision();
                    handState = HandState.GoingUp;

                    materialOffset.y           = 0;
                    material.mainTextureOffset = materialOffset;
                }
            }
            else if (handState == HandState.GoingUp)
            {
                position.y += ascentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y += ascentSpeed * grabbySpeedIncrement * Time.deltaTime;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingUp: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y >= OriginalYPosition)
                {
                    position.y = OriginalYPosition;
                    handState  = HandState.Idle;

                    materialOffset.y           = -0.5f;
                    material.mainTextureOffset = materialOffset;
                    grabbyPointPosition.y      = grabbyYOriginalPoint;
                }

                grabbyPoint.localPosition = grabbyPointPosition;
            }
            else if (handState == HandState.Yeeting)
            {
                var rotation = yeetingContrainerTransform.rotation;
                var euler    = rotation.eulerAngles;
                yeetingRotationTimer += Time.deltaTime;
                var delta = Mathf.Clamp01(yeetingRotationTimer / yeetingRotationMaxTime);

                if (delta >= 1)
                {
                    handState            = HandState.Idle;
                    yeetingRotationTimer = 0f;
                    euler.z      = yeetRotOriginal;
                    yeetingPower = 0;

                    AudioManager.Instance.PlayYeet();
                }
                else
                {
                    euler.z = Mathf.Lerp(yeetRotMin, yeetRotMax, delta);
                }

                if (delta > 0.8f && currentMergeableObject != null)
                {
                    currentMergeableObject.transform.SetParent(null);
                    currentMergeableObject.hoverScript.UpdateRotation = true;
                    currentMergeableObject.YeetToPosition.YeetInit(currentMergeableObject.transform.position, opponent.backCloud, 30, 0.5f);
                    currentMergeableObject.YeetToPosition.Yeet(Mathf.RoundToInt(currentMergeableObject.Damage * yeetingPower), onYeetEvent);
                    currentMergeableObject = null;
                }

                rotation.eulerAngles = euler;
                yeetingContrainerTransform.rotation = rotation;
            }
            else if (handState == HandState.ChargingYeet)
            {
                hover1.UpdateRotation = true;
                hover2.UpdateRotation = true;
            }

            transform.position = position;
        }
#endif
#if UNITY_EDITOR && KEYBOARD_MODE
        else
        {
            var   position    = transform.position;
            float sensitivity = this.sensitivity / 1000;
            position.x += Input.GetAxis("Horizontal") * sensitivity;
            position.z += Input.GetAxis("Vertical") * sensitivity;

            ClampPosition(ref position);

            hover1.UpdateRotation = false;
            hover2.UpdateRotation = false;

            if (handState == HandState.Idle)
            {
                if (Input.GetKeyDown(KeyCode.LeftControl))
                {
                    handState = HandState.GoingDown;
                }
                else if (holdingSomethingYeetable && Input.GetKeyDown(KeyCode.Space))
                {
                    handState = HandState.ChargingYeet;
                }
            }

            if (handState == HandState.ChargingYeet)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    yeetingPower += (oldAccel - accel).magnitude;
                    yeetingPower  = Mathf.Clamp(yeetingPower, 0, MAX_YEETING_POWER);

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);
                }
                else if (Input.GetKeyUp(KeyCode.Space))
                {
                    //Debug.LogFormat("Yoting {0}", yeetingPower);
                    handState = HandState.Yeeting;

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);

                    var direction = ourPosition.position.x <= opponentPosition.position.x;
                    if (yeetDirection != direction)
                    {
                        yeetRotMin *= -1;
                        yeetRotMax *= -1;
                    }
                    yeetDirection = direction;
                }
            }

            if (handState == HandState.GoingDown)
            {
                position.y -= descentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y    -= descentSpeed * grabbySpeedIncrement * Time.deltaTime;
                grabbyPoint.localPosition = grabbyPointPosition;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingDown: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y <= MaxDescentPosition)
                {
                    position.y = MaxDescentPosition;
                    DetectObjectCollision();
                    handState = HandState.GoingUp;

                    materialOffset.y           = 0;
                    material.mainTextureOffset = materialOffset;
                }
            }
            else if (handState == HandState.GoingUp)
            {
                position.y += ascentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y += ascentSpeed * grabbySpeedIncrement * Time.deltaTime;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingUp: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y >= OriginalYPosition)
                {
                    position.y = OriginalYPosition;
                    handState  = HandState.Idle;

                    materialOffset.y           = -0.5f;
                    material.mainTextureOffset = materialOffset;
                    grabbyPointPosition.y      = grabbyYOriginalPoint;
                }

                grabbyPoint.localPosition = grabbyPointPosition;
            }
            else if (handState == HandState.Yeeting)
            {
                var rotation = yeetingContrainerTransform.rotation;
                var euler    = rotation.eulerAngles;
                yeetingRotationTimer += Time.deltaTime;
                var delta = Mathf.Clamp01(yeetingRotationTimer / yeetingRotationMaxTime);

                if (delta >= 1)
                {
                    handState            = HandState.Idle;
                    yeetingRotationTimer = 0f;
                    euler.z      = yeetRotOriginal;
                    yeetingPower = 0;
                }
                else
                {
                    euler.z = Mathf.Lerp(yeetRotMin, yeetRotMax, delta);
                }

                if (delta > 0.8f && currentMergeableObject != null)
                {
                    currentMergeableObject.transform.SetParent(null);
                    currentMergeableObject.hoverScript.UpdateRotation = true;
                    currentMergeableObject.YeetToPosition.YeetInit(currentMergeableObject.transform.position, opponent.backCloud, 30, 0.5f);
                    currentMergeableObject.YeetToPosition.Yeet(Mathf.RoundToInt(currentMergeableObject.Damage * yeetingPower), onYeetEvent);
                    currentMergeableObject = null;
                }

                rotation.eulerAngles = euler;
                yeetingContrainerTransform.rotation = rotation;
            }
            else if (handState == HandState.ChargingYeet)
            {
                hover1.UpdateRotation = true;
                hover2.UpdateRotation = true;
            }

            transform.position = position;
        }
#endif
    }