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_TargetGraphic: {fileID: 11443318}
|
||||||
m_OnClick:
|
m_OnClick:
|
||||||
m_PersistentCalls:
|
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,
|
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
|
||||||
Culture=neutral, PublicKeyToken=null
|
Culture=neutral, PublicKeyToken=null
|
||||||
--- !u!114 &11411578
|
--- !u!114 &11411578
|
||||||
@ -457,8 +469,8 @@ MonoBehaviour:
|
|||||||
m_TargetGraphic: {fileID: 11431992}
|
m_TargetGraphic: {fileID: 11431992}
|
||||||
m_HandleRect: {fileID: 22417254}
|
m_HandleRect: {fileID: 22417254}
|
||||||
m_Direction: 2
|
m_Direction: 2
|
||||||
m_Value: 1
|
m_Value: .999378026
|
||||||
m_Size: .427392095
|
m_Size: .427392036
|
||||||
m_NumberOfSteps: 0
|
m_NumberOfSteps: 0
|
||||||
m_OnValueChanged:
|
m_OnValueChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
@ -645,7 +657,7 @@ MonoBehaviour:
|
|||||||
WatchButton: {fileID: 11491412}
|
WatchButton: {fileID: 11491412}
|
||||||
XButton: {fileID: 11494666}
|
XButton: {fileID: 11494666}
|
||||||
Container: {fileID: 147852}
|
Container: {fileID: 147852}
|
||||||
UIFriendPicture: {fileID: 11467422, guid: 16a1d168f1ef75b4690435675a9e69b0, type: 2}
|
FriendPicture: {fileID: 11469406, guid: 16a1d168f1ef75b4690435675a9e69b0, type: 2}
|
||||||
--- !u!114 &11478962
|
--- !u!114 &11478962
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
@ -1093,7 +1105,7 @@ RectTransform:
|
|||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_AnchorMin: {x: .5, y: 1}
|
m_AnchorMin: {x: .5, y: 1}
|
||||||
m_AnchorMax: {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_SizeDelta: {x: 90, y: 132}
|
||||||
m_Pivot: {x: .5, y: .5}
|
m_Pivot: {x: .5, y: .5}
|
||||||
--- !u!224 &22462244
|
--- !u!224 &22462244
|
||||||
|
|||||||
@ -62,7 +62,7 @@ Transform:
|
|||||||
m_PrefabInternal: {fileID: 100100000}
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
m_GameObject: {fileID: 193868}
|
m_GameObject: {fileID: 193868}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
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_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 496448}
|
- {fileID: 496448}
|
||||||
@ -75,7 +75,7 @@ Transform:
|
|||||||
m_PrefabInternal: {fileID: 100100000}
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
m_GameObject: {fileID: 136744}
|
m_GameObject: {fileID: 136744}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
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_LocalScale: {x: .800000012, y: .800000012, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 498100}
|
- {fileID: 498100}
|
||||||
|
|||||||
@ -10,6 +10,8 @@ GameObject:
|
|||||||
- 224: {fileID: 22403202}
|
- 224: {fileID: 22403202}
|
||||||
- 222: {fileID: 22221002}
|
- 222: {fileID: 22221002}
|
||||||
- 114: {fileID: 11467422}
|
- 114: {fileID: 11467422}
|
||||||
|
- 114: {fileID: 11469406}
|
||||||
|
- 114: {fileID: 11492734}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: UIFriendPicture
|
m_Name: UIFriendPicture
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -38,6 +40,47 @@ MonoBehaviour:
|
|||||||
m_FillAmount: 1
|
m_FillAmount: 1
|
||||||
m_FillClockwise: 1
|
m_FillClockwise: 1
|
||||||
m_FillOrigin: 0
|
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
|
--- !u!222 &22221002
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -48,6 +48,8 @@ namespace DeathBook.Model
|
|||||||
private Sprite picture;
|
private Sprite picture;
|
||||||
public Sprite Picture { get { return 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)
|
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)
|
foreach (Friendship f in deadFriendsList)
|
||||||
f.Update(deltaTime);
|
f.Update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SelectNode()
|
||||||
|
{
|
||||||
|
if (OnSelected != null)
|
||||||
|
{
|
||||||
|
OnSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,25 +4,25 @@ using System.Collections.Generic;
|
|||||||
using DeathBook.Model;
|
using DeathBook.Model;
|
||||||
|
|
||||||
public class NetworkingSphere : MonoBehaviour
|
public class NetworkingSphere : MonoBehaviour
|
||||||
{
|
{
|
||||||
public GameObjectsOptions gameObjects = new GameObjectsOptions();
|
public GameObjectsOptions gameObjects = new GameObjectsOptions();
|
||||||
public LevelOptions levelOptions = new LevelOptions();
|
public LevelOptions levelOptions = new LevelOptions();
|
||||||
private NetworkDisconnection sphere;
|
private NetworkDisconnection sphere;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class GameObjectsOptions
|
public class GameObjectsOptions
|
||||||
{
|
{
|
||||||
public Link LinkObj;
|
public Link LinkObj;
|
||||||
public PersonNode PersonObj;
|
public PersonNode PersonObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class LevelOptions
|
public class LevelOptions
|
||||||
{
|
{
|
||||||
public int NumPeople = 50;
|
public int NumPeople = 50;
|
||||||
public int AvgNumFriends = 20;
|
public int AvgNumFriends = 20;
|
||||||
public float FriendshipLikeliness = 0.4f;
|
public float FriendshipLikeliness = 0.4f;
|
||||||
public float SphereRadius = 1f;
|
public float SphereRadius = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float rotationSpeed = 0.7f;
|
public float rotationSpeed = 0.7f;
|
||||||
@ -32,33 +32,36 @@ public class NetworkingSphere : MonoBehaviour
|
|||||||
|
|
||||||
private bool dragging = false;
|
private bool dragging = false;
|
||||||
private Vector3 delta = new Vector3();
|
private Vector3 delta = new Vector3();
|
||||||
private Rigidbody rb;
|
private Rigidbody rb;
|
||||||
|
|
||||||
private LevelManager manager;
|
private LevelManager manager;
|
||||||
|
|
||||||
private PersonNode[] peopleNodes;
|
private PersonNode[] peopleNodes;
|
||||||
|
|
||||||
private PersonNode _selectedNode;
|
private PersonNode _selectedNode;
|
||||||
|
|
||||||
|
// Used to disable the physics when the user has clicked on a node
|
||||||
|
private bool _isRotatingTowardsNode = false;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
manager = LevelManager.Instance;
|
manager = LevelManager.Instance;
|
||||||
manager.NewLevel(levelOptions.NumPeople, levelOptions.AvgNumFriends, levelOptions.FriendshipLikeliness, levelOptions.SphereRadius);
|
manager.NewLevel(levelOptions.NumPeople, levelOptions.AvgNumFriends, levelOptions.FriendshipLikeliness, levelOptions.SphereRadius);
|
||||||
Level lvl = manager.GameLevel;
|
Level lvl = manager.GameLevel;
|
||||||
|
|
||||||
InstantiateNodes(lvl);
|
InstantiateNodes(lvl);
|
||||||
AssignLinks(lvl);
|
AssignLinks(lvl);
|
||||||
rb = GetComponent<Rigidbody>();
|
rb = GetComponent<Rigidbody>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnGUI()
|
void OnGUI()
|
||||||
{
|
{
|
||||||
int time = manager.GameLevel.DayTime;
|
int time = manager.GameLevel.DayTime;
|
||||||
GUI.Button(new Rect(50, 50, 100, 40), Utils.GetTimeString(time));
|
GUI.Button(new Rect(50, 50, 100, 40), Utils.GetTimeString(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
manager.GameLevel.Update(Time.deltaTime);
|
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
|
//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);
|
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)
|
if (Mathf.Sqrt(worldMousePos.x * worldMousePos.x + worldMousePos.y * worldMousePos.y) > levelOptions.SphereRadius + 1f)
|
||||||
{
|
{
|
||||||
transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed);
|
transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed);
|
||||||
@ -87,20 +90,20 @@ public class NetworkingSphere : MonoBehaviour
|
|||||||
delta = new Vector3();
|
delta = new Vector3();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dragging)
|
if (dragging && !_isRotatingTowardsNode)
|
||||||
{
|
{
|
||||||
MoveSphere();
|
MoveSphere();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//scroll
|
//scroll
|
||||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||||
{
|
{
|
||||||
// if (Camera.main.ScreenToViewportPoint(Input.mousePosition) < new Vector3(1,1,1))
|
// if (Camera.main.ScreenToViewportPoint(Input.mousePosition) < new Vector3(1,1,1))
|
||||||
if (Camera.main.ScreenToViewportPoint(Input.mousePosition).x < 1)
|
if (Camera.main.ScreenToViewportPoint(Input.mousePosition).x < 1)
|
||||||
{
|
{
|
||||||
Camera.main.fieldOfView -= Input.GetAxis("Mouse ScrollWheel") * 10f;
|
Camera.main.fieldOfView -= Input.GetAxis("Mouse ScrollWheel") * 10f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,26 +143,29 @@ public class NetworkingSphere : MonoBehaviour
|
|||||||
|
|
||||||
private void OnNodeClicked(PersonNode node)
|
private void OnNodeClicked(PersonNode node)
|
||||||
{
|
{
|
||||||
|
if (node == _selectedNode) return;
|
||||||
|
|
||||||
if (_selectedNode != null)
|
if (_selectedNode != null)
|
||||||
{
|
{
|
||||||
_selectedNode.Select(false);
|
_selectedNode.Select(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.Kill();
|
|
||||||
|
|
||||||
DetailsPanel.SetNode(node);
|
DetailsPanel.SetNode(node);
|
||||||
node.Select(true);
|
node.Select(true);
|
||||||
|
|
||||||
_selectedNode = node;
|
_selectedNode = node;
|
||||||
|
|
||||||
|
// Testing to see how it looks and feels like
|
||||||
|
FocusOnNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AssignLinks(Level lvl)
|
private void AssignLinks(Level lvl)
|
||||||
{
|
{
|
||||||
foreach (FriendshipLink f in lvl.Friendships)
|
foreach (FriendshipLink f in lvl.Friendships)
|
||||||
{
|
{
|
||||||
Link link = Instantiate(gameObjects.LinkObj) as Link;
|
Link link = Instantiate(gameObjects.LinkObj) as Link;
|
||||||
int id1 = f.Friend1.id;
|
int id1 = f.Friend1.id;
|
||||||
int id2 = f.Friend2.id;
|
int id2 = f.Friend2.id;
|
||||||
link.Model = f;
|
link.Model = f;
|
||||||
link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject);
|
link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject);
|
||||||
|
|
||||||
@ -168,4 +174,65 @@ public class NetworkingSphere : MonoBehaviour
|
|||||||
peopleNodes[id2].AddLink(link);
|
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 UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using DeathBook.Model;
|
using DeathBook.Model;
|
||||||
using DeathBook.Util;
|
using DeathBook.Util;
|
||||||
|
|
||||||
public class PersonDetailsPanel : MonoBehaviour, IObserver
|
public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||||
@ -14,7 +14,7 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
|||||||
public Button XButton;
|
public Button XButton;
|
||||||
public GameObject Container;
|
public GameObject Container;
|
||||||
|
|
||||||
public Image UIFriendPicture;
|
public UIFriendPicture FriendPicture;
|
||||||
|
|
||||||
private PersonNode _node;
|
private PersonNode _node;
|
||||||
private Person _model;
|
private Person _model;
|
||||||
@ -30,7 +30,7 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
|||||||
{
|
{
|
||||||
_model.UnSubscribe(this);
|
_model.UnSubscribe(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
_node = node;
|
_node = node;
|
||||||
_model = node.Model;
|
_model = node.Model;
|
||||||
|
|
||||||
@ -50,6 +50,9 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
|||||||
{
|
{
|
||||||
Name.text = _model.Name;
|
Name.text = _model.Name;
|
||||||
|
|
||||||
|
KillButton.gameObject.SetActive(_model.Alive);
|
||||||
|
WatchButton.gameObject.SetActive(_model.Alive);
|
||||||
|
|
||||||
foreach (Transform picture in FriendsPanel.transform)
|
foreach (Transform picture in FriendsPanel.transform)
|
||||||
{
|
{
|
||||||
Destroy(picture.gameObject);
|
Destroy(picture.gameObject);
|
||||||
@ -70,24 +73,19 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
|||||||
{
|
{
|
||||||
Person friend = _model.FriendList[i].Friend;
|
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);
|
Image picture = friendPicture.Picture;
|
||||||
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;
|
|
||||||
|
|
||||||
if (i == _model.FriendList.Count - 1)
|
picture.sprite = friend.Picture;
|
||||||
{
|
|
||||||
Debug.Log(friendPicture.rectTransform.position);
|
picture.transform.SetParent(FriendsPanel.transform);
|
||||||
}
|
picture.rectTransform.anchorMin = new Vector2(0.022f, 1f - (height - 0.01f) * (i + 1) - i * 0.01f);
|
||||||
else if (i == 0)
|
picture.rectTransform.anchorMax = new Vector2(0.26f, (1f - height * i));
|
||||||
{
|
picture.rectTransform.offsetMin = Vector2.zero;
|
||||||
Debug.Log(friendPicture.rectTransform.position);
|
picture.rectTransform.offsetMax = Vector2.zero;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,4 +94,9 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
|
|||||||
Container.SetActive(false);
|
Container.SetActive(false);
|
||||||
_node.Select(false);
|
_node.Select(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void KillNode()
|
||||||
|
{
|
||||||
|
_node.Kill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,177 +1,178 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DeathBook.Model;
|
using DeathBook.Model;
|
||||||
using DeathBook.Util;
|
using DeathBook.Util;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
[RequireComponent(typeof(Collider))]
|
[RequireComponent(typeof(Collider))]
|
||||||
public class PersonNode : MonoBehaviour, IObserver
|
public class PersonNode : MonoBehaviour, IObserver
|
||||||
{
|
{
|
||||||
private const float UpdateFrequency = 0.5f;
|
private const float UpdateFrequency = 0.5f;
|
||||||
private float time = 0;
|
private float time = 0;
|
||||||
|
|
||||||
public Action<PersonNode> OnClicked;
|
public Action<PersonNode> OnClicked;
|
||||||
|
|
||||||
public Color SelectedColor = Color.blue;
|
public Color SelectedColor = Color.blue;
|
||||||
|
|
||||||
public Color StartColor = Color.green;
|
public Color StartColor = Color.green;
|
||||||
public Color MiddleColor = Color.yellow;
|
public Color MiddleColor = Color.yellow;
|
||||||
public Color EndColor = Color.red;
|
public Color EndColor = Color.red;
|
||||||
|
|
||||||
public Renderer internQuad;
|
public Renderer internQuad;
|
||||||
public Renderer xQuad;
|
public Renderer xQuad;
|
||||||
|
|
||||||
private List<Link> _links;
|
private List<Link> _links;
|
||||||
private bool _highlighted = false;
|
private bool _highlighted = false;
|
||||||
private bool _selected = false;
|
private bool _selected = false;
|
||||||
|
|
||||||
private Person _model;
|
private Person _model;
|
||||||
private Renderer _renderer;
|
private Renderer _renderer;
|
||||||
private Transform _transform;
|
private Transform _transform;
|
||||||
|
|
||||||
|
|
||||||
public Person Model
|
public Person Model
|
||||||
{
|
{
|
||||||
get { return _model; }
|
get { return _model; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_model = value;
|
_model = value;
|
||||||
_model.Subscribe(this);
|
_model.Subscribe(this);
|
||||||
UpdateInfo();
|
_model.OnSelected += () => { OnClicked(this); };
|
||||||
SetProfilePicture();
|
UpdateInfo();
|
||||||
}
|
SetProfilePicture();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void SetProfilePicture()
|
|
||||||
{
|
private void SetProfilePicture()
|
||||||
internQuad.material.mainTexture = _model.Picture.texture;
|
{
|
||||||
internQuad.material.SetTexture("_MainTex", _model.Picture.texture);
|
internQuad.material.mainTexture = _model.Picture.texture;
|
||||||
}
|
internQuad.material.SetTexture("_MainTex", _model.Picture.texture);
|
||||||
|
}
|
||||||
void Awake()
|
|
||||||
{
|
void Awake()
|
||||||
_links = new List<Link>();
|
{
|
||||||
_renderer = GetComponent<Renderer>();
|
_links = new List<Link>();
|
||||||
_transform = GetComponent<Transform>();
|
_renderer = GetComponent<Renderer>();
|
||||||
}
|
_transform = GetComponent<Transform>();
|
||||||
|
}
|
||||||
void Update()
|
|
||||||
|
void Update()
|
||||||
{
|
{
|
||||||
time += Time.deltaTime;
|
time += Time.deltaTime;
|
||||||
if (time > UpdateFrequency)
|
if (time > UpdateFrequency)
|
||||||
{
|
{
|
||||||
_model.Update(time);
|
_model.Update(time);
|
||||||
time = 0;
|
time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find another way to do it if it lags to much
|
// 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));
|
_transform.LookAt(new Vector3(_transform.position.x, _transform.position.y, _transform.position.z + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLink(Link link)
|
public void AddLink(Link link)
|
||||||
{
|
{
|
||||||
_links.Add(link);
|
_links.Add(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Select(bool state)
|
public void Select(bool state)
|
||||||
{
|
{
|
||||||
_selected = state;
|
_selected = state;
|
||||||
UpdateLinks(state);
|
UpdateLinks(state);
|
||||||
|
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
_renderer.material.color = SelectedColor;
|
_renderer.material.color = SelectedColor;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UpdateInfo();
|
UpdateInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateLinks(bool isHighlighted)
|
private void UpdateLinks(bool isHighlighted)
|
||||||
{
|
{
|
||||||
foreach (Link link in _links)
|
foreach (Link link in _links)
|
||||||
{
|
{
|
||||||
link.Highlight(isHighlighted);
|
link.Highlight(isHighlighted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Kill()
|
public void Kill()
|
||||||
{
|
{
|
||||||
_model.Kill();
|
_model.Kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Notify()
|
public void Notify()
|
||||||
{
|
{
|
||||||
//Debug.Log("Received notification! " + Model.AwarenessLevel);
|
//Debug.Log("Received notification! " + Model.AwarenessLevel);
|
||||||
UpdateInfo();
|
UpdateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateInfo()
|
private void UpdateInfo()
|
||||||
{
|
{
|
||||||
//If dead -> set offline until all friends are aware, then add a big red X to profile pic
|
//If dead -> set offline until all friends are aware, then add a big red X to profile pic
|
||||||
if (_model.Alive)
|
if (_model.Alive)
|
||||||
{
|
{
|
||||||
xQuad.enabled = false;
|
xQuad.enabled = false;
|
||||||
SetColors();
|
SetColors();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xQuad.enabled = true;
|
xQuad.enabled = true;
|
||||||
gameObject.GetComponent<Renderer>().material.color = new Color32(50, 50, 50, 1);
|
gameObject.GetComponent<Renderer>().material.color = new Color32(50, 50, 50, 1);
|
||||||
UpdateLinks(false);
|
UpdateLinks(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetColors()
|
private void SetColors()
|
||||||
{
|
{
|
||||||
//set greyed out for offline
|
//set greyed out for offline
|
||||||
if (_model.Online)
|
if (_model.Online)
|
||||||
{
|
{
|
||||||
internQuad.material.color = new Color32(255, 255, 255, 1);
|
internQuad.material.color = new Color32(255, 255, 255, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
internQuad.material.color = new Color32(80, 80, 80, 1);
|
internQuad.material.color = new Color32(80, 80, 80, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_model.AwarenessLevel < 0.5)
|
if (_model.AwarenessLevel < 0.5)
|
||||||
{
|
{
|
||||||
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(StartColor, MiddleColor, _model.AwarenessLevel * 2);
|
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(StartColor, MiddleColor, _model.AwarenessLevel * 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(MiddleColor, EndColor, _model.AwarenessLevel * 2 - 1);
|
gameObject.GetComponent<Renderer>().material.color = Color.Lerp(MiddleColor, EndColor, _model.AwarenessLevel * 2 - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseEnter()
|
void OnMouseEnter()
|
||||||
{
|
{
|
||||||
if (!_selected && !_highlighted)
|
if (!_selected && !_highlighted)
|
||||||
{
|
{
|
||||||
UpdateLinks(true);
|
UpdateLinks(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_highlighted = true;
|
_highlighted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseExit()
|
void OnMouseExit()
|
||||||
{
|
{
|
||||||
if (!_selected)
|
if (!_selected)
|
||||||
{
|
{
|
||||||
UpdateLinks(false);
|
UpdateLinks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_highlighted = false;
|
_highlighted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseDown()
|
void OnMouseDown()
|
||||||
{
|
{
|
||||||
// The sphere should be subscribed to this event and update the data accordingly
|
// The sphere should be subscribed to this event and update the data accordingly
|
||||||
if (OnClicked != null)
|
if (OnClicked != null)
|
||||||
{
|
{
|
||||||
OnClicked(this);
|
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