Draw, Shuffle, Display DrawList, Display DiscardList, Use a card in hand.

pull/5/head
SherlockShiYL 2022-03-17 15:17:51 -07:00
parent 67923e8d57
commit 235369005d
7 changed files with 2745 additions and 43 deletions

View File

@ -0,0 +1,52 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5470971240814093006
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 497306795194634562}
- component: {fileID: 1940333407340412725}
m_Layer: 0
m_Name: Card
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &497306795194634562
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5470971240814093006}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 664.5282, y: 189.92244, z: -3.0574389}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1940333407340412725
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5470971240814093006}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eeaffccf69df3fc439ce26cfeccb72cd, type: 3}
m_Name:
m_EditorClassIdentifier:
cardData: {fileID: 0}
nameText: {fileID: 0}
costText: {fileID: 0}
attackText: {fileID: 0}
defenseText: {fileID: 0}
healthText: {fileID: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1abb286fb916b7e438ee6a04c1e0e21b
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

2324
Assets/Prefabs/UIDeck.prefab Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0890cb6eff04b7c46be2a388688fe4d6
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -123,7 +123,12 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &344141827
--- !u!224 &344141829 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
m_PrefabInstance: {fileID: 4683416251218580692}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1455724351
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -131,47 +136,165 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 344141829}
- component: {fileID: 344141828}
m_Layer: 0
m_Name: Deck
- component: {fileID: 1455724355}
- component: {fileID: 1455724354}
- component: {fileID: 1455724353}
- component: {fileID: 1455724352}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &344141828
--- !u!114 &1455724352
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 344141827}
m_GameObject: {fileID: 1455724351}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e2b93d08c3a9bb4c84596f4a7ff0c8b, type: 3}
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
cardDataList: []
drawList: []
handList: []
discardList: []
wasteList: []
randomSeed: 0
--- !u!4 &344141829
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1455724353
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1455724351}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
--- !u!223 &1455724354
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1455724351}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 25
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &1455724355
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1455724351}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 344141829}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!1 &1695983359
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1695983362}
- component: {fileID: 1695983361}
- component: {fileID: 1695983360}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1695983360
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1695983359}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &1695983361
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1695983359}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 10
--- !u!4 &1695983362
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 344141827}
m_GameObject: {fileID: 1695983359}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2076520015
GameObject:
@ -257,3 +380,120 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &4683416251218580692
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 1455724355}
m_Modifications:
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3351518597856635956, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4683416251428496599, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_Name
value: UIDeck
objectReference: {fileID: 0}
- target: {fileID: 5083260762951157943, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5277353724762008331, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5277353724762008331, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5277353724762008331, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchoredPosition.x
value: 425
objectReference: {fileID: 0}
- target: {fileID: 5277353724762008331, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}
propertyPath: m_AnchoredPosition.y
value: -75
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0890cb6eff04b7c46be2a388688fe4d6, type: 3}

View File

@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@ -9,8 +9,6 @@ public class CardDisplay : MonoBehaviour
public Text nameText;
public Image artworkImage;
public Text costText;
public Text attackText;
public Text defenseText;
@ -19,6 +17,10 @@ public class CardDisplay : MonoBehaviour
// Start is called before the first frame update
void Start()
{
}
public void SetCardData(CardData data)
{
cardData = data;
}
}

View File

@ -1,24 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Deck : MonoBehaviour
{
public List<CardData> cardDataList;
public List<CardData> drawList;
// Control Card Display
public List<GameObject> drawDisplayList;
public List<CardData> handList;
public List<CardData> discardList;
// Control Card Display
public List<GameObject> discardDisplayList;
public List<CardData> wasteList;
public int randomSeed;
public GameObject handCardTemplate;
public GameObject cardDisplayTemplate;
public GameObject drawListContent;
public GameObject discardListContent;
// Start is called before the first frame update
void Start()
{
randomSeed = 200;
Random.InitState(randomSeed);
// Add cards into cardDataList
for (int i = 0; i < cardDataList.Count; i++)
{
drawList.Add(cardDataList[i]);
GameObject tempDrawDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DrawListContent"));
tempDrawDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(cardDataList[i]);
tempDrawDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = cardDataList[i].artwork;
tempDrawDisplay.SetActive(true);
drawDisplayList.Add(tempDrawDisplay);
}
drawListContent.SetActive(false);
discardListContent.SetActive(false);
}
// Update is called once per frame
@ -31,8 +54,22 @@ public class Deck : MonoBehaviour
{
for (int i = 0; i < amount; i++)
{
handList.Add(drawList[drawList.Count - 1]);
drawList.RemoveAt(drawList.Count - 1);
if (drawList.Count == 0)
{
Shuffle();
}
if(drawList.Count==0)
{
return;
}
int randomIndex = Random.Range(0, discardList.Count);
GameObject cardObj = Instantiate(handCardTemplate.gameObject, transform.Find("Content/HandList"));
cardObj.SetActive(true);
cardObj.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(drawList[randomIndex]);
cardObj.transform.Find("Button").gameObject.GetComponent<Image>().sprite = drawList[randomIndex].artwork;
drawList.RemoveAt(randomIndex);
Destroy(drawDisplayList[randomIndex]);
drawDisplayList.RemoveAt(randomIndex);
}
}
@ -46,42 +83,75 @@ public class Deck : MonoBehaviour
//}
//else
//{
discardList.Add(handList[index]);
discardList.Add(handList[index]);
//}
handList.RemoveAt(index);
}
public void UseThisCard(GameObject card)
{
GameObject tempDiscardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DiscardListContent"));
tempDiscardDisplay.SetActive(true);
tempDiscardDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(card.transform.Find("Card").gameObject.gameObject.GetComponent<CardDisplay>().cardData);
tempDiscardDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = card.transform.Find("Card").gameObject.gameObject.GetComponent<CardDisplay>().cardData.artwork;
discardDisplayList.Add(tempDiscardDisplay);
discardList.Add(card.transform.Find("Card").gameObject.gameObject.GetComponent<CardDisplay>().cardData);
Destroy(card);
}
// When unit dead
public void AddACardIntoDiscardList(CardData card)
{
discardList.Add(card);
}
private void Shuffle()
public void Shuffle()
{
Debug.LogError("Start Shuffle.");
Debug.LogError("DrawList count: " + drawList.Count);
Debug.LogError("DiscardList count: " + discardList.Count);
// Put all cards in drawList into discardList
if (drawList.Count > 0)
for (int i = 0; i < drawList.Count; i++)
{
for (int i = 0; i < drawList.Count; i++)
{
discardList.Add(drawList[i]);
}
drawList.Clear();
discardList.Add(drawList[i]);
Destroy(drawDisplayList[i]);
}
drawDisplayList.Clear();
drawList.Clear();
do
while (discardList.Count != 0)
{
int index = Random.Range(0, discardList.Count);
drawList.Add(discardList[index]);
GameObject tempCardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DrawListContent"));
tempCardDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(discardList[index]);
tempCardDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = discardList[index].artwork;
tempCardDisplay.SetActive(true);
drawDisplayList.Add(tempCardDisplay);
discardList[index] = discardList[discardList.Count - 1];
discardList.RemoveAt(discardList.Count - 1);
} while (discardList.Count != 0);
Debug.LogError("DrawList count: " + drawList.Count);
Debug.LogError("DiscardList count: " + discardList.Count);
Debug.LogError("End Shuffle.");
};
for (int i = 0; i < discardDisplayList.Count; i++)
{
Destroy(discardDisplayList[i]);
}
}
public void ActivateDisplayDrawList()
{
drawListContent.SetActive(true);
}
public void DeactivateDisplayDrawList()
{
drawListContent.SetActive(false);
}
public void ActivateDisplayDiscardList()
{
discardListContent.SetActive(true);
}
public void DeactivateDisplayDiscardList()
{
discardListContent.SetActive(false);
}
}