2017-10-08 18:37:19 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
2017-10-03 04:15:13 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2017-10-08 18:37:19 -05:00
|
|
|
|
public abstract class SelectableObject : Photon.PunBehaviour, IEquatable<SelectableObject>
|
2017-10-03 04:15:13 -05:00
|
|
|
|
{
|
2017-10-05 03:13:27 -05:00
|
|
|
|
// PhotonView Id of interacting character
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private int _queuedInteractorId = -1;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private bool _isInteracting = false;
|
|
|
|
|
|
|
|
|
|
// Interactions NPC's or spies can perform on this object
|
|
|
|
|
public Interaction[] interactions;
|
|
|
|
|
|
|
|
|
|
// Interactions only spies can perform on this object
|
|
|
|
|
public Interaction[] spyInteractions;
|
|
|
|
|
|
2017-10-03 04:15:13 -05:00
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
private Color AvailableColor, InteractingColor;
|
|
|
|
|
private bool isMousedOver = false;
|
|
|
|
|
private float LerpFactor = 10;
|
|
|
|
|
private List<Material> _materials = new List<Material>();
|
|
|
|
|
private Color _currentColor;
|
|
|
|
|
private bool isSpy;
|
2017-10-03 04:15:13 -05:00
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
public Renderer[] Renderers
|
2017-10-05 03:13:27 -05:00
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
2017-10-05 03:13:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
public Color CurrentColor
|
2017-10-05 03:13:27 -05:00
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
get { return _currentColor; }
|
2017-10-03 04:15:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
public bool IsInteracting
|
2017-10-03 04:15:13 -05:00
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _isInteracting;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
photonView.RPC("SetIsInteractingRPC", PhotonTargets.All, value);
|
|
|
|
|
}
|
2017-10-03 04:15:13 -05:00
|
|
|
|
}
|
2017-10-05 03:13:27 -05:00
|
|
|
|
|
|
|
|
|
public StateController Interactor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_queuedInteractorId < 0)
|
|
|
|
|
return null;
|
|
|
|
|
PhotonView view = PhotonView.Find(_queuedInteractorId);
|
|
|
|
|
if (view)
|
|
|
|
|
return view.GetComponent<StateController>();
|
|
|
|
|
else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
|
|
|
|
photonView.RPC("SetInteractorRPC", PhotonTargets.All, -1);
|
|
|
|
|
IsInteracting = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
photonView.RPC("SetInteractorRPC", PhotonTargets.All, value.GetComponent<PhotonView>().viewID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
protected virtual void Start()
|
2017-10-05 03:13:27 -05:00
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
isSpy = CompareTag("Spy");
|
|
|
|
|
Renderers = GetComponentsInChildren<Renderer>();
|
|
|
|
|
AvailableColor = Color.green;
|
|
|
|
|
InteractingColor = Color.yellow;
|
|
|
|
|
foreach (var renderer in Renderers)
|
|
|
|
|
{
|
|
|
|
|
_materials.AddRange(renderer.materials);
|
|
|
|
|
}
|
2017-10-05 03:13:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
public Color TargetColor
|
2017-10-05 03:13:27 -05:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
if (isMousedOver)
|
|
|
|
|
{
|
|
|
|
|
if (Interactor)
|
|
|
|
|
return InteractingColor;
|
|
|
|
|
else
|
|
|
|
|
return AvailableColor;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Color color = Color.black;
|
|
|
|
|
color.a = 0.0f;
|
|
|
|
|
return color;
|
|
|
|
|
}
|
2017-10-05 03:13:27 -05:00
|
|
|
|
}
|
2017-10-09 02:03:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Update()
|
|
|
|
|
{
|
|
|
|
|
_currentColor = Color.Lerp(_currentColor, TargetColor, Time.deltaTime * LerpFactor);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < _materials.Count; i++)
|
2017-10-05 03:13:27 -05:00
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
_materials[i].SetColor("_GlowColor", _currentColor);
|
2017-10-05 03:13:27 -05:00
|
|
|
|
}
|
2017-10-09 02:03:39 -05:00
|
|
|
|
|
|
|
|
|
if (Interactor != null && !isSpy)
|
|
|
|
|
AcceptInteraction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMouseEnter()
|
|
|
|
|
{
|
|
|
|
|
if (!isSpy)
|
|
|
|
|
isMousedOver = true;
|
|
|
|
|
else if (!photonView.isMine)
|
|
|
|
|
isMousedOver = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMouseExit()
|
|
|
|
|
{
|
|
|
|
|
isMousedOver = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Selected()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Deselected()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasInteractions()
|
|
|
|
|
{
|
|
|
|
|
return (interactions.Length + spyInteractions.Length) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual string GetInteractionTitle()
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AcceptInteraction()
|
|
|
|
|
{
|
|
|
|
|
IsInteracting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RejectInteraction()
|
|
|
|
|
{
|
|
|
|
|
Interactor.IsInteracting = false;
|
2017-10-05 03:13:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[PunRPC]
|
|
|
|
|
protected void SetIsInteractingRPC(bool value)
|
|
|
|
|
{
|
|
|
|
|
_isInteracting = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[PunRPC]
|
|
|
|
|
protected void SetInteractorRPC(int viewId)
|
|
|
|
|
{
|
|
|
|
|
_queuedInteractorId = viewId;
|
|
|
|
|
}
|
2017-10-08 18:37:19 -05:00
|
|
|
|
|
|
|
|
|
public virtual bool Equals(SelectableObject other)
|
|
|
|
|
{
|
|
|
|
|
return photonView.viewID == other.photonView.viewID;
|
|
|
|
|
}
|
2017-10-03 04:15:13 -05:00
|
|
|
|
}
|