示例#1
0
    private void EnsureInit()
    {
        if (registerTile != null)
        {
            return;
        }
        if (SMALL_BURNING_PREFAB == null)
        {
            SMALL_BURNING_PREFAB = CommonPrefabs.Instance.BurningSmall;
            LARGE_BURNING_PREFAB = CommonPrefabs.Instance.BurningLarge;
        }

        if (SMALL_ASH == null)
        {
            SMALL_ASH = TileManager.GetTile(TileType.Effects, "SmallAsh") as OverlayTile;
            LARGE_ASH = TileManager.GetTile(TileType.Effects, "LargeAsh") as OverlayTile;
        }
        registerTile = GetComponent <RegisterTile>();
        pushable     = GetComponent <IPushable>();
        //this is just a guess - large items can't be picked up
        isLarge = GetComponent <Pickupable>() == null;
        if (Resistances.Flammable)
        {
            if (burningObjectOverlay == false)
            {
                burningObjectOverlay = GameObject.Instantiate(isLarge ? LARGE_BURNING_PREFAB : SMALL_BURNING_PREFAB, transform)
                                       .GetComponent <BurningOverlay>();
            }

            burningObjectOverlay.enabled = true;
            burningObjectOverlay.StopBurning();
        }
    }
示例#2
0
    public override void _PhysicsProcess(float delta)
    {
        Vector2 axisInput = new Vector2(0.0f, 0.0f);

        foreach (AxisMapping axisMapping in _axisMappings)
        {
            if (Input.IsActionPressed(axisMapping.ActionName))
            {
                axisInput += axisMapping.Axis;
            }
        }

        axisInput = axisInput.Normalized();
        Vector2 velocity = axisInput * WalkSpeed;
        KinematicCollision2D collision = MoveAndCollide(velocity * delta);

        if (collision != null)
        {
            Node2D collider = collision.Collider as Node2D;
            if (collider != null && collider.IsInGroup("pushable"))
            {
                IPushable pushedObject = collider as IPushable;
                pushedObject?.TryPush(collision.Normal, delta);
            }

            velocity = velocity.Slide(collision.Normal);
            MoveAndCollide(velocity * delta);
        }
    }
示例#3
0
    private void EnsureInit()
    {
        if (registerTile != null)
        {
            return;
        }
        if (SMALL_BURNING_PREFAB == null)
        {
            SMALL_BURNING_PREFAB = Resources.Load <GameObject>("SmallBurning");
            LARGE_BURNING_PREFAB = Resources.Load <GameObject>("LargeBurning");
        }
        registerTile = GetComponent <RegisterTile>();
        pushable     = GetComponent <IPushable>();
        //this is just a guess - large items can't be picked up
        isLarge = GetComponent <Pickupable>() == null;
        if (Resistances.Flammable)
        {
            if (burningObjectOverlay == false)
            {
                burningObjectOverlay = GameObject.Instantiate(isLarge ? LARGE_BURNING_PREFAB : SMALL_BURNING_PREFAB, transform)
                                       .GetComponent <BurningOverlay>();
            }

            burningObjectOverlay.enabled = true;
            burningObjectOverlay.StopBurning();
        }
    }
示例#4
0
 void OnTriggerExit2D(Collider2D other)
 {
     if (other.gameObject.GetComponent(typeof(IPushable <Vector3>)) as IPushable <Vector3> != null)
     {
         IPushable <Vector3> iPushable = other.gameObject.GetComponent(typeof(IPushable <Vector3>)) as IPushable <Vector3>;
         iPushable.Push(Vector3.zero);
     }
 }
示例#5
0
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.gameObject.GetComponent(typeof(IPushable <Vector3>)) as IPushable <Vector3> != null)
     {
         IPushable <Vector3> iPushable = other.gameObject.GetComponent(typeof(IPushable <Vector3>)) as IPushable <Vector3>;
         iPushable.Push(velocity);
     }
 }
示例#6
0
        public void IsPushable(string Tag, Vector Speed, IPushable Entity)
        {
            bool colided = Entity.components.IsAreaColidedWithTag(Tag, new Vector(Entity.Position.X + Speed.X, Entity.Position.Y + Speed.Y), Entity.Scale);

            if (colided)
            {
                IsPushable(Tag, Speed, Entity.components.GetColidedObject);
                Entity.components.GetColidedObject.Position.X += Speed.X;
                Entity.components.GetColidedObject.Position.Y += Speed.Y;
            }
        }
 private void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (hit.gameObject.CompareTag("Player"))
     {
         IPushable collision = hit.gameObject.GetComponent <IPushable>();
         if (collision != null)
         {
             collision.Push(speedX, hit.moveDirection.y);
         }
     }
 }
示例#8
0
 protected virtual void Awake()
 {
     if (transform.parent)         //clients dont have this set yet
     {
         objectLayer = transform.parent.GetComponent <ObjectLayer>() ?? transform.parent.GetComponentInParent <ObjectLayer>();
     }
     customNetTransform  = GetComponent <CustomNetTransform>();
     matrixRotationHooks = GetComponents <IMatrixRotation>();
     fireExposables      = GetComponents <IFireExposable>();
     CurrentsortingGroup = GetComponent <SortingGroup>();
     iPushable           = GetComponent <IPushable>();
 }
示例#9
0
 private void OnTriggerExit(Collider other)
 {
     if (other.TryGetComponent <IPushable>(out IPushable targetPushable))
     {
         // If we (the player) are not pushing this item
         if (targetPushable.GetState() == false)
         {
             target   = null;
             pushable = null;
         }
     }
 }
示例#10
0
    /*
     * private void OnCollisionStay2D(Collision2D collision)
     * {
     *  if (collision.gameObject.CompareTag(KDefine.TAG_PUSHABLE))
     *  {
     *      if ((collision.contacts[0].normal.y <= 0.7 || collision.contacts[0].normal.x >= -0.7) && collision.contacts[0].normal.y <= 0.7f)
     *      {
     *          collision.gameObject.GetComponent<IPushable>().Push(playerInput.fMove + playerInput.fMobileMove);
     *      }
     *  }
     * }*/

    private void OnCollisionExit2D(Collision2D collision)
    {
        if (!shooter.enabled)
        {
            shooter.enabled = true;
        }
        IPushable target = collision.gameObject.GetComponent <IPushable>();

        if (target != null)
        {
            collision.gameObject.GetComponent <IPushable>().IsContact = false;
        }
    }
示例#11
0
    void OnTriggerStay(Collider other)
    {
        IPushable pushable = other.GetComponent <IPushable>();

        if (pushable != null)
        {
            if (!creepsInsideCollider.Contains(other.gameObject))
            {
                creepsInsideCollider.Add(other.gameObject);
            }
            Debug.Log("Found a pushableThing");
        }
    }
示例#12
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.TryGetComponent <IPushable>(out IPushable targetPushable))
        {
            // If we (the player) are not pushing this item
            if (targetPushable.GetState() == false)
            {
                pushable = targetPushable;

                // trigger pressure plate stuff (one time)
                OnDown();
            }
        }
    }
示例#13
0
        public static void Check()
        {
            var dogs = new Stack <Dog>();

            dogs.Push(new Dog());

            //IPoppable<Animal> animals = dogs;

            IPushable <Animal> animals = new Stack <Animal>();
            IPushable <Cat>    cats    = animals; //allowed

            cats.Push(new Cat());
            //Stack<Animal> animals = dogs;
        }
示例#14
0
        private IEnumerator AimPhase(IPushable pushable, AimLogic aimLogic)
        {
            _visuals.Indicator.enabled = true;
            while (!pushable.IsPushed())
            {
                AimState state = aimLogic.GetCurrentAimState(Time.time);

                _visuals.Indicator.UpdateState(state);
                yield return(null);
            }

            pushable.IsPushed();
            yield return(null);
        }
示例#15
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!PhysicsHelper.IsInLayerMask(collision.gameObject, _layersToPush))
        {
            return;
        }

        IPushable pushable = collision.GetComponent <IPushable>();

        if (pushable != null)
        {
            Vector2 direction = (transform.position - collision.gameObject.transform.position) * -1;
            pushable.Push(direction, _knockbackAmount, _knockbackDuration);
        }
    }
示例#16
0
 protected virtual void Awake()
 {
     LocalPositionServer = TransformState.HiddenPos;
     LocalPositionClient = TransformState.HiddenPos;
     if (transform.parent)         //clients dont have this set yet
     {
         objectLayer = transform.parent.GetComponent <ObjectLayer>() ?? transform.parent.GetComponentInParent <ObjectLayer>();
     }
     customNetTransform  = GetComponent <CustomNetTransform>();
     matrixRotationHooks = GetComponents <IMatrixRotation>();
     fireExposables      = GetComponents <IFireExposable>();
     IPlayerEntersTiles  = GetComponents <IPlayerEntersTile>();
     IObjectEntersTiles  = GetComponents <IObjectEntersTile>();
     CurrentsortingGroup = GetComponent <SortingGroup>();
     iPushable           = GetComponent <IPushable>();
 }
示例#17
0
    //syncvar hook invoked client side when the buckledTo changes
    private void OnBuckledChangedHook(uint newBuckledTo)
    {
        //unsub if we are subbed
        if (buckledObject != NetId.Invalid)
        {
            var directionalObject = ClientScene.FindLocalObject(buckledObject).GetComponent <Directional>();
            if (directionalObject != null)
            {
                directionalObject.OnDirectionChange.RemoveListener(OnBuckledObjectDirectionChange);
            }

            IPushable pushable = null;
            if (NetworkIdentity.spawned[buckledObject].TryGetComponent(out pushable))
            {
                pushable.OnStartMove().RemoveListener(OnBuckledObjectPositionChange);
            }
        }

        if (PlayerManager.LocalPlayer == gameObject)
        {
            //have to do this with a lambda otherwise the Cmd will not fire
            UIManager.AlertUI.ToggleAlertBuckled(newBuckledTo != NetId.Invalid, () => CmdUnbuckle());
        }

        buckledObject = newBuckledTo;
        //sub
        if (buckledObject != NetId.Invalid)
        {
            var directionalObject = ClientScene.FindLocalObject(buckledObject).GetComponent <Directional>();
            if (directionalObject != null)
            {
                directionalObject.OnDirectionChange.AddListener(OnBuckledObjectDirectionChange);
            }

            // Hook a change of position event handler for when the buckled-to object change position (the object is pushed or pulled)
            IPushable pushable = null;
            if (NetworkIdentity.spawned[buckledObject].TryGetComponent(out pushable))
            {
                pushable.OnStartMove().AddListener(OnBuckledObjectPositionChange);
            }
        }

        //ensure we are in sync with server
        playerScript?.PlayerSync?.RollbackPrediction();
    }
示例#18
0
    private void Update()
    {
        if (pushable == null)
        {
            return;
        }

        if (pushable.GetState() == true)
        {
            // That means this item was picked up by a player
            pushable = null;
        }
        else
        {
            // Do pressure plate stuff
            OnPress();
        }
    }
示例#19
0
        public static void Main()
        {
            Stack <Dog> dogs = new Stack <Dog>();

            //Stack<Animal> animals = dogs; //error CS0029
            //AnimalCleaner.Wash(dogs); // error CS1503

            dogs.Push(new Dog());
            IPoppable <Animal> animals = dogs;

            AnimalCleaner.Wash(animals);

            ////////////////////////////////////////////////////
            IPushable <Animal> animals2 = new Stack <Animal>();
            IPushable <Dog>    dogs2    = animals2;

            dogs2.Push(new Dog());
        }
示例#20
0
    // Update is called once per frame
    void Update()
    {
        if (target == null)
        {
            return;
        }

        if (pushable.GetState() == true)
        {
            // That means this item was picked up by a player
            target   = null;
            pushable = null;
        }
        else
        {
            target.position += new Vector3(0, 0, 1) * Time.deltaTime;
        }
    }
示例#21
0
    public static Vector3 CalculatePush(IPushable Pushable, Vector3 Position)
    {
        float Distance = Clamp(Position.DistanceTo(Pushable.Translation), 1, MaxRocketDistance);
        float Power    =
            LogBase(-Distance + MaxRocketDistance + 1, 2)
            / LogBase(MaxRocketDistance + 1, 2);

        Vector3 Push = ((Pushable.Translation - Position) / MaxRocketDistance).Normalized() * MaxRocketPush * Power;

        {
            Vector3 Flat = Push.Flattened();
            Flat  *= RocketHorizontalMultiplyer;
            Push.x = Flat.x;
            Push.z = Flat.z;
        }
        Push.y *= RocketVerticalMultiplyer;

        return(Push);
    }
        private static void GenericTypesTests()
        {
            Console.WriteLine("--- {0} ---", System.Reflection.MethodBase.GetCurrentMethod().Name);
            Stack <int> stack = new Stack <int>();

            stack.Push(5);
            stack.Push(10);
            int x = stack.Pop();
            int y = stack.Pop();
            int xx = 5, yy = 10;

            Generics.Swap(b: ref yy, a: ref xx);

            Type g1 = typeof(G <>);
            Type g2 = typeof(G <,>);

            Console.WriteLine(g2.GetGenericArguments().Count());
            Type g3 = typeof(G <int, int>);

            Console.WriteLine(g3.GetGenericArguments().Count());

            Console.WriteLine(++Bob <int> .Count);
            Console.WriteLine(++Bob <int> .Count);
            Console.WriteLine(++Bob <string> .Count);
            Console.WriteLine(++Bob <object> .Count);

            // Covariance
            {
                // Assuming that Bear subclasses Animal:
                var bears = new Stack <Bear>();
                bears.Push(new Bear());
                // Because bears implements IPoppable<Bear>, we can convert it to IPoppable<Animal>:
                IPoppable <Animal> animals = bears;  // Legal
                Animal             a       = animals.Pop();
            }
            // Contravariance
            {
                IPushable <Animal> animals = new Stack <Animal>();
                IPushable <Bear>   bears   = animals; // Legal
                bears.Push(new Bear());
            }
            Console.WriteLine("=====================================================================");
        }
示例#23
0
    public void OnAttack()
    {
        _particleSystem.Play();
        Collider[] colliders       = new Collider[10];
        int        objectsHitCount = Physics.OverlapSphereNonAlloc(_playerTransform.position + (_playerTransform.right * _attackDistance), _radius, colliders);

        for (int i = 0; i < objectsHitCount; i++)
        {
            // Check if the colliders object has an IPushable, if it HAS HIT IT!
            IPushable objectToPush = colliders[i].GetComponent <IPushable>();

            if (objectToPush != null)
            {
                Vector3 force = colliders[i].transform.position - _playerTransform.position;
                force = force.normalized * _pushForce;

                objectToPush.Push(force);
            }
        }
    }
示例#24
0
        static void Main(string[] args)
        {
            // Stack covariance
            Animal animal    = new Bear(); // Bear is convertible to Animal (asumption above)
            var    bearStack = new Stack <Bear>();

            bearStack.Push(animal as Bear);
            bearStack.Push(new Bear());
            IPoppable <Animal> animalPop = bearStack;

            animal = animalPop.Pop();
            //Stack<Animal> animalst = bears;  // not a covariant parameter, classes do not permit covariant paramters since data flow in both directions
            ZooCleaner.Wash(bearStack); // OK, covariant method

            // contravariance
            var animalStack             = new Stack <Animal>();
            IPushable <Bear>  bearPush  = animalStack;  // legal
            IPushable <Camel> camelPush = animalStack;  // legal, contravariant

            animalStack.Push(new Bear());
            animalStack.Push(new Camel());
            camelPush.Push(new Camel());
            bearPush.Push(new Bear());

            // Interface covariance
            string        s         = "Hello";
            object        o         = s;
            IFoo <string> fooString = new FooString();

            //IFoo<object> fooObject; fooObject = fooString; // HEY! interfaces should be covariant!!!! Whats up?

            // Array covariance
            Bear[]   bearArr   = new Bear[] { new Bear(), new Bear() };
            Animal[] animalArr = bearArr; // OK, covariant
            animalArr[1] = new Bear();
            //animalArr[1] = new Camel();   ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
            //animalArr[1] = new Animal();  ditto
        }
示例#25
0
        public IEnumerator LifeCycle()
        {
            IPushable button = _visuals.MainButton;

            while (true)
            {
                //Start
                yield return(new WaitForPushable(button));

                GoToNextState();

                //Aiming
                var logic = new AimLogic(_settings.aim, Time.time);

                yield return(StartCoroutine(AimPhase(button, logic)));

                var state      = logic.GetCurrentAimState(Time.time);
                var trajectory = GetTrajectory(logic, state);

                GoToNextState();

                //Anim
                yield return(StartCoroutine(AnimPhase(trajectory)));

                GoToNextState();

                //Score
                yield return(StartCoroutine(ShowScorePhase(state)));

                //Reset
                Reset();
                yield return(null);

                GoToNextState();
            }
        }
示例#26
0
        public Tile PushContent(Directions direction)
        {
            Tile tile = getTileInDirection(direction);

            if (!tile.IsMoveableTile())
            {
                return(null);
            }

            if (!tile.IsOccupied())
            {
                tile.Entity = Entity;
                Entity      = null;
                return(tile);
            }

            if (tile.IsEntityNotPushable())
            {
                INotPushable entity = (INotPushable)tile.Entity;

                entity.Update();
                return(null);
            }
            else if (tile.IsEntityAPlayer())
            {
                Player player = (Player)tile.Entity;

                Tile newTile = tile.PushContent(direction);
                if (newTile == null)
                {
                    return(null);
                }

                player.Tile = newTile;

                tile.Entity = Entity;
                Entity      = null;
                return(tile);
            }
            else if (tile.IsEntityPushable())
            {
                IPushable entity = (IPushable)tile.Entity;

                if (IsEntityPushable())
                {
                    return(null);
                }
                if (tile.PushContent(direction) == null)
                {
                    return(null);
                }

                entity.Update(tile.getTileInDirection(direction));

                tile.Entity = Entity;
                Entity      = null;
                return(tile);
            }

            return(null);
        }
示例#27
0
 public WaitForPushable(IPushable pushable)
 {
     _pushable = pushable;
 }
示例#28
0
 static void SetColor(IPushable pushable)
 {
     pushable.Press();
 }
示例#29
0
 public void PushOn(IPushable pushable)
 {
     Console.WriteLine("Человек нажимает на это!");
     pushable.Press();
     Console.WriteLine("Сюда нажимали {0} раз!", pushable.ClickCount);
 }
示例#30
0
        static void Main(string[] args)
        {
            //Generic Type definition
            var nowystos = new Stack <int>();

            nowystos.Push(1);
            nowystos.Push(50);
            Console.WriteLine(nowystos.Pop());

            Type a1 = typeof(A <>);
            Type a2 = typeof(A <,>);
            Type a3 = typeof(A <int, int>);

            Console.WriteLine(a2.GetGenericArguments().Count());

            Console.WriteLine("Generics with static fields");
            Console.WriteLine(++Test <int> .Count);    //1
            Console.WriteLine(++Test <int> .Count);    //2
            Console.WriteLine(++Test <object> .Count); //1
            Console.WriteLine(++Test <object> .Count); //2

            //Kowariancja z out
            Stact2 <Beer> Beeers = new Stact2 <Beer>();

            Beeers.Push(new Beer());
            IPopable <Beer>   Beers   = Beeers;
            IPopable <Animal> Animals = Beers;

            Console.WriteLine(Animals.Pop().GetType().FullName);

            //Kontrawariancja z in
            IPushable <Animal> Animalss = new Stact2 <Animal>();
            IPushable <Beer>   Beerss   = Animalss;

            Beerss.Push(new Beer());
            Console.WriteLine(Beerss.GetType().FullName);

            //Delegates
            int[] valuesInts = { 1, 2, 3 };
            Transform(valuesInts, Square);
            for (int i = 0; i < valuesInts.Length; i++)
            {
                Console.WriteLine(valuesInts[i]);
            }
            Transformer <double> t2 = Square;

            Console.WriteLine(t2.Invoke(3.3));

            int[] valuesInts2 = { 1, 2, 3 };
            Transform2 <int>(valuesInts2, Square);
            for (int i = 0; i < valuesInts2.Length; i++)
            {
                Console.WriteLine(valuesInts2[i]);
            }

            Func <double, double> squareFunc = x =>
            {
                return(x * x);
            };
            Func <double, double, double> multiplyFunc = (x, y) =>
            {
                return(x * y);
            };
            Action <int> actionX = (x) =>
            {
                Console.WriteLine("Acion has fired with value of " + x);
            };

            D1 d1 = WriteSmth;
            D2 d2;

            d2 = new D2(d1);
            d2.Invoke();

            Console.WriteLine(squareFunc(5.5));
            Console.WriteLine(multiplyFunc(5.5, 5.5));

            //Events

            List <Stock> Stocks = new List <Stock>
            {
                new Stock("X1")
                {
                    Price = 22,
                },
                new Stock("X2")
                {
                    Price = 23
                }
            };

            foreach (var stock in Stocks)
            {
                stock.PriceChanged += StockHasChanged;
            }
            Stocks[0].Price = 2;


            //LING
            var linqExamples           = new LinqExamples();
            var dymicFunctionsExamples = new Generics.dynamic.Dynamic();
            var asyncExamples          = new AsyncExamples();
            var adoNetExamples         = new AdoNetExample();



            Console.ReadKey();
        }