Beispiel #1
0
        private void Update()
        {
            Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, maxDistance, mask))
            {
                Debug.DrawRay(ray.origin, ray.direction * hit.distance, Color.red);
                if (hit.collider.gameObject.layer == boardLayer)
                {
                    selEvent.SetSelectionSquare(FigureBoardSquare(hit.point, (BoxCollider)hit.collider));
                }
                else
                {
                    PieceModel model = hit.collider.GetComponentInParent <PieceModel>();
                    if (model != null)
                    {
                        selEvent.SetSelectionPiece(model.PieceID);
                    }
                    else
                    {
                        selEvent.SetSelectionNothing();
                    }
                }
            }
            else
            {
                Debug.DrawRay(ray.origin, ray.direction * maxDistance, Color.cyan);
                selEvent.SetSelectionNothing();
            }
        }
        private void CreateModelForPiece(int id)
        {
            Piece          piece      = board.Pieces[id];
            PiecePrototype behavior   = db.PiecePrototypes[piece.PrototypeID];
            int            modelIndex = 0;

            if (piece.OwnerPlayer == PlayerTurnOrder.First)
            {
                modelIndex = behavior.FirstModelIndex;
            }
            else if (piece.OwnerPlayer == PlayerTurnOrder.Second)
            {
                modelIndex = behavior.SecondModelIndex;
            }
            if (modelIndex > db.ModelPrefabs.Count)
            {
                modelIndex = 0;
            }
            GameObject gobj = (GameObject)Instantiate(db.ModelPrefabs[modelIndex]);

            gobj.layer = pieceLayer;
            foreach (var child in gobj.GetComponentsInChildren <Transform>())
            {
                child.gameObject.layer = pieceLayer;
            }
            PieceModel model = gobj.AddComponent <PieceModel>();

            model.PieceID           = id;
            gobj.transform.position = PiecePositionHelper.FigureCenter(db, piece.BoardPosition);
            gobj.transform.rotation = Quaternion.Euler(0, piece.OwnerPlayer == PlayerTurnOrder.Second ? 180 : 0, 0);
            modelGObjs[id]          = model;
        }
        private void DoPromotion(int piece)
        {
            PieceModel oldModel = GetModelObject(piece);

            GameObject.Destroy(oldModel.gameObject);
            CreateModelForPiece(piece);
        }
        private void OnPieceMove(int pieceIndex)
        {
            PieceModel model = models.GetModelObject(pieceIndex);
            Piece      data  = board.Pieces[pieceIndex];

            model.transform.position = PiecePositionHelper.FigureCenter(db, data.BoardPosition);
        }
        private void OnPieceCapture(int pieceIndex)
        {
            PieceModel model = models.GetModelObject(pieceIndex);

            GameObject.Destroy(model.gameObject);
        }