Started implementing game time, player awareness update after death.

Signed-off-by: RosimInc <rosim_inc@hotmail.com>
This commit is contained in:
RosimInc 2015-08-14 18:51:31 -04:00
parent 1a05475a6a
commit 9d06c3fe30
24 changed files with 1523 additions and 286 deletions

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,7 +151,7 @@ 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: .501960814}

View File

@ -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: -.0500000007} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: .800000012, y: .800000012, z: 1} m_LocalScale: {x: .800000012, y: .800000012, z: 1}
m_Children: m_Children:
- {fileID: 498100} - {fileID: 498100}

View File

@ -581,7 +581,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2} - target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMin.y propertyPath: m_AnchorMin.y
value: .590630949 value: .549793065
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2} - target: {fileID: 22417254, guid: c993e87661906234fba410e55ed66832, type: 2}
propertyPath: m_AnchorMax.x propertyPath: m_AnchorMax.x
@ -1082,6 +1082,18 @@ Prefab:
propertyPath: DetailsPanel propertyPath: DetailsPanel
value: value:
objectReference: {fileID: 724043967} objectReference: {fileID: 724043967}
- target: {fileID: 11432906, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2}
propertyPath: FriendshipLikeliness
value: .600000024
objectReference: {fileID: 0}
- target: {fileID: 11432906, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2}
propertyPath: NumPeople
value: 50
objectReference: {fileID: 0}
- target: {fileID: 11432906, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2}
propertyPath: AvgNumFriends
value: 4
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0

View File

@ -2,7 +2,7 @@
using System.Collections; using System.Collections;
[RequireComponent(typeof(LineRenderer))] [RequireComponent(typeof(LineRenderer))]
public class FriendshipLink : MonoBehaviour public class Link : MonoBehaviour
{ {
public Color HighlightedColor = new Color(1f, 1f, 1f, 0.5f); public Color HighlightedColor = new Color(1f, 1f, 1f, 0.5f);

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,25 +1,53 @@
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 : Observable, 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; } }
private Friendship other;
public Friendship Other { get { return other; } set { other = value; } }
public Friendship(Person p1, Person p2, int scale) private FriendshipLink link;
public FriendshipLink Link { get { return link; } }
private float awareness = 0; //on a scale from 0 to 1
public float Awareness { get { return awareness; } }
public Friendship(Person self, Person friend)
{ {
friend1 = p1; this.self = self;
friend2 = p2; this.friend = friend;
importance = scale;
} }
public Person GetFriend(Person p) public void Update(float deltaTime)
{ {
if (p == friend1) //This function is only called when friend is dead
return friend2; awareness = Mathf.Max(awareness + deltaTime * CalculateWeight(), 100);
return friend1;
NotifyObservers();
}
//returns a number between 0 and 1
private float CalculateWeight()
{
float weight = 0;
weight += link.Importance;
return weight;
}
internal enum Knowledge
{
Alive, Doubt, Dead
} }
} }
} }

View File

@ -0,0 +1,26 @@
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 risk = 0; //on a scale from 0 to 1
public float Risk { get { return risk; } }
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

@ -21,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);
} }
@ -60,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;
@ -80,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;
@ -90,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));
} }
@ -115,16 +111,24 @@ namespace DeathBook.Model
} }
list.Remove(smallest); list.Remove(smallest);
} }
Debug.Log("Friends + " + p1.FriendCount);
} }
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.Range(1,100));
p1.AddFriendship(f); Friendship f1 = new Friendship(p1, p2);
p2.AddFriendship(f); Friendship f2 = new Friendship(p2, p1);
f1.Other = f2;
f2.Other = f1;
p1.AddFriendship(f1);
p2.AddFriendship(f2);
return f; return f;
} }
@ -133,9 +137,7 @@ namespace DeathBook.Model
Vector3 pos = new Vector3(x, y, z); Vector3 pos = new Vector3(x, y, z);
//Vector2 times = //Vector2 times =
//Person p = new Person(id, pos,);
Person p = new Person(id, pos); Person p = new Person(id, pos);
p.initialPosition = pos;
return p; return p;
} }
@ -149,19 +151,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

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 43fe8f02e31afb5499ff01247a389c14 guid: ccfb5fe3d9ad971499b807bde15217c4
timeCreated: 1439506745 timeCreated: 1439591141
licenseType: Free licenseType: Free
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2

View File

@ -1,82 +1,86 @@
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 int id;
private string name; public int Id { get { return id; } }
private List<Friendship> friendList = new List<Friendship>();
public Vector3 initialPosition; private string firstName;
public int numFriends; 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; private int timeBetweenPosts; // f = 1/T;
private int connectionTime; public int TimeBetweenPosts { get { return timeBetweenPosts; } }
private int disconnectionTime;
private int awarenessLevel;
private bool alive;
private int happiness; private float connectionTime;
private bool connected; public float ConnectionTime { get { return connectionTime; } }
//private Node node; private float disconnectionTime;
public float DisconnectionTime { get { return disconnectionTime; } }
public string Name private float awarenessLevel = 0; //on a scale from 0 to 1
{ public float AwarenessLevel { get { return awarenessLevel; } }
get { return name; }
}
public bool Alive private bool alive = true;
{ public bool Alive { get { return alive; } }
get { return alive; }
}
public int AwarenessLevel //private int happiness = 1; //on a scale from 0 to 1
{ //public int Happiness { get { return happiness; } }
get { return awarenessLevel; }
}
public List<Friendship> FriendList private bool online = false;
{ public bool Online { get { return online; } }
get { return friendList; }
}
public int FriendsCount
{
get { return numFriends; }
}
public bool Online
{
get { return connected; }
}
public Person(int id, Vector3 pos) public Person(int id, Vector3 pos)
{ {
this.id = id; this.id = id;
initialPosition = pos; initialPosition = pos;
alive = true;
// TODO Use names from db // TODO Use names from db
name = String.Format("Firstname{0} Lastname{0}", id); firstName = "Mark";
lastName = "Zuckerberg";
} }
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 KillFriend(Friendship f)
{ {
return disconnectionTime > time && time > connectionTime; numAliveFriends--;
numDeadFriends++;
deadFriendsList.Add(f);
} }
private int calculateWeight() public void Update(float deltaTime)
{ {
//friendCount * ____ + 1/timeBetweenPosts + } //TODO Update if connected
return 0; int time = LevelManager.Instance.GameLevel.GameTime;
//The following actions are only performed if user is online
if (!Online)
return;
} }
} }
} }

View File

@ -5,7 +5,7 @@ using DeathBook.Model;
public class NetworkingSphere : MonoBehaviour public class NetworkingSphere : MonoBehaviour
{ {
public FriendshipLink LinkObj; public Link LinkObj;
public PersonNode PersonObj; public PersonNode PersonObj;
public int NumPeople = 50; public int NumPeople = 50;
public int AvgNumFriends = 20; public int AvgNumFriends = 20;
@ -22,14 +22,14 @@ public class NetworkingSphere : MonoBehaviour
private Rigidbody rb; private Rigidbody rb;
private PersonNode[] peopleNodes; private PersonNode[] peopleNodes;
//TODO private Friendship[] friendships;
private PersonNode _selectedNode; private PersonNode _selectedNode;
void Awake() void Awake()
{ {
LevelGenerator lGen = new LevelGenerator(); LevelManager manager = LevelManager.Instance;
Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius); manager.NewLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius);
Level lvl = manager.GameLevel;
InstantiateNodes(lvl); InstantiateNodes(lvl);
AssignLinks(lvl); AssignLinks(lvl);
@ -87,13 +87,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(PersonObj, person.InitialPosition, Quaternion.identity) as PersonNode;
pInst.OnClicked += OnNodeClicked; pInst.OnClicked += OnNodeClicked;
@ -119,11 +119,11 @@ 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(LinkObj) as Link;
int id1 = f.friend1.id; int id1 = f.Friend1.id;
int id2 = f.friend2.id; int id2 = f.Friend2.id;
link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject); link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject);
// Temporary stuff, for testing // Temporary stuff, for testing

View File

@ -1,30 +1,33 @@
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
private List<IObserver> observers; public abstract class Observable
{
public Observable() private List<IObserver> observers;
{
observers = new List<IObserver>(); public Observable()
} {
observers = new List<IObserver>();
public void Subscribe(IObserver observer) }
{
observers.Add(observer); public void Subscribe(IObserver observer)
} {
observers.Add(observer);
public void UnSubscribe(IObserver observer) }
{
observers.Remove(observer); public void UnSubscribe(IObserver observer)
} {
observers.Remove(observer);
public void NotifyObservers() }
{
foreach (IObserver observer in observers) public void NotifyObservers()
{ {
observer.Notify(); foreach (IObserver observer in observers)
} {
} observer.Notify();
}
}
}
} }

View File

@ -1,4 +1,7 @@
public interface IObserver namespace DeathBook.Util
{ {
void Notify(); public interface IObserver
{
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

@ -1,7 +1,8 @@
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;
public class PersonDetailsPanel : MonoBehaviour, IObserver public class PersonDetailsPanel : MonoBehaviour, IObserver
{ {

View File

@ -1,7 +1,8 @@
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 System; using System;
[RequireComponent(typeof(Collider))] [RequireComponent(typeof(Collider))]
@ -18,7 +19,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;
@ -39,7 +40,7 @@ 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>();
} }
@ -50,7 +51,7 @@ public class PersonNode : MonoBehaviour, IObserver
_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);
} }
@ -72,7 +73,7 @@ public class PersonNode : MonoBehaviour, IObserver
private void UpdateLinks(bool state) private void UpdateLinks(bool state)
{ {
foreach (FriendshipLink link in _links) foreach (Link link in _links)
{ {
link.Highlight(state, 1f); link.Highlight(state, 1f);
} }

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,16 +0,0 @@
using UnityEngine;
using System.Collections;
using DeathBook.Model;
public class SRTest : MonoBehaviour {
// Use this for initialization
void Start () {
Utils.Test();
}
// Update is called once per frame
void Update () {
}
}

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