Commit 54ef125e authored by Chae Ho Shin's avatar Chae Ho Shin

Merge remote-tracking branch 'origin/collision-model' into collision-model

parents 8e39be2f f54dd753
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class AlertManager : MonoBehaviour
{
[SerializeField]
GameObject alertObject;
[SerializeField]
Button okButton;
[SerializeField]
Button cancelButton;
[SerializeField]
Text alertText;
Queue<string> alertTextQueue;
// Start is called before the first frame update
void Start()
{
Close();
//string[] aa = { "a","b" };
//Alert(aa);
}
// Update is called once per frame
void Update()
{
}
public void Alert(string text,UnityAction ok = null,UnityAction cancel = null)
{
Open();
alertText.text = text;
okButton.onClick.AddListener(Close);
cancelButton.onClick.AddListener(Close);
if(ok != null)
{
okButton.onClick.AddListener(ok);
}
if(cancel != null)
{
cancelButton.onClick.AddListener(cancel);
}
}
public void Alert(IList<string> texts)
{
alertTextQueue = new Queue<string>(texts);
AlertQueue();
}
public void AlertQueue()
{
if(alertTextQueue.Count >= 2)
{
Alert(alertTextQueue.Dequeue(), AlertQueue, DeleteQueue);
}
else
{
Alert(alertTextQueue.Dequeue());
}
}
public void DeleteQueue()
{
alertTextQueue.Clear();
}
public void Open()
{
Time.timeScale = 0.0f;
alertObject.SetActive(true);
}
public void Close()
{
Time.timeScale = 1.0f;
okButton.onClick.RemoveAllListeners();
cancelButton.onClick.RemoveAllListeners();
alertObject.SetActive(false);
}
}
fileFormatVersion: 2
guid: fe82d3fd30784eb47b1817cc46e1e205
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
......@@ -9,6 +9,7 @@
new CollisionType(ObjectType.player,true),
new CollisionType(ObjectType.normalobject,true),
new CollisionType(ObjectType.interactive,false),
new CollisionType(ObjectType.clock,false),
new CollisionType(ObjectType.wall,true)
};
......@@ -16,6 +17,7 @@
new CollisionType(ObjectType.player,true),
new CollisionType(ObjectType.normalobject,true),
new CollisionType(ObjectType.interactive,true),
new CollisionType(ObjectType.clock,true),
new CollisionType(ObjectType.wall,true)
};
......@@ -23,6 +25,15 @@
new CollisionType(ObjectType.player,false),
new CollisionType(ObjectType.normalobject,true),
new CollisionType(ObjectType.interactive,true),
new CollisionType(ObjectType.clock,true),
new CollisionType(ObjectType.wall,true)
};
public static CollisionType[] Clock { get; private set; } = {
new CollisionType(ObjectType.player,false),
new CollisionType(ObjectType.normalobject,true),
new CollisionType(ObjectType.interactive,true),
new CollisionType(ObjectType.clock,false),
new CollisionType(ObjectType.wall,true)
};
......@@ -30,6 +41,7 @@
new CollisionType(ObjectType.player,false),
new CollisionType(ObjectType.normalobject,false),
new CollisionType(ObjectType.interactive,false),
new CollisionType(ObjectType.clock,false),
new CollisionType(ObjectType.wall,false)
};
......@@ -43,6 +55,7 @@
normalobject,
interactive,
wall,
clock,
etc
}
}
......@@ -11,6 +11,7 @@ namespace Assets.Scripts.Collision
player,
normalobject,
interactive,
clock,
wall
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Assets.Scripts.Interface;
public class GrabableObject : InteractiveObject
{
public override string InteractType
{
get
{
return "grab";
}
}
public override void OnInteract()
{
return;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Interface
{
public interface IGrabable
{
void OnGrabbed(IGraber graber);
void OnDisGrabbed(IGraber graber);
bool IsGrabbed { get; }
}
}
fileFormatVersion: 2
guid: 845b5f3d9f326274d960d67947d8f987
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Interface
{
public interface IGraber
{
void OnDisGrab(IGrabable grabed);
void OnGrab(IGrabable grabed);
Vector3 GraberV { get; }
bool IsGrab { get; }
}
}
fileFormatVersion: 2
guid: 981976f1f25218f498f2aa24ae06643b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,10 +6,11 @@ using System.Threading.Tasks;
namespace Assets.Scripts.Interface
{
interface IInteractable
public interface IInteractable
{
void OnInteract();
void OnInteract(IInteractor interactor);
void OnDisInteract(IInteractor interactor);
string InteractType { get; }
}
}
......@@ -6,8 +6,13 @@ using System.Threading.Tasks;
namespace Assets.Scripts.Interface
{
interface IInteractor
public interface IInteractor
{
void OnInteract();
void OnInteract(IInteractable interactable);
void OnDisInteract(IInteractable interactable);
IGraber IsGraber
{
get;
}
}
}
fileFormatVersion: 2
guid: 28d090e32f2ee964db867d683e0efa36
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,16 +2,12 @@
using System.Collections.Generic;
using UnityEngine;
public class LevelManager : MonoBehaviour
public class Level1Manager : LevelManager
{
public double gamma;
public PlayerMovement player;
public bool winstate = false;
// Start is called before the first frame update
void Start()
{
winstate = false;
}
// Update is called once per frame
......
fileFormatVersion: 2
guid: 85f33cc515852874d98f6c1e43799fe5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 863d3674af79b2d428796d1d39759169
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelManager : MonoBehaviour
{
public UIManager uiManager;
public double gamma;
public PlayerMovement player;
[SerializeField]
protected bool winstate = false;
// Start is called before the first frame update
void Start()
{
winstate = false;
}
// Update is called once per frame
void Update()
{
if (WinCondition())
{
WinState = true;
}
if (LoseCondition())
{
WinState = false;
}
}
protected virtual void OnWin()
{
uiManager.WinTextOn();
}
protected virtual void OnLose()
{
}
protected virtual bool LoseCondition()
{
return false;
}
protected virtual bool WinCondition()
{
return false;
}
public virtual bool WinState
{
set
{
if (value)
{
//if win
OnWin();
}
else
{
//if lose
OnLose();
}
}
}
}
fileFormatVersion: 2
guid: f16f22524f097944c8753aa297ecdb50
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
public class Clock : GrabableObject
{
public double starttime = 0.0f;
public Clock otherclock;
private new void Start()
{
base.Start();
time = starttime;
}
public override void OnCollisionStaychild(Collision collision)
{
base.OnCollisionStaychild(collision);
//Debug.Log("hit!");
//if(collision.transform.parent.name != "AnObject(Clone)")
// Debug.Log(collision.gameObject.name + " wow!");
if (collision.transform.parent != null)
{
var x = collision.transform.parent.gameObject.GetComponent(typeof(Clock)) as Clock;
if (x != null && x.Equals(otherclock))
{
Debug.Log("hit!");
if (Mathf.Abs((float)(otherclock.GetTime() - time)) <= 1.0f)
{
levelManager.WinState = true;
}
else
{
Debug.Log(Mathf.Abs((float)(otherclock.GetTime() - time)));
}
}
}
}
public double GetTime()
{
return time;
}
}
fileFormatVersion: 2
guid: 11c0c0a758005e0408c9a767ec478e97
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Assets.Scripts.Interface;
public class GrabableObject : InteractiveObject,IGrabable
{
protected bool toggle = false;
protected bool grabbed = false;
protected IGraber graber;
public override string InteractType
{
get
{
return "grab";
}
}
public bool IsGrabbed
{
get
{
return grabbed;
}
}
public void OnDisGrabbed(IGraber graber)
{
grabbed = false;
v = Vector3.zero;
}
public void OnGrabbed(IGraber graber)
{
grabbed = true;
}
public override void OnInteract(IInteractor interactor)
{
if (interactor.IsGraber != null)
{
graber = interactor.IsGraber;
if (!graber.IsGrab)
{
graber.OnGrab(this);
OnGrabbed(graber);
}
}
}
public override void OnDisInteract(IInteractor interactor)
{
if (interactor.IsGraber != null)
{
graber = interactor.IsGraber;
if (graber.IsGrab)
{
graber.OnDisGrab(this);
OnDisGrabbed(graber);
}
}
}
protected override void FixedUpdate()
{
if (grabbed)
{
v = graber.GraberV;
Debug.Log("being grabbed");
}
base.FixedUpdate();
}
}
......@@ -5,9 +5,12 @@ using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using Assets.Scripts.Interface;
public class PlayerMovement : FlatlandMovement,IInteractor
public class PlayerMovement : FlatlandMovement,IInteractor,IGraber
{
bool isinertial = true;
bool isGrab = false;
bool isInteracting = false;
IInteractable interactiongObject;
public GameObject background;
......@@ -18,7 +21,7 @@ public class PlayerMovement : FlatlandMovement,IInteractor
private Vector3 backgroundStartScale;
// Start is called before the first frame update
void Start()
protected override void Start()
{
base.Start();
v = new Vector3(0.0f, 0.0f, 0.0f);
......@@ -34,7 +37,7 @@ public class PlayerMovement : FlatlandMovement,IInteractor
}
void Update()
protected override void Update()
{
base.Update();
......@@ -50,10 +53,15 @@ public class PlayerMovement : FlatlandMovement,IInteractor
}
if (Input.GetKeyDown("g"))
{
Interact();
}
}
// Update is called once per frame
void FixedUpdate()
protected override void FixedUpdate()
{
base.FixedUpdate();
......@@ -168,16 +176,57 @@ public class PlayerMovement : FlatlandMovement,IInteractor
time += Time.fixedDeltaTime;
}
public bool isInertial()
public bool IsInertial
{
get
{
return isinertial;
}
}
//interactor 구현
public void OnInteract()
public void Interact()
{
if (isInteracting)
{
OnDisInteract(interactiongObject);
}
else
{
OnInteract(TryFindClosestInterativeObject());
}
}
public IGraber IsGraber
{
get
{
return this;
}
}
public void OnInteract(IInteractable interactable)
{
if(interactable == null)
{
return;
}
interactiongObject = interactable;
interactable.OnInteract(this);
}
public void OnDisInteract(IInteractable interactable)
{
if (interactable == null)
{
return;
}
interactable.OnDisInteract(this);
}
//충돌
public override void OnCollisionEnterchild(Collision collision)
{
base.OnCollisionEnterchild(collision);
......@@ -187,7 +236,7 @@ public class PlayerMovement : FlatlandMovement,IInteractor
if (x)
{
//상호작용가능한 물건일때
Debug.Log(x.InteractType);
//Debug.Log(x.InteractType);
interactiveObjects.Add(x);
//uiManager.InteractText = x.InteractType;
}
......@@ -199,12 +248,12 @@ public class PlayerMovement : FlatlandMovement,IInteractor
base.OnCollisionExitchild(collision);
if (collision.transform.parent != null)
{
Debug.Log("Collision");
//Debug.Log("Collision");
InteractiveObject x = collision.transform.parent.gameObject.GetComponent<InteractiveObject>();
if (x)
{
//상호작용가능한 물건일때
Debug.Log(x.InteractType);
//Debug.Log(x.InteractType);
interactiveObjects.Remove(x);
//uiManager.InteractText = x.InteractType;
}
......@@ -229,4 +278,34 @@ public class PlayerMovement : FlatlandMovement,IInteractor
return result;
}
//grab 구현
public void OnGrab(IGrabable grabed)
{
isGrab = true;
isInteracting = true;
}
public void OnDisGrab(IGrabable grabed)
{
isGrab = false;
isInteracting = false;
}
public Vector3 GraberV
{
get
{
return v;
}
}
public bool IsGrab
{
get
{
return isGrab;
}
}
}
fileFormatVersion: 2
guid: 12f466c4445ac32479d78a72afc69462
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -16,11 +16,6 @@ public class FlatlandMovement : MonoBehaviour
protected CollisionType[] howToCollison;
protected bool toggle = false;
protected bool grabbed = false;
protected int cnt = 0;
[SerializeField]
......@@ -64,7 +59,7 @@ public class FlatlandMovement : MonoBehaviour
public ObjectType ObjectType { get { return objectType; } }
protected void Start()
protected virtual void Start()
{
Physics.IgnoreLayerCollision(0, 1);
startScale = theobject.transform.localScale;
......@@ -83,6 +78,9 @@ public class FlatlandMovement : MonoBehaviour
case PresetType.wall:
howToCollison = CollisionPreset.Wall;
break;
case PresetType.clock:
howToCollison = CollisionPreset.Clock;
break;
case PresetType.etc:
break;
default:
......@@ -90,7 +88,7 @@ public class FlatlandMovement : MonoBehaviour
}
}
protected void FixedUpdate()
protected virtual void FixedUpdate()
{
if (isAutoMove)
{
......@@ -99,8 +97,8 @@ public class FlatlandMovement : MonoBehaviour
if (SpaceLength(nowDest, transform.position) < 0.1f || SpaceInnerPorduct(nowDest - tmp, v) < 0)
{
//목적지 근접 or 넘어가면
Debug.Log("dest" + nowDest);
Debug.Log("position" + transform.position);
//Debug.Log("dest" + nowDest);
//Debug.Log("position" + transform.position);
//넘어간만큼 보정.
//TODO : 좀더 엄밀하게 수정 필요.
......@@ -128,7 +126,7 @@ public class FlatlandMovement : MonoBehaviour
}
}
protected void Update()
protected virtual void Update()
{
}
......@@ -309,11 +307,11 @@ public class FlatlandMovement : MonoBehaviour
private void NextMove()
{
Debug.Log("a"+dests.Count);
//Debug.Log("a"+dests.Count);
var dest = dests.Dequeue();
var vel = pathVelocitys.Dequeue();
MoveToAbPosition(dest, vel);
Debug.Log("b"+dests.Count);
//Debug.Log("b"+dests.Count);
if (isPatrol)
{
dests.Enqueue(dest);
......@@ -403,7 +401,7 @@ public class FlatlandMovement : MonoBehaviour
StartCoroutine(_AcceleratetoConstantVelocityWithoutCorrection(finalcollisionforcedirection,(float)resultvbetamagnitude));
Debug.Log(collisions.Count);
//Debug.Log(collisions.Count);
}
/// <summary>
/// 나갔을때 호출
......
......@@ -5,16 +5,11 @@ using Assets.Scripts.Interface;
public abstract class InteractiveObject : Planemovement, IInteractable
{
public virtual string InteractType
public abstract string InteractType
{
get
{
return "grab";
}
get;
}
public virtual void OnInteract()
{
return;
}
public abstract void OnInteract(IInteractor interactor);
public abstract void OnDisInteract(IInteractor interactor);
}
......@@ -4,13 +4,10 @@ using UnityEngine;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
public class Planemovement : FlatlandMovement
public abstract class Planemovement : FlatlandMovement
{
public double starttime = 0.0f;
public Planemovement otherclock;
void Start()
new void Start()
{
base.Start();
//Renderer r = theobject.GetComponent<Renderer>();
......@@ -19,7 +16,6 @@ public class Planemovement : FlatlandMovement
v = new Vector3(0.0f, 0.0f, 0.0f);
//playergamma = 1.0f;
orientation = new Vector3(0.0f, 0.0f, 1.0f);
time = starttime;
gamma = 1.0f;
}
......@@ -30,7 +26,7 @@ public class Planemovement : FlatlandMovement
}
// For physics calcs
void FixedUpdate()
protected override void FixedUpdate()
{
base.FixedUpdate();
......@@ -47,26 +43,6 @@ public class Planemovement : FlatlandMovement
//alpha = 4 * Vector3.forward * Mathf.Cos(2 * Mathf.PI * cnt / 480) + 4 * Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480);
if ((levelManager.player.transform.position - transform.position).magnitude < 1f)
{
toggle = true;
}
else
{
toggle = false;
}
if (toggle && Input.GetKeyDown("g"))
{
grabbed = !grabbed;
}
if (grabbed)
{
v = levelManager.player.v;
Debug.Log("being grabbed");
}
if (alpha.magnitude > 0.0f)
{
......@@ -142,30 +118,4 @@ public class Planemovement : FlatlandMovement
time += Time.fixedDeltaTime * (float)(levelManager.player.gamma / gamma);
}
public override void OnCollisionStaychild(Collision collision)
{
base.OnCollisionStaychild(collision);
//Debug.Log("hit!");
//if(collision.transform.parent.name != "AnObject(Clone)")
// Debug.Log(collision.gameObject.name + " wow!");
if (collision.transform.parent != null)
{
var x = collision.transform.parent.gameObject.GetComponent(typeof(Planemovement)) as Planemovement;
if (x != null && x.Equals(otherclock))
{
Debug.Log("hit!");
if (Mathf.Abs((float)(otherclock.GetTime() - time)) <= 1.0f)
{
levelManager.winstate = true;
}
}
}
}
public double GetTime()
{
return time;
}
}
......@@ -54,7 +54,7 @@ public class PathRenderer : MonoBehaviour
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(1) && levelManager.player.isInertial() && pathcreatable)
if (Input.GetMouseButtonDown(1) && levelManager.player.IsInertial && pathcreatable)
{
RaycastHit hit1;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
......
......@@ -65,10 +65,6 @@ public class UIManager : MonoBehaviour
mytime.text = levelManager.player.time.ToString() + " s";
//clock1time.text = clock1.GetTime().ToString() + " s";
//clock2time.text = clock2.GetTime().ToString() + " s";
if (levelManager.winstate)
{
wintext.gameObject.SetActive(true);
}
//마우스 클릭시
......@@ -180,6 +176,18 @@ public class UIManager : MonoBehaviour
return new Vector3(v.x, v.z, 0.0f);
}
public void WinTextOn()
{
wintext.gameObject.SetActive(true);
wintext.GetComponent<Text>().text = "Clear!";
}
public void LoseTextOn()
{
wintext.gameObject.SetActive(true);
wintext.GetComponent<Text>().text = "Lose";
}
private void updatePathInfo(int pathNum)
{
pathName.text = "Path - " + pathNum;
......@@ -268,7 +276,7 @@ public class UIManager : MonoBehaviour
{
try
{
if (levelManager.player.isInertial() && pathRenderer.pathcreatable)
if (levelManager.player.IsInertial && pathRenderer.pathcreatable)
{
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
......
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