예제 #1
0
    //-------------------------------------------------INSTANIATE MAP-----------------------------------------------//
    public void CreateMap(SM.SceneObstacleData obstacleData)
    {
        int width  = obstacleData.MaxSize;
        int height = obstacleData.MaxSize;

        //Set map up
        Map = new Node[width, height];
        int size = width * height;

        SetListsSize(size);
        //Fill up Map
        float startX = MapStartPosition.x;
        float startZ = MapStartPosition.y;

        for (int n = 0; n < obstacleData.mData.Count; n++)
        {
            int   i          = (int)obstacleData.mData[n].obstacleArray.x;
            int   j          = (int)obstacleData.mData[n].obstacleArray.y;
            bool  isWalkable = ((int)obstacleData.mData[n].obstacleArray.z) == 1 ? false : true;
            float x          = startX + (i * Tilesize) + (Tilesize / 2); //Position from where we raycast - X
            float y          = startZ + (j * Tilesize) + (Tilesize / 2); //Position from where we raycast - Z
            int   ID         = (i * width) + j;                          //ID we give to our Node!
            Map[i, j] = new Node(i, j, 0, ID, x, y, isWalkable);         //Non walkable tile!
        }
    }
예제 #2
0
    public void RebuildFinderPathData(SM.SceneObstacleData obstacleData)
    {
//        float startX = MapStartPosition.x;
//        float startZ = MapStartPosition.y;
        for (int n = 0; n < obstacleData.mData.Count; n++)
        {
            int  i          = (int)obstacleData.mData[n].obstacleArray.x;
            int  j          = (int)obstacleData.mData[n].obstacleArray.y;
            bool isWalkable = ((int)obstacleData.mData[n].obstacleArray.z) == 1 ? false : true;
            Map[i, j].walkable = isWalkable;
        }
    }
예제 #3
0
        // 生成场景资源数据
        public IEnumerator BuildSceneResObj(SERoomDataTree sce, GameResPackage.AsyncLoadPackageData loadData, int gateIndex = -1)
        {
            string obstacleFileName = "Prefabs/" + m_RoomPrefabName + "-bytes.bytes";

            GameResPackage.AsyncLoadObjectData loadData2 = new GameResPackage.AsyncLoadObjectData();
            IEnumerator e = PoolManager.Singleton.Coroutine_Load(obstacleFileName, loadData2, false, false);

            while (true)
            {
                e.MoveNext();
                if (loadData2.m_isFinish)
                {
                    break;
                }
                yield return(e.Current);
            }
            if (loadData2.m_obj != null)
            {
                TextAsset asset = loadData2.m_obj as TextAsset;
                if (asset == null)
                {
                    Debug.Log("obstacleFileName=" + obstacleFileName);
                }
                else
                {
                    m_obstacleData = new SceneObstacleData();
                    m_obstacleData.Load(asset.bytes);
                }
            }
            loadData2 = new GameResPackage.AsyncLoadObjectData();
            e         = PoolManager.Singleton.Coroutine_Load(GameData.GetPrefabPath(m_RoomPrefabName), loadData2, false, false);
            while (true)
            {
                e.MoveNext();
                if (loadData2.m_isFinish)
                {
                    break;
                }
                yield return(e.Current);
            }
            if (loadData2.m_obj != null)
            {
                sce.mRoomObj = loadData2.m_obj as GameObject;
            }
            string roomDataName = m_RoomPrefabName + "-data";

            loadData2 = new GameResPackage.AsyncLoadObjectData();
            e         = PoolManager.Singleton.Coroutine_Load(GameData.GetPrefabPath(roomDataName), loadData2, false, false);
            while (true)
            {
                e.MoveNext();
                if (loadData2.m_isFinish)
                {
                    break;
                }
                yield return(e.Current);
            }
            if (loadData2.m_obj != null)
            {
                sce.mRoomData = loadData2.m_obj as GameObject;
            }
            sce.mRoomInfoTree = this;
//             for (int i = 0; i < m_gateList.Count; i++)
//             {
//                 sce.mGateData[i] = new SEGateData();
//                 if (null != m_gateList[i].BridgeData)
//                 {
//                     SceneBridgeInfo bridgeInfo = GameTable.SceneBridgeTableAsset.Lookup(m_gateList[i].BridgeData.bridgeObjId);
//                     if (null != bridgeInfo)
//                     {
//                         loadData2 = new GameResPackage.AsyncLoadObjectData();
//                         e = PoolManager.Singleton.Coroutine_Load(GameData.GetPrefabPath(bridgeInfo.bridgeHeadPrefab), loadData2, false, false);
//                         while (true)
//                         {
//                             e.MoveNext();
//                             if (loadData2.m_isFinish)
//                             {
//                                 break;
//                             }
//                             yield return e.Current;
//                         }
//                         if (loadData2.m_obj != null)
//                         {
//                             sce.mGateData[i].mBridgeHeadObj = loadData2.m_obj as GameObject;
//                         }
//                         loadData2 = new GameResPackage.AsyncLoadObjectData();
//                         e = PoolManager.Singleton.Coroutine_Load(GameData.GetPrefabPath(bridgeInfo.bridgeBodyPrefab), loadData2, false, false);
//                         while (true)
//                         {
//                             e.MoveNext();
//                             if (loadData2.m_isFinish)
//                             {
//                                 break;
//                             }
//                             yield return e.Current;
//                         }
//                         if (loadData2.m_obj != null)
//                         {
//                             sce.mGateData[i].mBridgeBodyObj = loadData2.m_obj as GameObject;
//                         }
//                         loadData2 = new GameResPackage.AsyncLoadObjectData();
//                         e = PoolManager.Singleton.Coroutine_Load(GameData.GetPrefabPath(bridgeInfo.bridgeTailPrefab), loadData2, false, false);
//                         while (true)
//                         {
//                             e.MoveNext();
//                             if (loadData2.m_isFinish)
//                             {
//                                 break;
//                             }
//                             yield return e.Current;
//                         }
//                         if (loadData2.m_obj != null)
//                         {
//                             sce.mGateData[i].mBridgeTailObj = loadData2.m_obj as GameObject;
//                         }
//                         //sce.mGateData[i].mBridgeHeadObj = GameData.LoadPrefab<GameObject>(bridgeInfo.bridgeHeadPrefab);
//                         //sce.mGateData[i].mBridgeBodyObj = GameData.LoadPrefab<GameObject>(bridgeInfo.bridgeBodyPrefab);
//                     }
//                     sce.mGateData[i].mIsHaveTunnel = true;
//                     sce.mGateData[i].mBridgeCenterLength = m_gateList[i].BridgeData.bridgeCenterLength;
//                     sce.mGateData[i].mNextRoomNode = new SERoomDataTree();
//                     m_gateList[i].isGateOpen = true;
//                     GameResPackage.AsyncLoadPackageData loadData3 = new GameResPackage.AsyncLoadPackageData();
//                     IEnumerator e6 = m_gateList[i].BridgeData.nextRoomNode.BuildSceneResObj(sce.mGateData[i].mNextRoomNode, loadData3, (i + 2) % 4);//一共四个门0对应2,1对应3。0+2%4= 2,1+2%4=3,2+2%4=0,3+2%4=1。·
//                     while (true)
//                     {
//                         e6.MoveNext();
//                         if (loadData3.m_isFinish)
//                         {
//                             break;
//                         }
//                         yield return e6.Current;
//                     }
//                 }
//                 else
//                 {//当该房间的这个门是没有联通出去的路的,但是这个门是另外房间进来的门那这个门要有意义。否则无意义
//                     if (gateIndex == i)
//                     {
//                         m_gateList[i].isGateOpen = true;
//                         m_gateList[i].gateOpenCondId = ENGateOpenCondType.enNone;
//                     }
//                     else
//                     {
//                         m_gateList[i].isGateOpen = false;
//                     }
//                 }
//             }
            loadData.m_isFinish = true;
        }
예제 #4
0
    public static void GenRoomPathData()
    {
        GameObject[] objArray = Selection.gameObjects;
        if (null == objArray)
        {
            Debug.Log("please select room res!!!");
            return;
        }
        if (objArray.Length <= 0)
        {
            return;
        }
        if (null == objArray[0])
        {
            return;
        }
        // 选择的物件
        GameObject obj     = GameObject.Instantiate(objArray[0]) as GameObject;
        Transform  locator = obj.transform.Find("Locator");

        if (null == locator)
        {
            Debug.Log("not exist locator!!!!");
            return;
        }
        ChangeColliderLayerName(obj);
        GameObject  colliderObj = GameObject.Find("collider");
        BoxCollider box         = null;

        if (null == colliderObj)
        {
            colliderObj = new GameObject("collider");
            box         = colliderObj.AddComponent <BoxCollider>();
            box.size    = new Vector3(mTileSize, 1f, mTileSize);
        }
        else
        {
            box = colliderObj.GetComponent <BoxCollider>();
        }
        Vector3 offsetPos = new Vector3(locator.position.x, locator.position.y, locator.position.z);
        int     nMaxSize  = 0;

        for (int x = 0; x < mblockCount; x++)
        {
            for (int y = 0; y < mblockCount; y++)
            {
                Vector3 pos = new Vector3(x * mTileSize + mTileSize / 2, 0.5f, y * mTileSize + mTileSize / 2);
                colliderObj.transform.position = new Vector3(offsetPos.x + pos.x, offsetPos.y, offsetPos.z + pos.z);
                bool ishave = CheckCollider(obj, box.bounds);
                if (ishave)
                {
                    if (nMaxSize < y)
                    {
                        nMaxSize = y;
                    }
                    if (nMaxSize < x)
                    {
                        nMaxSize = x;
                    }
                }
            }
        }
        Debug.Log("nMaxSize=" + nMaxSize);
        GameObject preObj = GameObject.Find("preObj");

        if (null == preObj)
        {
            preObj = new GameObject("preObj");
        }
        offsetPos = new Vector3(locator.position.x, locator.position.y + 10.0f, locator.position.z);
        SM.SceneObstacleData obstacleData = new SM.SceneObstacleData();
        obstacleData.MaxSize = nMaxSize;
        //nMaxSize += 2;
        for (int x = 0; x < nMaxSize; x++)
        {
            for (int y = 0; y < nMaxSize; y++)
            {
                Vector3 pos = new Vector3(x * mTileSize + mTileSize / 2, 0.5f, y * mTileSize + mTileSize / 2);
                colliderObj.transform.position = new Vector3(offsetPos.x + pos.x, offsetPos.y, offsetPos.z + pos.z);
                RaycastHit[] hit;
                hit = Physics.SphereCastAll(colliderObj.transform.position, mTileSize / 2, Vector3.down, 1000f);
                bool ishave = false;
                SM.SceneObstacleData.ObData obData = new SM.SceneObstacleData.ObData();
                foreach (RaycastHit h in hit)
                {
                    //Debug.Log("h.collider.gameObject.transform:" + h.collider.gameObject.transform.parent.name);
                    if ("Collider" == h.collider.gameObject.transform.parent.name)
                    //if (LayerMask.NameToLayer("EnableCollider") == h.collider.gameObject.layer)
                    {
                        if (h.collider.gameObject.transform.parent.parent.name.Contains("RemovableGate_E"))
                        {
                            obData.enDirection = SM.ENGateDirection.enEAST;
                            //Debug.Log("name:" + h.collider.gameObject.transform.parent.parent.name);
                        }
                        else if (h.collider.gameObject.transform.parent.parent.name.Contains("RemovableGate_W"))
                        {
                            obData.enDirection = SM.ENGateDirection.enWEST;
                            //Debug.Log("name:" + h.collider.gameObject.transform.parent.parent.name);
                        }
                        else if (h.collider.gameObject.transform.parent.parent.name.Contains("RemovableGate_N"))
                        {
                            obData.enDirection = SM.ENGateDirection.enNORTH;
                            //Debug.Log("name:" + h.collider.gameObject.transform.parent.parent.name);
                        }
                        else if (h.collider.gameObject.transform.parent.parent.name.Contains("RemovableGate_S"))
                        {
                            obData.enDirection = SM.ENGateDirection.enSOUTH;
                            //Debug.Log("name:" + h.collider.gameObject.transform.parent.parent.name);
                        }
                        ishave = true;
                        break;
                    }
                }
                obData.obstacleArray = new Vector3(x, y, ishave ? 1 : 0);
                obstacleData.mData.Add(obData);
                ////////////////////////////////////////////////////
                GameObject childObj = new GameObject("x_" + x.ToString("00") + "_y_" + y.ToString("00") + "(" + ishave.ToString() + ")");
                childObj.transform.parent   = preObj.transform;
                childObj.transform.position = colliderObj.transform.position;
                if (!ishave)
                {
                    BoxCollider box1 = childObj.AddComponent <BoxCollider>();
                    box1.size = new Vector3(mTileSize, 0.1f, mTileSize);
                }
            }
        }
        preObj.LocalPositionY(-10f);
//         for (int i = 0; i < Map.GetLength(1); i++)
//         {
//             for (int j = 0; j < Map.GetLength(0); j++)
//             {
//                 bool isWalkable = Mathf.CeilToInt(Map[j, i].obstacleArray.z) == 1 ? false : true;
//                 if (!isWalkable)
//                     continue;
//                 for (int y = i - 1; y < i + 2; y++)
//                 {
//                     for (int x = j - 1; x < j + 2; x++)
//                     {
//                         if (y < 0 || x < 0 || y >= Map.GetLength(1) || x >= Map.GetLength(0))
//                             continue;
//                         isWalkable = Mathf.CeilToInt(Map[x, y].obstacleArray.z) == 1 ? false : true;
//                         if (!isWalkable)
//                             continue;
//                         Vector3 pos1 = new Vector3(j * mTileSize/* + mTileSize / 2*/, 0.5f, i * mTileSize/* + mTileSize / 2*/);
//                         Vector3 start = new Vector3(offsetPos.x + pos1.x, offsetPos.y, offsetPos.z + pos1.z);
//
//                         Vector3 pos = new Vector3(x * mTileSize/* + mTileSize / 2*/, 0.5f, y * mTileSize/* + mTileSize / 2*/);
//                         Vector3 end = new Vector3(offsetPos.x + pos.x, offsetPos.y, offsetPos.z + pos.z);
//
//                         UnityEngine.Debug.DrawLine(start, end, Color.green);
//                     }
//                 }
//             }
//         }
        string path = AssetDatabase.GetAssetPath(objArray[0]);

        Debug.Log("path=" + path);
        path  = Path.GetDirectoryName(path);
        path += "/";
        string fileName = path + objArray[0].name + "-bytes.bytes";

        using (FileStream targetFile = new FileStream(fileName, FileMode.Create))
        {
            byte[] buff = obstacleData.Save();
            targetFile.Write(buff, 0, buff.Length);
        }
        Debug.Log("fileName=" + fileName);
        GameObject.DestroyImmediate(colliderObj);
    }