Inheritance: MonoBehaviour
Beispiel #1
0
        public static TriggerVolume FromScenarioTriggerVolume(ScenarioTag tag, ScenarioTag.TriggerVolume tvDefinition)
        {
            var ent = new TriggerVolume();

            ent.FriendlyName = tvDefinition.Description;

            var orient = GetOrientation(tvDefinition.Orientation, tvDefinition.OrientationAxis);

            var xform = new TransformComponent(ent, tvDefinition.Position, orient);

            var renderModel = ModelFactory.Cuboid(Vector3.Zero, tvDefinition.Size, new Vector4(1f, 1f, 0f, 0.5f));

            renderModel.Flags       = ModelFlags.IsTransparent;
            renderModel.RenderLayer = RenderLayers.Scripting;

            var wireframeRenderModel = ModelFactory.Cuboid(Vector3.Zero, tvDefinition.Size, new Vector4(1f, 1f, 0f, 1f));

            wireframeRenderModel.Flags       = ModelFlags.Wireframe;
            wireframeRenderModel.RenderLayer = RenderLayers.Scripting;

            ent.SetComponents(xform,
                              TriggerGeometryComponent.Cuboid(ent, xform, tvDefinition.Size, tvDefinition.Description),
                              new RenderModelComponent(ent, renderModel),
                              new RenderModelComponent(ent, wireframeRenderModel));
            return(ent);

            Quaternion GetOrientation(Vector3 angle, Vector3 axis)
            {
                //BUG? The Z value of the angle vector is not used here, and is present in ~5 triggers in the game
                var a = MathF.Atan2(angle.Y, angle.X);

                return(Quaternion.CreateFromAxisAngle(axis, a));
            }
        }
Beispiel #2
0
        private void OnPlayerCollide(TriggerVolume triggerVolume, Collider collider)
        {
            PlayerUnit playerUnit = collider.GetComponent <PlayerUnit>();

            OnPicked(playerUnit);
            Destroy(gameObject);
        }
        public void Load()
        {
            if (File.Exists("Media\\Maps\\" + Engine.Singleton.CurrentLevel.Name + "\\Triggers.xml"))
            {
                XmlDocument Filee = new XmlDocument();
                Filee.Load("Media\\Maps\\" + Engine.Singleton.CurrentLevel.Name + "\\Triggers.xml");

                XmlElement root = Filee.DocumentElement;
                XmlNodeList Items = root.SelectNodes("//Triggers/Trigger");

                foreach (XmlNode item in Items)
                {
                    TriggerVolume newTrigg = new TriggerVolume();
                    newTrigg.ID = item["ID"].InnerText;
                    newTrigg.EnterActivator = item["EnteredActivator"].InnerText;
                    newTrigg.LeftActivator = item["LeftActivator"].InnerText;

                    float Size = float.Parse(item["Size"].InnerText);

                    newTrigg.BeginShapeBuild();
                    newTrigg.AddBoxPart(Vector3.ZERO, Quaternion.IDENTITY, new Vector3(Size, Size, Size));
                    newTrigg.EndShapeBuild();

                    newTrigg.Position = new Vector3(float.Parse(item["Position_x"].InnerText), float.Parse(item["Position_y"].InnerText), float.Parse(item["Position_z"].InnerText));

                    newTrigg.PrzypiszMetody();

                    T.Add(newTrigg.ID, newTrigg);
                    Engine.Singleton.ObjectManager.Add(newTrigg);
                }
            }
        }
    private void OnVolumeTriggerEnter(TriggerVolume triggerVolume, Collider collider)
    {
        BaseUnit targetBaseUnit = collider.gameObject.GetComponent <BaseUnit>();

        LineRenderDisplay lineRenderDisplayClone = Instantiate(lineRenderDisplayPrefab);

        lineRenderDisplayClone.transform.parent        = this.transform;
        lineRenderDisplayClone.transform.localPosition = Vector3.zero;
        lineRenderDisplayClone.transform.localRotation = Quaternion.identity;

        lineRenderDisplayClone.Inialize(this, targetBaseUnit);

        lineRenderDisplays.Add(lineRenderDisplayClone);


        if (!colorProportion.ContainsKey(targetBaseUnit.Color))
        {
            colorProportion.Add(targetBaseUnit.Color, 0.0f);
        }

        colorProportion[targetBaseUnit.Color] += 1.0f;


        UpdateColor();
    }
Beispiel #5
0
 private void OnTriggerVolumeExit(TriggerVolume arg1, Collider arg2)
 {
     if (targetToFollow != null && arg2.transform == targetToFollow)
     {
         targetToFollow = null;
     }
 }
Beispiel #6
0
 public void TriggerPassed(TriggerVolume trigger, CarController player)
 {
     if (player == player1)
     {
         if (trigger == zone1 && currentZoneP1 == zone3)
         {
             UpdateTrigger(trigger, player);
         }
         if (trigger == zone2 && currentZoneP1 == zone1)
         {
             UpdateTrigger(trigger, player);
         }
         if (trigger == zone3 && currentZoneP1 == zone2)
         {
             UpdateTrigger(trigger, player);
         }
         //   Debug.Log("Player 1 passed " + zonesPassedP1);
     }
     if (player == player2)
     {
         if (trigger == zone1 && currentZoneP2 == zone3)
         {
             UpdateTrigger(trigger, player);
         }
         if (trigger == zone2 && currentZoneP2 == zone1)
         {
             UpdateTrigger(trigger, player);
         }
         if (trigger == zone3 && currentZoneP2 == zone2)
         {
             UpdateTrigger(trigger, player);
         }
         //   Debug.Log("Player 2 passed " + zonesPassedP2);
     }
 }
        private void OnAttackTriggerVolumeStay(TriggerVolume volume, Collider collider1)
        {
            PlayerUnit playerUnit = collider1.GetComponent <PlayerUnit>();

            playerHealth = playerUnit.AttributePool.GetAttribute(AttributeType.Health);
            ExecuteAttack();
        }
Beispiel #8
0
    protected override void OnEnterTriggerVolume(TriggerVolume triggerVolume, Collider2D collision)
    {
        MyUnit myUnit = collision.GetComponent <MyUnit>();

        if (myUnit != null)
        {
            switch (triggerVolume.type)
            {
            case TriggerVolume.Type.Death:
                OnEnterDeath(triggerVolume, collision);
                break;

            case TriggerVolume.Type.Win:
                OnEnterWin(triggerVolume, collision);
                break;

            case TriggerVolume.Type.Gun:
                OnEnterGun(triggerVolume, collision);
                break;

            case TriggerVolume.Type.BulletBundle:
                OnEnterBulletBundle(triggerVolume, collision);
                break;

            default:
                break;
            }
        }
    }
    protected virtual void OnEnterTriggerVolume(TriggerVolume triggerVolume, Collider2D collision)
    {
        switch (triggerVolume.type)
        {
        case TriggerVolume.Type.Death:
            OnEnterDeath(triggerVolume, collision);
            break;

        case TriggerVolume.Type.Win:
            OnEnterWin(triggerVolume, collision);
            break;

        default:
            break;
        }
        MyUnit myUnit = collision.GetComponent <MyUnit>();

        if (myUnit != null)
        {
            switch (triggerVolume.type)
            {
            case TriggerVolume.Type.Death:
                OnEnterDeath(triggerVolume, collision);
                break;

            case TriggerVolume.Type.Win:
                OnEnterWin(triggerVolume, collision);
                break;

            default:
                break;
            }
        }
    }
Beispiel #10
0
 private void OnSightTriggerVolumeExit(TriggerVolume volume, Collider collider)
 {
     if (collider.tag == "Player")
     {
         currentTarget = null;
         ChangeStateTo(BehaviorState.Patrolling);
     }
 }
Beispiel #11
0
 private void OnSightTriggerVolumeEnter(TriggerVolume volume, Collider collider)
 {
     if (collider.tag == "Player")
     {
         currentTarget = collider.GetComponent <PlayerUnit> ();
         ChangeStateTo(BehaviorState.SeekingTarget);
     }
 }
Beispiel #12
0
 private void OnTriggerExit(Collider other)
 {
     if (other.GetComponent <TriggerVolume>() == lastClickedTrigger)
     {
         lastClickedTrigger.ResetCharacter();
         lastClickedTrigger = null;
     }
 }
    protected void OnEnterDeath(TriggerVolume triggerVolume, Collider2D collision)
    {
        MyUnit myUnit = collision.GetComponent <MyUnit>();

        if (myUnit != null)
        {
            myUnit.Die();
        }
    }
Beispiel #14
0
        public void OnEnter(TriggerVolume trigger, Collider2D collision)
        {
            MyPlayer myPlayer = collision.GetComponent <MyPlayer>();

            if (myPlayer != null)
            {
                myPlayer.Die();
            }
        }
    protected void OnEnterWin(TriggerVolume triggerVolume, Collider2D collision)
    {
        MyUnit myUnit = collision.GetComponent <MyUnit>();

        if (myUnit != null && myUnit.CompareTag("Player"))
        {
            myUnit.Ceremony();
            gameMode.StartCoroutine(gameMode.GameWinCoroutine());
        }
    }
Beispiel #16
0
        public void OnEnter(TriggerVolume trigger, Collider2D collision)
        {
            MyPlayer myPlayer = collision.GetComponent <MyPlayer>();

            if (myPlayer != null)
            {
                myPlayer.Ceremony();
                myGameMode.StartCoroutine(myGameMode.GameWinCoroutine());
            }
        }
Beispiel #17
0
 void Start()
 {
     rb2d = GetComponent<Rigidbody2D>();
     //rb2d.
     if (null != CollideVolume)
     {
         triggerVolume = CollideVolume.GetComponent<TriggerVolume>();
         triggerVolume.OnVolumeEntered += TriggerEnter;
     }
 }
Beispiel #18
0
        public override bool ExecuteObjectOperation(SceneNodeModel treeNode, ObjectOperation operation, int itemIndex)
        {
            var blockRef    = scenario.Sections[Section.TriggerVolumes];
            var blockEditor = scenario.MetadataStream.GetBlockEditor(blockRef.TagBlock.Pointer.Address);

            switch (operation)
            {
            case ObjectOperation.Add:
                blockEditor.Add();

                var vol = new TriggerVolume(scenario)
                {
                    //really should be reading these from the stream...
                    ForwardVector = new RealVector3D(1, 0, 0),
                    UpVector      = new RealVector3D(0, 0, 1),
                    Size          = new RealVector3D(1, 1, 1)
                };

                scenario.TriggerVolumes.Add(vol);
                AddTriggerVolumeElement(vol);
                break;

            case ObjectOperation.Remove:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                blockEditor.Remove(itemIndex);
                scenario.TriggerVolumes.RemoveAt(itemIndex);
                RemoveTriggerVolumeElement(itemIndex);

                UpdateBlockIndexes(itemIndex, scenario.TriggerVolumes.Count);
                break;

            case ObjectOperation.Copy:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                var destIndex = itemIndex + 1;
                blockEditor.Copy(itemIndex, destIndex);
                vol = new TriggerVolume(scenario);
                scenario.TriggerVolumes.Insert(destIndex, vol);
                InsertTriggerVolumeElement(vol, destIndex);
                vol.CopyFrom(scenario.TriggerVolumes[itemIndex]);

                UpdateBlockIndexes(itemIndex, scenario.TriggerVolumes.Count);
                break;
            }

            blockEditor.UpdateBlockReference(blockRef);
            return(true);
        }
Beispiel #19
0
    private void Awake()
    {
        _prevPosition  = transform.position;
        _prevRotation  = transform.rotation;
        _triggerVolume = GetComponent <TriggerVolume>();
        var input = GetComponent <GripInput>();

        input.Activated   += (sender) => Grip();
        input.Deactivated += (sender) => ReleaseGrip();
        IsLeftHand         = input.Hand == GripInput.HandType.Left;
    }
 protected override void Awake()
 {
     base.Awake();
     _triggerVolume = GetComponent <TriggerVolume>();
     if (_triggerVolume == null)
     {
         Debug.LogError("Could not find trigger volume.");
         enabled = false;
         return;
     }
 }
Beispiel #21
0
 private void UpdateTrigger(TriggerVolume trigger, CarController player)
 {
     if (player == player1)
     {
         currentZoneP1 = trigger;
         zonesPassedP1++;
     }
     if (player == player2)
     {
         currentZoneP2 = trigger;
         zonesPassedP2++;
     }
 }
Beispiel #22
0
    protected void OnEnterBulletBundle(TriggerVolume triggerVolume, Collider2D collision)
    {
        GunSlinger gunSlinger = collision.GetComponent <GunSlinger>();

        if (gunSlinger != null)
        {
            BulletBundle bulletBundle = triggerVolume.GetComponentInParent <BulletBundle>();
            Destroy(triggerVolume.gameObject);

            gunSlinger.AddBullet(new Gun.BulletInfo(bulletBundle.bulletPrefab, bulletBundle.num));
            Destroy(bulletBundle.gameObject);
        }
    }
Beispiel #23
0
        private void InsertTriggerVolumeElement(TriggerVolume vol, int index)
        {
            var box = new BoxManipulator3D
            {
                DiffuseColor = TriggerVolume.DefaultColour,
                Position     = ((IRealVector3D)vol.Position).ToVector3(),
                Size         = ((IRealVector3D)vol.Size).ToVector3()
            };

            BindTriggerVolume(vol, box);

            TriggerVolumes.Insert(index, box);
            TriggerVolumeGroup.Children.Add(box);
        }
Beispiel #24
0
    private void OnVolumeTriggerEnter(TriggerVolume triggerVolume, Collider collider)
    {
        BaseUnit targetBaseUnit = collider.gameObject.GetComponent<BaseUnit>();

        LineRenderDisplay lineRenderDisplayClone = Instantiate(lineRenderDisplayPrefab);
        lineRenderDisplayClone.transform.parent = this.transform;
        lineRenderDisplayClone.transform.localPosition = Vector3.zero;
        lineRenderDisplayClone.transform.localRotation = Quaternion.identity;

        lineRenderDisplayClone.Inialize(this, targetBaseUnit);

        lineRenderDisplays.Add(lineRenderDisplayClone);

        AddColor(targetBaseUnit.Color);
    }
Beispiel #25
0
        private void OnSightTriggerVolumeStay(TriggerVolume volume, Collider collider)
        {
            if (currentTarget != null)
            {
                return;
            }

            if (collider.tag != "Player")
            {
                return;
            }
            else
            {
                currentTarget = collider.GetComponent <PlayerUnit> ();
                ChangeStateTo(BehaviorState.SeekingTarget);
            }
        }
Beispiel #26
0
    protected void OnEnterGun(TriggerVolume triggerVolume, Collider2D collision)
    {
        GunSlinger gunSlinger = collision.GetComponent <GunSlinger>();

        if (gunSlinger != null)
        {
            Gun gun = triggerVolume.GetComponentInParent <Gun>();
            Destroy(triggerVolume.gameObject);

            if (gunSlinger.EquippedGun != null)
            {
                gunSlinger.EquippedGun.RuleManager.overridedGameRule = null;
                gunSlinger.Unequip();
            }

            gunSlinger.Equip(gun);
        }
    }
    private void OnVolumeTriggerExit(TriggerVolume triggerVolume, Collider collider)
    {
        BaseUnit          targetBaseUnit           = collider.gameObject.GetComponent <BaseUnit>();
        LineRenderDisplay currentLineRenderDisplay = GetLineRenderOf(targetBaseUnit);

        lineRenderDisplays.Remove(currentLineRenderDisplay);
        Destroy(currentLineRenderDisplay.gameObject);


        colorProportion[targetBaseUnit.Color] -= 1.0f;

        if (colorProportion[targetBaseUnit.Color] <= 0.0f)
        {
            colorProportion.Remove(targetBaseUnit.Color);
        }

        UpdateColor();
    }
    protected override void OnHitShotBullet(GunSlinger shooter, Gun usedGun, Bullet bullet, Collider2D collider)
    {
        TriggerVolume triggerVolume = collider.gameObject.GetComponent <TriggerVolume>();

        if (triggerVolume != null)
        {
            switch (triggerVolume.type)
            {
            case TriggerVolume.Type.EnemyBarrack:
                //Debug.Log(shooter + " hits EnemyBarrack!");
                bullet.Ricochet();
                break;

            case TriggerVolume.Type.OurBarrack:
                //Debug.Log(shooter + " hits OurBarrack!");
                bullet.Ricochet();
                break;

            default:
                break;
            }
        }
        else
        {
            MyUnit  hittedUnit = collider.gameObject.GetComponent <MyUnit>();
            MyBotAi hittedAi   = collider.gameObject.GetComponent <MyBotAi>();
            if (hittedUnit != null && hittedAi != null && !hittedUnit.IsDead)
            {
                MyUnit  shotUnit = shooter.GetComponent <MyUnit>();
                MyBotAi shotAi   = shooter.GetComponent <MyBotAi>();

                if (shotUnit != null && shotAi != null)
                {
                    if (!shotAi.IsSameSide(hittedAi))
                    {
                        bullet.Ricochet();
                        hittedUnit.TakeDamage(0.5f);
                    }
                }
            }
        }
    }
Beispiel #29
0
        void GunSlinger.IGameRule.OnUnequip(GunSlinger gunSlinger, Gun gun)
        {
            gun.RuleManager.overridedGameRule = null;
            gun.GetComponent <Rigidbody2D>().AddForce(Vector2.up * 200);

            GameObject newGo = new GameObject("TriggerVolume");

            TriggerVolume triggerVolume = newGo.AddComponent <TriggerVolume>();

            triggerVolume.type = TriggerVolume.Type.Gun;

            BoxCollider2D boxCollider = newGo.AddComponent <BoxCollider2D>();

            boxCollider.enabled   = false;
            boxCollider.isTrigger = true;
            boxCollider.size      = gun.GetComponent <BoxCollider2D>().size;

            newGo.transform.parent        = gun.transform;
            newGo.transform.localPosition = Vector3.zero;

            triggerVolume.EnableTriggerAfterSeconds(3);
        }
Beispiel #30
0
 private void BindTriggerVolume(TriggerVolume vol, BoxManipulator3D box)
 {
     box.DataContext = vol;
     BindingOperations.SetBinding(box, BoxManipulator3D.ForwardVectorProperty,
                                  new Binding(nameof(TriggerVolume.ForwardVector))
     {
         Mode = BindingMode.TwoWay, Converter = SharpDXVectorConverter.Instance
     });
     BindingOperations.SetBinding(box, BoxManipulator3D.UpVectorProperty,
                                  new Binding(nameof(TriggerVolume.UpVector))
     {
         Mode = BindingMode.TwoWay, Converter = SharpDXVectorConverter.Instance
     });
     BindingOperations.SetBinding(box, BoxManipulator3D.PositionProperty,
                                  new Binding(nameof(TriggerVolume.Position))
     {
         Mode = BindingMode.TwoWay, Converter = SharpDXVectorConverter.Instance
     });
     BindingOperations.SetBinding(box, BoxManipulator3D.SizeProperty,
                                  new Binding(nameof(TriggerVolume.Size))
     {
         Mode = BindingMode.TwoWay, Converter = SharpDXVectorConverter.Instance
     });
 }
Beispiel #31
0
 private void OnTriggerVolumeEnter(TriggerVolume triggerVolume, Collider collider)
 {
     targetToFollow = collider.transform;
 }
Beispiel #32
0
 private void OnSightTriggerVolumeEnter(TriggerVolume volume, Collider collider)
 {
     currentTarget = collider.GetComponent<PlayerUnit>();
     ChangeStateTo(BehaviorState.SeekingTarget);
 }
Beispiel #33
0
 private void OnSightTriggerVolumeExit(TriggerVolume volume, Collider collider)
 {
     currentTarget = null;
     ChangeStateTo(BehaviorState.Patrolling);
 }
Beispiel #34
0
 private void OnTriggerVolumeEnter(TriggerVolume triggerVolume, Collider collider)
 {
     targetToFollow = collider.transform;
 }
Beispiel #35
0
 void Start()
 {
     currentZoneP1 = zone3;
     currentZoneP2 = zone3;
 }
Beispiel #36
0
 private void OnTriggerVolumeExit(TriggerVolume arg1, Collider arg2)
 {
     if (targetToFollow != null && arg2.transform == targetToFollow)
         targetToFollow = null;
 }
 private void OnAttackTriggerVolumeExit(TriggerVolume volume, Collider collider1)
 {
     enemy.ChangeStateTo(BehaviorState.Patrolling);
 }
Beispiel #38
0
 private void Awake()
 {
     triggerVolume = GetComponent<TriggerVolume>();
 }
Beispiel #39
0
 private void OnPlayerCollide(TriggerVolume triggerVolume, Collider collider)
 {
     PlayerUnit playerUnit = collider.GetComponent<PlayerUnit>();
     OnPicked(playerUnit);
     Destroy(gameObject);
 }
Beispiel #40
0
 private void OnAttackTriggerVolumeExit(TriggerVolume volume, Collider collider1)
 {
     enemy.ChangeStateTo(BehaviorState.Patrolling);
 }
Beispiel #41
0
    private void OnVolumeTriggerExit(TriggerVolume triggerVolume, Collider collider)
    {
        BaseUnit targetBaseUnit = collider.gameObject.GetComponent<BaseUnit>();
        LineRenderDisplay currentLineRenderDisplay = GetLineRenderOf(targetBaseUnit);

        RemoveColor(targetBaseUnit.Color);
        lineRenderDisplays.Remove(currentLineRenderDisplay);
        Destroy(currentLineRenderDisplay.gameObject);
    }
Beispiel #42
0
 private void OnAttackTriggerVolumeStay(TriggerVolume volume, Collider collider1)
 {
     PlayerUnit playerUnit = collider1.GetComponent<PlayerUnit>();
     playerHealth = playerUnit.AttributePool.GetAttribute(AttributeType.Health);
     ExecuteAttack();
 }