Exemplo n.º 1
0
    public virtual void UpdateNodeSideInfo(NodeSideInfo newInfo)
    {
        _startNodeInfo = newInfo;

        _targetPosition = _startNodeInfo.GetWorldPosition();
        _startPosition  = _startNodeInfo.GetWorldPosition();
    }
Exemplo n.º 2
0
    private void BuildLine()
    {
        List <Vector3> positionList = new List <Vector3>(_selectedInfoList.Count * 2);

        if (_selectedInfoList.Count > 0)
        {
            Vector3 closestEdge = Vector3.zero;

            Vector3 currentSideOffset = Vector3.zero;
            Vector3 nextSideOffset    = Vector3.zero;

            NodeSideInfo current = null;
            NodeSideInfo next    = null;

            if (_selectedInfoList.Count == 1)
            {
                current = _selectedInfoList[0];

                currentSideOffset = BoardManager.SideToOffset(current._side).ToVector3() * 0.1f;
                Vector3 currentMouseNodePos = GameStateManager.Instance.MouseNodeSidePosition;

                Vector3 diff = (currentMouseNodePos - currentSideOffset).normalized;
                positionList.Add(current.GetWorldPosition() + currentSideOffset);
                positionList.Add(current.GetWorldPosition() + (BoardManager.SideToVector3Offset(Side.Right) * 0.5f) + currentSideOffset);
            }
            else
            {
                for (int i = 0; i < _selectedInfoList.Count - 1; ++i)
                {
                    current = _selectedInfoList[i];
                    next    = _selectedInfoList[i + 1];

                    currentSideOffset = BoardManager.SideToOffset(current._side).ToVector3() * 0.1f;
                    nextSideOffset    = BoardManager.SideToOffset(next._side).ToVector3() * 0.1f;

                    closestEdge = NodeSideInfo.GetClosestEdge(current, next);
                    positionList.Add(current.GetWorldPosition() + currentSideOffset);
                    positionList.Add(closestEdge + nextSideOffset);
                }
                current           = _selectedInfoList[_selectedInfoList.Count - 1];
                currentSideOffset = BoardManager.SideToOffset(current._side).ToVector3() * 0.1f;
                positionList.Add(current.GetWorldPosition() + currentSideOffset);
            }

            _lineRenderer.positionCount = positionList.Count;
            _lineRenderer.SetPositions(positionList.ToArray());
        }
    }
Exemplo n.º 3
0
    public static Vector3 GetClosestEdge(NodeSideInfo a, NodeSideInfo b)
    {
        Vector3 result = Vector3.zero;
        Vector3 aPos   = a.GetWorldPosition();
        Vector3 bPos   = b.GetWorldPosition();

        if (a._side == b._side)
        {
            Vector3 diffHalf = (bPos - aPos) * 0.5f;
            result = aPos + diffHalf;
        }
        else if (a._node == b._node)
        {
            result = a._node.WorldPosition +
                     BoardManager.SideToVector3Offset(a._side) +
                     BoardManager.SideToVector3Offset(b._side);
        }
        else
        {
            Vector3 diff = (bPos - aPos);
            result = a._node.WorldPosition + diff;
        }

        return(result);
    }
Exemplo n.º 4
0
    public NodeSideInfo GetClosesetNodeSideInfo(NodeSideInfo info, Node target)
    {
        if (info._node == target)
        {
            return(null);
        }

        int deltaX = target.X - info._node.X;
        int deltaY = target.Y - info._node.Y;
        int deltaZ = target.Z - info._node.Z;

        if (deltaX >= 2 || deltaY >= 2 || deltaZ >= 2)
        {
            return(null);
        }

        int   closest         = 0;
        float closestDistance = 999.0f;

        for (int i = 0; i < (int)Side.Count; ++i)
        {
            Vector3 targetSidePosition = target.GetWorldPositionBySide((Side)i);
            float   distance           = Vector3.Distance(targetSidePosition, info.GetWorldPosition());
            if (distance < closestDistance)
            {
                closestDistance = distance;
                closest         = i;
            }
        }

        return(_nodeSideInfos[Index3D(target.X, target.Y, target.Z), closest]);
    }
Exemplo n.º 5
0
 //레벨을 위함이 아니다...
 public GameObject CreateObjectAtNode(NodeSideInfo info, GameObject prefab, Vector3 offset, Quaternion rotation)
 {
     if (!Object.ReferenceEquals(info, null))
     {
         //오브젝트를 설치하고 노드의 속성을 업데이트 한다.
         GameObject go = Instantiate(prefab, info.GetWorldPosition() + offset, rotation);
         return(go);
     }
     return(null);
 }
Exemplo n.º 6
0
    public void SetSittingNode(int x, int y, int z, Side side)
    {
        if (!Object.ReferenceEquals(_sittingNodeInfo, null))
        {
            _sittingNodeInfo.SittingObject = null;
        }
        _sittingNodeInfo = BoardManager.Instance.CurrentBoard.GetNodeInfoAt(x, y, z, side);
        _sittingNodeInfo.SittingObject = gameObject;

        transform.position = _sittingNodeInfo.GetWorldPosition();
        OnMovementDone(_sittingNodeInfo);
    }
Exemplo n.º 7
0
    IEnumerator FollowPath()
    {
        NodeSideInfo currentNodeInfo = _path[0];

        if (_path.Length == 1)
        {
            BoardMoveBase toUseMovement = null;
            currentNodeInfo = _path[_targetIndex];
            if (_sittingNodeInfo._side != currentNodeInfo._side)
            {
                toUseMovement = _availableMovements[1];
            }
            else
            {
                toUseMovement = _availableMovements[0];
            }
            toUseMovement.MoveTo(currentNodeInfo);
        }
        else
        {
            while (true)
            {
                if (transform.position == _sittingNodeInfo.GetWorldPosition())
                {
                    BoardMoveBase toUseMovement = null;

                    currentNodeInfo = _path[_targetIndex];
                    if (_sittingNodeInfo._side != currentNodeInfo._side)
                    {
                        toUseMovement = _availableMovements[1];
                    }
                    else
                    {
                        toUseMovement = _availableMovements[0];
                    }
                    toUseMovement.MoveTo(currentNodeInfo);

                    _targetIndex++;
                    if (_targetIndex >= _path.Length)
                    {
                        _targetIndex = 0;
                        yield break;
                    }
                }
                yield return(null);
            }
        }

        _followingDone = true;
    }
Exemplo n.º 8
0
        public static Mesh BuildQuadsFromNodeInfoList(List <NodeSideInfo> list, Vector2[,] inputUV, float lineWidth)
        {
            Mesh mesh = new Mesh();

            mesh.name = "ListMesh";

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector2> uvs       = new List <Vector2>();
            List <Vector3> normals   = new List <Vector3>();
            List <int>     triangles = new List <int>();

            Vector3[] localVertices = new Vector3[4];
            Vector3[] localNormals  = new Vector3[4];
            Vector2[] localUVs      = new Vector2[4];

            int[] localTriangles = new int[6];

            List <Vector3> vertexList = new List <Vector3>();
            List <Side>    sideList   = new List <Side>();

            for (int i = 0; i < list.Count - 1; ++i)
            {
                NodeSideInfo current = list[i];
                NodeSideInfo next    = list[i + 1];

                Vector3 closestEdge = NodeSideInfo.GetClosestEdge(current, next);

                vertexList.Add(current.GetWorldPosition());
                vertexList.Add(closestEdge);
                vertexList.Add(next.GetWorldPosition());

                sideList.Add(current._side);
                sideList.Add(next._side);
            }


            int quadIndexCount = 0;

            int sideIndex = 0;

            for (int i = 0; i < vertexList.Count; i += 3)
            {
                Vector3 min    = vertexList[i + 0];
                Vector3 middle = vertexList[i + 1];
                Vector3 max    = vertexList[i + 2];

                Side minSide = sideList[sideIndex];
                Side maxSide = sideList[sideIndex + 1];

                //if (minSide == maxSide)
                {
                    BuildLineQuadData(min, middle,
                                      minSide,
                                      lineWidth, quadIndexCount++,
                                      ref localVertices, ref localNormals, ref localTriangles);
                    vertices.AddRange(localVertices);
                    normals.AddRange(localNormals);
                    triangles.AddRange(localTriangles);

                    BuildLineQuadData(middle, max,
                                      maxSide,
                                      lineWidth, quadIndexCount++,
                                      ref localVertices, ref localNormals, ref localTriangles);
                    vertices.AddRange(localVertices);
                    normals.AddRange(localNormals);
                    triangles.AddRange(localTriangles);
                }
                //else
                //{
                //    BuildCornerLineQuadData(
                //        min, middle,
                //        minSide, maxSide,
                //        lineWidth, quadIndexCount++,
                //        ref localVertices, ref localNormals, ref localTriangles);

                //    vertices.AddRange(localVertices);
                //    normals.AddRange(localNormals);
                //    triangles.AddRange(localTriangles);

                //    BuildCornerLineQuadData(
                //        middle, max,
                //        minSide, maxSide,
                //        lineWidth, quadIndexCount++,
                //        ref localVertices, ref localNormals, ref localTriangles);

                //    vertices.AddRange(localVertices);
                //    normals.AddRange(localNormals);
                //    triangles.AddRange(localTriangles);
                //}

                sideIndex += 2;
            }

            mesh.vertices  = vertices.ToArray();
            mesh.normals   = normals.ToArray();
            mesh.triangles = triangles.ToArray();
            mesh.uv        = uvs.ToArray();

            mesh.RecalculateNormals();
            mesh.RecalculateBounds();

            return(mesh);
        }
Exemplo n.º 9
0
        public void InstallObjectAtNode(NodeSideInfo info, int prefabIndex, Vector3 offset, Quaternion rotation)
        {
            if (prefabIndex > _installPrefabList.Count)
            {
                return;
            }

            if (!Object.ReferenceEquals(info, null))
            {
                if (info.InstalledObject != null)
                {
                    //설치하려는 자리에 이미 노드가 있다.... 어떻게 처리 할까??
                }
                else
                {
                    //오브젝트를 설치하고 노드의 속성을 업데이트 한다.
                    GameObject  go          = Instantiate(_installPrefabList[prefabIndex], info.GetWorldPosition() + offset, rotation);
                    LevelObject levelObject = go.GetComponent <LevelObject>();
                    levelObject.Offset       = offset;
                    levelObject.Rotation     = rotation;
                    levelObject._prefabIndex = prefabIndex;
                    info.InstalledObject     = go;
                }
            }
        }
Exemplo n.º 10
0
    public List <NodeSideInfo> GetReachables(NodeSideInfo info)
    {
        List <NodeSideInfo> result = new List <NodeSideInfo>();
        Node node = info._node;

        int minusX = 0;
        int plusX  = 0;
        int minusY = 0;
        int plusY  = 0;
        int minusZ = 0;
        int plusZ  = 0;

        int localUp = 0;

        switch (info._side)
        {
        case Side.Back:
        case Side.Front:
        {
            minusX = -1;
            plusX  = 1;
            minusY = -1;
            plusY  = 1;

            localUp = (info._side == Side.Back) ? -1 : 1;
        }
        break;

        case Side.Left:
        case Side.Right:
        {
            minusY  = -1;
            plusY   = 1;
            minusZ  = -1;
            plusZ   = 1;
            localUp = (info._side == Side.Left) ? -1 : 1;
        }
        break;

        case Side.Top:
        case Side.Bottom:
        {
            minusX  = -1;
            plusX   = 1;
            minusZ  = -1;
            plusZ   = 1;
            localUp = (info._side == Side.Bottom) ? -1 : 1;
        }
        break;
        }

        int minX = node.X + minusX;
        int maxX = node.X + plusX;
        int minY = node.Y + minusY;
        int maxY = node.Y + plusY;
        int minZ = node.Z + minusZ;
        int maxZ = node.Z + plusZ;

        Bounds upBound = new Bounds(
            info.GetWorldPosition() + BoardManager.SideToVector3Offset(info._side),
            new Vector3(BoardManager.Instance.NodeRadius * 2.1f,
                        BoardManager.Instance.NodeRadius * 2.1f,
                        BoardManager.Instance.NodeRadius * 2.1f));

        switch (info._side)
        {
        case Side.Back:
        case Side.Front:
        {
            for (int y = minY; y <= maxY; ++y)
            {
                for (int x = minX; x <= maxX; ++x)
                {
                    if (x == minX && y == minY ||
                        x == maxX && y == minY ||
                        x == minX && y == maxY ||
                        x == maxX && y == maxY)
                    {
                        continue;
                    }
                    bool topExist = false;

                    int diffX = x - node.X;
                    int diffY = y - node.Y;
                    int diffZ = 0;

                    if (IsInBound(x, y, node.Z + localUp))
                    {
                        Node         currentNode = Nodes[Index3D(x, y, node.Z + localUp)];
                        NodeSideInfo closest     = GetClosesetNodeSideInfo(info, currentNode);
                        if (currentNode.IsSolid)
                        {
                            topExist = true;
                            if (upBound.Contains(currentNode.GetWorldPositionBySide(closest._side)))
                            {
                                result.Add(closest);
                            }
                        }
                    }

                    if (topExist)
                    {
                        continue;
                    }

                    if (IsInBound(x, y, node.Z))
                    {
                        Node currentNode = Nodes[Index3D(x, y, node.Z)];
                        if (currentNode.IsSolid)
                        {
                            result.Add(GetNodeInfoAt(currentNode.X, currentNode.Y, currentNode.Z, info._side));
                        }
                        else
                        {
                            result.Add(GetNodeInfoAt(node.X, node.Y, node.Z,
                                                     BoardManager.NormalToSide(new Vector3(diffX, diffY, diffZ))));
                        }
                    }
                }
            }
        }
        break;

        case Side.Left:
        case Side.Right:
        {
            for (int y = minY; y <= maxY; ++y)
            {
                for (int z = minZ; z <= maxZ; ++z)
                {
                    if (y == minY && z == minZ ||
                        y == maxY && z == minZ ||
                        y == minY && z == maxZ ||
                        y == maxY && z == maxZ)
                    {
                        continue;
                    }
                    bool topExist = false;

                    int diffX = 0;
                    int diffY = y - node.Y;
                    int diffZ = z - node.Z;

                    if (IsInBound(node.X + localUp, y, z))
                    {
                        Node         currentNode = Nodes[Index3D(node.X + localUp, y, z)];
                        NodeSideInfo closest     = GetClosesetNodeSideInfo(info, currentNode);
                        if (currentNode.IsSolid)
                        {
                            topExist = true;
                            if (upBound.Contains(currentNode.GetWorldPositionBySide(closest._side)))
                            {
                                result.Add(closest);
                            }
                        }
                    }

                    if (topExist)
                    {
                        continue;
                    }

                    if (IsInBound(node.X, y, z))
                    {
                        Node currentNode = Nodes[Index3D(node.X, y, z)];
                        if (currentNode.IsSolid)
                        {
                            result.Add(GetNodeInfoAt(currentNode.X, currentNode.Y, currentNode.Z, info._side));
                        }
                        else
                        {
                            result.Add(GetNodeInfoAt(node.X, node.Y, node.Z,
                                                     BoardManager.NormalToSide(new Vector3(diffX, diffY, diffZ))));
                        }
                    }
                }
            }
        }
        break;

        case Side.Top:
        case Side.Bottom:
        {
            for (int z = minZ; z <= maxZ; ++z)
            {
                for (int x = minX; x <= maxX; ++x)
                {
                    if (x == minX && z == minZ ||
                        x == maxX && z == minZ ||
                        x == minX && z == maxZ ||
                        x == maxX && z == maxZ)
                    {
                        continue;
                    }
                    bool topExist = false;

                    int diffX = x - node.X;
                    int diffY = 0;
                    int diffZ = z - node.Z;

                    if (IsInBound(x, node.Y + 1, z))
                    {
                        Node         currentNode = Nodes[Index3D(x, node.Y + 1, z)];
                        NodeSideInfo closest     = GetClosesetNodeSideInfo(info, currentNode);
                        if (currentNode.IsSolid)
                        {
                            topExist = true;
                            if (upBound.Contains(currentNode.GetWorldPositionBySide(closest._side)))
                            {
                                result.Add(closest);
                            }
                        }
                    }

                    if (topExist)
                    {
                        continue;
                    }

                    if (IsInBound(x, node.Y, z))
                    {
                        Node currentNode = Nodes[Index3D(x, node.Y, z)];
                        if (currentNode.IsSolid)
                        {
                            result.Add(GetNodeInfoAt(currentNode.X, currentNode.Y, currentNode.Z, info._side));
                        }
                        else
                        {
                            result.Add(GetNodeInfoAt(node.X, node.Y, node.Z,
                                                     BoardManager.NormalToSide(new Vector3(diffX, diffY, diffZ))));
                        }
                    }
                }
            }
        }
        break;
        }
        return(result);
    }