diff --git a/Assets/Scenes/BeamTest.unity b/Assets/Scenes/BeamTest.unity index 86bf24c..495da21 100644 --- a/Assets/Scenes/BeamTest.unity +++ b/Assets/Scenes/BeamTest.unity @@ -145,8 +145,8 @@ Camera: height: 1 near clip plane: .300000012 far clip plane: 1000 - field of view: 60 - orthographic: 1 + field of view: 49 + orthographic: 0 orthographic size: 5 m_Depth: -1 m_CullingMask: @@ -165,141 +165,12 @@ Transform: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 61719360} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -10} + m_LocalRotation: {x: -.259112954, y: .110958092, z: -.0299803261, w: -.958983839} + m_LocalPosition: {x: 2.95000005, y: 9.18000031, z: -15.3199997} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 ---- !u!1001 &110979653 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_LocalPosition.x - value: -4.78000021 - objectReference: {fileID: 0} - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_LocalPosition.y - value: 2.84048653 - objectReference: {fileID: 0} - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_LocalRotation.x - value: .70710659 - objectReference: {fileID: 0} - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_LocalRotation.w - value: -.707106948 - objectReference: {fileID: 0} - - target: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - propertyPath: m_RootOrder - value: 4 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - m_IsPrefabParent: 0 ---- !u!4 &312333934 stripped -Transform: - m_PrefabParentObject: {fileID: 456258, guid: c5b66487a8909dc42a46e73c0b340df0, type: 2} - m_PrefabInternal: {fileID: 110979653} ---- !u!120 &326773241 stripped -LineRenderer: - m_PrefabParentObject: {fileID: 12095142, guid: fab430cecad80ad4391987a06b550cb7, - type: 2} - m_PrefabInternal: {fileID: 1631297195} ---- !u!1001 &397033313 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalPosition.x - value: -.573046267 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalPosition.y - value: -.809006572 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_RootOrder - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: StartPoint - value: - objectReference: {fileID: 1070389998} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: EndPoint - value: - objectReference: {fileID: 1040435545} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: BeamLine - value: - objectReference: {fileID: 1979266189} - - target: {fileID: 195136, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 195134, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: StartObject - value: - objectReference: {fileID: 312333934} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: EndObject - value: - objectReference: {fileID: 1398388657} - - target: {fileID: 12095142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_Materials.Array.data[0] - value: - objectReference: {fileID: 2100000, guid: 40733a86ddd05214d99d64b3771e45b6, type: 2} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - m_IsPrefabParent: 0 ---- !u!4 &734198074 stripped -Transform: - m_PrefabParentObject: {fileID: 495134, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - m_PrefabInternal: {fileID: 1631297195} + m_RootOrder: 0 --- !u!1 &736567784 GameObject: m_ObjectHideFlags: 0 @@ -373,7 +244,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 7 + m_RootOrder: 2 --- !u!114 &736567789 MonoBehaviour: m_ObjectHideFlags: 0 @@ -385,17 +256,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0907c1567bad554c8b995de3459e517, type: 3} m_Name: m_EditorClassIdentifier: + Link: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} SpherePrototype: {fileID: 140654, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2} - PointsAmount: 1000 - SphereRadius: 5 ---- !u!4 &1040435545 stripped -Transform: - m_PrefabParentObject: {fileID: 495134, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - m_PrefabInternal: {fileID: 397033313} ---- !u!4 &1070389998 stripped -Transform: - m_PrefabParentObject: {fileID: 495136, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - m_PrefabInternal: {fileID: 397033313} + PointsAmount: 400 + SphereRadius: 7 --- !u!1 &1126063559 GameObject: m_ObjectHideFlags: 0 @@ -411,7 +275,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!108 &1126063560 Light: m_ObjectHideFlags: 0 @@ -455,237 +319,4 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 3 ---- !u!1 &1398388656 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1398388657} - - 33: {fileID: 1398388660} - - 64: {fileID: 1398388659} - - 23: {fileID: 1398388658} - m_Layer: 0 - m_Name: Person2 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1398388657 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1398388656} - m_LocalRotation: {x: .70710659, y: 0, z: 0, w: -.707106948} - m_LocalPosition: {x: .200000003, y: 3.32999992, z: 0} - m_LocalScale: {x: .100000001, y: .100000001, z: .100000001} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 5 ---- !u!23 &1398388658 -MeshRenderer: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1398388656} - 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!64 &1398388659 -MeshCollider: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1398388656} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Convex: 0 - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!33 &1398388660 -MeshFilter: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1398388656} - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!1 &1439566042 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1439566043} - - 33: {fileID: 1439566046} - - 64: {fileID: 1439566045} - - 23: {fileID: 1439566044} - m_Layer: 0 - m_Name: Person3 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1439566043 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1439566042} - m_LocalRotation: {x: .70710659, y: 0, z: 0, w: -.707106948} - m_LocalPosition: {x: 5.21999979, y: 2.51999998, z: 0} - m_LocalScale: {x: .100000001, y: .100000001, z: .100000001} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 6 ---- !u!23 &1439566044 -MeshRenderer: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1439566042} - 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!64 &1439566045 -MeshCollider: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1439566042} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Convex: 0 - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!33 &1439566046 -MeshFilter: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1439566042} - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!1001 &1631297195 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalPosition.x - value: -.573046267 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalPosition.y - value: -.809006572 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_RootOrder - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: StartPoint - value: - objectReference: {fileID: 1777942510} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: EndPoint - value: - objectReference: {fileID: 734198074} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: BeamLine - value: - objectReference: {fileID: 326773241} - - target: {fileID: 195136, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 195134, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: StartObject - value: - objectReference: {fileID: 1398388657} - - target: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: EndObject - value: - objectReference: {fileID: 1439566043} - - target: {fileID: 12095142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_Materials.Array.data[0] - value: - objectReference: {fileID: 2100000, guid: 40733a86ddd05214d99d64b3771e45b6, type: 2} - - target: {fileID: 195142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - propertyPath: m_Name - value: AspiBeam 1 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - m_IsPrefabParent: 0 ---- !u!4 &1777942510 stripped -Transform: - m_PrefabParentObject: {fileID: 495136, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - m_PrefabInternal: {fileID: 1631297195} ---- !u!120 &1979266189 stripped -LineRenderer: - m_PrefabParentObject: {fileID: 12095142, guid: fab430cecad80ad4391987a06b550cb7, - type: 2} - m_PrefabInternal: {fileID: 397033313} + m_RootOrder: 1 diff --git a/Assets/Tests/Beam/Beam.cs b/Assets/Tests/Beam/FriendshipLink.cs similarity index 65% rename from Assets/Tests/Beam/Beam.cs rename to Assets/Tests/Beam/FriendshipLink.cs index 6a7c042..d235180 100644 --- a/Assets/Tests/Beam/Beam.cs +++ b/Assets/Tests/Beam/FriendshipLink.cs @@ -1,21 +1,34 @@ using UnityEngine; using System.Collections; -public class Beam : MonoBehaviour +public class FriendshipLink : MonoBehaviour { - public Transform StartPoint; - public Transform EndPoint; - public LineRenderer BeamLine; + [SerializeField] + private Transform StartPoint; + + [SerializeField] + private Transform EndPoint; + + [SerializeField] + private LineRenderer BeamLine; //public ParticleSystem BeamParticles; - public Transform StartObject; - public Transform EndObject; + [SerializeField] + private Transform StartObject; + + [SerializeField] + private Transform EndObject; private float LIFETIME_RATIO = 0.025f; void Awake() { BeamLine.SetWidth(0.2f, 0.2f); + + Renderer lineRenderer = BeamLine.GetComponent(); + + lineRenderer.material = Instantiate(lineRenderer.material); + //Activate(false); } @@ -34,8 +47,8 @@ public class Beam : MonoBehaviour private void UpdateVisualEffects() { - StartPoint.position = StartObject.position + new Vector3(0f, 0f, 0.5f); - EndPoint.position = EndObject.position + new Vector3(0f, 0f, 0.5f); + StartPoint.position = StartObject.position + new Vector3(0f, 0f, 0f); + EndPoint.position = EndObject.position + new Vector3(0f, 0f, 0f); float angle = Vector3.Angle(EndPoint.position - StartPoint.position, transform.right); @@ -50,4 +63,10 @@ public class Beam : MonoBehaviour BeamLine.SetPosition(0, StartPoint.position); BeamLine.SetPosition(1, EndPoint.position); } + + public void AttachToObjects(GameObject origin, GameObject destination) + { + StartObject = origin.transform; + EndObject = destination.transform; + } } diff --git a/Assets/Tests/Beam/Beam.cs.meta b/Assets/Tests/Beam/FriendshipLink.cs.meta similarity index 100% rename from Assets/Tests/Beam/Beam.cs.meta rename to Assets/Tests/Beam/FriendshipLink.cs.meta diff --git a/Assets/Tests/Beam/AspiBeam.prefab b/Assets/Tests/Beam/FriendshipLink.prefab similarity index 99% rename from Assets/Tests/Beam/AspiBeam.prefab rename to Assets/Tests/Beam/FriendshipLink.prefab index 9dd054e..6c30efa 100644 --- a/Assets/Tests/Beam/AspiBeam.prefab +++ b/Assets/Tests/Beam/FriendshipLink.prefab @@ -73,7 +73,7 @@ GameObject: - 4: {fileID: 495142} - 114: {fileID: 11495142} m_Layer: 0 - m_Name: AspiBeam + m_Name: FriendshipLink m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -135,7 +135,7 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 195142} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -3.6500001, z: 0} + m_LocalPosition: {x: -.573046267, y: -.809006572, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 495136} @@ -154,9 +154,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c495d00d780bd3d49866ec60f5efbf66, type: 3} m_Name: m_EditorClassIdentifier: - StartPoint: {fileID: 0} - EndPoint: {fileID: 0} - BeamLine: {fileID: 0} + StartPoint: {fileID: 495136} + EndPoint: {fileID: 495134} + BeamLine: {fileID: 12095142} StartObject: {fileID: 0} EndObject: {fileID: 0} --- !u!120 &12095142 @@ -169,7 +169,7 @@ LineRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_Materials: - - {fileID: 2100000, guid: 6e2fd46a10c2e3d4eaf42976ce304c87, type: 2} + - {fileID: 2100000, guid: 40733a86ddd05214d99d64b3771e45b6, type: 2} m_SubsetIndices: m_StaticBatchRoot: {fileID: 0} m_UseLightProbes: 0 diff --git a/Assets/Tests/Beam/AspiBeam.prefab.meta b/Assets/Tests/Beam/FriendshipLink.prefab.meta similarity index 100% rename from Assets/Tests/Beam/AspiBeam.prefab.meta rename to Assets/Tests/Beam/FriendshipLink.prefab.meta diff --git a/Assets/Tests/Beam/Materials/laserPic.mat b/Assets/Tests/Beam/Materials/laserPic.mat index 14f5b7b..3f0025c 100644 --- a/Assets/Tests/Beam/Materials/laserPic.mat +++ b/Assets/Tests/Beam/Materials/laserPic.mat @@ -19,7 +19,7 @@ Material: name: _MainTex second: m_Texture: {fileID: 2800000, guid: dce27f2c9adab1144824c9b2040f18d5, type: 3} - m_Scale: {x: 1, y: 1} + m_Scale: {x: 24.6399994, y: 1} m_Offset: {x: 0, y: 0} data: first: @@ -150,4 +150,4 @@ Material: data: first: name: _TintColor - second: {r: .5, g: .5, b: .5, a: .5} + second: {r: .257352948, g: .10029196, b: .233522967, a: .501960814} diff --git a/Assets/Tests/Sphere.cs b/Assets/Tests/Sphere.cs index 97323a4..a085ad5 100644 --- a/Assets/Tests/Sphere.cs +++ b/Assets/Tests/Sphere.cs @@ -3,74 +3,62 @@ using System.Collections; public class Sphere : MonoBehaviour { + public FriendshipLink Link; public GameObject SpherePrototype; public int PointsAmount = 50; public float SphereRadius = 1f; + private GameObject[] nodes; + void Awake() { - // First test (Orion Elenzil) - /* - for (int i = 0; i < PointsAmount; i++) - { - float theta = (360f / PointsAmount) * i; - float phi = (Mathf.PI / 2 / PointsAmount) * i; + InstantiateNodes(); + AssignLinks(); + } - float x = Mathf.Cos(Mathf.Sqrt(phi)) * Mathf.Cos(theta); - float y = Mathf.Cos(Mathf.Sqrt(phi)) * Mathf.Sin(theta); - float z = (UnityEngine.Random.value < 0.5f ? -1 : 1) * Mathf.Sin(Mathf.Sqrt(phi)); - Debug.Log(UnityEngine.Random.value); - Instantiate(SpherePrototype, new Vector3(x, y, z), Quaternion.identity); - }*/ + private void InstantiateNodes() + { + /* Sphere uniform distribution using the spiral method with the golden angle + * ~2.39996323 rad, the golden angle (the most irrational angle) + * is used here to make sure that the sin and cos functions + * dont end up drawing clusters of points and the spirals are way + * less visible. + */ + nodes = new GameObject[PointsAmount]; - // Second test (default unit sphere random distribution) - /* - for (int i = 0; i < PointsAmount; i++) - { - float u = UnityEngine.Random.Range(-1f, 1f); - float a = UnityEngine.Random.Range(0f, 2 * Mathf.PI); - - float x = Mathf.Sqrt(1 - u * u) * Mathf.Cos(a); - float y = Mathf.Sqrt(1 - u * u) * Mathf.Sin(a); - float z = u; + float goldenAngle = Mathf.PI * (3 - Mathf.Sqrt(5)); - Instantiate(SpherePrototype, new Vector3(x, y, z), Quaternion.identity); - }*/ - - // Third test (sphere semi-uniform distribution) - /* - for (int i = 0; i < PointsAmount; i++) - { - float u = (SphereRadius * 2 / PointsAmount) * i - SphereRadius; - float a = UnityEngine.Random.Range(0f, 2 * Mathf.PI); // ((2 * Mathf.PI) / PointsAmount) * i; - - Debug.Log(a); - - float x = Mathf.Sqrt(SphereRadius * SphereRadius - u * u) * Mathf.Cos(a); - float y = Mathf.Sqrt(SphereRadius * SphereRadius - u * u) * Mathf.Sin(a); - float z = u; - - Instantiate(SpherePrototype, new Vector3(x, y, z), Quaternion.identity); - }*/ - - // Fourth test (sphere uniform distribution using the spiral method) - float dlong = Mathf.PI * (3 - Mathf.Sqrt(5)); //~2.39996323 - - float dz = (2f/PointsAmount) * SphereRadius; + float zDistance = (2f / PointsAmount) * SphereRadius; float longitude = 0f; - float z = SphereRadius - dz/2; + float z = SphereRadius; for (int i = 0; i < PointsAmount; i++) - { + { float r = Mathf.Sqrt(SphereRadius * SphereRadius - z * z); - float x = Mathf.Cos(longitude) * r; - float y = Mathf.Sin(longitude) * r; + float x = Mathf.Sin(longitude) * r; + float y = Mathf.Cos(longitude) * r; - Instantiate(SpherePrototype, new Vector3(x, y, z), Quaternion.identity); + GameObject simon = Instantiate(SpherePrototype, new Vector3(x, y, z), Quaternion.identity) as GameObject; - z -= dz; - longitude += dlong; - } + simon.transform.parent = this.transform; + + nodes[i] = simon; + + z -= zDistance; + longitude += goldenAngle; + } + } + + private void AssignLinks() + { + for (int i = 0; i < nodes.Length / 4; i++) + { + FriendshipLink link = Instantiate(Link) as FriendshipLink; + + int destinationIndex = Random.Range(nodes.Length / 2, nodes.Length - 1); + + link.AttachToObjects(nodes[i], nodes[destinationIndex]); + } } }