mirror of
https://github.com/ConjureETS/DeathBook.git
synced 2026-03-24 04:20:58 +00:00
- Started the selection behavior when we click on a person node
This commit is contained in:
parent
c04fa49a39
commit
f626c164dd
@ -96,6 +96,7 @@ MonoBehaviour:
|
|||||||
SphereRadius: 7
|
SphereRadius: 7
|
||||||
rotationSpeed: .699999988
|
rotationSpeed: .699999988
|
||||||
torqueForce: 1
|
torqueForce: 1
|
||||||
|
DetailsPanel: {fileID: 0}
|
||||||
--- !u!1001 &100100000
|
--- !u!1001 &100100000
|
||||||
Prefab:
|
Prefab:
|
||||||
m_ObjectHideFlags: 1
|
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
@ -1,9 +1,10 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace DeathBook.Model
|
namespace DeathBook.Model
|
||||||
{
|
{
|
||||||
public class Person
|
public class Person : Observable
|
||||||
{
|
{
|
||||||
public int id;
|
public int id;
|
||||||
private string name;
|
private string name;
|
||||||
@ -21,10 +22,34 @@ namespace DeathBook.Model
|
|||||||
|
|
||||||
//private Node node;
|
//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)
|
public Person(int id, float x, float y, float z)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
initialPosition = new Vector3(x, y, z);
|
initialPosition = new Vector3(x, y, z);
|
||||||
|
alive = true;
|
||||||
|
|
||||||
|
// Temporary
|
||||||
|
name = String.Format("Firstname{0} Lastname{0}", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddFriendship(Friendship f)
|
public void AddFriendship(Friendship f)
|
||||||
|
|||||||
@ -14,13 +14,17 @@ public class NetworkingSphere : MonoBehaviour
|
|||||||
public float rotationSpeed = 0.7f;
|
public float rotationSpeed = 0.7f;
|
||||||
|
|
||||||
public float torqueForce = 50f;
|
public float torqueForce = 50f;
|
||||||
|
|
||||||
|
public PersonDetailsPanel DetailsPanel;
|
||||||
|
|
||||||
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 PersonTest[] peopleNodes;
|
private PersonTest[] peopleNodes;
|
||||||
//TODO private Friendship[] friendships;
|
//TODO private Friendship[] friendships;
|
||||||
private GameObject[] nodes;
|
|
||||||
|
private PersonTest _selectedNode;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@ -73,30 +77,43 @@ public class NetworkingSphere : MonoBehaviour
|
|||||||
rb.angularVelocity *= 0.8f;
|
rb.angularVelocity *= 0.8f;
|
||||||
}
|
}
|
||||||
delta += new Vector3(deltaX, deltaY, 0);
|
delta += new Vector3(deltaX, deltaY, 0);
|
||||||
//rigidbody.AddTorque();
|
|
||||||
rb.AddTorque(Vector3.down * delta.x * torqueForce * Time.deltaTime, ForceMode.Impulse);
|
rb.AddTorque(Vector3.down * delta.x * torqueForce * Time.deltaTime, ForceMode.Impulse);
|
||||||
rb.AddTorque(Vector3.right * delta.y * 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)
|
private void InstantiateNodes(Level lvl)
|
||||||
{
|
{
|
||||||
peopleNodes = new PersonTest[lvl.people.Count];
|
peopleNodes = new PersonTest[lvl.people.Count];
|
||||||
|
|
||||||
int ctr = 0;
|
for (int i = 0; i < lvl.people.Count; i++)
|
||||||
foreach (Person p in lvl.people)
|
|
||||||
{
|
{
|
||||||
|
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;
|
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)
|
private void AssignLinks(Level lvl)
|
||||||
{
|
{
|
||||||
foreach (Friendship f in lvl.friendships)
|
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 UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using DeathBook.Model;
|
||||||
|
|
||||||
public class PersonDetailsPanel : MonoBehaviour
|
public class PersonDetailsPanel : MonoBehaviour, IObserver
|
||||||
{
|
{
|
||||||
public Image ProfilePicture;
|
public Image ProfilePicture;
|
||||||
public Text Name;
|
public Text Name;
|
||||||
@ -10,4 +11,22 @@ public class PersonDetailsPanel : MonoBehaviour
|
|||||||
public Button KillButton;
|
public Button KillButton;
|
||||||
public Button WatchButton;
|
public Button WatchButton;
|
||||||
public Button XButton;
|
public Button XButton;
|
||||||
|
|
||||||
|
private Person _model;
|
||||||
|
|
||||||
|
public void SetModel(Person model)
|
||||||
|
{
|
||||||
|
_model = model;
|
||||||
|
UpdateInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Notify()
|
||||||
|
{
|
||||||
|
UpdateInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateInfo()
|
||||||
|
{
|
||||||
|
Name.text = _model.Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,35 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using DeathBook.Model;
|
||||||
|
using System;
|
||||||
|
|
||||||
[RequireComponent(typeof(Collider))]
|
[RequireComponent(typeof(Collider))]
|
||||||
|
[RequireComponent(typeof(Renderer))]
|
||||||
public class PersonTest : MonoBehaviour
|
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 List<FriendshipLink> _links;
|
||||||
private bool _highlighted = false;
|
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()
|
void Awake()
|
||||||
{
|
{
|
||||||
_links = new List<FriendshipLink>();
|
_links = new List<FriendshipLink>();
|
||||||
|
_renderer = GetComponent<Renderer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLink(FriendshipLink link)
|
public void AddLink(FriendshipLink link)
|
||||||
@ -21,26 +37,49 @@ public class PersonTest : MonoBehaviour
|
|||||||
_links.Add(link);
|
_links.Add(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseOver()
|
public void Select(bool state)
|
||||||
{
|
{
|
||||||
if (!_highlighted)
|
_selected = state;
|
||||||
{
|
UpdateLinks(state);
|
||||||
_highlighted = true;
|
_renderer.material.color = state ? SelectedColor : NormalColor;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (FriendshipLink link in _links)
|
private void UpdateLinks(bool state)
|
||||||
{
|
{
|
||||||
link.Highlight(true, 1f);
|
foreach (FriendshipLink link in _links)
|
||||||
}
|
{
|
||||||
|
link.Highlight(state, 1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnMouseEnter()
|
||||||
|
{
|
||||||
|
if (!_selected && !_highlighted)
|
||||||
|
{
|
||||||
|
UpdateLinks(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
_highlighted = true;
|
||||||
|
}
|
||||||
|
|
||||||
void OnMouseExit()
|
void OnMouseExit()
|
||||||
{
|
{
|
||||||
_highlighted = false;
|
if (!_selected)
|
||||||
|
|
||||||
foreach (FriendshipLink link in _links)
|
|
||||||
{
|
{
|
||||||
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_Script: {fileID: 11500000, guid: 91655186257590a4297df8939c1a2256, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
SelectedColor: {r: 1, g: 0, b: 0, a: 1}
|
||||||
--- !u!135 &13525706
|
--- !u!135 &13525706
|
||||||
SphereCollider:
|
SphereCollider:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user