- Added the links highlighting when hovering on a node and stopping the

sphere rotation when hovering over it
This commit is contained in:
Patrice Vignola 2015-08-12 13:48:16 -04:00
parent d6f894d453
commit d414ed7f6e
11 changed files with 118 additions and 125 deletions

View File

@ -145,7 +145,7 @@ Camera:
height: 1
near clip plane: .300000012
far clip plane: 1000
field of view: 49
field of view: 59
orthographic: 0
orthographic size: 5
m_Depth: -1
@ -165,8 +165,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 61719360}
m_LocalRotation: {x: -.259112954, y: .110958092, z: -.0299803261, w: -.958983839}
m_LocalPosition: {x: 2.95000005, y: 9.18000031, z: -15.3199997}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -15.1300001}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -180,7 +180,6 @@ GameObject:
m_Component:
- 4: {fileID: 736567788}
- 33: {fileID: 736567787}
- 135: {fileID: 736567786}
- 23: {fileID: 736567785}
- 114: {fileID: 736567789}
m_Layer: 0
@ -196,7 +195,7 @@ MeshRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 736567784}
m_Enabled: 1
m_Enabled: 0
m_CastShadows: 1
m_ReceiveShadows: 1
m_Materials:
@ -214,18 +213,6 @@ MeshRenderer:
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!135 &736567786
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 736567784}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: .5
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &736567787
MeshFilter:
m_ObjectHideFlags: 0
@ -257,7 +244,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Link: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2}
SpherePrototype: {fileID: 140654, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2}
Person: {fileID: 11406500, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2}
PointsAmount: 400
SphereRadius: 7
rotationSpeed: .699999988

View File

@ -1,8 +1,11 @@
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(LineRenderer))]
public class FriendshipLink : MonoBehaviour
{
public Color HighlightedColor = new Color(1f, 1f, 1f, 0.5f);
[SerializeField]
private Transform StartPoint;
@ -21,13 +24,19 @@ public class FriendshipLink : MonoBehaviour
private float LIFETIME_RATIO = 0.025f;
private Renderer _renderer;
private Color _defaultColor;
void Awake()
{
// Set the importance (weight) of the link here
BeamLine.SetWidth(0.2f, 0.2f);
Renderer lineRenderer = BeamLine.GetComponent<Renderer>();
_renderer = BeamLine.GetComponent<Renderer>();
lineRenderer.material = Instantiate(lineRenderer.material);
_renderer.material = Instantiate(_renderer.material);
_defaultColor = _renderer.material.GetColor("_TintColor");
//Activate(false);
}
@ -69,4 +78,11 @@ public class FriendshipLink : MonoBehaviour
StartObject = origin.transform;
EndObject = destination.transform;
}
public void Highlight(bool state, float weight)
{
// For now, the weight does nothing but it should eventually influence the intensity and size of the link
_renderer.material.SetColor("_TintColor", state ? HighlightedColor : _defaultColor);
}
}

View File

@ -154,6 +154,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c495d00d780bd3d49866ec60f5efbf66, type: 3}
m_Name:
m_EditorClassIdentifier:
HighlightedColor: {r: 1, g: 1, b: 1, a: .501960814}
StartPoint: {fileID: 495136}
EndPoint: {fileID: 495134}
BeamLine: {fileID: 12095142}

View File

@ -1,86 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &106018
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 4: {fileID: 456258}
- 33: {fileID: 3369818}
- 64: {fileID: 6498216}
- 23: {fileID: 2339886}
m_Layer: 0
m_Name: Person
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &456258
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 106018}
m_LocalRotation: {x: .70710659, y: 0, z: 0, w: -.707106948}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: .100000001, y: .100000001, z: .100000001}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!23 &2339886
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 106018}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 1
m_ReflectionProbeUsage: 1
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_ImportantGI: 0
m_AutoUVMaxDistance: .5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!33 &3369818
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 106018}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!64 &6498216
MeshCollider:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 106018}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 106018}
m_IsPrefabParent: 1

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: c5b66487a8909dc42a46e73c0b340df0
timeCreated: 1439311712
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +1,16 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Sphere : MonoBehaviour
public class Center : MonoBehaviour
{
public FriendshipLink Link;
public GameObject SpherePrototype;
public PersonTest Person;
public int PointsAmount = 50;
public float SphereRadius = 1f;
public float rotationSpeed = 0.7f;
private GameObject[] nodes;
private PersonTest[] people;
void Awake()
{
@ -19,7 +20,17 @@ public class Sphere : MonoBehaviour
void Update()
{
transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed);
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);
}
}
private void InstantiateNodes()
@ -30,7 +41,7 @@ public class Sphere : MonoBehaviour
* dont end up drawing clusters of points and the spirals are way
* less visible.
*/
nodes = new GameObject[PointsAmount];
people = new PersonTest[PointsAmount];
float goldenAngle = Mathf.PI * (3 - Mathf.Sqrt(5));
@ -45,11 +56,11 @@ public class Sphere : MonoBehaviour
float x = Mathf.Sin(longitude) * r;
float y = Mathf.Cos(longitude) * r;
GameObject simon = Instantiate(SpherePrototype, new Vector3(x, y, z), Quaternion.identity) as GameObject;
PersonTest simon = Instantiate(Person, new Vector3(x, y, z), Quaternion.identity) as PersonTest;
simon.transform.parent = this.transform;
nodes[i] = simon;
people[i] = simon;
z -= zDistance;
longitude += goldenAngle;
@ -58,13 +69,17 @@ public class Sphere : MonoBehaviour
private void AssignLinks()
{
for (int i = 0; i < nodes.Length / 4; i++)
for (int i = 0; i < people.Length / 4; i++)
{
FriendshipLink link = Instantiate(Link) as FriendshipLink;
int destinationIndex = Random.Range(nodes.Length / 2, nodes.Length - 1);
int destinationIndex = Random.Range(people.Length / 2, people.Length - 1);
link.AttachToObjects(nodes[i], nodes[destinationIndex]);
link.AttachToObjects(people[i].gameObject, people[destinationIndex].gameObject);
// Temporary stuff, for testing
people[i].AddLink(link);
people[destinationIndex].AddLink(link);
}
}
}

View File

@ -0,0 +1,44 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(Collider))]
public class PersonTest : MonoBehaviour
{
// Temporary, for test
private List<FriendshipLink> _links;
private bool _highlighted = false;
void Awake()
{
_links = new List<FriendshipLink>();
}
public void AddLink(FriendshipLink link)
{
_links.Add(link);
}
void OnMouseOver()
{
if (!_highlighted)
{
_highlighted = true;
foreach (FriendshipLink link in _links)
{
link.Highlight(true, 1f);
}
}
}
void OnMouseExit()
{
_highlighted = false;
foreach (FriendshipLink link in _links)
{
link.Highlight(false, 1f);
}
}
}

View File

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

View File

@ -11,8 +11,9 @@ GameObject:
- 33: {fileID: 3385696}
- 135: {fileID: 13525706}
- 23: {fileID: 2372112}
- 114: {fileID: 11406500}
m_Layer: 0
m_Name: Sphere
m_Name: PersonTest
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -61,6 +62,17 @@ MeshFilter:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 140654}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &11406500
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 140654}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91655186257590a4297df8939c1a2256, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!135 &13525706
SphereCollider:
m_ObjectHideFlags: 1