Skip to content
Snippets Groups Projects
Commit a9b9014d authored by MaZiFAU's avatar MaZiFAU
Browse files

Some refactoring and minor bug fixes

parent 74a8996a
Branches
No related tags found
No related merge requests found
Showing
with 145 additions and 66 deletions
...@@ -63,6 +63,3 @@ sysinfo.txt ...@@ -63,6 +63,3 @@ sysinfo.txt
# Crashlytics generated file # Crashlytics generated file
crashlytics-build.properties crashlytics-build.properties
# Ignore UserSettings
UserSettings/
using UnityEngine;
using UnityEngine.UI;
[ExecuteAlways]
[RequireComponent(typeof(ContentSizeFitter))]
public class ContentSizeFitterMaxWidth : MonoBehaviour
{
public float maxWidth;
RectTransform _rtfm;
ContentSizeFitter _fitter;
ILayoutElement _layout;
void OnEnable()
{
_rtfm = (RectTransform)transform;
_fitter = GetComponent<ContentSizeFitter>();
_layout = GetComponent<ILayoutElement>();
}
void Update()
{
_fitter.horizontalFit = _layout.preferredWidth > maxWidth
? ContentSizeFitter.FitMode.Unconstrained
: ContentSizeFitter.FitMode.PreferredSize;
if (_layout.preferredWidth > maxWidth)
{
_fitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
_rtfm.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, maxWidth);
}
else
_fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
}
void OnValidate() => OnEnable();
}
\ No newline at end of file
fileFormatVersion: 2
guid: 7c2193a3ac4b5604eb3358d292b04fa7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System; using System;
using System.Collections; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
...@@ -17,13 +17,16 @@ public class DataContainerGadgetCollection : ScriptableObject, ISerializationCal ...@@ -17,13 +17,16 @@ public class DataContainerGadgetCollection : ScriptableObject, ISerializationCal
public void OnBeforeSerialize() public void OnBeforeSerialize()
{ {
GadgetType.Clear(); var keys = DataContainerGadgetDict.Keys.ToArray();
GadgetData.Clear(); var vals = DataContainerGadgetDict.Values.ToArray();
foreach (var kvp in DataContainerGadgetDict) for (int i = 0; i < keys.Length; i++)
{ {
GadgetType.Add(kvp.Key); if (GadgetType.Count <= i) GadgetType.Add(keys[i]);
GadgetData.Add(kvp.Value); else GadgetType[i] = keys[i];
if (GadgetData.Count <= i) GadgetData.Add(vals[i]);
else GadgetData[i] = vals[i];
} }
} }
......
...@@ -29,7 +29,7 @@ private void CreateSegment(float angle, float radius) ...@@ -29,7 +29,7 @@ private void CreateSegment(float angle, float radius)
verticeList.Add(center0); verticeList.Add(center0);
//Center-Point of upper side //Center-Point of upper side
Vector3 center1 = new Vector3(0, height/2, 0); Vector3 center1 = new Vector3(0, 0, 0);
int center1Index = 1; int center1Index = 1;
verticeList.Add(center1); verticeList.Add(center1);
...@@ -37,7 +37,7 @@ private void CreateSegment(float angle, float radius) ...@@ -37,7 +37,7 @@ private void CreateSegment(float angle, float radius)
float negAngle = posAngle * -1; float negAngle = posAngle * -1;
int i = 2; int i = 2;
for (float x = negAngle; x < posAngle; x += angleAccuracy) for (float x = negAngle; x < posAngle; x += angleAccuracy, i += 2)
{ {
float nextAngle; float nextAngle;
...@@ -55,8 +55,8 @@ private void CreateSegment(float angle, float radius) ...@@ -55,8 +55,8 @@ private void CreateSegment(float angle, float radius)
//Add first Points at the beginning of the angle //Add first Points at the beginning of the angle
float firstPointX = radius * Mathf.Cos(negAngle * Mathf.Deg2Rad); float firstPointX = radius * Mathf.Cos(negAngle * Mathf.Deg2Rad);
float firstPointZ = radius * Mathf.Sin(negAngle * Mathf.Deg2Rad); float firstPointZ = radius * Mathf.Sin(negAngle * Mathf.Deg2Rad);
verticeList.Add(new Vector3(firstPointX, 0, firstPointZ)); verticeList.Add(new Vector3(firstPointX, -height/2, firstPointZ));
verticeList.Add(new Vector3(firstPointX, height, firstPointZ)); verticeList.Add(new Vector3(firstPointX, +height/2, firstPointZ));
//Adding triangles for left side //Adding triangles for left side
if (absoluteAngle != 360) if (absoluteAngle != 360)
...@@ -72,8 +72,8 @@ private void CreateSegment(float angle, float radius) ...@@ -72,8 +72,8 @@ private void CreateSegment(float angle, float radius)
i += 2; i += 2;
} }
verticeList.Add(new Vector3(newPointX, 0, newPointZ)); verticeList.Add(new Vector3(newPointX, -height/2, newPointZ));
verticeList.Add(new Vector3(newPointX, height, newPointZ)); verticeList.Add(new Vector3(newPointX, +height/2, newPointZ));
//Adding triangles for upper- and lower-side //Adding triangles for upper- and lower-side
triangleList.Add(center0Index); triangleList.Add(center0Index);
...@@ -100,8 +100,6 @@ private void CreateSegment(float angle, float radius) ...@@ -100,8 +100,6 @@ private void CreateSegment(float angle, float radius)
triangleList.Add(i); triangleList.Add(i);
triangleList.Add(i + 1); triangleList.Add(i + 1);
} }
i += 2;
} }
mesh = new Mesh mesh = new Mesh
...@@ -109,8 +107,9 @@ private void CreateSegment(float angle, float radius) ...@@ -109,8 +107,9 @@ private void CreateSegment(float angle, float radius)
vertices = verticeList.ToArray(), vertices = verticeList.ToArray(),
triangles = triangleList.ToArray() triangles = triangleList.ToArray()
}; };
mesh.RecalculateNormals();
GetComponent<MeshFilter>().mesh = mesh; GetComponent<MeshFilter>().mesh = mesh;
GetComponent<MeshCollider>().sharedMesh = mesh; GetComponent<MeshCollider>().sharedMesh = mesh;
mesh.RecalculateNormals();
} }
} }
...@@ -42,7 +42,6 @@ public static class CommunicationEvents ...@@ -42,7 +42,6 @@ public static class CommunicationEvents
public static Process process_mmt_frameIT_server; public static Process process_mmt_frameIT_server;
public static bool takeNewToolID = false; //0=no, 1=instead, 2=both
public static int ToolID_new; public static int ToolID_new;
public static int ToolID_selected;//Script public static int ToolID_selected;//Script
......
...@@ -150,12 +150,20 @@ public Fact SpawnAngle(Fact fact) ...@@ -150,12 +150,20 @@ public Fact SpawnAngle(Fact fact)
float angleValue = Vector3.Angle(from, to); //We always get an angle between 0 and 180° here float angleValue = Vector3.Angle(from, to); //We always get an angle between 0 and 180° here
//Change scale and rotation, so that the angle is in between the two lines //Change scale and rotation, so that the angle is in between the two lines
var v3T = angle.transform.localScale;
v3T = new Vector3(length, v3T.y, length);
Vector3 forwoard = (from + to).normalized;
Vector3 up = Vector3.Cross(to, from); Vector3 up = Vector3.Cross(to, from);
if (up.sqrMagnitude < Math3d.vectorPrecission) { //Angle is 180° (or 0°)
Vector3 arbitary = up == Vector3.forward ? Vector3.right : Vector3.forward;
up = Vector3.Cross(arbitary, to);
forwoard = to;
} else
forwoard = Vector3.Cross(forwoard, up);
//Place the Angle at position of point2 //Place the Angle at position of point2
angle.transform.SetPositionAndRotation(point2, Quaternion.LookRotation(Vector3.Cross((from+to).normalized,up), up)); angle.transform.SetPositionAndRotation(point2, Quaternion.LookRotation(forwoard, up));
//Set text of angle //Set text of angle
TextMeshPro[] texts = angle.GetComponentsInChildren<TextMeshPro>(); TextMeshPro[] texts = angle.GetComponentsInChildren<TextMeshPro>();
......
...@@ -34,6 +34,7 @@ public abstract class Gadget ...@@ -34,6 +34,7 @@ public abstract class Gadget
/// <remarks>Do NOT rename elements! Do NOT change values! Deserialization relies on it!</remarks> /// <remarks>Do NOT rename elements! Do NOT change values! Deserialization relies on it!</remarks>
public enum GadgetIDs public enum GadgetIDs
{ {
Unused = -3,
Undefined = -1, Undefined = -1,
Pointer = 0, Pointer = 0,
Tape = 1, Tape = 1,
......
...@@ -21,8 +21,7 @@ void Awake() ...@@ -21,8 +21,7 @@ void Awake()
public void AnimationTrigger() public void AnimationTrigger()
{ {
routine = Animation(); StartCoroutine(routine = Animation());
StartCoroutine(routine);
IEnumerator Animation() IEnumerator Animation()
{ {
...@@ -43,5 +42,7 @@ public void ResetAnimation() ...@@ -43,5 +42,7 @@ public void ResetAnimation()
{ {
if (routine != null) if (routine != null)
StopCoroutine(routine); StopCoroutine(routine);
imageToChange.color = imageToChangeDefaultColor;
} }
} }
...@@ -32,7 +32,7 @@ private void Awake() ...@@ -32,7 +32,7 @@ private void Awake()
CommunicationEvents.PushoutFactFailEvent.AddListener(LetItRain); CommunicationEvents.PushoutFactFailEvent.AddListener(LetItRain);
CommunicationEvents.AnimateExistingFactEvent.AddListener(HighlightWithFireworks); CommunicationEvents.AnimateExistingFactEvent.AddListener(HighlightWithFireworks);
rain = rain_wait = 0f.LerpInTime(0, 0, -1); // yield return break rain = rain_wait = IEnumeratorExtensions.yield_break;
} }
public void Start() public void Start()
...@@ -49,10 +49,10 @@ public void Start() ...@@ -49,10 +49,10 @@ public void Start()
// Update is called once per frame // Update is called once per frame
public void Update() public void Update()
{ {
Highlighting(Cursor.Hit); HighlightCurserHit(Cursor.Hit);
} }
private void Highlighting(RaycastHit hit) private void HighlightCurserHit(RaycastHit hit)
{ {
FactObject selected_fact_obj = hit.transform?.GetComponentInChildren<FactObject>(); FactObject selected_fact_obj = hit.transform?.GetComponentInChildren<FactObject>();
...@@ -97,7 +97,7 @@ public static void HighlightFact(Fact startFact, FactObject.FactMaterials tmp_ma ...@@ -97,7 +97,7 @@ public static void HighlightFact(Fact startFact, FactObject.FactMaterials tmp_ma
public void HighlightWithFireworks(Fact fact) public void HighlightWithFireworks(Fact fact)
{ {
while (rain_wait.MoveNext()) ; //stop rain rain_wait = IEnumeratorExtensions.yield_break; //stop rain
StartCoroutine(BlossomAndDie()); StartCoroutine(BlossomAndDie());
HighlightFact(fact, FactObject.FactMaterials.Solution); HighlightFact(fact, FactObject.FactMaterials.Solution);
...@@ -127,20 +127,19 @@ IEnumerator BlossomAndDie() ...@@ -127,20 +127,19 @@ IEnumerator BlossomAndDie()
public void LetItRain(Fact startFact) public void LetItRain(Fact startFact)
{ {
bool restart = !rain_wait.MoveNext(); // check if couroutine is waiting
if (!rain_wait.MoveNext()) {
if (restart) {
StopCoroutine(rain); StopCoroutine(rain);
StartCoroutine(rain = BlossomAndDie()); StartCoroutine(rain = BlossomAndDie());
} }
rain_wait = 0f.LerpInTime(0, 0, timerDuration); rain_wait = 0f.LerpInTime(0, 0, timerDuration); //reset timer
IEnumerator BlossomAndDie() IEnumerator BlossomAndDie()
{ {
Destroy(active_rainwork); Destroy(active_rainwork);
active_rainwork = GameObject.Instantiate(RainPrefab, new Vector3(0, 40, 0), Quaternion.identity); active_rainwork = GameObject.Instantiate(RainPrefab, new Vector3(0, 40, 0), Quaternion.identity);
Color start = directionalLight.color; Color start = directionalLight.color; // may not be original one
for (IEnumerator<float> lerper = MathfExtensions.LerpInTime(0, 1, lerpTime) for (IEnumerator<float> lerper = MathfExtensions.LerpInTime(0, 1, lerpTime)
; lerper.MoveNext();) ; lerper.MoveNext();)
{ {
......
...@@ -35,8 +35,8 @@ void Start() ...@@ -35,8 +35,8 @@ void Start()
}; };
var rect = GetComponent<RectTransform>(); var rect = GetComponent<RectTransform>();
x_Start = (int)(rect.rect.x + X_Pacece_Between_Items * .5f); x_Start = (int)(+rect.rect.x + X_Pacece_Between_Items * .5f);
y_Start = (int)(-rect.rect.y - y_Pacece_Between_Items * .5f);//); y_Start = (int)(-rect.rect.y - y_Pacece_Between_Items * .5f);
number_of_Column = Mathf.Max(1, (int)(rect.rect.width / prefab_Point.GetComponent<RectTransform>().rect.width) - 1); number_of_Column = Mathf.Max(1, (int)(rect.rect.width / prefab_Point.GetComponent<RectTransform>().rect.width) - 1);
AddFactEvent.AddListener(AddFact); AddFactEvent.AddListener(AddFact);
...@@ -65,8 +65,7 @@ public void UpdatePositions() ...@@ -65,8 +65,7 @@ public void UpdatePositions()
} }
public void AnimateFact(Fact fact) { public void AnimateFact(Fact fact) {
var factIcon = displayedFacts[fact.Id]; displayedFacts[fact.Id].GetComponentInChildren<ImageHintAnimation>().AnimationTrigger();
factIcon.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger();
} }
private GameObject CreateDisplay(Transform transform, Fact fact) private GameObject CreateDisplay(Transform transform, Fact fact)
......
...@@ -39,21 +39,17 @@ public void setScroll(Scroll s) ...@@ -39,21 +39,17 @@ public void setScroll(Scroll s)
originalScroll.GetChild(0).GetComponent<TextMeshProUGUI>().text = s.description; originalScroll.GetChild(0).GetComponent<TextMeshProUGUI>().text = s.description;
//Clear all current ScrollFacts //Clear all current ScrollFacts
for (int i = 0; i < originalViewport.GetChild(0).childCount; i++) { originalViewport.GetChild(0).gameObject.DestroyAllChildren();
GameObject.Destroy(originalViewport.GetChild(0).transform.GetChild(i).gameObject);
}
ParameterDisplays = new List<GameObject>(); ParameterDisplays = new List<GameObject>();
for (int i = 0; i < s.requiredFacts.Count; i++) for (int i = 0; i < s.requiredFacts.Count; i++)
{ {
var originalObj = Instantiate(parameterDisplayPrefab, Vector3.zero, Quaternion.identity, transform); var originalObj = Instantiate(parameterDisplayPrefab, parent: originalViewport.GetChild(0));
var originalScrollFact = originalObj.transform.GetChild(0).GetComponent<RenderedScrollFact>(); var originalScrollFact = originalObj.transform.GetChild(0).GetComponent<RenderedScrollFact>();
originalScrollFact.ID = i; originalScrollFact.ID = i;
originalScrollFact.Label = s.requiredFacts[i].label; originalScrollFact.Label = s.requiredFacts[i].label;
originalScrollFact.factUri = s.requiredFacts[i].@ref.uri; originalScrollFact.factUri = s.requiredFacts[i].@ref.uri;
originalObj.transform.SetParent(originalViewport.GetChild(0));
ParameterDisplays.Add(originalObj); ParameterDisplays.Add(originalObj);
} }
} }
...@@ -206,8 +202,7 @@ public List<string> processRenderedScroll(Scroll rendered, List<string> hintUris ...@@ -206,8 +202,7 @@ public List<string> processRenderedScroll(Scroll rendered, List<string> hintUris
var obj = ParameterDisplays.Find(x => x.transform.GetChild(0).GetComponent<RenderedScrollFact>().factUri.Equals(rendered.requiredFacts[i].@ref.uri)); var obj = ParameterDisplays.Find(x => x.transform.GetChild(0).GetComponent<RenderedScrollFact>().factUri.Equals(rendered.requiredFacts[i].@ref.uri));
if (this.dynamicScrollDescriptionsActive) if (this.dynamicScrollDescriptionsActive)
{ { //Update ScrollParameter label
//Update ScrollParameter label
obj.transform.GetChild(0).GetComponent<RenderedScrollFact>().Label = rendered.requiredFacts[i].label; obj.transform.GetChild(0).GetComponent<RenderedScrollFact>().Label = rendered.requiredFacts[i].label;
} }
...@@ -252,30 +247,17 @@ public void animateHint(GameObject scrollParameter, string scrollParameterUri) { ...@@ -252,30 +247,17 @@ public void animateHint(GameObject scrollParameter, string scrollParameterUri) {
fact = LatestRenderedHints.Find(x => x.Id.Equals(scrollParameterUri)); fact = LatestRenderedHints.Find(x => x.Id.Equals(scrollParameterUri));
var factId = fact.Id; var factId = fact.Id;
//If there is an equal existing fact -> Animate that fact AND ScrollParameter
if (StageStatic.stage.factState.ContainsKey(factId))
{
Fact existingFact = StageStatic.stage.factState[factId];
//Animate ScrollParameter //Animate ScrollParameter
scrollParameter.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger(); scrollParameter.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger();
//Animate Fact in FactPanel
AnimateExistingFactEvent.Invoke(existingFact); //If there is an equal existing fact -> Animate that fact AND ScrollParameter
if (StageStatic.stage.factState.ContainsKey(factId))
{ //Animate Fact in FactPanel
AnimateExistingFactEvent.Invoke(StageStatic.stage.factState[factId]);
} }
//If not -> Generate a Fact-Representation with such dependent facts else { //Generate new FactRepresentation and animate it
else
{
//Animate ScrollParameter
scrollParameter.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger();
//Generate new FactRepresentation and animate it
AnimateNonExistingFactEvent.Invoke(fact); AnimateNonExistingFactEvent.Invoke(fact);
} }
} }
} }
public void animateScrollParameter(string label)
{
var obj = ParameterDisplays.Find(x => x.transform.GetChild(0).GetComponent<RenderedScrollFact>().Label == label);
obj.GetComponentInChildren<Animator>().SetTrigger("animateHint");
}
} }
...@@ -12,8 +12,6 @@ public static class Loader ...@@ -12,8 +12,6 @@ public static class Loader
/// <summary> Defines last <see cref="Scene"/> loaded by this and/ or to be loaded when calling <see cref="LoaderCallback"/>.</summary> /// <summary> Defines last <see cref="Scene"/> loaded by this and/ or to be loaded when calling <see cref="LoaderCallback"/>.</summary>
private static string nextscene; private static string nextscene;
private class MonoDummy : MonoBehaviour { };
/// <summary> /// <summary>
/// <c>return <see cref="loadingscene"/> == <see langword="null"/> ? 1f : <see cref="loadingscene"/>.progress;</c> /// <c>return <see cref="loadingscene"/> == <see langword="null"/> ? 1f : <see cref="loadingscene"/>.progress;</c>
/// </summary> /// </summary>
......
fileFormatVersion: 2
guid: 52ae36f76caa802468ca9d4b2ff72441
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f1f40d918407d2f4bbfbc0c6d52f34e7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class IEnumeratorExtensions
{
public static void FastForward(this IEnumerator that)
{
while(that.MoveNext()) ;
}
public static IEnumerator yield_break => _YieldBreak;
private static IEnumerator _YieldBreak = YieldBreak();
public static IEnumerator YieldBreak()
{
yield break;
}
}
fileFormatVersion: 2
guid: 9852cb26f72b49f4887f729152b672f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment