mirror of
https://github.com/ConjureETS/DeathBook.git
synced 2026-03-24 04:20:58 +00:00
Merge branch 'master' of https://github.com/ConjureETS/DeathBook
Conflicts: Assets/Prefabs/NetworkingSphere.prefab Assets/Scenes/Gameplay.unity Assets/Scripts/Models/Person.cs Assets/Scripts/NetworkingSphere.cs Signed-off-by: RosimInc <rosim_inc@hotmail.com>
This commit is contained in:
commit
bcbf97fa44
@ -395,7 +395,19 @@ MonoBehaviour:
|
||||
m_TargetGraphic: {fileID: 11443318}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 11476684}
|
||||
m_MethodName: KillNode
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
--- !u!114 &11411578
|
||||
@ -457,8 +469,8 @@ MonoBehaviour:
|
||||
m_TargetGraphic: {fileID: 11431992}
|
||||
m_HandleRect: {fileID: 22417254}
|
||||
m_Direction: 2
|
||||
m_Value: 1
|
||||
m_Size: .427392095
|
||||
m_Value: .999378026
|
||||
m_Size: .427392036
|
||||
m_NumberOfSteps: 0
|
||||
m_OnValueChanged:
|
||||
m_PersistentCalls:
|
||||
@ -645,7 +657,7 @@ MonoBehaviour:
|
||||
WatchButton: {fileID: 11491412}
|
||||
XButton: {fileID: 11494666}
|
||||
Container: {fileID: 147852}
|
||||
UIFriendPicture: {fileID: 11467422, guid: 16a1d168f1ef75b4690435675a9e69b0, type: 2}
|
||||
FriendPicture: {fileID: 11469406, guid: 16a1d168f1ef75b4690435675a9e69b0, type: 2}
|
||||
--- !u!114 &11478962
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 1
|
||||
@ -1093,7 +1105,7 @@ RectTransform:
|
||||
m_RootOrder: 0
|
||||
m_AnchorMin: {x: .5, y: 1}
|
||||
m_AnchorMax: {x: .5, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: -65.9999924}
|
||||
m_AnchoredPosition: {x: 0, y: -65.95298}
|
||||
m_SizeDelta: {x: 90, y: 132}
|
||||
m_Pivot: {x: .5, y: .5}
|
||||
--- !u!224 &22462244
|
||||
|
||||
@ -62,7 +62,7 @@ Transform:
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
m_GameObject: {fileID: 193868}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: -544.163269, y: -235.973114, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 496448}
|
||||
@ -75,7 +75,7 @@ Transform:
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
m_GameObject: {fileID: 136744}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -.00100000005}
|
||||
m_LocalScale: {x: .800000012, y: .800000012, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 498100}
|
||||
|
||||
@ -10,6 +10,8 @@ GameObject:
|
||||
- 224: {fileID: 22403202}
|
||||
- 222: {fileID: 22221002}
|
||||
- 114: {fileID: 11467422}
|
||||
- 114: {fileID: 11469406}
|
||||
- 114: {fileID: 11492734}
|
||||
m_Layer: 5
|
||||
m_Name: UIFriendPicture
|
||||
m_TagString: Untagged
|
||||
@ -38,6 +40,47 @@ MonoBehaviour:
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
--- !u!114 &11469406
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 1
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
m_GameObject: {fileID: 115844}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 343d57f2bac42ae48ba9722c53e5526f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!114 &11492734
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 1
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
m_GameObject: {fileID: 115844}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -1862395651, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
delegates:
|
||||
- eventID: 4
|
||||
callback:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 11469406}
|
||||
m_MethodName: OnClick
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
m_TypeName: UnityEngine.EventSystems.EventTrigger+TriggerEvent, UnityEngine.UI,
|
||||
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
--- !u!222 &22221002
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -48,6 +48,8 @@ namespace DeathBook.Model
|
||||
private Sprite picture;
|
||||
public Sprite Picture { get { return picture; } }
|
||||
|
||||
private Action onSelected;
|
||||
public Action OnSelected {get {return onSelected;} set { onSelected = value; } }
|
||||
|
||||
public Person(int id, string fName, string lName, Vector3 pos, int conn, int disconn, float freq, Sprite pic)
|
||||
{
|
||||
@ -126,5 +128,13 @@ namespace DeathBook.Model
|
||||
foreach (Friendship f in deadFriendsList)
|
||||
f.Update(deltaTime);
|
||||
}
|
||||
|
||||
public void SelectNode()
|
||||
{
|
||||
if (OnSelected != null)
|
||||
{
|
||||
OnSelected();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,25 +4,25 @@ using System.Collections.Generic;
|
||||
using DeathBook.Model;
|
||||
|
||||
public class NetworkingSphere : MonoBehaviour
|
||||
{
|
||||
public GameObjectsOptions gameObjects = new GameObjectsOptions();
|
||||
public LevelOptions levelOptions = new LevelOptions();
|
||||
private NetworkDisconnection sphere;
|
||||
|
||||
[System.Serializable]
|
||||
public class GameObjectsOptions
|
||||
{
|
||||
public Link LinkObj;
|
||||
public PersonNode PersonObj;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class LevelOptions
|
||||
{
|
||||
public int NumPeople = 50;
|
||||
public int AvgNumFriends = 20;
|
||||
public float FriendshipLikeliness = 0.4f;
|
||||
public float SphereRadius = 1f;
|
||||
{
|
||||
public GameObjectsOptions gameObjects = new GameObjectsOptions();
|
||||
public LevelOptions levelOptions = new LevelOptions();
|
||||
private NetworkDisconnection sphere;
|
||||
|
||||
[System.Serializable]
|
||||
public class GameObjectsOptions
|
||||
{
|
||||
public Link LinkObj;
|
||||
public PersonNode PersonObj;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class LevelOptions
|
||||
{
|
||||
public int NumPeople = 50;
|
||||
public int AvgNumFriends = 20;
|
||||
public float FriendshipLikeliness = 0.4f;
|
||||
public float SphereRadius = 1f;
|
||||
}
|
||||
|
||||
public float rotationSpeed = 0.7f;
|
||||
@ -32,33 +32,36 @@ public class NetworkingSphere : MonoBehaviour
|
||||
|
||||
private bool dragging = false;
|
||||
private Vector3 delta = new Vector3();
|
||||
private Rigidbody rb;
|
||||
|
||||
private Rigidbody rb;
|
||||
|
||||
private LevelManager manager;
|
||||
|
||||
private PersonNode[] peopleNodes;
|
||||
|
||||
private PersonNode _selectedNode;
|
||||
|
||||
// Used to disable the physics when the user has clicked on a node
|
||||
private bool _isRotatingTowardsNode = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
manager = LevelManager.Instance;
|
||||
manager.NewLevel(levelOptions.NumPeople, levelOptions.AvgNumFriends, levelOptions.FriendshipLikeliness, levelOptions.SphereRadius);
|
||||
{
|
||||
manager = LevelManager.Instance;
|
||||
manager.NewLevel(levelOptions.NumPeople, levelOptions.AvgNumFriends, levelOptions.FriendshipLikeliness, levelOptions.SphereRadius);
|
||||
Level lvl = manager.GameLevel;
|
||||
|
||||
InstantiateNodes(lvl);
|
||||
AssignLinks(lvl);
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
int time = manager.GameLevel.DayTime;
|
||||
GUI.Button(new Rect(50, 50, 100, 40), Utils.GetTimeString(time));
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
int time = manager.GameLevel.DayTime;
|
||||
GUI.Button(new Rect(50, 50, 100, 40), Utils.GetTimeString(time));
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
{
|
||||
manager.GameLevel.Update(Time.deltaTime);
|
||||
|
||||
//TEMPORARY QUICK FIX: Even though we are never moving the sphere, it starts moving as soon as it stops rotating
|
||||
@ -70,7 +73,7 @@ public class NetworkingSphere : MonoBehaviour
|
||||
|
||||
Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(screenMousePos);
|
||||
|
||||
// If the world position of the mouse is greater than the radius of the sphere, we are outside
|
||||
// If the world position of the mouse is greater than the radius of the sphere, we are outside
|
||||
if (Mathf.Sqrt(worldMousePos.x * worldMousePos.x + worldMousePos.y * worldMousePos.y) > levelOptions.SphereRadius + 1f)
|
||||
{
|
||||
transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed);
|
||||
@ -87,20 +90,20 @@ public class NetworkingSphere : MonoBehaviour
|
||||
delta = new Vector3();
|
||||
}
|
||||
|
||||
if (dragging)
|
||||
if (dragging && !_isRotatingTowardsNode)
|
||||
{
|
||||
MoveSphere();
|
||||
}
|
||||
|
||||
|
||||
//scroll
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||
{
|
||||
// if (Camera.main.ScreenToViewportPoint(Input.mousePosition) < new Vector3(1,1,1))
|
||||
if (Camera.main.ScreenToViewportPoint(Input.mousePosition).x < 1)
|
||||
{
|
||||
Camera.main.fieldOfView -= Input.GetAxis("Mouse ScrollWheel") * 10f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//scroll
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||
{
|
||||
// if (Camera.main.ScreenToViewportPoint(Input.mousePosition) < new Vector3(1,1,1))
|
||||
if (Camera.main.ScreenToViewportPoint(Input.mousePosition).x < 1)
|
||||
{
|
||||
Camera.main.fieldOfView -= Input.GetAxis("Mouse ScrollWheel") * 10f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,26 +143,29 @@ public class NetworkingSphere : MonoBehaviour
|
||||
|
||||
private void OnNodeClicked(PersonNode node)
|
||||
{
|
||||
if (node == _selectedNode) return;
|
||||
|
||||
if (_selectedNode != null)
|
||||
{
|
||||
_selectedNode.Select(false);
|
||||
}
|
||||
|
||||
node.Kill();
|
||||
}
|
||||
|
||||
DetailsPanel.SetNode(node);
|
||||
node.Select(true);
|
||||
|
||||
_selectedNode = node;
|
||||
|
||||
// Testing to see how it looks and feels like
|
||||
FocusOnNode(node);
|
||||
}
|
||||
|
||||
private void AssignLinks(Level lvl)
|
||||
{
|
||||
foreach (FriendshipLink f in lvl.Friendships)
|
||||
{
|
||||
{
|
||||
Link link = Instantiate(gameObjects.LinkObj) as Link;
|
||||
int id1 = f.Friend1.id;
|
||||
int id2 = f.Friend2.id;
|
||||
int id2 = f.Friend2.id;
|
||||
link.Model = f;
|
||||
link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject);
|
||||
|
||||
@ -168,4 +174,65 @@ public class NetworkingSphere : MonoBehaviour
|
||||
peopleNodes[id2].AddLink(link);
|
||||
}
|
||||
}
|
||||
|
||||
public void FocusOnNode(PersonNode node)
|
||||
{
|
||||
StopCoroutine("RotateTowardsNodeCoroutine");
|
||||
StartCoroutine("RotateTowardsNodeCoroutine", node);
|
||||
|
||||
/*
|
||||
Debug.Log(node.transform.eulerAngles);
|
||||
|
||||
float xangle = (Mathf.Atan2(finalPos.z, finalPos.y) - Mathf.Atan2(initialPos.z, initialPos.y)) * Mathf.Rad2Deg;
|
||||
|
||||
Debug.Log(node.transform.position);
|
||||
transform.Rotate(new Vector3(90, 0, 0));
|
||||
//transform.rotation = transform.rotation * Quaternion.AngleAxis(xangle, Vector3.right);
|
||||
Debug.Log(xangle);
|
||||
float yAngle = (Mathf.Atan2(finalPos.x, finalPos.z) - Mathf.Atan2(node.transform.position.x, node.transform.position.z)) * Mathf.Rad2Deg;
|
||||
Debug.Log(yAngle);
|
||||
//transform.Rotate(new Vector3(xangle, yAngle, 0));
|
||||
|
||||
//float zAngle = (Mathf.Atan2(finalPos.y, finalPos.x) - Mathf.Atan2(initialPos.y, initialPos.x)) * Mathf.Rad2Deg;
|
||||
|
||||
//transform.rotation = transform.rotation * Quaternion.AngleAxis(xangle, Vector3.right) * Quaternion.AngleAxis(yAngle, Vector3.up) * Quaternion.AngleAxis(zAngle, Vector3.forward);
|
||||
*/
|
||||
}
|
||||
|
||||
private IEnumerator RotateTowardsNodeCoroutine(PersonNode node)
|
||||
{
|
||||
_isRotatingTowardsNode = true;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
|
||||
//Vector3 finalPos = new Vector3(0f, 0f, -SphereRadius);
|
||||
|
||||
Quaternion initialRot = transform.localRotation;
|
||||
|
||||
|
||||
transform.localRotation = Quaternion.identity; // Temporary hack for the game jam
|
||||
|
||||
|
||||
Vector3 nodePos = node.transform.position;
|
||||
|
||||
Vector3 longDir = nodePos;
|
||||
longDir.y = 0;
|
||||
|
||||
float xAngle = Mathf.Asin(nodePos.normalized.y) * Mathf.Rad2Deg; // Latitude
|
||||
float yAngle = Vector3.Angle(-Vector3.forward, longDir) * (longDir.x < 0 ? -1 : 1); // Longitude
|
||||
|
||||
Quaternion finalRot = Quaternion.AngleAxis(-xAngle, Vector3.right) * Quaternion.AngleAxis(yAngle, Vector3.up);
|
||||
|
||||
float ratio = 0f;
|
||||
|
||||
while (ratio < 1f)
|
||||
{
|
||||
ratio += Time.deltaTime / 1.5f;
|
||||
|
||||
transform.localRotation = Quaternion.Lerp(initialRot, finalRot, Mathf.SmoothStep(0f, 1f, ratio));
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_isRotatingTowardsNode = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
using DeathBook.Model;
|
||||
using DeathBook.Model;
|
||||
using DeathBook.Util;
|
||||
|
||||
public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||
@ -14,7 +14,7 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||
public Button XButton;
|
||||
public GameObject Container;
|
||||
|
||||
public Image UIFriendPicture;
|
||||
public UIFriendPicture FriendPicture;
|
||||
|
||||
private PersonNode _node;
|
||||
private Person _model;
|
||||
@ -30,7 +30,7 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||
{
|
||||
_model.UnSubscribe(this);
|
||||
}
|
||||
|
||||
|
||||
_node = node;
|
||||
_model = node.Model;
|
||||
|
||||
@ -50,6 +50,9 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||
{
|
||||
Name.text = _model.Name;
|
||||
|
||||
KillButton.gameObject.SetActive(_model.Alive);
|
||||
WatchButton.gameObject.SetActive(_model.Alive);
|
||||
|
||||
foreach (Transform picture in FriendsPanel.transform)
|
||||
{
|
||||
Destroy(picture.gameObject);
|
||||
@ -70,24 +73,19 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||
{
|
||||
Person friend = _model.FriendList[i].Friend;
|
||||
|
||||
Image friendPicture = Instantiate(UIFriendPicture) as Image;
|
||||
UIFriendPicture friendPicture = Instantiate(FriendPicture) as UIFriendPicture;
|
||||
|
||||
friendPicture.sprite = friend.Picture;
|
||||
friendPicture.Model = friend;
|
||||
|
||||
friendPicture.transform.SetParent(FriendsPanel.transform);
|
||||
friendPicture.rectTransform.anchorMin = new Vector2(0.022f, 1f - (height - 0.01f) * (i + 1) - i * 0.01f);
|
||||
friendPicture.rectTransform.anchorMax = new Vector2(0.26f, (1f - height * i));
|
||||
friendPicture.rectTransform.offsetMin = Vector2.zero;
|
||||
friendPicture.rectTransform.offsetMax = Vector2.zero;
|
||||
Image picture = friendPicture.Picture;
|
||||
|
||||
if (i == _model.FriendList.Count - 1)
|
||||
{
|
||||
Debug.Log(friendPicture.rectTransform.position);
|
||||
}
|
||||
else if (i == 0)
|
||||
{
|
||||
Debug.Log(friendPicture.rectTransform.position);
|
||||
}
|
||||
picture.sprite = friend.Picture;
|
||||
|
||||
picture.transform.SetParent(FriendsPanel.transform);
|
||||
picture.rectTransform.anchorMin = new Vector2(0.022f, 1f - (height - 0.01f) * (i + 1) - i * 0.01f);
|
||||
picture.rectTransform.anchorMax = new Vector2(0.26f, (1f - height * i));
|
||||
picture.rectTransform.offsetMin = Vector2.zero;
|
||||
picture.rectTransform.offsetMax = Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,4 +94,9 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||
Container.SetActive(false);
|
||||
_node.Select(false);
|
||||
}
|
||||
|
||||
public void KillNode()
|
||||
{
|
||||
_node.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,177 +1,178 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DeathBook.Model;
|
||||
using DeathBook.Util;
|
||||
using System;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class PersonNode : MonoBehaviour, IObserver
|
||||
using DeathBook.Util;
|
||||
using System;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class PersonNode : MonoBehaviour, IObserver
|
||||
{
|
||||
private const float UpdateFrequency = 0.5f;
|
||||
private float time = 0;
|
||||
|
||||
public Action<PersonNode> OnClicked;
|
||||
|
||||
public Color SelectedColor = Color.blue;
|
||||
|
||||
public Color StartColor = Color.green;
|
||||
public Color MiddleColor = Color.yellow;
|
||||
public Color EndColor = Color.red;
|
||||
|
||||
public Renderer internQuad;
|
||||
public Renderer xQuad;
|
||||
|
||||
private List<Link> _links;
|
||||
private bool _highlighted = false;
|
||||
private bool _selected = false;
|
||||
|
||||
private Person _model;
|
||||
private Renderer _renderer;
|
||||
private float time = 0;
|
||||
|
||||
public Action<PersonNode> OnClicked;
|
||||
|
||||
public Color SelectedColor = Color.blue;
|
||||
|
||||
public Color StartColor = Color.green;
|
||||
public Color MiddleColor = Color.yellow;
|
||||
public Color EndColor = Color.red;
|
||||
|
||||
public Renderer internQuad;
|
||||
public Renderer xQuad;
|
||||
|
||||
private List<Link> _links;
|
||||
private bool _highlighted = false;
|
||||
private bool _selected = false;
|
||||
|
||||
private Person _model;
|
||||
private Renderer _renderer;
|
||||
private Transform _transform;
|
||||
|
||||
|
||||
public Person Model
|
||||
{
|
||||
get { return _model; }
|
||||
set
|
||||
{
|
||||
_model = value;
|
||||
_model.Subscribe(this);
|
||||
UpdateInfo();
|
||||
SetProfilePicture();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetProfilePicture()
|
||||
{
|
||||
internQuad.material.mainTexture = _model.Picture.texture;
|
||||
internQuad.material.SetTexture("_MainTex", _model.Picture.texture);
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_links = new List<Link>();
|
||||
_renderer = GetComponent<Renderer>();
|
||||
_transform = GetComponent<Transform>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
|
||||
|
||||
public Person Model
|
||||
{
|
||||
get { return _model; }
|
||||
set
|
||||
{
|
||||
_model = value;
|
||||
_model.Subscribe(this);
|
||||
_model.OnSelected += () => { OnClicked(this); };
|
||||
UpdateInfo();
|
||||
SetProfilePicture();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetProfilePicture()
|
||||
{
|
||||
internQuad.material.mainTexture = _model.Picture.texture;
|
||||
internQuad.material.SetTexture("_MainTex", _model.Picture.texture);
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_links = new List<Link>();
|
||||
_renderer = GetComponent<Renderer>();
|
||||
_transform = GetComponent<Transform>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time > UpdateFrequency)
|
||||
{
|
||||
_model.Update(time);
|
||||
time = 0;
|
||||
}
|
||||
|
||||
// Find another way to do it if it lags to much
|
||||
_transform.LookAt(new Vector3(_transform.position.x, _transform.position.y, _transform.position.z + 1));
|
||||
}
|
||||
|
||||
public void AddLink(Link link)
|
||||
{
|
||||
_links.Add(link);
|
||||
}
|
||||
|
||||
public void Select(bool state)
|
||||
{
|
||||
_selected = state;
|
||||
UpdateLinks(state);
|
||||
|
||||
if (state)
|
||||
{
|
||||
_renderer.material.color = SelectedColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLinks(bool isHighlighted)
|
||||
{
|
||||
foreach (Link link in _links)
|
||||
{
|
||||
link.Highlight(isHighlighted);
|
||||
}
|
||||
}
|
||||
|
||||
// Find another way to do it if it lags to much
|
||||
_transform.LookAt(new Vector3(_transform.position.x, _transform.position.y, _transform.position.z + 1));
|
||||
}
|
||||
|
||||
public void AddLink(Link link)
|
||||
{
|
||||
_links.Add(link);
|
||||
}
|
||||
|
||||
public void Select(bool state)
|
||||
{
|
||||
_selected = state;
|
||||
UpdateLinks(state);
|
||||
|
||||
if (state)
|
||||
{
|
||||
_renderer.material.color = SelectedColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLinks(bool isHighlighted)
|
||||
{
|
||||
foreach (Link link in _links)
|
||||
{
|
||||
link.Highlight(isHighlighted);
|
||||
}
|
||||
}
|
||||
|
||||
public void Kill()
|
||||
{
|
||||
_model.Kill();
|
||||
}
|
||||
|
||||
public void Notify()
|
||||
}
|
||||
|
||||
public void Notify()
|
||||
{
|
||||
//Debug.Log("Received notification! " + Model.AwarenessLevel);
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
private void UpdateInfo()
|
||||
{
|
||||
//If dead -> set offline until all friends are aware, then add a big red X to profile pic
|
||||
if (_model.Alive)
|
||||
{
|
||||
xQuad.enabled = false;
|
||||
SetColors();
|
||||
}
|
||||
else
|
||||
{
|
||||
xQuad.enabled = true;
|
||||
gameObject.GetComponent<Renderer>().material.color = new Color32(50, 50, 50, 1);
|
||||
UpdateLinks(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetColors()
|
||||
{
|
||||
//set greyed out for offline
|
||||
if (_model.Online)
|
||||
{
|
||||
internQuad.material.color = new Color32(255, 255, 255, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
internQuad.material.color = new Color32(80, 80, 80, 1);
|
||||
}
|
||||
|
||||
if (_model.AwarenessLevel < 0.5)
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(StartColor, MiddleColor, _model.AwarenessLevel * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(MiddleColor, EndColor, _model.AwarenessLevel * 2 - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseEnter()
|
||||
{
|
||||
if (!_selected && !_highlighted)
|
||||
{
|
||||
UpdateLinks(true);
|
||||
}
|
||||
|
||||
_highlighted = true;
|
||||
}
|
||||
|
||||
void OnMouseExit()
|
||||
{
|
||||
if (!_selected)
|
||||
{
|
||||
UpdateLinks(false);
|
||||
}
|
||||
|
||||
_highlighted = false;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
// The sphere should be subscribed to this event and update the data accordingly
|
||||
if (OnClicked != null)
|
||||
{
|
||||
OnClicked(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Debug.Log("Received notification! " + Model.AwarenessLevel);
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
private void UpdateInfo()
|
||||
{
|
||||
//If dead -> set offline until all friends are aware, then add a big red X to profile pic
|
||||
if (_model.Alive)
|
||||
{
|
||||
xQuad.enabled = false;
|
||||
SetColors();
|
||||
}
|
||||
else
|
||||
{
|
||||
xQuad.enabled = true;
|
||||
gameObject.GetComponent<Renderer>().material.color = new Color32(50, 50, 50, 1);
|
||||
UpdateLinks(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetColors()
|
||||
{
|
||||
//set greyed out for offline
|
||||
if (_model.Online)
|
||||
{
|
||||
internQuad.material.color = new Color32(255, 255, 255, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
internQuad.material.color = new Color32(80, 80, 80, 1);
|
||||
}
|
||||
|
||||
if (_model.AwarenessLevel < 0.5)
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(StartColor, MiddleColor, _model.AwarenessLevel * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(MiddleColor, EndColor, _model.AwarenessLevel * 2 - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseEnter()
|
||||
{
|
||||
if (!_selected && !_highlighted)
|
||||
{
|
||||
UpdateLinks(true);
|
||||
}
|
||||
|
||||
_highlighted = true;
|
||||
}
|
||||
|
||||
void OnMouseExit()
|
||||
{
|
||||
if (!_selected)
|
||||
{
|
||||
UpdateLinks(false);
|
||||
}
|
||||
|
||||
_highlighted = false;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
// The sphere should be subscribed to this event and update the data accordingly
|
||||
if (OnClicked != null)
|
||||
{
|
||||
OnClicked(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
33
Assets/Scripts/UIFriendPicture.cs
Normal file
33
Assets/Scripts/UIFriendPicture.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using DeathBook.Model;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(Image))]
|
||||
public class UIFriendPicture : MonoBehaviour
|
||||
{
|
||||
private Person _model;
|
||||
|
||||
public Person Model
|
||||
{
|
||||
get { return _model; }
|
||||
set { _model = value; }
|
||||
}
|
||||
|
||||
private Image _picture;
|
||||
|
||||
public Image Picture
|
||||
{
|
||||
get { return _picture; }
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_picture = GetComponent<Image>();
|
||||
}
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
_model.SelectNode();
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/UIFriendPicture.cs.meta
Normal file
12
Assets/Scripts/UIFriendPicture.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 343d57f2bac42ae48ba9722c53e5526f
|
||||
timeCreated: 1439693427
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user