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/Scripts/Models/Person.cs Signed-off-by: RosimInc <rosim_inc@hotmail.com>
This commit is contained in:
commit
46f1f7a320
@ -96,6 +96,7 @@ MonoBehaviour:
|
||||
SphereRadius: 7
|
||||
rotationSpeed: .699999988
|
||||
torqueForce: 1
|
||||
DetailsPanel: {fileID: 0}
|
||||
--- !u!1001 &100100000
|
||||
Prefab:
|
||||
m_ObjectHideFlags: 1
|
||||
|
||||
1491
Assets/Prefabs/PersonDetailsPanel.prefab
Normal file
1491
Assets/Prefabs/PersonDetailsPanel.prefab
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/Prefabs/PersonDetailsPanel.prefab.meta
Normal file
8
Assets/Prefabs/PersonDetailsPanel.prefab.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c993e87661906234fba410e55ed66832
|
||||
timeCreated: 1439501018
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@ -258,14 +258,15 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: d0907c1567bad554c8b995de3459e517, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
nextPosition: {x: 0, y: 0, z: 0}
|
||||
moveSpeed: 1
|
||||
Link: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2}
|
||||
Person: {fileID: 11406500, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2}
|
||||
PointsAmount: 200
|
||||
LinkObj: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2}
|
||||
PersonObj: {fileID: 11406500, guid: d4b0e683ea5ec974987ea1f6741b333c, type: 2}
|
||||
NumPeople: 50
|
||||
AvgNumFriends: 8
|
||||
FriendshipLikeliness: .400000006
|
||||
SphereRadius: 7
|
||||
rotationSpeed: .699999988
|
||||
torqueForce: 35
|
||||
torqueForce: .100000001
|
||||
DetailsPanel: {fileID: 0}
|
||||
--- !u!54 &736567790
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -1,29 +1,55 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace DeathBook.Model
|
||||
{
|
||||
public class Person
|
||||
public class Person : Observable
|
||||
{
|
||||
public int id;
|
||||
private string name;
|
||||
private List<Friendship> friendList = new List<Friendship>();
|
||||
public Vector3 initialPosition;
|
||||
public float connectionTime;
|
||||
public float disconnectionTime;
|
||||
public float awarenessLevel;
|
||||
public bool alive;
|
||||
public bool connected;
|
||||
|
||||
public int numFriends;
|
||||
public int timeBetweenPosts; // f = 1/T;
|
||||
public float importance; // Size of the quad
|
||||
private int timeBetweenPosts; // f = 1/T;
|
||||
private int connectionTime;
|
||||
private int disconnectionTime;
|
||||
private int awarenessLevel;
|
||||
private bool alive;
|
||||
|
||||
private int happiness;
|
||||
private bool connected;
|
||||
|
||||
public Person(int id)
|
||||
//private Node node;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public bool Alive
|
||||
{
|
||||
get { return alive; }
|
||||
}
|
||||
|
||||
public List<Friendship> FriendList
|
||||
{
|
||||
get { return friendList; }
|
||||
}
|
||||
|
||||
public int FriendsCount
|
||||
{
|
||||
get { return numFriends; }
|
||||
}
|
||||
|
||||
public Person(int id, float x, float y, float z)
|
||||
{
|
||||
this.id = id;
|
||||
initialPosition = new Vector3(x, y, z);
|
||||
alive = true;
|
||||
|
||||
// Temporary
|
||||
name = String.Format("Firstname{0} Lastname{0}", id);
|
||||
}
|
||||
|
||||
public void AddFriendship(Friendship f)
|
||||
|
||||
@ -14,13 +14,17 @@ public class NetworkingSphere : MonoBehaviour
|
||||
public float rotationSpeed = 0.7f;
|
||||
|
||||
public float torqueForce = 50f;
|
||||
|
||||
public PersonDetailsPanel DetailsPanel;
|
||||
|
||||
private bool dragging = false;
|
||||
private Vector3 delta = new Vector3();
|
||||
private Rigidbody rb;
|
||||
|
||||
private PersonTest[] peopleNodes;
|
||||
//TODO private Friendship[] friendships;
|
||||
private GameObject[] nodes;
|
||||
|
||||
private PersonTest _selectedNode;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@ -73,30 +77,43 @@ public class NetworkingSphere : MonoBehaviour
|
||||
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 PersonTest[lvl.people.Count];
|
||||
|
||||
int ctr = 0;
|
||||
foreach (Person p in lvl.people)
|
||||
for (int i = 0; i < lvl.people.Count; i++)
|
||||
{
|
||||
Person person = lvl.people[i];
|
||||
|
||||
PersonTest pInst = Instantiate(PersonObj, p.initialPosition, Quaternion.identity) as PersonTest;
|
||||
PersonTest pInst = Instantiate(PersonObj, person.initialPosition, Quaternion.identity) as PersonTest;
|
||||
|
||||
pInst.OnClicked += OnNodeClicked;
|
||||
|
||||
pInst.Model = person;
|
||||
pInst.transform.parent = this.transform;
|
||||
|
||||
peopleNodes[ctr++] = pInst;
|
||||
peopleNodes[i] = pInst;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNodeClicked(PersonTest node)
|
||||
{
|
||||
if (_selectedNode != null)
|
||||
{
|
||||
_selectedNode.Select(false);
|
||||
}
|
||||
|
||||
DetailsPanel.SetModel(node.Model);
|
||||
node.Select(true);
|
||||
|
||||
_selectedNode = node;
|
||||
}
|
||||
|
||||
private void AssignLinks(Level lvl)
|
||||
{
|
||||
foreach (Friendship f in lvl.friendships)
|
||||
|
||||
9
Assets/Scripts/ObserverPattern.meta
Normal file
9
Assets/Scripts/ObserverPattern.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6311c3ae692eaf4e8eaefeade0e6efe
|
||||
folderAsset: yes
|
||||
timeCreated: 1439504971
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Scripts/ObserverPattern/IObservable.cs
Normal file
30
Assets/Scripts/ObserverPattern/IObservable.cs
Normal file
@ -0,0 +1,30 @@
|
||||
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
|
||||
public abstract class Observable
|
||||
{
|
||||
private List<IObserver> observers;
|
||||
|
||||
public Observable()
|
||||
{
|
||||
observers = new List<IObserver>();
|
||||
}
|
||||
|
||||
public void Subscribe(IObserver observer)
|
||||
{
|
||||
observers.Add(observer);
|
||||
}
|
||||
|
||||
public void UnSubscribe(IObserver observer)
|
||||
{
|
||||
observers.Remove(observer);
|
||||
}
|
||||
|
||||
public void NotifyObservers()
|
||||
{
|
||||
foreach (IObserver observer in observers)
|
||||
{
|
||||
observer.Notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/ObserverPattern/IObservable.cs.meta
Normal file
12
Assets/Scripts/ObserverPattern/IObservable.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fa909f4a3c7e864ab7aac7e4412a385
|
||||
timeCreated: 1439504995
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
4
Assets/Scripts/ObserverPattern/IObserver.cs
Normal file
4
Assets/Scripts/ObserverPattern/IObserver.cs
Normal file
@ -0,0 +1,4 @@
|
||||
public interface IObserver
|
||||
{
|
||||
void Notify();
|
||||
}
|
||||
12
Assets/Scripts/ObserverPattern/IObserver.cs.meta
Normal file
12
Assets/Scripts/ObserverPattern/IObserver.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acec16464aa31de4682453e1430bba0b
|
||||
timeCreated: 1439504989
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +1,9 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
using DeathBook.Model;
|
||||
|
||||
public class PersonDetailsPanel : MonoBehaviour
|
||||
public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||
{
|
||||
public Image ProfilePicture;
|
||||
public Text Name;
|
||||
@ -10,4 +11,29 @@ public class PersonDetailsPanel : MonoBehaviour
|
||||
public Button KillButton;
|
||||
public Button WatchButton;
|
||||
public Button XButton;
|
||||
|
||||
private Person _model;
|
||||
|
||||
public void SetModel(Person model)
|
||||
{
|
||||
if (_model != null)
|
||||
{
|
||||
_model.UnSubscribe(this);
|
||||
}
|
||||
|
||||
_model.Subscribe(this);
|
||||
|
||||
_model = model;
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
public void Notify()
|
||||
{
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
private void UpdateInfo()
|
||||
{
|
||||
Name.text = _model.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +1,35 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DeathBook.Model;
|
||||
using System;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class PersonTest : MonoBehaviour
|
||||
{
|
||||
public PersonDetailsPanel DetailsPanel;
|
||||
public Action<PersonTest> OnClicked;
|
||||
|
||||
public Color NormalColor;
|
||||
public Color SelectedColor;
|
||||
|
||||
// Temporary, for test
|
||||
private List<FriendshipLink> _links;
|
||||
private bool _highlighted = false;
|
||||
private bool _selected = false;
|
||||
|
||||
private Person _model;
|
||||
private Renderer _renderer;
|
||||
|
||||
public Person Model
|
||||
{
|
||||
set { _model = value; }
|
||||
get { return _model; }
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_links = new List<FriendshipLink>();
|
||||
_renderer = GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
public void AddLink(FriendshipLink link)
|
||||
@ -21,26 +37,49 @@ public class PersonTest : MonoBehaviour
|
||||
_links.Add(link);
|
||||
}
|
||||
|
||||
void OnMouseOver()
|
||||
public void Select(bool state)
|
||||
{
|
||||
if (!_highlighted)
|
||||
{
|
||||
_highlighted = true;
|
||||
_selected = state;
|
||||
UpdateLinks(state);
|
||||
_renderer.material.color = state ? SelectedColor : NormalColor;
|
||||
}
|
||||
|
||||
foreach (FriendshipLink link in _links)
|
||||
{
|
||||
link.Highlight(true, 1f);
|
||||
}
|
||||
private void UpdateLinks(bool state)
|
||||
{
|
||||
foreach (FriendshipLink link in _links)
|
||||
{
|
||||
link.Highlight(state, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseEnter()
|
||||
{
|
||||
if (!_selected && !_highlighted)
|
||||
{
|
||||
UpdateLinks(true);
|
||||
}
|
||||
|
||||
_highlighted = true;
|
||||
}
|
||||
|
||||
void OnMouseExit()
|
||||
{
|
||||
_highlighted = false;
|
||||
|
||||
foreach (FriendshipLink link in _links)
|
||||
if (!_selected)
|
||||
{
|
||||
link.Highlight(false, 1f);
|
||||
UpdateLinks(false);
|
||||
}
|
||||
|
||||
_highlighted = false;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
// The sphere should be subscribed to this event and update the data accordingly
|
||||
if (OnClicked != null)
|
||||
{
|
||||
OnClicked(this);
|
||||
}
|
||||
|
||||
Debug.Log("clicked");
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,6 +89,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 91655186257590a4297df8939c1a2256, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
SelectedColor: {r: 1, g: 0, b: 0, a: 1}
|
||||
--- !u!135 &13525706
|
||||
SphereCollider:
|
||||
m_ObjectHideFlags: 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user