Пример #1
0
    private void OnEnable()
    {
        Tools.hidden = true;

        _minDisntance = EditorPrefs.GetFloat("AirWallMinDistance", 1f);

        if (_sceneMask == 0)
        {
            _sceneMask = 1 << LayerMask.NameToLayer("Scene");
        }

        _airWall = Selection.activeGameObject.GetComponent <AirWall>();
        if (_airWall.points != null)
        {
            _tempPoints = new List <Vector3>(_airWall.points);
            if (_airWall.points.Length == 0)
            {
                _airWall.points = null;
            }
        }
        else
        {
            _tempPoints = new List <Vector3>();
        }
    }
Пример #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("HardObject"))
     {
         OnHit(false);
         SoundManager.instance.PlayEfx(Efx.HIT_HARD, transform.position);
         EffectManager.instance.Explode(other.ClosestPoint(transform.position), ExplosionType.HARD);
     }
     else if (other.CompareTag("SoftObject"))
     {
         OnHit(true);
         other.SendMessage("Damage");
         EffectManager.instance.Explode(other.ClosestPoint(transform.position), ExplosionType.SOFT);
     }
     else if (other.CompareTag("AirWall"))
     {
         AirWall airWall = other.GetComponent <AirWall>();
         if (airWall && AirWall.isBulletBlocked)
         {
             OnHit(false);
             SoundManager.instance.PlayEfx(Efx.HIT_HARD, transform.position);
             EffectManager.instance.Explode(other.ClosestPoint(transform.position), ExplosionType.HARD);
         }
     }
     else if (other.CompareTag("EnemyShield"))
     {
         OnHit(false);
         SoundManager.instance.PlayEfx(Efx.HIT_HARD_ENEMY, transform.position);
         EffectManager.instance.Explode(other.ClosestPoint(transform.position), ExplosionType.SOFT);
     }
     else if (other.CompareTag("Enemy"))
     {
         OnHit(true);
         other.GetComponent <Enemy>().Damage();
         EffectManager.instance.Explode(other.ClosestPoint(transform.position), ExplosionType.SOFT);
     }
     else if (other.CompareTag("EnemyBullet"))
     {
         EnemyBullet bullet = other.GetComponent <EnemyBullet>();
         if (bullet.canBeHitted)
         {
             OnHit(true);
             bullet.Damage();
         }
     }
 }
Пример #3
0
    private void BakeAirWall()
    {
        _collideMain = Selection.activeGameObject;
        List <AirWall> airWalls = new List <AirWall>();
        int            count    = _collideMain.transform.childCount;

        for (int ii = 0; ii < count; ++ii)
        {
            AirWall airWall = _collideMain.transform.GetChild(ii).GetComponent <AirWall>();
            if (airWall != null)
            {
                int childCount = airWall.transform.childCount;
                if (childCount > 0)
                {
                    for (int jj = childCount - 1; jj >= 0; --jj)
                    {
                        DestroyImmediate(airWall.transform.GetChild(jj).gameObject);
                    }
                }
                airWalls.Add(airWall);
            }
        }

        for (int ii = 0; ii < airWalls.Count; ++ii)
        {
            Vector3[] points = airWalls[ii].points;
            for (int jj = 0; jj < points.Length - 1; ++jj)
            {
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.name  = "SubWall" + (jj + 1);
                cube.layer = LayerMask.NameToLayer("AirWall");
                cube.transform.SetParent(airWalls[ii].transform);
                Vector3 relativePos = points[jj] - points[jj + 1];
                relativePos.y = 0;
                Quaternion rotation = Quaternion.LookRotation(relativePos);
                cube.transform.rotation = rotation;
                cube.transform.position = (points[jj] + points[jj + 1]) * 0.5f;
                float distance = Vector2.Distance(new Vector2(points[jj].x, points[jj].z), new Vector2(points[jj + 1].x, points[jj + 1].z));
                cube.transform.localScale = new Vector3(0.1f, _wallHeight * 2f, distance);
                cube.isStatic             = true;
            }
        }
    }
Пример #4
0
    // Update is called once per frame
    private void Update()
    {
        // only update lookahead pos if accelerating or changed direction
        float xMoveDelta = (target.position - m_LastTargetPosition).x;

        bool updateLookAheadTarget = Mathf.Abs(xMoveDelta) > lookAheadMoveThreshold;

        if (updateLookAheadTarget)
        {
            m_LookAheadPos = lookAheadFactor * Vector3.right * Mathf.Sign(xMoveDelta);
        }
        else
        {
            m_LookAheadPos = Vector3.MoveTowards(m_LookAheadPos, Vector3.zero, Time.deltaTime * lookAheadReturnSpeed);
        }

        Vector3 aheadTargetPos = target.position + m_LookAheadPos + Vector3.forward * m_OffsetZ;
        Vector3 newPos         = Vector3.SmoothDamp(transform.position, aheadTargetPos, ref m_CurrentVelocity, damping);

        //U3D摄像机理解:https://blog.csdn.net/n5/article/details/50083205
        float orthographicSize = GetComponent <Camera>().orthographicSize;
        float aspectRatio      = Screen.width * 1.0f / Screen.height;
        float cameraHeight     = orthographicSize * 2;
        float cameraWidth      = cameraHeight * aspectRatio;

        //镜头偏移值
        var offset = 0.35f;  //=>该偏移量只在图块比城堡右侧宽出来一个格子时显示效果最佳

        //边界值
        newPos.x = newPos.x > AirWall.getInstance().max_X - cameraWidth / 2 - offset ? AirWall.getInstance().max_X - cameraWidth / 2 - offset : newPos.x;
        //newPos.x = newPos.x < AirWall.getInstance().min_X + cameraWidth / 2 - offset ? AirWall.getInstance().min_X + cameraWidth / 2 - offset : newPos.x;
        newPos.x = newPos.x < 0 ? 0 : newPos.x;
        newPos.y = newPos.y < 0 ? 0 : newPos.y;

        transform.position = newPos;

        m_LastTargetPosition = target.position;
    }
Пример #5
0
    void Start()
    {
        BlockItem item = new BlockItem();

        item.creat(Vector3.zero);

        BlockItem item1 = new BlockItem();

        item1.creat(new Vector3(-AirWallConst.blockSize, 0f, 0f));

        BlockItem item2 = new BlockItem();

        item2.creat(new Vector3(-AirWallConst.blockSize, 0f, AirWallConst.blockSize));

        BlockItem item3 = new BlockItem();

        item3.creat(new Vector3(AirWallConst.blockSize, 0f, 0f));

        BlockItem item4 = new BlockItem();

        item4.creat(new Vector3(AirWallConst.blockSize, 0f, AirWallConst.blockSize));

        BlockItem item5 = new BlockItem();

        item5.creat(new Vector3(0f, 0f, -AirWallConst.blockSize));

        BlockItem item6 = new BlockItem();

        item6.creat(new Vector3(AirWallConst.blockSize, 0f, -AirWallConst.blockSize));

        BlockItem item7 = new BlockItem();

        item7.creat(new Vector3(AirWallConst.blockSize * 2, 0f, -AirWallConst.blockSize * 2));

        AirWall wall0 = new AirWall(item.pos, "0");

        wall0.creat();

        AirWall wall1 = new AirWall(item1.pos, "1");

        wall1.creat();

        AirWall wall2 = new AirWall(item2.pos, "2");

        wall2.creat();

        AirWall wall3 = new AirWall(item3.pos, "3");

        wall3.creat();

        AirWall wall4 = new AirWall(item4.pos, "4");

        wall4.creat();

        AirWall wall5 = new AirWall(item5.pos, "5");

        wall5.creat();

        AirWall wall6 = new AirWall(item6.pos, "6");

        wall6.creat();

        AirWall wall7 = new AirWall(item7.pos, "7");

        wall7.creat();

        item.destroy();
        wall0.destroy();

        //BlockItem item8 = new BlockItem();
        //item8.creat(new Vector3(AirWallConst.blockSize * 3, 0f, -AirWallConst.blockSize * 2));
        //AirWall wall8 = new AirWall(item8.pos, "8");
        //wall8.creat();
    }
Пример #6
0
    private void BakeAirWall()
    {
        _collideMain = Selection.activeGameObject;
        if (_collideMain == null || airWalls == null)
        {
            return;
        }
        //如果Airwalls下还有其它的非AirWall,把它们整理到一个节点下
        List <Transform> otherList = new List <Transform>();
        var otherTrans             = _collideMain.transform.FindChild("_Others");

        if (otherTrans == null)
        {
            otherTrans = new GameObject("_Others").transform;
            otherTrans.SetParent(_collideMain.transform);
            otherTrans.localPosition = Vector3.zero;
            otherTrans.localRotation = Quaternion.identity;
            otherTrans.localScale    = Vector3.one;
        }

        if (airWalls.Count > 0)
        {
            airWalls.Clear();
        }

        //destory old child
        int count = _collideMain.transform.childCount;

        for (int ii = 0; ii < count; ++ii)
        {
            var     child   = _collideMain.transform.GetChild(ii);
            AirWall airWall = child.GetComponent <AirWall>();
            if (airWall != null)
            {
                int childCount = airWall.transform.childCount;
                if (childCount > 0)
                {
                    for (int jj = childCount - 1; jj >= 0; --jj)
                    {
                        DestroyImmediate(airWall.transform.GetChild(jj).gameObject);
                    }
                }
                airWalls.Add(airWall);
            }
            else
            {
                otherList.Add(child);
            }
        }

        for (int ii = 0; ii < otherList.Count; ++ii)
        {
            otherList[ii].SetParent(otherTrans);
        }
        //bug 设置 HideFlags之后,还是会报“ptr->GetHideFlags () == m_RequiredHideFlags”
        GameObject cubePrefab = GameObject.CreatePrimitive(PrimitiveType.Cube);

        cubePrefab.hideFlags = HideFlags.None;
        //create new child
        for (int ii = 0; ii < airWalls.Count; ++ii)
        {
            //bug points 会丢失
            Vector3[] points = airWalls[ii].points;
            if (points == null || points.Length <= 0)
            {
                Debug.LogWarningFormat("airWalls[{0}] point null", ii);
                continue;
            }
            for (int jj = 0; jj < points.Length - 1; ++jj)
            {
                AirWall    airWall = airWalls[ii].transform.GetComponent <AirWall>();
                GameObject cube    = Instantiate(cubePrefab);
                cube.name  = "SubWall" + (jj + 1);
                cube.layer = LayerMask.NameToLayer("AirWall");
                cube.transform.SetParent(airWalls[ii].transform);
                Vector3 relativePos = points[jj] - points[jj + 1];
                relativePos.y = 0;
                Quaternion rotation = Quaternion.LookRotation(relativePos);
                cube.transform.rotation = rotation;
                if (airWall != null)
                {
                    //position = point  - cube thick *0.5f
                    var     pos    = (points[jj] + points[jj + 1]) * 0.5f;
                    Vector3 newPos = pos;
                    switch (airWall.DirType)
                    {
                    case AirWallDir.Top:
                        newPos = new Vector3(pos.x + _wallThick * 0.5f, pos.y, pos.z);
                        break;

                    case AirWallDir.Bottom:
                        newPos = new Vector3(pos.x - _wallThick * 0.5f, pos.y, pos.z);
                        break;

                    case AirWallDir.Left:
                        newPos = new Vector3(pos.x, pos.y, pos.z + _wallThick * 0.5f);
                        break;

                    case AirWallDir.Right:
                        newPos = new Vector3(pos.x, pos.y, pos.z - _wallThick * 0.5f);
                        break;
                    }
                    cube.transform.position = newPos;
                }
                else
                {
                    Debug.LogError("not contains AirWall Component");
                }
                //axis z = lenth
                float distance = Vector2.Distance(new Vector2(points[jj].x, points[jj].z), new Vector2(points[jj + 1].x, points[jj + 1].z));
                cube.transform.localScale = new Vector3(_wallThick, _wallHeight * 2f, distance);
                cube.isStatic             = true;
            }
        }
        DestroyImmediate(cubePrefab);
    }
Пример #7
0
 // Use this for initialization
 void Start()
 {
     instance = this;
     Invoke("updateAirWallViaBlockPos", 0.5f);
 }