Skip to content
Snippets Groups Projects
Commit 74a8996a authored by Marco Zimmer's avatar Marco Zimmer
Browse files

+ Misc: bug fixes, consistencies (Angle), refactoring;

parent fbf2233a
Branches MaZiFAU_TopSort
No related tags found
No related merge requests found
Showing
with 130 additions and 159 deletions
......@@ -2,14 +2,15 @@
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: LineMaterial
m_Shader: {fileID: 4800000, guid: 2649b895a4c22d649852a0ca4c825c74, type: 3}
m_ShaderKeywords:
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
......@@ -55,6 +56,7 @@ Material:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _ColorMask: 15
......@@ -81,3 +83,4 @@ Material:
m_Colors:
- _Color: {r: 0.2737103, g: 0.5471698, b: 0.028390888, a: 0.43529412}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
......@@ -2,14 +2,15 @@
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: RayMaterial
m_Shader: {fileID: 4800000, guid: 2649b895a4c22d649852a0ca4c825c74, type: 3}
m_ShaderKeywords:
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
......@@ -55,6 +56,7 @@ Material:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _ColorMask: 15
......@@ -81,3 +83,4 @@ Material:
m_Colors:
- _Color: {r: 0.027450988, g: 0.5252068, b: 0.54901963, a: 0.43529412}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
......@@ -81,6 +81,6 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.18332769, g: 0.6415094, b: 0.021181926, a: 0.9843137}
- _Color: {r: 0.993973, g: 1, b: 0, a: 0.9843137}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
......@@ -188,7 +188,7 @@ GameObject:
- component: {fileID: 7137147696081341476}
m_Layer: 12
m_Name: AngleOuter
m_TagString: Untagged
m_TagString: Selectable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -270,7 +270,7 @@ MeshCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 0
m_Convex: 1
m_CookingOptions: 30
m_Mesh: {fileID: 0}
--- !u!114 &3394522495515098196
......@@ -327,7 +327,7 @@ GameObject:
- component: {fileID: 3394522496185282007}
m_Layer: 12
m_Name: AngleInner
m_TagString: Untagged
m_TagString: Selectable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......
......@@ -14,7 +14,6 @@ public class CheckServer : MonoBehaviour
public static Process process;
public static ProcessStartInfo processInfo;
// Start is called before the first frame update
......@@ -29,8 +28,6 @@ void Start()
StartCoroutine(waiter(CommunicationEvents.IPslot2, 4, CommunicationEvents.IPcheckGeneration));
StartCoroutine(waiter(CommunicationEvents.IPslot3, 5, CommunicationEvents.IPcheckGeneration));
StartCoroutine(waiter(CommunicationEvents.IPslot3, 6, CommunicationEvents.IPcheckGeneration));
}
public void CheckIPAdr()
......@@ -44,49 +41,31 @@ public void CheckIPAdr()
//StartCoroutine(waiter(CommunicationEvents.IPslot1, 3, CommunicationEvents.IPcheckGeneration));
//StartCoroutine(waiter(CommunicationEvents.IPslot2, 4, CommunicationEvents.IPcheckGeneration));
//StartCoroutine(waiter(CommunicationEvents.IPslot3, 5, CommunicationEvents.IPcheckGeneration));
}
IEnumerator waiter(String NetwAddress, int NA_id, double ics)
{
//while(CommunicationEvents.IPcheckGeneration== ics)
while (CheckNetLoop == 1)
{
//Wait for 1 seconds
yield return new WaitForSecondsRealtime(1f);
if(CommunicationEvents.CheckServerA[NA_id] == 1)
if (CommunicationEvents.CheckServerA[NA_id] == 1)
{
CommunicationEvents.CheckServerA[NA_id] = 0;
switch (NA_id){
case 1:
NetwAddress = CommunicationEvents.lastIP;
break;
case 2:
NetwAddress = CommunicationEvents.newIP;
break;
case 3:
NetwAddress = CommunicationEvents.IPslot1;
break;
case 4:
NetwAddress = CommunicationEvents.IPslot2;
break;
case 5:
NetwAddress = CommunicationEvents.IPslot3;
break;
case 6:
NetwAddress = CommunicationEvents.selecIP;
break;
//default:
}
NetwAddress = NA_id switch
{
1 => CommunicationEvents.lastIP,
2 => CommunicationEvents.newIP,
3 => CommunicationEvents.IPslot1,
4 => CommunicationEvents.IPslot2,
5 => CommunicationEvents.IPslot3,
6 => CommunicationEvents.selecIP,
_ => NetwAddress,
};
if (string.IsNullOrEmpty(NetwAddress))
{
......@@ -128,70 +107,34 @@ IEnumerator waiter(String NetwAddress, int NA_id, double ics)
}
}
}
}
}
public void StartCheck(String NetwAddress, int NA_id, double ics)
public void StartCheck(String NetwAddress, int NA_id, double ics)
{
CommunicationEvents.ServerRunningA_test[NA_id] = false;
StartCoroutine(ServerRoutine(NetwAddress, NA_id, ics));
}
void PrepareGame()
{
//WaitingText.text = "Press any key to start the game";
//CommunicationEvents.ServerRunning_test = true;
//UnityEngine.Debug.Log("server fin");
}
IEnumerator ServerRoutine(String NetwAddress, int NA_id, double ics)
{
using UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
IEnumerator ServerRoutine(String NetwAddress, int NA_id, double ics)
{
UnityEngine.Debug.Log("no running server " + request.error);
CommunicationEvents.ServerRunningA_test[NA_id] = false;
UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
yield return request.SendWebRequest();
while (true)
while (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
using UnityWebRequest request2 = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
yield return request2.SendWebRequest();
if (request2.result == UnityWebRequest.Result.ConnectionError
|| request2.result == UnityWebRequest.Result.ProtocolError)
{
// UnityEngine.Debug.Log("no running server");
}
else
{
break;
}
UnityEngine.Debug.Log("Wait for Server to Respond: " + request.error);
request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
yield return request.SendWebRequest();
yield return null;
request.Dispose();
}
}
request.Dispose();
//PrepareGame();
if (CommunicationEvents.IPcheckGeneration == ics || (NA_id!=6))// && NA_id!=2))
{
CommunicationEvents.ServerRunningA_test[NA_id] = true;
}
yield return null;
}
void Update()
{
if (CommunicationEvents.IPcheckGeneration == ics || (NA_id != 6))// && NA_id!=2))
CommunicationEvents.ServerRunningA_test[NA_id] = true;
}
}
}
......@@ -29,7 +29,7 @@ private void CreateSegment(float angle, float radius)
verticeList.Add(center0);
//Center-Point of upper side
Vector3 center1 = new Vector3(0, height, 0);
Vector3 center1 = new Vector3(0, height/2, 0);
int center1Index = 1;
verticeList.Add(center1);
......@@ -104,10 +104,13 @@ private void CreateSegment(float angle, float radius)
i += 2;
}
mesh = new Mesh();
mesh.vertices = verticeList.ToArray();
mesh.triangles = triangleList.ToArray();
mesh = new Mesh
{
vertices = verticeList.ToArray(),
triangles = triangleList.ToArray()
};
GetComponent<MeshFilter>().mesh = mesh;
GetComponent<MeshCollider>().sharedMesh = mesh;
mesh.RecalculateNormals();
}
}
fileFormatVersion: 2
guid: 1346ddcf92354374f97f2f7051bb47bc
guid: dfe354480e19bef46898d1159390cbdd
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class MathfExtensions
{
/// <summary>
/// Lineary Lerps between <paramref name="start"/> and <paramref name="end"/> within <paramref name="time"/>, using <see cref="Time.deltaTime"/>.
/// Guarantees returning <paramref name="end"/> at last step,
/// </summary>
/// <param name="start">Value to start</param>
/// <param name="end">Value to end</param>
/// <param name="time">Time to pass</param>
/// <returns>IEnumerator<float> with statet behaviour</returns>
public static IEnumerator<float> LerpInTime(float start, float end, float time)
{
if (time < 0) yield break;
for (float current_time = 0; time > current_time; current_time += Time.deltaTime)
yield return Mathf.Lerp(start, end, current_time / time);
yield return end;
}
/// \copydoc LerpInTime(float, float, float)
/// <remarks>Wrappes static method and exposes it as Extension.</remarks>
/// <param name="iotta">Ignored. Here to expose Extension.</param>
public static IEnumerator<float> LerpInTime(this float iotta, float start, float end, float time)
=> LerpInTime(start, end, time);
}
fileFormatVersion: 2
guid: 634d033901bea8e4f97e5d743273c7ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -7,25 +7,19 @@ public static class RendererExtensions
public static IEnumerator ProgrammMaterialChange(this Renderer renderer, IEnumerable<(float delay, float lerp_time, Material new_material)> instructions, bool loop = false)
{
Material last_material;
float start_time, end_time;
do
foreach (var (delay, lerp_time, new_material) in instructions)
{
last_material = renderer.material;
start_time = Time.time;
end_time = start_time + lerp_time;
yield return new WaitForSeconds(delay);
while (end_time >= Time.time)
last_material = renderer.material;
for (IEnumerator<float> lerper = MathfExtensions.LerpInTime(0, 1, lerp_time)
; lerper.MoveNext();)
{
renderer.material.Lerp(last_material, new_material
, (Time.time - start_time) / lerp_time);
renderer.material.Lerp(last_material, new_material , lerper.Current);
yield return null;
}
renderer.material = new_material;
}
while (loop);
}
......
......@@ -32,7 +32,6 @@ public static class CommunicationEvents
public static bool ServerAutoStart = true;
public static bool ServerRunning = true;
public static bool ServerRunning_test = true;
//CHANGE HERE PORT OF SERVER
public static string ServerPortDefault = "8085"; //used for Local
......@@ -103,7 +102,6 @@ public static string CreateHierarchiePath(List<Directories> hierarchie, string p
public static string CreatePathToFile(out bool file_exists, string name, string format = null, List<Directories> hierarchie = null, bool use_install_folder = false)
{
string ending = "";
string path;
if (!string.IsNullOrEmpty(format))
switch (format)
{
......@@ -114,18 +112,11 @@ public static string CreatePathToFile(out bool file_exists, string name, string
break;
}
//OperationSystem Opsys is set above;
switch (Opsys)
string path = Opsys switch
{
default:
case OperationSystem.Windows:
path = use_install_folder ? Application.dataPath : Application.persistentDataPath;
break;
case OperationSystem.Android:
path = Application.persistentDataPath;
break;
}
OperationSystem.Android => Application.persistentDataPath,
OperationSystem.Windows or _ => use_install_folder ? Application.dataPath : Application.persistentDataPath,
};
if (hierarchie != null)
{
......
......@@ -51,8 +51,18 @@ public static PointFact AddPointFact(Vector3 point, Vector3 normal, bool sameste
/// <param name="pid"><see cref="Fact.Id"/> of <see cref="PointFact"/> which lies on <paramref name="lid"/></param>
/// <param name="lid"><see cref="Fact.Id"/> of <see cref="LineFact"/> on which <paramref name="pid"/> lies</param>
/// \copydetails FactManager
public static OnLineFact AddOnLineFact(string pid, string lid, bool samestep = false, Gadget gadget = null, string scroll_label = null)
public static OnLineFact AddOnLineFact(string pid, string lid, bool samestep = false, Gadget gadget = null, string scroll_label = null, bool is_certain = false)
{
if (!is_certain)
{
AbstractLineFact line = (AbstractLineFact)StageStatic.stage.factState[lid];
PointFact line_point = (PointFact)StageStatic.stage.factState[line.Pid1];
PointFact point = (PointFact)StageStatic.stage.factState[pid];
if (!Math3d.IsPointApproximatelyOnLine(line_point.Point, line.Dir, point.Point))
return null;
}
return (OnLineFact)AddFactIfNotFound(
new OnLineFact(pid, lid, StageStatic.stage.factState)
, out _, samestep, gadget, scroll_label);
......@@ -97,7 +107,7 @@ void AddHitIfOnLine(RaycastHit hit)
if (Math3d.IsPointApproximatelyOnLine(rayP1.Point, rayFact.Dir, hit.transform.position))
{
AddOnLineFact(
hit.transform.gameObject.GetComponent<FactObject>().URI, rayFact.Id, true, gadget, scroll_label);
hit.transform.gameObject.GetComponent<FactObject>().URI, rayFact.Id, true, gadget, scroll_label, true);
}
}
......@@ -108,8 +118,8 @@ void AddHitIfOnLine(RaycastHit hit)
AddHitIfOnLine(hit);
// for good measure
AddOnLineFact(rayFact.Pid1, rayFact.Id, true, gadget, scroll_label);
AddOnLineFact(rayFact.Pid2, rayFact.Id, true, gadget, scroll_label);
AddOnLineFact(rayFact.Pid1, rayFact.Id, true, gadget, scroll_label, true);
AddOnLineFact(rayFact.Pid2, rayFact.Id, true, gadget, scroll_label, true);
return rayFact;
}
......
......@@ -172,7 +172,7 @@ public stepnote(FactOrganizer that, string Id, bool samestep, bool creation, Gad
this.scroll_label = scroll_label;
this.GadgetTime = StageStatic.stage_time;
stepnote prev = default(stepnote);
stepnote prev = default;
if (samestep) {
prev = that.Workflow[that.marker - 1];
......@@ -201,7 +201,7 @@ public stepnote(FactOrganizer that, string Id, bool samestep, bool creation, Gad
bool set_workflow = !samestep || new_gadget || prev.gadget_rank != this.gadget_rank
|| gadget_entree.last_occurrence >= that.marker;
stepnote gadget_prev = set_workflow ? default(stepnote) /*unused then*/
stepnote gadget_prev = set_workflow ? default /*unused then*/
: that.Workflow[gadget_entree.last_occurrence];
if ( set_workflow || gadget_prev.GadgetFlow == null
......
......@@ -13,51 +13,36 @@ public GameObject
Ray,
Angle;
private GameObject FactRepresentation;
//private Camera camera;
void Start()
{
AddFactEvent.AddListener(FactAction);
AddFactEvent.AddListener(SpawnFactRepresentation_Wrapped);
RemoveFactEvent.AddListener(DeleteObject);
AnimateNonExistingFactEvent.AddListener(animateNonExistingFactTrigger);
//Default FactRepresenation = Sphere-Prefab for Points
this.FactRepresentation = Sphere;
//camera = Camera.main;
}
public void FactAction(Fact fact) {
getAction(fact)?.Invoke(fact);
}
private void SpawnFactRepresentation_Wrapped(Fact fact) => SpawnFactRepresentation(fact);
public Func<Fact, Fact> getAction(Fact fact)
public Fact SpawnFactRepresentation(Fact fact)
{
return fact switch
Func<Fact, Fact> func = fact switch
{
PointFact pointFact
=> SpawnPoint,
LineFact lineFact
=> SpawnLine,
AngleFact angleFact
=> SpawnAngle,
RayFact rayFact
=> SpawnRay,
PointFact => SpawnPoint,
LineFact => SpawnLine,
AngleFact => SpawnAngle,
RayFact => SpawnRay,
_ => null,
};
return func?.Invoke(fact);
}
public Fact SpawnPoint(Fact pointFact)
{
PointFact fact = ((PointFact)pointFact);
this.FactRepresentation = Sphere;
GameObject point = GameObject.Instantiate(FactRepresentation);
GameObject point = GameObject.Instantiate(Sphere);
point.transform.position = fact.Point;
point.transform.up = fact.Normal;
point.GetComponentInChildren<TextMeshPro>().text = fact.Label;
......@@ -75,8 +60,7 @@ public Fact SpawnLine(Fact fact)
Vector3 point1 = pointFact1.Point;
Vector3 point2 = pointFact2.Point;
//Change FactRepresentation to Line
this.FactRepresentation = Line;
GameObject line = GameObject.Instantiate(FactRepresentation);
GameObject line = GameObject.Instantiate(Line);
//Place the Line in the centre of the two points
line.transform.position = Vector3.Lerp(point1, point2, 0.5f);
//Change scale and rotation, so that the two points are connected by the line
......@@ -117,8 +101,7 @@ public Fact SpawnRay(Fact fact)
point2 += dir * 100;
//Change FactRepresentation to Line
this.FactRepresentation = Ray;
GameObject line = GameObject.Instantiate(FactRepresentation);
GameObject line = GameObject.Instantiate(Ray);
//Place the Line in the centre of the two points
line.transform.position = Vector3.Lerp(point1, point2, 0.5f);
//Change scale and rotation, so that the two points are connected by the line
......@@ -159,8 +142,7 @@ public Fact SpawnAngle(Fact fact)
length = lengthFactor * (point1 - point2).magnitude;
//Change FactRepresentation to Angle
this.FactRepresentation = Angle;
GameObject angle = GameObject.Instantiate(FactRepresentation);
GameObject angle = GameObject.Instantiate(Angle);
//Calculate Angle:
Vector3 from = (point3 - point2).normalized;
......@@ -204,7 +186,7 @@ public void animateNonExistingFactTrigger(Fact fact) {
}
public IEnumerator animateNonExistingFact(Fact fact) {
Fact returnedFact = getAction(fact).Invoke(fact);
Fact returnedFact = SpawnFactRepresentation(fact);
ShinyThings.HighlightFact(returnedFact, FactObject.FactMaterials.Hint);
......
......@@ -68,7 +68,7 @@ void CreateRayAndAngles(string IntersectionId, string LotPointId, bool samestep)
var intersectionId = FactManager.AddPointFact(IntersectionPoint, normal, gadget: this).Id;
if (BaseLine is RayFact) // Add OnLineFact only on Ray not Line
FactManager.AddOnLineFact(intersectionId, Workflow[0], true, gadget: this);
FactManager.AddOnLineFact(intersectionId, Workflow[0], true, gadget: this, is_certain: true);
CreateRayAndAngles(intersectionId, tempFactId, true);
ResetGadget();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment