using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class Gem : MonoBehaviour {

public GameObject sphere;

public GameObject selector;

public List<Gem> Near = new List<Gem>();

public string[] gemMaterials = {"Red", "Blue", "Green", "Orange", "Yellow", "Black", "Purple"} ;

public string color = "";

public bool isSelected = false;

public bool isMatched = false;

public int XCoord{

get

{

return Mathf.RoundToInt(transform.localPosition.x);

}

}

public int YCoord{

get

{

return Mathf.RoundToInt(transform.localPosition.y);

}

}

// Use this for initialization

void Start () {

CreateGem();

}

// Update is called once per frame

void Update () {

}

public void ToggleSeletor(){

isSelected = !isSelected;

selector.SetActive(isSelected);

}

public void CreateGem(){

color = gemMaterials[Random.Range(0, gemMaterials.Length - 1)];

print (gemMaterials.Length);

Material m= Resources.Load("Materials/"+color) as Material;

sphere.renderer.material = m;

print (color);

print (m);

print (sphere.renderer.material);

isMatched = false;

}

public void AddNear(Gem g)

{

if(!Near.Contains(g))

Near.Add(g);

}

public bool IsNearWith(Gem g)

{

if(Near.Contains(g))

{

return true;

}

return false;

}

public void RemoveNear(Gem g)

{

Near.Remove(g);

}

void OnMouseDown()

{

if(!GameObject.Find("Board").GetComponent<Board>().isSwapping)

{

ToggleSeletor();

GameObject.Find("Board").GetComponent<Board>().SwapGem(this);

}

}

}

////////////////////////////////////////////////////////////////////////////////////////////


using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class Board : MonoBehaviour {

public List<Gem> gems = new List<Gem>();

public int GridWidth;

public int GridHeight;

public GameObject gemPrefabs;

public Gem lastGem;

public Vector3 gem1Start,gem1End,gem2Start,gem2End;

public bool isSwapping = false;

public Gem gem1, gem2;

public float startTimer;

public float swapRate = 3f;

public int AmountToMatch = 3;

public bool isMatched = false;

// Use this for initialization

void Start () {

for(int y = 0; y < GridHeight; y++)

{

for(int x = 0; x < GridWidth; x++)

{

GameObject g = Instantiate(gemPrefabs,new Vector3(x, y, 0), Quaternion.identity) as GameObject;

g.transform.parent = gameObject.transform;

gems.Add(g.GetComponent<Gem>());

}

}

gameObject.transform.position = new Vector3(-2.5f, -2f, 0);

}

public void TogglesPhysics(bool isOn)

{

for(int i = 0; i <gems.Count; i++)

{

gems[i].rigidbody.isKinematic = isOn;

}

}

public void SwapGem(Gem currentGem){

if(lastGem == null){

lastGem = currentGem;

}

else if(lastGem == currentGem){

lastGem = null;

}

else{

if(lastGem.IsNearWith(currentGem))

{

gem1Start = lastGem.transform.position;

gem1End = currentGem.transform.position;

gem2Start = currentGem.transform.position;

gem2End = lastGem.transform.position;

startTimer = Time.time;

TogglesPhysics(true);

gem1 = lastGem;

gem2 = currentGem;

isSwapping = true;

}

else

{

lastGem.ToggleSeletor();

lastGem = currentGem;

}

}

}

// Update is called once per frame

void Update () {

if(isMatched)

{

for(int i = 0; i < gems.Count; i++)

{

if(gems[i].isMatched)

{

gems[i].CreateGem();

gems[i].transform.position= new Vector3(gems[i].transform.position.x, gems[i].transform.position.y + 6, gems[i].transform.position.z);

}

}

}

isMatched = false;

if(isSwapping){

MoveGem(gem1, gem1End, gem1Start);

MoveNegGem(gem2, gem2End, gem2Start);

if(Vector3.Distance(gem1.transform.position, gem1End) <= .1f || Vector3.Distance(gem2.transform.position, gem2End) < .1f){

gem1.transform.position = gem1End;

gem2.transform.position = gem2End;

gem1.ToggleSeletor();

gem2.ToggleSeletor();

lastGem = null;

isSwapping = false;

TogglesPhysics(true);

CheckMatch();

}

}

}

public void CheckMatch(){

List<Gem> gem1List = new List<Gem>();

List<Gem> gem2List = new List<Gem>();

ConstructMatchList(gem1.color, gem1, gem1.XCoord, gem1.YCoord, ref gem1List);

FixedMatchList(gem1, gem1List);

ConstructMatchList(gem2.color, gem2, gem1.XCoord, gem2.YCoord, ref gem2List);

FixedMatchList(gem2, gem2List);

print("gem1" + gem1List.Count);

}

public void ConstructMatchList(string color, Gem gem, int XCoord, int YCoord, ref List<Gem> MatchList){

if(gem == null)

{

return;

}

else if(gem.color != color)

{

return;

}

else if(MatchList.Contains(gem))

{

return;

}

else{

MatchList.Add(gem);

if(XCoord == gem.XCoord || YCoord == gem.YCoord)

{

foreach(Gem g in gem.Near)

{

ConstructMatchList(color, g, XCoord, YCoord, ref MatchList);

}

}

}

}

public void FixedMatchList(Gem gem, List<Gem> ListToFix){

List<Gem> rows  = new List<Gem>();

List<Gem> collumns = new List<Gem>();

for(int i = 0; i < ListToFix.Count; i++)

{

if(gem.XCoord == ListToFix[i].XCoord)

{

rows.Add(ListToFix[i]);

}

if(gem.YCoord == ListToFix[i].YCoord)

{

collumns.Add(ListToFix[i]);

}

}

if(rows.Count >= AmountToMatch)

{

isMatched = false;

for(int i = 0; i < rows.Count; i++){

rows[i].isMatched = true;

}

}

if(collumns.Count >= AmountToMatch)

{

isMatched = true;

for(int i = 0; i < collumns.Count; i++){

collumns[i].isMatched = true;

}

}

}

public void MoveGem(Gem gemToMove, Vector3 toPos, Vector3 fromPos)

{

Vector3 center = (fromPos + toPos) * .5f;

center -= new Vector3(0.0f, .1f);

Vector3 riseCenter = fromPos - center;

Vector3 setCenter = toPos - center;

float fracComplete = (Time.time - startTimer)/swapRate;

gemToMove.transform.position = Vector3.Slerp(riseCenter, setCenter, fracComplete);

gemToMove.transform.position += center;

}

public void MoveNegGem(Gem gemToMove, Vector3 toPos, Vector3 fromPos){

}

}


'Computer Language > 유니티' 카테고리의 다른 글

Hexa  (0) 2014.11.25
3인칭 시점  (0) 2014.11.13
사인과 코사인 응용 방안  (0) 2014.11.12
Dialog() 다이아로그  (0) 2014.11.10
더미와 다이어로그  (0) 2014.11.10

using UnityEngine;

using System.Collections;


public class Point{

int X;

int Y;

int Z;

public Point(int x, int y, int z){

X = x;

Y = y;

Z = z;

}

public override string ToString ()

{

return "[ "+ X + " " + Y + " " + Z + "] ";

}

}

public class Hexa : MonoBehaviour {

Point MapPos;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

}

public void SetMapPos(Point pos){

MapPos = pos;

}

public void SetMapPos(int x, int y, int z){

MapPos = new Point(x, y, z);

}

public void OnMouseDown(){

PlayerManager pm = PlayerManager.GetInstance();

Debug.Log("A" + MapPos + "OnMouseDown");

pm.MovePlayer(pm.players[pm.CurTurnIndex].CurHexa , this);

}

}



using UnityEngine;

using System.Collections;


public class MapManager : MonoBehaviour {

public static MapManager inst = null;

public GameObject Hexa_prefab;

public float HexW;

public float HexH;

public int MapSizeX;

public int MapSizeY;

public int MapSizeZ;

Hexa[][][] Map;

void Awake(){

inst = this;

SetSizeHexa();

}

public static MapManager GetInstance(){

print ("map manager" + inst);

return inst;

}

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

}

public void SetSizeHexa(){

HexW = Hexa_prefab.transform.renderer.bounds.size.x;

HexW = Hexa_prefab.transform.renderer.bounds.size.z;

}

public Vector3 GetWorldPos(int x, int y, int z){

float X = 0;

float Z = 0;

X = x * HexW + ( z * HexW * 0.5f);

Z = ( -z ) * HexH * 0.75f;

return new Vector3(X, 0, Z); 

}

public void CreateMap(){

Map = new Hexa[MapSizeX * 2 + 1][][];

for(int x = -MapSizeX; x <= MapSizeX; x++){

Map[x + MapSizeX] = new Hexa[MapSizeY * 2 + 1][];

for(int y = -MapSizeY; y <= MapSizeY; y++){

Map[x + MapSizeX][y + MapSizeY] = new Hexa[MapSizeZ * 2 + 1];

for(int z = -MapSizeZ; z <= MapSizeZ; z++){

if(x + y + z == 0){

Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ] = ((GameObject)Instantiate(Hexa_prefab)).GetComponent<Hexa>();

Vector3 pos = GetWorldPos(x, y, z);

//print (pos);

Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ].transform.position = pos;

Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ].SetMapPos(x, y, z);

}

}

}

}

}

public Hexa GetPlayerHexaPosition(int x, int y, int z){

return Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ];

}

}



using UnityEngine;

using System.Collections;


public class PlayerBase : MonoBehaviour {

public Hexa CurHexa;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

}

}


'Computer Language > 유니티' 카테고리의 다른 글

잼과 이동관련  (0) 2014.11.26
3인칭 시점  (0) 2014.11.13
사인과 코사인 응용 방안  (0) 2014.11.12
Dialog() 다이아로그  (0) 2014.11.10
더미와 다이어로그  (0) 2014.11.10

//


// 

// 2013/06/07 N.Kobyasahi

//

using UnityEngine;

using System.Collections;



public class ThirdPersonCamera : MonoBehaviour

{

public float smooth = 3f;

public Transform standardPos; // the usual position for the camera, specified by a transform in the game

Transform frontPos; // Front Camera locater

Transform jumpPos; // Jump Camera locater

bool bQuickSwitch = false; //Change Camera Position Quickly

void Start()

{

//standardPos = GameObject.Find ("CamPos").transform;

if(GameObject.Find ("FrontPos"))

frontPos = GameObject.Find ("FrontPos").transform;


if(GameObject.Find ("JumpPos"))

jumpPos = GameObject.Find ("JumpPos").transform;


//繧ォ繝。繝ゥ繧偵せ繧ソ繝シ繝医☆繧

transform.position = standardPos.position;

transform.forward = standardPos.forward;

}


void FixedUpdate ()

{

if(Input.GetButton("Fire1")) // left Ctlr

{

// Change Front Camera

setCameraPositionFrontView();

}

else if(Input.GetButton("Fire2")) //Alt

{

// Change Jump Camera

setCameraPositionJumpView();

}

else

{

// return the camera to standard position and direction

setCameraPositionNormalView();

}

}


void setCameraPositionNormalView()

{

if(bQuickSwitch == false){

// the camera to standard position and direction

transform.position = Vector3.Lerp(transform.position, standardPos.position, Time.fixedDeltaTime * smooth);

transform.forward = Vector3.Lerp(transform.forward, standardPos.forward, Time.fixedDeltaTime * smooth);

}

else{

// the camera to standard position and direction / Quick Change

transform.position = standardPos.position;

transform.forward = standardPos.forward;

bQuickSwitch = false;

}

}


void setCameraPositionFrontView()

{

// Change Front Camera

bQuickSwitch = true;

transform.position = frontPos.position;

transform.forward = frontPos.forward;

}


void setCameraPositionJumpView()

{

// Change Jump Camera

bQuickSwitch = false;

transform.position = Vector3.Lerp(transform.position, jumpPos.position, Time.fixedDeltaTime * smooth);

transform.forward = Vector3.Lerp(transform.forward, jumpPos.forward, Time.fixedDeltaTime * smooth);

}

}




'Computer Language > 유니티' 카테고리의 다른 글

잼과 이동관련  (0) 2014.11.26
Hexa  (0) 2014.11.25
사인과 코사인 응용 방안  (0) 2014.11.12
Dialog() 다이아로그  (0) 2014.11.10
더미와 다이어로그  (0) 2014.11.10

사인 코사인 속도 덜어질때, 점프 , 바운스 띄용띄용, 타격감, 허리업.

코사인 속독 올라갈때

'Computer Language > 유니티' 카테고리의 다른 글

Hexa  (0) 2014.11.25
3인칭 시점  (0) 2014.11.13
Dialog() 다이아로그  (0) 2014.11.10
더미와 다이어로그  (0) 2014.11.10
캐릭터,리그 ,애니메이터  (0) 2014.07.21

using UnityEngine;

using System.Collections;


public class Dialog : MonoBehaviour {

public delegate void OnButtonEvent();

public event OnButtonEvent eventButtonOk;

public event OnButtonEvent eventButtonCancel;

public UILabel Title, Message;

public UIPlayTween PlayDestroy;

public void OnButtonOkClick(){

PlayDestroy.Play(true);

eventButtonOk();

}

public void OnButtonCancelClick(){

PlayDestroy.Play(true);

Destroy(gameObject);

eventButtonCancel();

}

public void OnScaleDown(){

Destroy(this.gameObject);

}

public void OnScaleUp(){

}

// Use this for initialization

void Start () {

}

}


'Computer Language > 유니티' 카테고리의 다른 글

3인칭 시점  (0) 2014.11.13
사인과 코사인 응용 방안  (0) 2014.11.12
더미와 다이어로그  (0) 2014.11.10
캐릭터,리그 ,애니메이터  (0) 2014.07.21
파티클 1번과 2번 2번을 주로 애용  (0) 2014.07.21

public void OnButtonCharacterShow(){

print ("show");

DialogMgr.ShowDialog(CharacterSelectPrefab, OnCharacterSelectOk, OnCharacterSelectCancel, "Character Select", "Buy ??");

}


void OnCharacterSelectOk(){

print ("Select ok");

}

void OnCharacterSelectCancel(){

print ("Select Cancel");

}

//////////////////////////////////////////////////////////

using UnityEngine;

using System.Collections;


public class DialogMgr : MonoBehaviour{

static GameObject DialogPrefab;

static GameObject DialogParent;

static GameObject DialogPurchasePrefab;

static GameObject DialogPurchaseParent;

static string title = "Game Purchase";

static string message = "";

//static GameObject AddressDialogPrefab;

//static GameObject AddressDialogParent;

public static void ShowDialog(GameObject prefab, Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction,

string title, string message){

if(null == DialogParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

DialogParent = cam.gameObject;

}

GameObject obj = null;

if (prefab == null) {

Debug.LogError("prefab is null");

return;

}

else {

obj = NGUITools.AddChild(DialogParent, prefab);

obj.transform.position = new Vector3(0.0f, 0.0f, -1.5f);

}

Dialog dlg = obj.GetComponent<Dialog>();

dlg.Title.text = title;

dlg.Message.text = message;

dlg.eventButtonOk += okFunction;

dlg.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj, 100);

}

/*

public static void ShowAddressDialog( Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction){

if(null == AddressDialogParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

AddressDialogParent = cam.gameObject;

}

if(null == AddressDialogPrefab){

DialogPrefab = Resources.Load("Prefabs/AddressBody") as GameObject;

}

GameObject obj = NGUITools.AddChild(AddressDialogParent, AddressDialogPrefab);

Dialog dlg = obj.GetComponent<Dialog>();

//dlg.Title.text = title;

//dlg.Message.text = message;

dlg.eventButtonOk += okFunction;

dlg.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj, 100);

}

*/

public static void ShowPurchaseDialog(Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction){

if(null == DialogPurchaseParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

DialogPurchaseParent = cam.gameObject;

}

if(null == DialogPurchasePrefab){

DialogPurchasePrefab = Resources.Load("Prefabs/Player_BackGround") as GameObject;

}

GameObject obj1 = NGUITools.AddChild(DialogPurchaseParent, DialogPurchasePrefab);

Dialog dlgPurchase = obj1.GetComponent<Dialog>();

dlgPurchase.Title.text = title;

dlgPurchase.Message.text = message;

dlgPurchase.eventButtonOk += okFunction;

dlgPurchase.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj1, 300);

}

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

}

}


Dummy.prefab


https://www.mixamo.com

'Computer Language > 유니티' 카테고리의 다른 글

Dialog() 다이아로그  (0) 2014.11.10
더미와 다이어로그  (0) 2014.11.10
파티클 1번과 2번 2번을 주로 애용  (0) 2014.07.21
ITWEEN PATH탐지. 쉐이크, 좌우이동  (0) 2014.07.01
코루틴 예제  (0) 2014.07.01

using UnityEngine;

using System.Collections;


/*

 * 1

public class Player : MonoBehaviour {

public float Speed = 1;

public GameObject FirePrefab;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

float h = Input.GetAxis("Horizontal");

float v = Input.GetAxis("Vertical");

transform.Translate(Speed * new Vector3(h, 0, v));

if(Input.GetButtonUp("Fire1")){

GameObject particle = Instantiate(FirePrefab, transform.position, Quaternion.identity) as GameObject;

float duration = particle.GetComponent<ParticleSystem>().duration;

Destroy(particle, duration);

}

}

}

*/


 //2

public class Player : MonoBehaviour {

public GameObject FireParticle;

public int Speed;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

if(Input.GetKeyDown(KeyCode.Space)){

FireParticle.SetActive(true);

float duration = FireParticle.GetComponent<ParticleSystem>().duration;

Invoke("sleep" , duration);

}

}

void sleep(){

FireParticle.SetActive(false);

}

}


 

'Computer Language > 유니티' 카테고리의 다른 글

더미와 다이어로그  (0) 2014.11.10
캐릭터,리그 ,애니메이터  (0) 2014.07.21
ITWEEN PATH탐지. 쉐이크, 좌우이동  (0) 2014.07.01
코루틴 예제  (0) 2014.07.01
하스스톤 디딤돌  (0) 2014.07.01


using UnityEngine;

using System.Collections;


public class TestPath : MonoBehaviour {

public Transform[] Path;

public float duration = 0.02f;

float percent = 0;

float startTime;

// Use this for initialization

void Start () {

startTime = Time.time;

/* put on path

Vector3[] points = new Vector3[Path.Length];

for(int i = 0; i < Path.Length; i++){

points[i] = Path[i].position;

}

*/

}

// Update is called once per frame

void Update () {

//percent = Mathf.Clamp01(Time.time - startTime) / duration;

percent = (Time.time - startTime) / duration;

iTween.PutOnPath(gameObject, Path, percent % 1);

Vector3 next = iTween.PointOnPath(Path, (percent + 0.1f) % 1);

//transform.LookAt(next);

Vector3 forward = next - transform.position;

transform.rotation = Quaternion.LookRotation(forward);

}

}


TestShake.cs 흔들어 주세요..


using UnityEngine;

using System.Collections;


public class TestPath : MonoBehaviour {

public Transform[] Path;

public float duration = 0.02f;

float percent = 0;

float startTime;

// Use this for initialization

void Start () {

startTime = Time.time;

/* put on path

Vector3[] points = new Vector3[Path.Length];

for(int i = 0; i < Path.Length; i++){

points[i] = Path[i].position;

}

*/

}

// Update is called once per frame

void Update () {

//percent = Mathf.Clamp01(Time.time - startTime) / duration;

percent = (Time.time - startTime) / duration;

iTween.PutOnPath(gameObject, Path, percent % 1);

Vector3 next = iTween.PointOnPath(Path, (percent + 0.1f) % 1);

//transform.LookAt(next);

Vector3 forward = next - transform.position;

transform.rotation = Quaternion.LookRotation(forward);

}

}


TestTween.cs 좌우로 흔들고 마지막에 크게.

using UnityEngine;

using System.Collections;


public class TestTween : MonoBehaviour {

bool isForward;

void Update () {

if(Input.GetMouseButton(0)){

if(isForward){

iTween.MoveTo(gameObject, new Vector3(3, 0, 0), 1.0f);

}

else{

//1)

//iTween.MoveTo(gameObject, new Vector3(-3, 0, 0), 1.0f);

//2)

//iTween.MoveTo(gameObject, iTween.Hash("x", -3, "easyType", "easeInCirc" , "time", 1.0f));

//3)

Hashtable table = new Hashtable();

table.Add("x", -3);

table.Add("easyType", iTween.EaseType.easeInElastic);

table.Add("time", 1.0f);

table.Add ("oncompletetarget", gameObject);

table.Add("oncomplete", "OnCompleteMove");

iTween.MoveTo(gameObject, table);

}

isForward = !isForward;

}

}

void OnCompleteMove(){

iTween.PunchScale(gameObject,1.5f * Vector3.one, 0.5f);

}

}



'Computer Language > 유니티' 카테고리의 다른 글

캐릭터,리그 ,애니메이터  (0) 2014.07.21
파티클 1번과 2번 2번을 주로 애용  (0) 2014.07.21
코루틴 예제  (0) 2014.07.01
하스스톤 디딤돌  (0) 2014.07.01
SkinnedMeshRenderer  (0) 2014.06.27

.81640625using UnityEngine;

using System.Collections;


public class TestCoroutine : MonoBehaviour {

public float moveSpeed = 1;

public Vector3[] path;

// Use this for initialization

void Start () {

//StartCoroutine(MoveToPosition(new Vector3(3, 0, 0)));

StartCoroutine(MoveOnPath(true));

}

IEnumerator MoveCube1(){

transform.Translate(2, 0, 0);

yield return new WaitForSeconds(1.0f);

transform.Translate(0, 2, 0);

yield return new WaitForSeconds(2.0f);

transform.Translate(2, 2, 0);

yield return new WaitForSeconds(3.0f);

}

IEnumerator MoveCube2(){

int count = 3;

while(Time.time < 2 && count > 0){

yield return new WaitForSeconds(0.01f);

transform.Translate(2f, 0, 0);

count -= 1;

}

}

IEnumerator MoveCube3(){

while(Time.time < 3)

{

transform.Translate(0.05f, 0, 0);

yield return 0;

}

}

IEnumerator MoveToPosition(Vector3 target)

{

while((transform.position - target).sqrMagnitude > 0.01f)

{

transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime);

yield return 0;

}

}

IEnumerator MoveOnPath(bool loop)

{

foreach(Vector3 point in path)

yield return StartCoroutine(MoveToPosition(point));

}

// Update is called once per frame

void Update () {

}

}



'Computer Language > 유니티' 카테고리의 다른 글

파티클 1번과 2번 2번을 주로 애용  (0) 2014.07.21
ITWEEN PATH탐지. 쉐이크, 좌우이동  (0) 2014.07.01
하스스톤 디딤돌  (0) 2014.07.01
SkinnedMeshRenderer  (0) 2014.06.27
GUI 씬 전환  (0) 2014.06.23

+ Recent posts