Commit aacb5038 authored by 18류지석's avatar 18류지석

생명석 완성. 플레이어와의 상호작용은 함수만 구현함.

parent b62bd7d5
......@@ -22,7 +22,7 @@ GameObject:
- component: {fileID: 50720349360822072}
- component: {fileID: 61973677923814376}
- component: {fileID: 114071444104977984}
m_Layer: 0
m_Layer: 13
m_Name: DroppedLifeUnitPrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -105,3 +105,6 @@ MonoBehaviour:
unitSprite: {fileID: 1440159976580912, guid: 672b38cc92ccf35439b6137b951daf15, type: 2}
highlightSprite: {fileID: 1638220072418960, guid: e279edc92751d234782d0cc881edfe87,
type: 2}
playerLayer:
serializedVersion: 2
m_Bits: 0
......@@ -20,7 +20,7 @@ GameObject:
m_Component:
- component: {fileID: 4652270508485928}
- component: {fileID: 212024161364399972}
m_Layer: 14
m_Layer: 0
m_Name: LifeUnitHighlight
m_TagString: Untagged
m_Icon: {fileID: 0}
......
......@@ -20,7 +20,7 @@ GameObject:
m_Component:
- component: {fileID: 4153958457646730}
- component: {fileID: 212455254602000724}
m_Layer: 13
m_Layer: 0
m_Name: LifeUnitSprite
m_TagString: Untagged
m_Icon: {fileID: 0}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
fileFormatVersion: 2
guid: 2cda990e2423bbf4892e6590ba056729
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,10 +2,12 @@
using System.Collections.Generic;
using UnityEngine;
public class DroppedLifeStone : MonoBehaviour {
public class DroppedLifeStone : MonoBehaviour
{
LifeStoneInfo info;
public Sprite[] sprites;
public GameObject unitSprite, highlightSprite;
public LayerMask playerLayer;
float unitSize;
Rigidbody2D rb2D;
BoxCollider2D bc2D;
......@@ -32,9 +34,10 @@ public class DroppedLifeStone : MonoBehaviour {
transform.position = pos - new Vector3(inSize.x * unitSize, 0, 0);
for(int i=0; i<inSize.x * inSize.y; i++)
for (int i = 0; i < inSize.x * inSize.y; i++)
{
if (inFill[i] != ' ')
{
if (inFill[i] != ' ') {
unitObj[i] = Instantiate(unitSprite, transform);
unitObj[i].transform.localPosition = new Vector3((i % inSize.x) * unitSize, ((int)(i / inSize.x)) * unitSize, 0);
unitObj[i].GetComponent<SpriteRenderer>().sprite = sprites[inFill[i] - 'A'];
......@@ -47,5 +50,19 @@ public class DroppedLifeStone : MonoBehaviour {
bc2D.offset = new Vector2(unitSize * inSize.x / 2f, unitSize * inSize.y / 2f);
bc2D.size = new Vector2(unitSize * inSize.x, unitSize * inSize.y);
}
public void ApplyLifeStone()
{
GameObject.Find("LifeStoneUI").GetComponent<LifeStoneManager>().PushLifeStone(info);
Destroy(gameObject);
}
public void HighlightSwitch(bool enabled)
{
Vector2Int inSize = info.getSize();
string inFill = info.getFill();
for (int i = 0; i < inSize.x * inSize.y; i++)
{
if (inFill[i] != ' ')
highObj[i].GetComponent<SpriteRenderer>().enabled = enabled;
}
}
}
\ No newline at end of file
......@@ -28,35 +28,82 @@ public class LifeStoneFrame : MonoBehaviour {
/// The sprites
/// </summary>
Sprite[] sprites;
float frameBorder;
public LifeStoneFrame(Transform superGO, GameObject standardImage, int lifeStoneRow, float lifeStoneSize, Sprite[] _sprites)
public void Init(Transform superGO, GameObject standardImage, int lifeStoneRow, float lifeStoneSize, Sprite[] _sprites, float _frameBorder)
{
frameBorder = _frameBorder;
sprites = new Sprite[_sprites.GetLength(0)];
_sprites.CopyTo(sprites, 0);
this.lifeStoneRow = lifeStoneRow;
this.lifeStoneSize = lifeStoneSize;
frameTop = Instantiate(standardImage, superGO);
frameTop.name = "FrameTop";
frameTop.GetComponent<Image>().sprite = sprites[2];
frameTop.GetComponent<RectTransform>().sizeDelta = new Vector2(lifeStoneSize * (3f + frameBorder * 2), lifeStoneSize * frameBorder);
frameTop.transform.localPosition = new Vector3(0, lifeStoneSize * (frameBorder + lifeStoneRow));
frameRows = new GameObject[50];
for (int i = 49; i >= lifeStoneRow; i--)
{
frameRows[i] = Instantiate(standardImage, superGO);
frameRows[i].name = "FrameRow" + i.ToString("D2");
frameRows[i].GetComponent<Image>().color = new Color(255, 255, 255, 0);
frameRows[i].GetComponent<Image>().sprite = sprites[1];
frameRows[i].GetComponent<RectTransform>().sizeDelta = new Vector2(lifeStoneSize * (3f + frameBorder * 2), lifeStoneSize);
frameRows[i].transform.localPosition = new Vector3(0, lifeStoneSize * (frameBorder + lifeStoneRow - 1));
}
for(int i=lifeStoneRow - 1; i>=0; i--)
{
frameRows[i] = Instantiate(standardImage, superGO);
frameRows[i].name = "FrameRow" + i.ToString("D2");
frameRows[i].GetComponent<Image>().sprite = sprites[1];
frameRows[i].GetComponent<RectTransform>().sizeDelta = new Vector2(lifeStoneSize * (3f + frameBorder * 2), lifeStoneSize);
frameRows[i].transform.localPosition = new Vector3(0, lifeStoneSize * (frameBorder + i));
}
frameBottom = Instantiate(standardImage,superGO);
frameBottom.name = "FrameBottom";
frameBottom.GetComponent<Image>().sprite = sprites[0];
frameBottom.GetComponent<RectTransform>().sizeDelta = new Vector2(lifeStoneSize * 3.4f, lifeStoneSize * 0.2f);
frameBottom.GetComponent<RectTransform>().sizeDelta = new Vector2(lifeStoneSize * (3f + frameBorder * 2), lifeStoneSize * frameBorder);
frameBottom.transform.localPosition = new Vector3(0, 0);
frameRows = new GameObject[50];
for(int i=0; i<lifeStoneRow; i++)
}
public void AddRow(int afterRow)
{
frameRows[i] = Instantiate(standardImage, superGO);
frameRows[i].name = "FrameRow" + i.ToString("D2");
frameRows[i].GetComponent<Image>().sprite = sprites[1];
frameRows[i].GetComponent<RectTransform>().sizeDelta = new Vector2(lifeStoneSize * 3.4f, lifeStoneSize);
frameRows[i].transform.localPosition = new Vector3(0, lifeStoneSize * (0.2f + i));
int prevLifeStoneRow = lifeStoneRow;
lifeStoneRow = afterRow;
StartCoroutine(ExpandEnumerator(prevLifeStoneRow, lifeStoneRow));
}
IEnumerator ExpandEnumerator(int prev, int after)
{
float d = 0;
float v = 0;
float a = lifeStoneSize * 0.02f;
while (true)
{
d += v;
v += a;
if(d >= lifeStoneSize * (after - prev))
{
d = lifeStoneSize * (after - prev);
a = 0;
}
frameTop.transform.localPosition = new Vector3(0, lifeStoneSize * (frameBorder + prev) + d);
for (int i=prev; i< after; i++)
{
if(d > (after - i - 1) * lifeStoneSize)
{
frameRows[i].GetComponent<Image>().color = new Color(255, 255, 255, 1);
frameRows[i].transform.localPosition = new Vector3(0, lifeStoneSize * (frameBorder + i - after + prev) + d);
}
}
if (a == 0) break;
yield return null;
}
StartCoroutine(GameObject.Find("LifeStoneUI").GetComponent<LifeStoneManager>().VibrateEnumerator(30));
frameTop = Instantiate(standardImage, superGO);
frameTop.name = "FrameTop";
frameTop.GetComponent<Image>().sprite = sprites[2];
frameTop.GetComponent<RectTransform>().sizeDelta = new Vector2(lifeStoneSize * 3.4f, lifeStoneSize * 0.2f);
frameTop.transform.localPosition = new Vector3(0, lifeStoneSize * (0.2f + lifeStoneRow));
}
}
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
public class LifeStoneInfo : MonoBehaviour {
public class LifeStoneInfo {
/// <summary>
/// width, height of LifeStone
/// ex) □
......
......@@ -52,13 +52,14 @@ public class LifeStoneManager : MonoBehaviour {
/// Array of lifestone GameObject
/// </summary>
[HideInInspector]public GameObject[,] lifeStoneUnit;
[HideInInspector]public LifeStoneFrame lifeStoneFrame;
public GameObject droppedLifeStonePrefab;
public float frameBorder;
void Start () {
transform.position = new Vector3(lifeStoneLocation.x, lifeStoneLocation.y, 0);
lifeStoneFrame = new LifeStoneFrame(frameSuper.transform, standardImage, lifeStoneRowNum, lifeStoneSize, sprites);
frameSuper.GetComponent<LifeStoneFrame>().Init(frameSuper.transform, standardImage, lifeStoneRowNum, lifeStoneSize, sprites, frameBorder);
lifeStoneArray = new int[50, 3];
lifeStoneUnit = new GameObject[50, 3];
for (int i = 0; i < 50; i++) for (int j = 0; j < 3; j++) lifeStoneArray[i, j] = 0;
......@@ -66,15 +67,31 @@ public class LifeStoneManager : MonoBehaviour {
}
IEnumerator TestEnumerator()
{
PushLifeStone(CreateLifeStoneInfo(5, 0.2f, 3));
yield return null;
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 1), "AAA"));
yield return new WaitForSeconds(2);
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 2), "AAAA A"));
yield return new WaitForSeconds(2);
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 2), "AAAA A"));
yield return new WaitForSeconds(2);
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 2), "AAAA A"));
yield return new WaitForSeconds(2);
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 2), "AAAA A"));
yield return new WaitForSeconds(2);
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 2), "AAAA A"));
yield return new WaitForSeconds(2);
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 2), "AAAA A"));
yield return new WaitForSeconds(2);
/*PushLifeStone(CreateLifeStoneInfo(5, 0.2f, 3));
yield return new WaitForSeconds(2);
PushLifeStone(CreateLifeStoneInfo(3, 0.2f, 0));
yield return new WaitForSeconds(2);
PushLifeStone(CreateLifeStoneInfo(4, 0.2f, 0));
yield return new WaitForSeconds(2);
InstantiateDroppedLifeStone(CreateLifeStoneInfo(4, 0.1f, 0), GameObject.Find("Player").transform.position + new Vector3(2,2,0));
/*PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 8), "AAAAAAAAAAAAAAAAAAAAAAAA"));
yield return new WaitForSeconds(2);
ExpandRow(4);
PushLifeStone(new LifeStoneInfo(new Vector2Int(3, 8), "AAAAAAAAAAAAAAAAAAAAAAAA"));
PushLifeStone(new LifeStoneInfo(new Vector2Int(2, 5), " AAAABA A "));
yield return new WaitForSeconds(2);
PushLifeStone(new LifeStoneInfo(new Vector2Int(2, 3), " AAA A"));
......@@ -84,6 +101,12 @@ public class LifeStoneManager : MonoBehaviour {
ChangeToNormal(2, 3);
yield return new WaitForSeconds(2);
DestroyStone(3);*/
}
public void ExpandRow(int rowNum)
{
lifeStoneRowNum += rowNum;
frameSuper.GetComponent<LifeStoneFrame>().AddRow(lifeStoneRowNum);
}
public void InstantiateDroppedLifeStone(LifeStoneInfo info, Vector3 pos)
{
......@@ -94,8 +117,8 @@ public class LifeStoneManager : MonoBehaviour {
{
System.Random rnd = new System.Random();
num = Mathf.Max(1, num);
size.y = Mathf.Min(3, size.y);
if (num >= size.x * size.y)
size.x = Mathf.Min(3, size.x);
if (num > size.x * size.y)
return CreateLifeStoneInfo(size, goldPer, ameNum);
int[,] tmpArray = new int[size.y, size.x] ;
......@@ -174,14 +197,35 @@ public class LifeStoneManager : MonoBehaviour {
}
public LifeStoneInfo CreateLifeStoneInfo(LifeStoneInfo lifeStoneInfo)
{
return lifeStoneInfo;
Vector2Int size = lifeStoneInfo.getSize();
Vector2Int newSize;
string fill = lifeStoneInfo.getFill();
string newFill = "";
Vector2Int maxPoint = new Vector2Int(-1, -1);
Vector2Int minPoint = new Vector2Int(size.x + 1, size.y + 1);
for (int j = 0; j < size.y; j++)
for (int i = 0; i < size.x; i++)
if (fill[j * size.x + i] != ' ')
{
maxPoint.x = Mathf.Max(i, maxPoint.x);
maxPoint.y = Mathf.Max(j, maxPoint.y);
minPoint.x = Mathf.Min(i, minPoint.x);
minPoint.y = Mathf.Min(j, minPoint.y);
}
newSize = maxPoint - minPoint + Vector2Int.one;
for(int j = minPoint.y; j <= maxPoint.y; j++)
newFill += fill.Substring(j * size.x + minPoint.x, newSize.x);
return new LifeStoneInfo(newSize, newFill);
}
/// <summary>
/// push LifeStone in LifeStoneFrame
/// </summary>
/// <param name="pushInfo"></param>
void PushLifeStone(LifeStoneInfo pushInfo)
public void PushLifeStone(LifeStoneInfo pushInfo)
{
System.Random rnd = new System.Random();
Vector2Int pSize = pushInfo.getSize();
......@@ -219,9 +263,15 @@ public class LifeStoneManager : MonoBehaviour {
selectedCol = (int)selColCand[rnd.Next(selColCand.Count)];
float vibration = pushInfo.getAmount() * vibrationVariable * lifeStoneSize;
int cutRow = pSize.y;
for (int pj = 0; pj < pSize.y; pj++)
{
if (selectedRow + pj >= lifeStoneRowNum) break;
if (selectedRow + pj >= lifeStoneRowNum)
{
cutRow = pj;
break;
}
for (int pi = 0; pi < pSize.x; pi++)
if (pFill[pj * pSize.x + pi] != ' ')
{
......@@ -234,12 +284,41 @@ public class LifeStoneManager : MonoBehaviour {
lifeStoneSize,
new Vector2Int(xtmp, ytmp),
new Vector2Int(xtmp, lifeStoneRowNum + pj),
new Vector2(0.2f * lifeStoneSize, 0.2f * lifeStoneSize),
new Vector2(frameBorder * lifeStoneSize, frameBorder * lifeStoneSize),
vibration);
vibration = 0;
}
}
if (cutRow < pSize.y)
{
char[] chFill = pFill.ToCharArray();
for (int i = 0; i < pSize.x; i++)
{
Queue<Vector2Int> queue = new Queue<Vector2Int>();
char[] newFill = new char[pSize.x * (pSize.y - cutRow)];
for (int t = 0; t < pSize.x * (pSize.y - cutRow); t++) newFill[t] = ' ';
if (chFill[cutRow * pSize.x + i] != ' ')
{
queue.Enqueue(new Vector2Int(i, cutRow));
while (queue.Count > 0)
{
Vector2Int vtmp = queue.Dequeue();
newFill[(vtmp.y - cutRow) * pSize.x + vtmp.x] = chFill[vtmp.y * pSize.x + vtmp.x];
chFill[vtmp.y * pSize.x + vtmp.x] = ' ';
if (vtmp.x + 1 < pSize.x && chFill[ vtmp.y * pSize.x + (vtmp.x + 1)] != ' ') queue.Enqueue(new Vector2Int(vtmp.x + 1, vtmp.y ));
if (vtmp.x - 1 >= 0 && chFill[ vtmp.y * pSize.x + (vtmp.x - 1)] != ' ') queue.Enqueue(new Vector2Int(vtmp.x - 1, vtmp.y ));
if (vtmp.y + 1 < pSize.y && chFill[(vtmp.y + 1) * pSize.x + vtmp.x ] != ' ') queue.Enqueue(new Vector2Int(vtmp.x , vtmp.y + 1));
if (vtmp.y - 1 >= cutRow && chFill[(vtmp.y - 1) * pSize.x + vtmp.x ] != ' ') queue.Enqueue(new Vector2Int(vtmp.x , vtmp.y - 1));
}
InstantiateDroppedLifeStone(CreateLifeStoneInfo(
new LifeStoneInfo(new Vector2Int(pSize.x, pSize.y - cutRow), new string(newFill))),
GameObject.Find("Player").transform.position + new Vector3(droppedLifeStonePrefab.GetComponent<DroppedLifeStone>().unitSprite.GetComponent<SpriteRenderer>().bounds.size.x * i,0,0));
}
}
}
}
public int CountType(int type)
{
......@@ -286,7 +365,7 @@ public class LifeStoneManager : MonoBehaviour {
Vector2Int vtmp = (Vector2Int)candArray[i];
lifeStoneUnit[vtmp.y, vtmp.x].GetComponent<LifeUnitInFrame>().unitDestroy();
lifeStoneUnit[vtmp.y, vtmp.x] = null;
yield return new WaitForSeconds(0.1f);
yield return new WaitForSeconds(0.02f);
}
}
......@@ -339,7 +418,7 @@ public class LifeStoneManager : MonoBehaviour {
}
}
public IEnumerator vibrateEnumerator(float vibration)
public IEnumerator VibrateEnumerator(float vibration)
{
while(vibration > lifeStoneSize * 0.05f)
{
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Text;
using System;
public class LifeStoneTest : MonoBehaviour {
public GameObject numText, ameNumText, goldPerText, goldText, amethystText, destroyText, rowText;
public GameObject ui;
LifeStoneManager uii;
private void Start()
{
uii = ui.GetComponent<LifeStoneManager>();
}
public void push()
{
uii.PushLifeStone(uii.CreateLifeStoneInfo(Convert.ToInt32(numText.GetComponent<InputField>().text), Convert.ToSingle(goldPerText.GetComponent<InputField>().text), Convert.ToInt32(ameNumText.GetComponent<InputField>().text)));
}
public void gold()
{
int tmp = Convert.ToInt32(goldText.GetComponent<InputField>().text);
if (tmp > 0) uii.ChangeFromNormal(2, tmp);
else if (tmp < 0) uii.ChangeToNormal(2, -tmp);
}
public void amethyst()
{
int tmp = Convert.ToInt32(amethystText.GetComponent<InputField>().text);
if (tmp > 0) uii.ChangeFromNormal(3, tmp);
else if (tmp < 0) uii.ChangeToNormal(3, -tmp);
}
public void dest()
{
uii.DestroyStone(Convert.ToInt32(destroyText.GetComponent<InputField>().text));
}
public void row()
{
uii.ExpandRow(Convert.ToInt32(rowText.GetComponent<InputField>().text));
}
}
fileFormatVersion: 2
guid: 050cdf1acdf12e9409463fdfa82ace6c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -58,7 +58,7 @@ public class LifeUnitInFrame : MonoBehaviour {
}
IEnumerator FadeInEnumerator()
{
StartCoroutine("FallEnumerator");
float alpha = 0;
float fadeTime = 0.3f;
while (alpha <= 1f)
......@@ -68,7 +68,7 @@ public class LifeUnitInFrame : MonoBehaviour {
yield return null;
}
GetComponent<Image>().color = new Color(255, 255, 255, 1f);
StartCoroutine("FallEnumerator");
}
IEnumerator FallEnumerator()
{
......@@ -85,7 +85,7 @@ public class LifeUnitInFrame : MonoBehaviour {
yield return null;
}
if (vibration != 0)
StartCoroutine(GameObject.Find("LifeStoneUI").GetComponent<LifeStoneManager>().vibrateEnumerator(vibration));
StartCoroutine(GameObject.Find("LifeStoneUI").GetComponent<LifeStoneManager>().VibrateEnumerator(vibration));
}
}
......@@ -52,4 +52,4 @@ Physics2DSettings:
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: ffdffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe9fffffffdfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
......@@ -22,7 +22,7 @@ TagManager:
- Platform
- OuterWall
- Item
- ItemHighlight
-
-
-
-
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment