-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7da2e79
commit 766e0b9
Showing
12 changed files
with
349 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
using System.IO; | ||
using Unity.Netcode; | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
using UnityEngine.UI; | ||
using UnityExtensionMethods; | ||
|
||
namespace Cgs.CardGameView.Multiplayer | ||
{ | ||
public class Board : CgsNetPlayable | ||
{ | ||
public string GameBoardId | ||
{ | ||
get => IsOnline ? _idNetworkVariable.Value : _gameBoardId; | ||
set | ||
{ | ||
_gameBoardId = value; | ||
if (IsOnline) | ||
_idNetworkVariable.Value = value; | ||
} | ||
} | ||
|
||
private string _gameBoardId = string.Empty; | ||
private readonly NetworkVariable<CgsNetString> _idNetworkVariable = new(); | ||
|
||
public Vector2 Size | ||
{ | ||
get => IsOnline ? _sizeNetworkVariable.Value : _size; | ||
set | ||
{ | ||
_size = value; | ||
if (IsOnline) | ||
_sizeNetworkVariable.Value = value; | ||
} | ||
} | ||
|
||
private Vector2 _size; | ||
private readonly NetworkVariable<Vector2> _sizeNetworkVariable = new(); | ||
|
||
protected override void OnStartPlayable() | ||
{ | ||
var rectTransform = (RectTransform) transform; | ||
|
||
rectTransform.localScale = Vector3.one; | ||
|
||
rectTransform.anchorMin = Vector2.zero; | ||
rectTransform.anchorMax = Vector2.zero; | ||
rectTransform.offsetMin = | ||
new Vector2(Position.x, Position.y) * CardGameManager.PixelsPerInch; | ||
rectTransform.offsetMax = | ||
new Vector2(Size.x, Size.y) * CardGameManager.PixelsPerInch + | ||
rectTransform.offsetMin; | ||
|
||
var boardFilepath = CardGameManager.Current.GameBoardsDirectoryPath + "/" + GameBoardId + "." + | ||
CardGameManager.Current.GameBoardImageFileType; | ||
var boardImageSprite = File.Exists(boardFilepath) | ||
? UnityFileMethods.CreateSprite(boardFilepath) | ||
: null; | ||
Debug.Log($"boardImage: {GameBoardId} {boardImageSprite != null}"); | ||
if (boardImageSprite != null) | ||
{ | ||
var image = gameObject.GetOrAddComponent<Image>(); | ||
image.sprite = boardImageSprite; | ||
} | ||
|
||
rectTransform.localScale = Vector3.one; | ||
} | ||
|
||
protected override void OnPointerEnterPlayable(PointerEventData eventData) | ||
{ | ||
// Disable preview | ||
} | ||
|
||
protected override void OnPointerExitPlayable(PointerEventData eventData) | ||
{ | ||
// Disable preview | ||
} | ||
|
||
protected override void OnPointerUpSelectPlayable(PointerEventData eventData) | ||
{ | ||
// Disable select | ||
} | ||
|
||
protected override void OnSelectPlayable(BaseEventData eventData) | ||
{ | ||
// Disable select | ||
} | ||
|
||
protected override void OnDeselectPlayable(BaseEventData eventData) | ||
{ | ||
// Disable select | ||
} | ||
|
||
protected override void OnBeginDragPlayable(PointerEventData eventData) | ||
{ | ||
// Disable drag | ||
} | ||
|
||
protected override void OnDragPlayable(PointerEventData eventData) | ||
{ | ||
// Disable drag | ||
} | ||
|
||
protected override void OnEndDragPlayable(PointerEventData eventData) | ||
{ | ||
// Disable drag | ||
} | ||
|
||
protected override void PostDragPlayable(PointerEventData eventData) | ||
{ | ||
// Disable drag | ||
} | ||
|
||
protected override void ActOnDrag() | ||
{ | ||
// Disable drag | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.