Пример #1
0
 void Awake()
 {
     _animator       = GetComponent <Animator>();
     _rigidbody2D    = GetComponent <Rigidbody2D>();
     _physicsEffects = GetComponent <PhysicsEffects>();
     _audioSource    = GetComponent <AudioSource>();
 }
Пример #2
0
    /**
     * Implements the moving logic
     */
    private void Move(bool enableVertical, bool enableHorizontal)
    {
        _vertical   = (enableVertical) ? Input.GetVertical() : 0;
        _horizontal = (enableHorizontal) ? Input.GetHorizontal() : 0;

        // If we are pulling a box and trying to move in the pulling direction, we instruct the box to pull
        if (_playerState == PlayerState.pulling && DoesMoveInPullDirection())
        {
            _pushableToPull.Pull(viewDirection.Inverse(), this);
        }

        // Otherwise, move normally
        else
        {
            // Scale movement speed by the input axis value and the passed time to get a delta which must be applied to the current position
            Vector2 deltaPosition = new Vector2(
                _horizontal,
                _vertical
                ) * (speed * Time.deltaTime);

            if (!Mathf.Approximately(deltaPosition.x, 0.0f) || !Mathf.Approximately(deltaPosition.y, 0.0f))
            {
                _lookDirection.Set(deltaPosition.x, deltaPosition.y);
                _lookDirection.Normalize();
            }

            Animator.SetFloat(LookXProperty, _lookDirection.x);
            Animator.SetFloat(LookYProperty, _lookDirection.y);
            Animator.SetFloat(SpeedProperty, deltaPosition.magnitude);

            PhysicsEffects.MoveBody(
                Rigidbody2D.position + deltaPosition
                );
        }
    }
Пример #3
0
    private void Awake()
    {
        _renderer       = GetComponent <Renderer>();
        _collider       = GetComponent <Collider2D>();
        _physicsEffects = GetComponent <PhysicsEffects>();
        _hingeJoint2D   = this.gameObject.AddComponent <HingeJoint2D>();

        _hingeJoint2D.enabled = false;
    }
Пример #4
0
    void FixedUpdate()
    {
        if (!isDead)
        {
            Vector2 position = Rigidbody2D.position;
            position += ComputeOffset();

            PhysicsEffects.MoveBody(position);
        }
    }
Пример #5
0
    public override void PostInitShared()
    {
        base.PostInitShared();
        GameObject gameObject = null;

        gameObject = (this.item == null || !this.item.info.worldModelPrefab.isValid ? UnityEngine.Object.Instantiate <GameObject>(this.itemModel) : this.item.info.worldModelPrefab.Instantiate(null));
        gameObject.transform.SetParent(base.transform, false);
        gameObject.transform.localPosition = Vector3.zero;
        gameObject.transform.localRotation = Quaternion.identity;
        gameObject.SetLayerRecursive(base.gameObject.layer);
        Collider component = gameObject.GetComponent <Collider>();

        if (component)
        {
            component.enabled = false;
            component.enabled = true;
        }
        if (base.isServer)
        {
            WorldModel worldModel = gameObject.GetComponent <WorldModel>();
            float      single     = (worldModel ? worldModel.mass : 1f);
            float      single1    = 0.1f;
            float      single2    = 0.1f;
            Rigidbody  rigidbody  = base.gameObject.AddComponent <Rigidbody>();
            rigidbody.mass          = single;
            rigidbody.drag          = single1;
            rigidbody.angularDrag   = single2;
            rigidbody.interpolation = RigidbodyInterpolation.None;
            ConVar.Physics.ApplyDropped(rigidbody);
            Renderer[] componentsInChildren = gameObject.GetComponentsInChildren <Renderer>(true);
            for (int i = 0; i < (int)componentsInChildren.Length; i++)
            {
                componentsInChildren[i].enabled = false;
            }
        }
        if (this.item != null)
        {
            PhysicsEffects physicsEffect = base.gameObject.GetComponent <PhysicsEffects>();
            if (physicsEffect != null)
            {
                physicsEffect.entity = this;
                if (this.item.info.physImpactSoundDef != null)
                {
                    physicsEffect.physImpactSoundDef = this.item.info.physImpactSoundDef;
                }
            }
        }
        gameObject.SetActive(true);
    }
Пример #6
0
    public override void PostInitShared()
    {
        base.PostInitShared();
        GameObject gameObject = null;

        gameObject = ((item == null || !item.info.worldModelPrefab.isValid) ? Object.Instantiate(itemModel) : item.info.worldModelPrefab.Instantiate());
        gameObject.transform.SetParent(base.transform, false);
        gameObject.transform.localPosition = Vector3.zero;
        gameObject.transform.localRotation = Quaternion.identity;
        TransformEx.SetLayerRecursive(gameObject, base.gameObject.layer);
        childCollider = gameObject.GetComponent <Collider>();
        if ((bool)childCollider)
        {
            childCollider.enabled = false;
            childCollider.enabled = true;
        }
        if (base.isServer)
        {
            WorldModel component   = gameObject.GetComponent <WorldModel>();
            float      mass        = (component ? component.mass : 1f);
            float      drag        = 0.1f;
            float      angularDrag = 0.1f;
            Rigidbody  rigidbody   = base.gameObject.AddComponent <Rigidbody>();
            rigidbody.mass          = mass;
            rigidbody.drag          = drag;
            rigidbody.angularDrag   = angularDrag;
            rigidbody.interpolation = RigidbodyInterpolation.None;
            ConVar.Physics.ApplyDropped(rigidbody);
            Renderer[] componentsInChildren = gameObject.GetComponentsInChildren <Renderer>(true);
            for (int i = 0; i < componentsInChildren.Length; i++)
            {
                componentsInChildren[i].enabled = false;
            }
        }
        if (item != null)
        {
            PhysicsEffects component2 = base.gameObject.GetComponent <PhysicsEffects>();
            if (component2 != null)
            {
                component2.entity = this;
                if (item.info.physImpactSoundDef != null)
                {
                    component2.physImpactSoundDef = item.info.physImpactSoundDef;
                }
            }
        }
        gameObject.SetActive(true);
    }
Пример #7
0
    public override void PostInitShared()
    {
        base.PostInitShared();
        GameObject go = this.item == null || !this.item.info.worldModelPrefab.isValid ? (GameObject)Object.Instantiate <GameObject>((M0)this.itemModel) : this.item.info.worldModelPrefab.Instantiate((Transform)null);

        go.get_transform().SetParent(((Component)this).get_transform(), false);
        go.get_transform().set_localPosition(Vector3.get_zero());
        go.get_transform().set_localRotation(Quaternion.get_identity());
        go.SetLayerRecursive(((Component)this).get_gameObject().get_layer());
        Collider component1 = (Collider)go.GetComponent <Collider>();

        if (Object.op_Implicit((Object)component1))
        {
            component1.set_enabled(false);
            component1.set_enabled(true);
        }
        if (this.isServer)
        {
            WorldModel component2 = (WorldModel)go.GetComponent <WorldModel>();
            float      num1       = Object.op_Implicit((Object)component2) ? component2.mass : 1f;
            float      num2       = 0.1f;
            float      num3       = 0.1f;
            M0         m0         = ((Component)this).get_gameObject().AddComponent <Rigidbody>();
            ((Rigidbody)m0).set_mass(num1);
            ((Rigidbody)m0).set_drag(num2);
            ((Rigidbody)m0).set_angularDrag(num3);
            ((Rigidbody)m0).set_interpolation((RigidbodyInterpolation)0);
            Physics.ApplyDropped((Rigidbody)m0);
            foreach (Renderer componentsInChild in (Renderer[])go.GetComponentsInChildren <Renderer>(true))
            {
                componentsInChild.set_enabled(false);
            }
        }
        if (this.item != null)
        {
            PhysicsEffects component2 = (PhysicsEffects)((Component)this).get_gameObject().GetComponent <PhysicsEffects>();
            if (Object.op_Inequality((Object)component2, (Object)null))
            {
                component2.entity = (BaseEntity)this;
                if (Object.op_Inequality((Object)this.item.info.physImpactSoundDef, (Object)null))
                {
                    component2.physImpactSoundDef = this.item.info.physImpactSoundDef;
                }
            }
        }
        go.SetActive(true);
    }
Пример #8
0
    /**
     * Call this to let the player fall
     * (play animation, sound and let player die)
     *
     * This method is for example used by the `Chasm` class
     */
    public void InitiateFall()
    {
        if (_playerState != PlayerState.falling && _playerState != PlayerState.thrown)
        {
            // While falling, the player is probably not on safe terrain, so we tell Spawnable to not safe any respawn
            // positions
            // (since we change layers during falling, Chasm may not register as unsafe terrain while falling)
            spawnable.RegisterTouchingUnsafeTerrain(this);

            _playerState = PlayerState.falling;
            // If the player is being moved by a platform, they should no longer be moved when falling
            PhysicsEffects.RemoveCustomOrigin();
            // We place the player at the center of its collider for the falling animation to get a position somewhat
            // centered around the point where the player entered the chasm
            PhysicsEffects.Teleport(Collider.bounds.center);

            Animator.SetTrigger(FallTrigger);
        }
    }
Пример #9
0
Файл: GUI.cs Проект: Hengle/LD43
    private void DrawEffectMenu(bool newSelection)
    {
        if (newSelection)
        {
            Tools.current = Tool.None;
        }

        GUIutilities.WriteTitle("Physic Effects Mode");
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Space();

        physicModeCheck[0] = EditorGUILayout.ToggleLeft("All Rigidbodies", physicModeCheck[0], GUILayout.Width(150));
        if (rootContainer == null)
        {
            physicModeCheck[0] = true;
            GUI.enabled        = false;
        }
        else
        {
            GUI.enabled = true;
        }
        physicModeCheck[1] = EditorGUILayout.ToggleLeft("Only in Root Container", physicModeCheck[1]);


        GUI.enabled = true;
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();
        GUIutilities.WriteTitle("Physic Effect (SPACEBAR to activate)");
        for (int i = 0; i < oldPhysicModeCheck.Length; i++)
        {
            if (oldPhysicModeCheck[i] != physicModeCheck[i])
            {
                if (physicModeCheck[i] == true)
                {
                    for (int j = 0; j < oldPhysicModeCheck.Length; j++)
                    {
                        if (j == i)
                        {
                            continue;
                        }
                        physicModeCheck[j] = false;
                    }
                    break;
                }
                else
                {
                    physicModeCheck[i] = true;
                }
            }
        }
        for (int i = 0; i < oldPhysicModeCheck.Length; i++)
        {
            oldPhysicModeCheck[i] = physicModeCheck[i];
            if (physicModeCheck[i])
            {
                physicsMode = (PhysicsMode)i;
            }
        }


        physicsEffects = (PhysicsEffects)GUILayout.SelectionGrid((int)physicsEffects, convertEnumToStringArray(), convertEnumToStringArray().Length);
        if (physicsEffects == PhysicsEffects.Explosion)
        {
            EditorGUILayout.Space();
            GUIutilities.SliderMinMax("Vertical Offset", ref ExplosionParams.minVerticalOffset, ref ExplosionParams.maxVerticalOffset, ref ExplosionParams.verticalOffset, 100);
            GUIutilities.SliderMinMax("Radius", ref ExplosionParams.minRadius, ref ExplosionParams.maxRadius, ref ExplosionParams.radius, 100);
            GUIutilities.SliderMinMax("Power", ref ExplosionParams.minPower, ref ExplosionParams.maxPower, ref ExplosionParams.power, 100);
        }
        if (physicsEffects == PhysicsEffects.SimpleForce)
        {
            EditorGUILayout.Space();
            GUIutilities.SliderMinMax("Vertical Offset", ref SimpleForceParams.minVerticalOffset, ref SimpleForceParams.maxVerticalOffset, ref SimpleForceParams.verticalOffset, 100);
            GUIutilities.SliderMinMax("Radius", ref SimpleForceParams.minRadius, ref SimpleForceParams.maxRadius, ref SimpleForceParams.radius, 100);
            GUIutilities.simpleSlider("powerX", ref SimpleForceParams.powerX, -100, 100, 100);
            GUIutilities.simpleSlider("powerY", ref SimpleForceParams.powerY, 0, 100, 100);
            GUIutilities.simpleSlider("powerZ", ref SimpleForceParams.powerZ, -100, 100, 100);
        }
        if (physicsEffects == PhysicsEffects.BlackHole)
        {
            EditorGUILayout.Space();
            GUIutilities.SliderMinMax("Vertical Offset", ref BlackHoleParams.minVerticalOffset, ref BlackHoleParams.maxVerticalOffset, ref BlackHoleParams.verticalOffset, 100);
            GUIutilities.SliderMinMax("Radius", ref BlackHoleParams.minRadius, ref BlackHoleParams.maxRadius, ref BlackHoleParams.radius, 100);
            GUIutilities.SliderMinMax("Power", ref BlackHoleParams.minPower, ref BlackHoleParams.maxPower, ref BlackHoleParams.power, 100);


            GUIutilities.SliderMinMax(new GUIContent("Modifier", "Modifies the internal equation for the black hole. A value between 1 and 2 appears to create a blob; a value from 0 to 1 creates an oscillating system. Not all values have been tested. Use at your own risk!!"), ref BlackHoleParams.minModifier, ref BlackHoleParams.maxModifier, ref BlackHoleParams.modifier, 100);
        }
    }
Пример #10
0
 protected virtual void Awake()
 {
     _animator       = GetComponent <Animator>();
     _rigidbody2D    = GetComponent <Rigidbody2D>();
     _physicsEffects = GetComponent <PhysicsEffects>();
 }