示例#1
0
 TrigEvent(GameObject other)
 {
     // if collid with body, according to https://www.youtube.com/watch?v=35lpSHgvibU
     if (other.CompareTag("Body"))
     {
         ArenaNode  OtherNode           = Utils.GetBottomLevelArenaNodeInGameObject(other);
         ArenaNode  ThisNode            = Utils.GetBottomLevelArenaNodeInGameObject(gameObject);
         List <int> ThisNodeCoordinate  = ThisNode.GetCoordinate();
         List <int> OtherNodeCoordinate = OtherNode.GetCoordinate();
         if (!Utils.IsListEqual(ThisNodeCoordinate, OtherNodeCoordinate,
                                Mathf.Min(ThisNodeCoordinate.Count, OtherNodeCoordinate.Count)))
         {
             ThisNode.Kill();
         }
     }
 } // TrigEvent
        DiscreteStep(int Action_)
        {
            if (GetActionSpaceType() != SpaceType.discrete)
            {
                Debug.LogError("ActionSpaceType is not Discrete, DiscreteStep() should not be called.");
            }


            if (AllowGunAttack)
            {
                if (IsShowAimLine)
                {
                    IsHit = Physics.Raycast(RaycastEmitter.transform.position, RaycastEmitter.transform.up,
                                            out AimRaycast);

                    if (IsHit)
                    {
                        AimLine.DrawLineInGameView(RaycastEmitter.transform.position,
                                                   RaycastEmitter.transform.position + RaycastEmitter.transform.up * AimRaycast.distance,
                                                   ((Action_ == Attack) && (NumBullet > 0) &&
                                                    (!Reloading) && (CoolingSteps == 0)) ? AimLineColorWhenAttack : AimLineColor);
                    }
                }
                else
                {
                    AimLine.DrawLineInGameView(RaycastEmitter.transform.position,
                                               RaycastEmitter.transform.position + RaycastEmitter.transform.up * 0f,
                                               AimLineColor);
                }

                switch (Action_)
                {
                case Attack:
                    if ((NumBullet > 0) && (!Reloading) && (CoolingSteps == 0))
                    {
                        CoolingSteps = NumCoolingSteps + 1;
                        if (ShootType == ShootTypes.Raycast)
                        {
                            if (!IsShowAimLine)
                            {
                                // not showing aim line, so raycast need to be done here
                                IsHit = Physics.Raycast(RaycastEmitter.transform.position,
                                                        RaycastEmitter.transform.up,
                                                        out AimRaycast);
                                if (IsHit)
                                {
                                    AimLine.DrawLineInGameView(RaycastEmitter.transform.position,
                                                               RaycastEmitter.transform.position + RaycastEmitter.transform.up * AimRaycast.distance,
                                                               AimLineColorWhenAttack);
                                }
                            }

                            if (IsHit)
                            {
                                if (TrigTags.Contains(AimRaycast.collider.gameObject.tag))
                                {
                                    ArenaNode SubjectNode = Utils.GetBottomLevelArenaNodeInGameObject(
                                        AimRaycast.collider.gameObject);
                                    if (IsKill)
                                    {
                                        SubjectNode.Kill();
                                    }
                                    if (KillHealth != 0f)
                                    {
                                        SubjectNode.IncrementAttribute("Health", -KillHealth);
                                    }
                                }
                                if (AimRaycast.collider.gameObject.tag == "ObstacleDestroyable")
                                {
                                    AimRaycast.collider.gameObject.GetComponent <Destroyable>().Hitted();
                                }
                            }
                        }
                        else if (ShootType == ShootTypes.Bullet)
                        {
                            GameObject Temp_Bullet_Handeler;
                            Temp_Bullet_Handeler = Instantiate(Bullet, BulletEmitter.transform.position,
                                                               BulletEmitter.transform.rotation) as GameObject;
                            Temp_Bullet_Handeler.GetComponent <Rigidbody>().AddForce(
                                BulletEmitter.transform.up * BulletFarwardForce);
                        }
                        NumBullet -= 1.0f;

                        foreach (Dictionary <string,
                                             UIPercentageBar> UIPercentageBars in AllAgentCamerasUIPercentageBars)
                        {
                            UIPercentageBars["Ammo"].UpdatePercentage(GetBulletPercentage());
                        }
                        if (NumBullet < 1.0f)
                        {
                            Reloading = true;
                        }
                    }
                    break;

                default:
                    break;
                }

                if (CoolingSteps > 0)
                {
                    CoolingSteps--;
                }

                if (Reloading)
                {
                    NumBullet += NumBulletPerLoad;
                    foreach (Dictionary <string, UIPercentageBar> UIPercentageBars in AllAgentCamerasUIPercentageBars)
                    {
                        UIPercentageBars["Ammo"].UpdatePercentage(GetBulletPercentage());
                    }
                    if (NumBullet >= FullNumBullet)
                    {
                        Reloading = false;
                    }
                }
            }
        } // DiscreteStep