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