- More rotation related changes

This commit is contained in:
Patrice Vignola 2015-08-15 23:11:45 -04:00
parent 1f055792f5
commit 2d92c524ed
30 changed files with 2185 additions and 588 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@ -135,7 +135,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 195142} m_GameObject: {fileID: 195142}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -.573046267, y: -.809006572, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 495136} - {fileID: 495136}
@ -151,15 +151,13 @@ MonoBehaviour:
m_GameObject: {fileID: 195142} m_GameObject: {fileID: 195142}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c495d00d780bd3d49866ec60f5efbf66, type: 3} m_Script: {fileID: 11500000, guid: 9c9bbff116cac264d9d7fdcce8cf92e5, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
HighlightedColor: {r: 1, g: 1, b: 1, a: .501960814} HighlightedColor: {r: 1, g: 1, b: 1, a: .258823544}
StartPoint: {fileID: 495136} StartPoint: {fileID: 495136}
EndPoint: {fileID: 495134} EndPoint: {fileID: 495134}
BeamLine: {fileID: 12095142} BeamLine: {fileID: 12095142}
StartObject: {fileID: 0}
EndObject: {fileID: 0}
--- !u!120 &12095142 --- !u!120 &12095142
LineRenderer: LineRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@ -88,8 +88,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d0907c1567bad554c8b995de3459e517, type: 3} m_Script: {fileID: 11500000, guid: d0907c1567bad554c8b995de3459e517, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
gameObjects:
LinkObj: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} LinkObj: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2}
PersonObj: {fileID: 11417564, guid: 7a5b1db47a2c30e419038df40dffa79a, type: 2} PersonObj: {fileID: 11417564, guid: 7a5b1db47a2c30e419038df40dffa79a, type: 2}
levelOptions:
NumPeople: 50 NumPeople: 50
AvgNumFriends: 8 AvgNumFriends: 8
FriendshipLikeliness: .400000006 FriendshipLikeliness: .400000006

View File

@ -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:
@ -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

View File

@ -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,8 +75,8 @@ 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: -9.99999975e-05} m_LocalPosition: {x: 0, y: 0, z: -.00100000005}
m_LocalScale: {x: .899999976, y: .899999976, z: 1} m_LocalScale: {x: .800000012, y: .800000012, z: 1}
m_Children: m_Children:
- {fileID: 498100} - {fileID: 498100}
m_Father: {fileID: 410576} m_Father: {fileID: 410576}

View File

@ -431,12 +431,12 @@ CanvasRenderer:
RectTransform: RectTransform:
m_PrefabParentObject: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, m_PrefabParentObject: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832,
type: 2} type: 2}
m_PrefabInternal: {fileID: 1267491657} m_PrefabInternal: {fileID: 1009381200}
--- !u!114 &724043967 stripped --- !u!114 &724043967 stripped
MonoBehaviour: MonoBehaviour:
m_PrefabParentObject: {fileID: 11476684, guid: c993e87661906234fba410e55ed66832, m_PrefabParentObject: {fileID: 11476684, guid: c993e87661906234fba410e55ed66832,
type: 2} type: 2}
m_PrefabInternal: {fileID: 1267491657} m_PrefabInternal: {fileID: 1009381200}
m_Script: {fileID: 11500000, guid: 88fb1885d6f8fd6409e3866b7707a12a, type: 3} m_Script: {fileID: 11500000, guid: 88fb1885d6f8fd6409e3866b7707a12a, type: 3}
--- !u!1 &997683484 --- !u!1 &997683484
GameObject: GameObject:
@ -500,6 +500,100 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0} m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 997683484} m_GameObject: {fileID: 997683484}
--- !u!1001 &1009381200
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 523974151}
m_Modifications:
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMin.x
value: .0299999993
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMin.y
value: .0299999993
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.x
value: .970000029
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.y
value: .970000029
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_Pivot.x
value: .5
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_Pivot.y
value: .5
objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: c993e87661906234fba410e55ed66832, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1057734534 --- !u!1 &1057734534
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -651,100 +745,6 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 1 m_RootOrder: 1
--- !u!1001 &1267491657
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 523974151}
m_Modifications:
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMin.x
value: .0299999993
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMin.y
value: .0299999993
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.x
value: .970000029
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.y
value: .970000029
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_Pivot.x
value: .5
objectReference: {fileID: 0}
- target: {fileID: 22436630, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_Pivot.y
value: .5
objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMin.y
value: .572607875
objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: c993e87661906234fba410e55ed66832, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1413393085 --- !u!1 &1413393085
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,10 +1,21 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using DeathBook.Util;
using DeathBook.Model;
[RequireComponent(typeof(LineRenderer))] [RequireComponent(typeof(LineRenderer))]
public class FriendshipLink : MonoBehaviour public class Link : MonoBehaviour, IObserver
{ {
public Color HighlightedColor = new Color(1f, 1f, 1f, 0.5f); private float highlightAlpha = 0.8f;
private float defaultAlpha = 0.5f;
private Color currentDefaultColor;
private Color currentHighlightColor;
private static float defaultScale = 0.03f;
private float hightlightScale = 0.2f;
private bool isHighlighted = false;
[SerializeField] [SerializeField]
private Transform StartPoint; private Transform StartPoint;
@ -16,16 +27,28 @@ public class FriendshipLink : MonoBehaviour
private LineRenderer BeamLine; private LineRenderer BeamLine;
//public ParticleSystem BeamParticles; //public ParticleSystem BeamParticles;
[SerializeField]
private Transform StartObject; private Transform StartObject;
[SerializeField]
private Transform EndObject; private Transform EndObject;
private FriendshipLink model;
public FriendshipLink Model
{
get { return model; }
set
{
model = value;
model.Subscribe(this);
//Make it between 0.1 and 0.4
GetColors(Model.Awareness);
hightlightScale = Model.Importance * 0.3f + 0.1f;
Highlight(false);
}
}
private float LIFETIME_RATIO = 0.025f; private float LIFETIME_RATIO = 0.025f;
private Renderer _renderer; private Renderer _renderer;
private Color _defaultColor;
void Awake() void Awake()
{ {
@ -36,11 +59,18 @@ public class FriendshipLink : MonoBehaviour
_renderer.material = Instantiate(_renderer.material); _renderer.material = Instantiate(_renderer.material);
_defaultColor = _renderer.material.GetColor("_TintColor"); //_defaultColor = _renderer.material.GetColor("_TintColor");
//Activate(false); //Activate(false);
} }
public void Notify()
{
GetColors(Model.Awareness);
UpdateBeam();
//TODO SR
}
void Update() void Update()
{ {
UpdateVisualEffects(); UpdateVisualEffects();
@ -79,10 +109,35 @@ public class FriendshipLink : MonoBehaviour
EndObject = destination.transform; EndObject = destination.transform;
} }
public void Highlight(bool state, float weight) public void Highlight(bool state)
{ {
// For now, the weight does nothing but it should eventually influence the intensity and size of the link ; isHighlighted = state;
UpdateBeam();
}
_renderer.material.SetColor("_TintColor", state ? HighlightedColor : _defaultColor); private void GetColors(float level)
{
//If level is 0.0, green [0,1,0].
//If level is 0.5, yellow [1,1,0].
//If level is 1.0, red [1,0,0].
float r = 1f;
float g = 1f;
if (level < 0.5f)
r = Mathf.Lerp(0, 1, level*2);
else
g = Mathf.Lerp(1, 0, level * 2 - 1);
currentDefaultColor = new Color(r, g, 0f, defaultAlpha);
currentHighlightColor = new Color(r, g, 0f, highlightAlpha);
}
private void UpdateBeam()
{
float width = isHighlighted ? hightlightScale : defaultScale;
BeamLine.SetWidth(width, width);
_renderer.material.SetColor("_TintColor", isHighlighted ? currentHighlightColor : currentDefaultColor);
} }
} }

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a24d489629b440b4d9fcfafc24239241 guid: 9c9bbff116cac264d9d7fdcce8cf92e5
timeCreated: 1439446791 timeCreated: 1439591140
licenseType: Free licenseType: Free
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2

View File

@ -1,18 +1,61 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
using DeathBook.Util;
namespace DeathBook.Model namespace DeathBook.Model
{ {
public class Friendship public class Friendship : Updatable
{ {
public Person friend1, friend2; private Person self;
private int importance; //on a scale from 1 to 100 public Person Self { get { return self; } }
private Person friend;
public Person Friend { get { return friend; } }
public Friendship(Person p1, Person p2, int scale) private Friendship other;
public Friendship Other { get { return other; } set { other = value; } }
private FriendshipLink link;
public FriendshipLink Link { get { return link; } }
private bool noticedDeath = false;
public Friendship(Person self, Person friend, FriendshipLink link)
{ {
friend1 = p1; this.self = self;
friend2 = p2; this.friend = friend;
importance = scale; this.link = link;
} }
public void Update(float deltaTime)
{
if (noticedDeath)
return;
//This function is only called when friend is dead
//awareness = Mathf.Min(awareness + deltaTime * CalculateWeight(), 1);
link.Awareness = Mathf.Min(link.Awareness + deltaTime * 0.1f, 1f);
if (link.Awareness >= 1f)
{
self.NoticeDeath(this);
noticedDeath = true;
}
}
//returns a number between 0 and 1
private float CalculateWeight()
{
float weight = 0;
weight += link.Importance;
//weight += friend.TimeBetweenPosts;
return weight * 0.1f;
}
/*internal enum Knowledge
{
Alive, Doubt, Dead
}*/
} }
} }

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using DeathBook.Util;
namespace DeathBook.Model
{
public class FriendshipLink : Observable
{
private Person friend1, friend2;
public Person Friend1 { get { return friend1; } }
public Person Friend2 { get { return friend2; } }
private float importance; //on a scale from 0 to 1
public float Importance { get { return importance; } }
private float awareness = 0; //on a scale from 0 to 1
public float Awareness
{
get { return awareness; }
set { awareness = value; NotifyObservers(); }
}
public FriendshipLink(Person p1, Person p2, float importance)
{
friend1 = p1;
friend2 = p2;
this.importance = importance;
}
}
}

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: c495d00d780bd3d49866ec60f5efbf66 guid: 5c672f95914b3f04088de0f562834941
timeCreated: 1439307989 timeCreated: 1439578834
licenseType: Free licenseType: Free
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2

View File

@ -1,24 +1,40 @@
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using DeathBook.Util;
namespace DeathBook.Model namespace DeathBook.Model
{ {
public class Level public class Level : Observable, Updatable
{ {
private const float TimeScale = 30f;
private int score; private int score;
public int Score { get { return score; } }
public List<Person> people; private List<Person> people;
public List<Friendship> friendships; public List<Person> People { get { return people; } }
private List<FriendshipLink> friendships;
public List<FriendshipLink> Friendships { get { return friendships; } }
//1 = 1 minute
private float gameTime;
public int GameTime { get { return (int)(gameTime * TimeScale); } }
//private Generator gen; private float globalAwareness; //on a scale from 0 to 1
private int gameTime; public float GlobalAwareness { get { return globalAwareness; } }
private int globalAwareness;
public Level(List<Person> people, List<Friendship> friendships) public Level(List<Person> people, List<FriendshipLink> friendships)
{ {
this.people = people; this.people = people;
this.friendships = friendships; this.friendships = friendships;
} }
public void Update(float deltaTime)
{
gameTime += deltaTime;
NotifyObservers();
//TODO Global awareness - start trends
}
} }
} }

View File

@ -10,6 +10,9 @@ namespace DeathBook.Model
private float probability; private float probability;
private float radius; private float radius;
private const float minConnTime = 3;
private const float maxConnTime = 20;
public Level GenerateLevel(int numPeople, int avgFriends, float probability, float radius) public Level GenerateLevel(int numPeople, int avgFriends, float probability, float radius)
{ {
this.numPeople = numPeople; this.numPeople = numPeople;
@ -18,7 +21,7 @@ namespace DeathBook.Model
this.radius = radius; this.radius = radius;
List<Person> people = CreatePeople(); List<Person> people = CreatePeople();
List<Friendship> friendships = CreateFriendships(people); List<FriendshipLink> friendships = CreateFriendships(people);
return new Level(people, friendships); return new Level(people, friendships);
} }
@ -48,7 +51,8 @@ namespace DeathBook.Model
x = Mathf.Cos(longitude) * r; x = Mathf.Cos(longitude) * r;
y = Mathf.Sin(longitude) * r; y = Mathf.Sin(longitude) * r;
p = new Person(i, x, y, z); p = CreatePerson(i, x, y, z);
people.Add(p); people.Add(p);
z -= dz; z -= dz;
@ -56,16 +60,12 @@ namespace DeathBook.Model
longitude += dlong; longitude += dlong;
} }
Debug.Log("People: " + people.Count);
return people; return people;
} }
private List<Friendship> CreateFriendships(List<Person> people) private List<FriendshipLink> CreateFriendships(List<Person> people)
{ {
Debug.Log("Creating friendships" + probability); List<FriendshipLink> friendships = new List<FriendshipLink>();
List<Friendship> friendships = new List<Friendship>();
Person p1, p2; Person p1, p2;
int totalCount = people.Count; int totalCount = people.Count;
@ -76,7 +76,7 @@ namespace DeathBook.Model
for (int i = 0; i < totalCount; i++) for (int i = 0; i < totalCount; i++)
{ {
p1 = people[i]; p1 = people[i];
missing = avgConnections - p1.numFriends; // TODO Add randomness missing = avgConnections - p1.FriendCount; // TODO Add randomness
if (missing <= 0) if (missing <= 0)
continue; continue;
@ -86,7 +86,7 @@ namespace DeathBook.Model
for (int j = i+1; j < totalCount; j++) for (int j = i+1; j < totalCount; j++)
{ {
p2 = people[j]; p2 = people[j];
if (p2.numFriends < avgConnections * 1.2) if (p2.FriendCount < avgConnections * 1.2)
list.AddLast(new DistanceNode(p1, p2)); list.AddLast(new DistanceNode(p1, p2));
} }
@ -112,17 +112,33 @@ namespace DeathBook.Model
list.Remove(smallest); list.Remove(smallest);
} }
} }
Debug.Log(friendships.Count);
return friendships; return friendships;
} }
private Friendship CreateFriendship(Person p1, Person p2) private FriendshipLink CreateFriendship(Person p1, Person p2)
{ {
Friendship f = new Friendship(p1, p2, Random.Range(1,100)); FriendshipLink f = new FriendshipLink(p1, p2, Random.value);
p1.AddFriendship(f); Friendship f1 = new Friendship(p1, p2, f);
p2.AddFriendship(f); Friendship f2 = new Friendship(p2, p1, f);
f1.Other = f2;
f2.Other = f1;
p1.AddFriendship(f1);
p2.AddFriendship(f2);
return f; return f;
} }
private Person CreatePerson(int id, float x, float y, float z)
{
Vector3 pos = new Vector3(x, y, z);
//Vector2 times =
Person p = new Person(id, pos);
return p;
}
} }
internal class DistanceNode internal class DistanceNode
@ -133,19 +149,7 @@ namespace DeathBook.Model
public DistanceNode(Person p1, Person p2) public DistanceNode(Person p1, Person p2)
{ {
p = p2; p = p2;
dist = (p2.initialPosition - p1.initialPosition).sqrMagnitude; dist = (p2.InitialPosition - p1.InitialPosition).sqrMagnitude;
} }
} }
/*
* 1. Friendship urgency - 0-1
* Number of friends missing
* VS number of nodes left
*
* 2. Friendship possibility
* Closeness
* 0 < distance^2 < root(2)*rSq < 4*rSq
*
*/
} }

View File

@ -0,0 +1,23 @@
using UnityEngine;
using System.Collections.Generic;
namespace DeathBook.Model
{
public class LevelManager
{
private static LevelManager instance = new LevelManager();
public static LevelManager Instance { get {return instance; } }
private Level level = null;
public Level GameLevel { get { return level; } }
private LevelGenerator gen = new LevelGenerator();
private LevelManager() {}
public void NewLevel(int numPeople, int avgFriends, float probability, float radius)
{
level = gen.GenerateLevel(numPeople, avgFriends, probability, radius);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ccfb5fe3d9ad971499b807bde15217c4
timeCreated: 1439591141
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,92 +1,124 @@
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
using DeathBook.Util;
namespace DeathBook.Model namespace DeathBook.Model
{ {
public class Person : Observable public class Person : Observable, Updatable
{ {
public int id; public Action OnSelected;
private string name;
private List<Friendship> friendList = new List<Friendship>();
public Vector3 initialPosition;
public int numFriends;
private int timeBetweenPosts; // f = 1/T;
private int connectionTime;
private int disconnectionTime;
private int awarenessLevel;
private bool alive;
private int happiness; public int id;
private bool connected; public int Id { get { return id; } }
private string firstName;
private string lastName;
public string Name { get { return firstName + " " + lastName; } }
public string FirstName { get { return firstName; } }
private Vector3 initialPosition;
public Vector3 InitialPosition { get { return initialPosition; } }
private List<Friendship> friendsList = new List<Friendship>();
public List<Friendship> FriendList { get { return friendsList; } }
private List<Friendship> deadFriendsList = new List<Friendship>();
public List<Friendship> DeadFriendList { get { return deadFriendsList; } }
private int numAliveFriends = 0;
private int numDeadFriends = 0;
private int friendCount = 0;
public int FriendCount { get { return friendCount; } }
private int timeBetweenPosts; // f = 1/T;
public int TimeBetweenPosts { get { return timeBetweenPosts; } }
private float connectionTime;
public float ConnectionTime { get { return connectionTime; } }
private float disconnectionTime;
public float DisconnectionTime { get { return disconnectionTime; } }
private float awarenessLevel = 0; //on a scale from 0 to 1
public float AwarenessLevel { get { return awarenessLevel; } }
private bool alive = true;
public bool Alive { get { return alive; } }
private bool online = true;
public bool Online { get { return online; } }
private Sprite picture; private Sprite picture;
public Sprite Picture { get { return picture; } }
//private Node node;
public string Name public Person(int id, Vector3 pos)
{
get { return name; }
}
public bool Alive
{
get { return alive; }
}
public int AwarenessLevel
{
get { return awarenessLevel; }
}
public List<Friendship> FriendList
{
get { return friendList; }
}
public int FriendsCount
{
get { return numFriends; }
}
public bool Online
{
get { return connected; }
}
public Sprite Picture
{
get { return picture; }
}
public Person(int id, float x, float y, float z)
{ {
this.id = id; this.id = id;
initialPosition = new Vector3(x, y, z); initialPosition = pos;
alive = true;
// TODO Use names from db
firstName = "Mark";
lastName = "Zuckerberg";
// For testing purposes // For testing purposes
picture = UnityEngine.Random.Range(0, 2) == 0 ? PictureGenerator.GetFemalePicture() : PictureGenerator.GetMalePicture(); picture = UnityEngine.Random.Range(0, 2) == 0 ? PictureGenerator.GetFemalePicture() : PictureGenerator.GetMalePicture();
// Temporary
name = String.Format("Firstname{0} Lastname{0}", id);
} }
public void AddFriendship(Friendship f) public void AddFriendship(Friendship f)
{ {
friendList.Add(f); friendsList.Add(f);
numFriends++; numAliveFriends++;
friendCount++;
} }
private bool isConnected(int time) public void NotifyFriendWasKilled(Friendship f)
{ {
return disconnectionTime > time && time > connectionTime; //Debug.Log("I am " + id + " and my friend " + f.Friend.Id + " was killed");
numAliveFriends--;
numDeadFriends++;
deadFriendsList.Add(f);
} }
private int calculateWeight() public void Kill()
{ {
//friendCount * ____ + 1/timeBetweenPosts + } //Debug.Log("Person " + id + " died!");
return 0; alive = false;
foreach (Friendship f in friendsList)
f.Friend.NotifyFriendWasKilled(f.Other);
NotifyObservers();
}
public void NoticeDeath(Friendship f)
{
//TODO apply more rules here
awarenessLevel = Mathf.Min(AwarenessLevel + 0.2f, 1f);
//Debug.Log("I am " + id + " and I know my friend " + f.Friend.Id + " was killed.. " + AwarenessLevel);
//TODO remove from dead friends list to accelerate
NotifyObservers();
}
public void Update(float deltaTime)
{
//TODO Update if connected
int time = LevelManager.Instance.GameLevel.GameTime;
//The following actions are only performed if user is online
if (!Online)
return;
foreach (Friendship f in deadFriendsList)
f.Update(deltaTime);
}
public void SelectNode()
{
if (OnSelected != null)
{
OnSelected();
}
} }
} }
} }

View File

@ -0,0 +1,32 @@
using System.Collections.Generic;
using UnityEngine;
namespace DeathBook.Model
{
public class Utils
{
public static void Test()
{
float mean = 50;
float range = 50;
int numSteps = 2;
int numTries = 100;
for (int i = 0; i < numTries; i++)
{
Debug.Log(GetRandomValue(mean, range, numSteps));
}
}
public static float GetRandomValue(float mean, float range, int numSteps)
{
float sum = 0;
for (int i = 0; i < numSteps; i++)
{
sum += Random.value;
}
return (sum / numSteps * 2 - 1) * range + mean;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 710c7285af897124a8e7e5c5ecf05109
timeCreated: 1439506723
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,14 +5,27 @@ using DeathBook.Model;
public class NetworkingSphere : MonoBehaviour public class NetworkingSphere : MonoBehaviour
{ {
public FriendshipLink LinkObj; public GameObjectsOptions gameObjects = new GameObjectsOptions();
public LevelOptions levelOptions = new LevelOptions();
private NetworkDisconnection sphere;
[System.Serializable]
public class GameObjectsOptions
{
public Link LinkObj;
public PersonNode PersonObj; public PersonNode PersonObj;
}
[System.Serializable]
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;
public float torqueForce = 50f; public float torqueForce = 50f;
public PersonDetailsPanel DetailsPanel; public PersonDetailsPanel DetailsPanel;
@ -21,23 +34,35 @@ public class NetworkingSphere : MonoBehaviour
private Vector3 delta = new Vector3(); private Vector3 delta = new Vector3();
private Rigidbody rb; private Rigidbody rb;
private LevelManager manager;
private PersonNode[] peopleNodes; private PersonNode[] peopleNodes;
//TODO private Friendship[] friendships;
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()
{ {
LevelGenerator lGen = new LevelGenerator(); manager = LevelManager.Instance;
Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius); manager.NewLevel(levelOptions.NumPeople, levelOptions.AvgNumFriends, levelOptions.FriendshipLikeliness, levelOptions.SphereRadius);
Level lvl = manager.GameLevel;
InstantiateNodes(lvl); InstantiateNodes(lvl);
AssignLinks(lvl); AssignLinks(lvl);
rb = GetComponent<Rigidbody>(); rb = GetComponent<Rigidbody>();
} }
/*void OnGUI()
{
GUI.Button(new Rect(10, 100, 400, 40), manager.GameLevel.GameTime + "");
}*/
void Update() 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 //TEMPORARY QUICK FIX: Even though we are never moving the sphere, it starts moving as soon as it stops rotating
transform.position = Vector3.zero; transform.position = Vector3.zero;
@ -48,12 +73,12 @@ 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) > 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);
} }
//when right btn clicked, call MoveSphere //when right btn clicked, call the change rotation
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{ {
dragging = true; dragging = true;
@ -64,11 +89,12 @@ 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)
{ {
@ -97,13 +123,13 @@ public class NetworkingSphere : MonoBehaviour
private void InstantiateNodes(Level lvl) private void InstantiateNodes(Level lvl)
{ {
peopleNodes = new PersonNode[lvl.people.Count]; peopleNodes = new PersonNode[lvl.People.Count];
for (int i = 0; i < lvl.people.Count; i++) for (int i = 0; i < lvl.People.Count; i++)
{ {
Person person = lvl.people[i]; Person person = lvl.People[i];
PersonNode pInst = Instantiate(PersonObj, person.initialPosition, Quaternion.identity) as PersonNode; PersonNode pInst = Instantiate(gameObjects.PersonObj, person.InitialPosition, Quaternion.identity) as PersonNode;
pInst.OnClicked += OnNodeClicked; pInst.OnClicked += OnNodeClicked;
@ -116,6 +142,8 @@ 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);
@ -132,11 +160,12 @@ public class NetworkingSphere : MonoBehaviour
private void AssignLinks(Level lvl) private void AssignLinks(Level lvl)
{ {
foreach (Friendship f in lvl.friendships) foreach (FriendshipLink f in lvl.Friendships)
{ {
FriendshipLink link = Instantiate(LinkObj) as FriendshipLink; 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.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject); link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject);
// Temporary stuff, for testing // Temporary stuff, for testing
@ -171,6 +200,9 @@ public class NetworkingSphere : MonoBehaviour
private IEnumerator RotateTowardsNodeCoroutine(PersonNode node) private IEnumerator RotateTowardsNodeCoroutine(PersonNode node)
{ {
_isRotatingTowardsNode = true;
rb.angularVelocity = Vector3.zero;
//Vector3 finalPos = new Vector3(0f, 0f, -SphereRadius); //Vector3 finalPos = new Vector3(0f, 0f, -SphereRadius);
Quaternion initialRot = transform.localRotation; Quaternion initialRot = transform.localRotation;
@ -184,10 +216,10 @@ public class NetworkingSphere : MonoBehaviour
Vector3 longDir = nodePos; Vector3 longDir = nodePos;
longDir.y = 0; longDir.y = 0;
float longitude = Vector3.Angle(-Vector3.forward, longDir) * (longDir.x < 0 ? -1 : 1); float xAngle = Mathf.Asin(nodePos.normalized.y) * Mathf.Rad2Deg; // Latitude
float latitude = Mathf.Asin(nodePos.normalized.y) * Mathf.Rad2Deg; float yAngle = Vector3.Angle(-Vector3.forward, longDir) * (longDir.x < 0 ? -1 : 1); // Longitude
Quaternion finalRot = Quaternion.AngleAxis(-latitude, Vector3.right) * Quaternion.AngleAxis(longitude, Vector3.up); Quaternion finalRot = Quaternion.AngleAxis(-xAngle, Vector3.right) * Quaternion.AngleAxis(yAngle, Vector3.up);
float ratio = 0f; float ratio = 0f;
@ -199,5 +231,7 @@ public class NetworkingSphere : MonoBehaviour
yield return null; yield return null;
} }
_isRotatingTowardsNode = false;
} }
} }

View File

@ -1,8 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
// Using an abstract class to avoid repeating code, but could be implemented as an interface if inheritance is somehow needed for the subjects namespace DeathBook.Util
public abstract class Observable
{ {
// Using an abstract class to avoid repeating code, but could be implemented as an interface if inheritance is somehow needed for the subjects
public abstract class Observable
{
private List<IObserver> observers; private List<IObserver> observers;
public Observable() public Observable()
@ -27,4 +29,5 @@ public abstract class Observable
observer.Notify(); observer.Notify();
} }
} }
}
} }

View File

@ -1,4 +1,7 @@
public interface IObserver namespace DeathBook.Util
{ {
public interface IObserver
{
void Notify(); void Notify();
}
} }

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace DeathBook.Util
{
public interface Updatable
{
void Update(float deltaTime);
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 897f94f455c7ce64394a644bd3cf070b
timeCreated: 1439591140
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using UnityEngine.UI; using UnityEngine.UI;
using DeathBook.Model; using DeathBook.Model;
using DeathBook.Util;
public class PersonDetailsPanel : MonoBehaviour, IObserver public class PersonDetailsPanel : MonoBehaviour, IObserver
{ {
@ -13,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;
@ -49,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);
@ -67,17 +71,21 @@ public class PersonDetailsPanel : MonoBehaviour, IObserver
for (int i = 0; i < _model.FriendList.Count; i++) for (int i = 0; i < _model.FriendList.Count; i++)
{ {
Person friend = _model.FriendList[i].friend1 == _model ? _model.FriendList[i].friend2 : _model.FriendList[i].friend1; 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)); picture.sprite = friend.Picture;
friendPicture.rectTransform.offsetMin = Vector2.zero;
friendPicture.rectTransform.offsetMax = Vector2.zero; 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;
} }
} }
@ -86,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();
}
} }

View File

@ -2,11 +2,15 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using DeathBook.Model; using DeathBook.Model;
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 float time = 0;
public Action<PersonNode> OnClicked; public Action<PersonNode> OnClicked;
public Color SelectedColor = Color.blue; public Color SelectedColor = Color.blue;
@ -18,7 +22,7 @@ public class PersonNode : MonoBehaviour, IObserver
public Renderer internQuad; public Renderer internQuad;
public Renderer xQuad; public Renderer xQuad;
private List<FriendshipLink> _links; private List<Link> _links;
private bool _highlighted = false; private bool _highlighted = false;
private bool _selected = false; private bool _selected = false;
@ -26,6 +30,7 @@ public class PersonNode : MonoBehaviour, IObserver
private Renderer _renderer; private Renderer _renderer;
private Transform _transform; private Transform _transform;
public Person Model public Person Model
{ {
get { return _model; } get { return _model; }
@ -33,6 +38,7 @@ public class PersonNode : MonoBehaviour, IObserver
{ {
_model = value; _model = value;
_model.Subscribe(this); _model.Subscribe(this);
_model.OnSelected += () => { OnClicked(this); };
UpdateInfo(); UpdateInfo();
SetProfilePicture(); SetProfilePicture();
} }
@ -46,18 +52,25 @@ public class PersonNode : MonoBehaviour, IObserver
void Awake() void Awake()
{ {
_links = new List<FriendshipLink>(); _links = new List<Link>();
_renderer = GetComponent<Renderer>(); _renderer = GetComponent<Renderer>();
_transform = GetComponent<Transform>(); _transform = GetComponent<Transform>();
} }
void Update() void Update()
{ {
time += Time.deltaTime;
if (time > UpdateFrequency)
{
_model.Update(time);
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(FriendshipLink link) public void AddLink(Link link)
{ {
_links.Add(link); _links.Add(link);
} }
@ -77,16 +90,22 @@ public class PersonNode : MonoBehaviour, IObserver
} }
} }
private void UpdateLinks(bool state) private void UpdateLinks(bool isHighlighted)
{ {
foreach (FriendshipLink link in _links) foreach (Link link in _links)
{ {
link.Highlight(state, 1f); link.Highlight(isHighlighted);
} }
} }
public void Kill()
{
_model.Kill();
}
public void Notify() public void Notify()
{ {
//Debug.Log("Received notification! " + Model.AwarenessLevel);
UpdateInfo(); UpdateInfo();
} }
@ -155,7 +174,5 @@ public class PersonNode : MonoBehaviour, IObserver
{ {
OnClicked(this); OnClicked(this);
} }
Debug.Log("clicked");
} }
} }

View 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();
}
}

View 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:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 43c96e134d44b1646b218de6f0e4c659
timeCreated: 1439592514
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,114 +0,0 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DeathBook.Model;
public class SphereSR : MonoBehaviour
{
public FriendshipLink LinkObj;
public PersonNode PersonObj;
public int NumPeople = 50;
public int AvgNumFriends = 20;
public float FriendshipLikeliness = 0.4f;
public float SphereRadius = 1f;
public float rotationSpeed = 0.7f;
public float torqueForce = 50f;
private bool dragging = false;
private Vector3 delta = new Vector3();
private Rigidbody rb;
private PersonNode[] peopleNodes;
//TODO private Friendship[] friendships;
private GameObject[] nodes;
void Awake()
{
LevelGenerator lGen = new LevelGenerator();
Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius);
InstantiateNodes(lvl);
AssignLinks(lvl);
rb = GetComponent<Rigidbody>();
}
void Update()
{
Vector3 screenMousePos = Input.mousePosition;
screenMousePos.z = transform.position.z - Camera.main.transform.position.z;
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 (Mathf.Sqrt(worldMousePos.x * worldMousePos.x + worldMousePos.y * worldMousePos.y) > SphereRadius + 1f)
{
transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed);
}
//when right btn clicked, call the chnge rotation
if (Input.GetMouseButtonDown(1))
{
dragging = true;
}
else if (Input.GetMouseButtonUp(1))
{
dragging = false;
delta = new Vector3();
}
if (dragging)
{
MoveSphere();
}
}
void MoveSphere()
{
float deltaX = Input.GetAxis("Mouse X");
float deltaY = Input.GetAxis("Mouse Y");
if (deltaX == 0 && deltaY == 0)
{
delta = new Vector3();
rb.angularVelocity *= 0.8f;
}
delta += new Vector3(deltaX, deltaY, 0);
//rigidbody.AddTorque();
rb.AddTorque(Vector3.down * delta.x * torqueForce * Time.deltaTime, ForceMode.Impulse);
rb.AddTorque(Vector3.right * delta.y * torqueForce * Time.deltaTime, ForceMode.Impulse);
Debug.Log(delta.x + ", " + delta.y);
}
private void InstantiateNodes(Level lvl)
{
peopleNodes = new PersonNode[lvl.people.Count];
int ctr = 0;
foreach (Person p in lvl.people)
{
PersonNode pInst = Instantiate(PersonObj, p.initialPosition, Quaternion.identity) as PersonNode;
pInst.transform.parent = this.transform;
peopleNodes[ctr++] = pInst;
}
}
private void AssignLinks(Level lvl)
{
foreach (Friendship f in lvl.friendships)
{
FriendshipLink link = Instantiate(LinkObj) as FriendshipLink;
int id1 = f.friend1.id;
int id2 = f.friend2.id;
link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject);
// Temporary stuff, for testing
peopleNodes[id1].AddLink(link);
peopleNodes[id2].AddLink(link);
}
}
}