Commit 8a24918b authored by 16이진형's avatar 16이진형

grab 호출 구조 변경

parent 3c98bc0f
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);
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 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,9 +6,9 @@ using System.Threading.Tasks; ...@@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace Assets.Scripts.Interface namespace Assets.Scripts.Interface
{ {
interface IInteractable public interface IInteractable
{ {
void OnInteract(); void OnInteract(IInteractor interactor);
string InteractType { get; } string InteractType { get; }
} }
......
...@@ -6,8 +6,13 @@ using System.Threading.Tasks; ...@@ -6,8 +6,13 @@ using System.Threading.Tasks;
namespace Assets.Scripts.Interface namespace Assets.Scripts.Interface
{ {
interface IInteractor public interface IInteractor
{ {
void OnInteract(); void OnInteract(IInteractable interactable);
IGraber IsGraber
{
get;
}
} }
} }
...@@ -3,13 +3,15 @@ using System.Collections.Generic; ...@@ -3,13 +3,15 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Assets.Scripts.Interface; using Assets.Scripts.Interface;
public class GrabableObject : InteractiveObject public class GrabableObject : InteractiveObject,IGrabable
{ {
protected bool toggle = false; protected bool toggle = false;
protected bool grabbed = false; protected bool grabbed = false;
protected IGraber graber;
public override string InteractType public override string InteractType
{ {
get get
...@@ -18,30 +20,38 @@ public class GrabableObject : InteractiveObject ...@@ -18,30 +20,38 @@ public class GrabableObject : InteractiveObject
} }
} }
public override void OnInteract() public bool IsGrabbed
{
get
{ {
return; return grabbed;
}
} }
protected override void FixedUpdate() public void OnGrabbed(IGraber graber)
{
if ((levelManager.player.transform.position - transform.position).magnitude < 1f)
{ {
toggle = true; grabbed = !grabbed;
} }
else
public override void OnInteract(IInteractor interactor)
{ {
toggle = false; if (interactor.IsGraber != null)
{
graber = interactor.IsGraber;
if (!graber.IsGrab)
{
graber.OnGrab(this);
OnGrabbed(graber);
}
}
} }
if (toggle && Input.GetKeyDown("g")) protected override void FixedUpdate()
{ {
grabbed = !grabbed;
}
if (grabbed) if (grabbed)
{ {
v = levelManager.player.v; v = graber.GraberV;
Debug.Log("being grabbed"); Debug.Log("being grabbed");
} }
......
...@@ -5,9 +5,10 @@ using MathNet.Numerics.LinearAlgebra; ...@@ -5,9 +5,10 @@ using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Double;
using Assets.Scripts.Interface; using Assets.Scripts.Interface;
public class PlayerMovement : FlatlandMovement,IInteractor public class PlayerMovement : FlatlandMovement,IInteractor,IGraber
{ {
bool isinertial = true; bool isinertial = true;
bool isGrab = false;
public GameObject background; public GameObject background;
...@@ -50,6 +51,11 @@ public class PlayerMovement : FlatlandMovement,IInteractor ...@@ -50,6 +51,11 @@ public class PlayerMovement : FlatlandMovement,IInteractor
} }
if (Input.GetKeyDown("g"))
{
OnInteract(TryFindClosestInterativeObject());
}
} }
// Update is called once per frame // Update is called once per frame
...@@ -175,12 +181,26 @@ public class PlayerMovement : FlatlandMovement,IInteractor ...@@ -175,12 +181,26 @@ public class PlayerMovement : FlatlandMovement,IInteractor
return isinertial; return isinertial;
} }
} }
//interactor 구현
public void OnInteract() public IGraber IsGraber
{
get
{
return this;
}
}
public void OnInteract(IInteractable interactable)
{
if(interactable == null)
{ {
return; return;
} }
interactable.OnInteract(this);
}
//충돌
public override void OnCollisionEnterchild(Collision collision) public override void OnCollisionEnterchild(Collision collision)
{ {
base.OnCollisionEnterchild(collision); base.OnCollisionEnterchild(collision);
...@@ -232,4 +252,26 @@ public class PlayerMovement : FlatlandMovement,IInteractor ...@@ -232,4 +252,26 @@ public class PlayerMovement : FlatlandMovement,IInteractor
return result; return result;
} }
//grab 구현
public void OnGrab(IGrabable grabed)
{
isGrab = true;
}
public Vector3 GraberV
{
get
{
return v;
}
}
public bool IsGrab
{
get
{
return isGrab;
}
}
} }
...@@ -5,16 +5,10 @@ using Assets.Scripts.Interface; ...@@ -5,16 +5,10 @@ using Assets.Scripts.Interface;
public abstract class InteractiveObject : Planemovement, IInteractable public abstract class InteractiveObject : Planemovement, IInteractable
{ {
public virtual string InteractType public abstract string InteractType
{ {
get get;
{
return "grab";
}
} }
public virtual void OnInteract() public abstract void OnInteract(IInteractor interactor);
{
return;
}
} }
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