A lot of stuff to Commit because I forgot to Commit in between (Don't do stuff like this, kids)

This commit is contained in:
cblech
2025-01-05 13:47:14 +01:00
parent 03d130cde6
commit 8c961cbf2d
87 changed files with 22246 additions and 42 deletions
+77
View File
@@ -0,0 +1,77 @@
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UIElements;
using static Swizzles.E3;
public class CraneControl : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler,IPointerDownHandler,IPointerUpHandler
{
[SerializeField]
private OutlineFx.OutlineFx _outline;
[SerializeField]
private float _speed = 3;
[SerializeField]
private UnityEvent _onHooked;
private bool mouseIsDown = false;
public void OnPointerEnter(PointerEventData eventData)
{
_outline.enabled = true;
}
public void OnPointerExit(PointerEventData eventData)
{
_outline.enabled = false;
}
public void OnPointerDown(PointerEventData eventData)
{
mouseIsDown = true;
}
public void OnPointerUp(PointerEventData eventData)
{
mouseIsDown = false;
}
private void Update()
{
if(!mouseIsDown) return;
var mouseWorldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition).Swiz(X,Y,Zero);
var ownPosition = transform.position;
mouseWorldPoint += ownPosition.Swiz(Zero, Zero, Z);
var stepDistance = Time.deltaTime * _speed;
var towardMousePosition = mouseWorldPoint - ownPosition;
if (towardMousePosition.magnitude>stepDistance)
{
towardMousePosition.Normalize();
towardMousePosition *= stepDistance;
}
transform.position += towardMousePosition;
if(transform.position.x>45)
transform.position = new Vector3(45,transform.position.y,transform.position.z);
if(transform.position.x<-45)
transform.position = new Vector3(-45,transform.position.y,transform.position.z);
if(transform.position.y>35)
transform.position = new Vector3(transform.position.x,35,transform.position.z);
if(transform.position.y<-35)
transform.position = new Vector3(transform.position.x,-35,transform.position.z);
}
private void OnTriggerEnter2D(Collider2D other)
{
Debug.Log(other.gameObject.name);
if(!other.gameObject.CompareTag("Bike")) return;
other.transform.parent.SetParent(transform);
other.transform.parent.localPosition = Vector3.zero;
_onHooked.Invoke();
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d1aef65c5e477a4428a670a40e27e9f6
@@ -49,7 +49,11 @@ public class SceneSwitcherEditorWindow : EditorWindow
Button button = new Button();
button.text = scene.name;
int sceneIndex = scene.index; // Capture the index in a local variable
button.clicked += () => SceneSwitcher.Instance.SwitchScene(sceneIndex);
button.clicked += () =>
{
SceneSwitcher.Instance.SwitchScene(sceneIndex);
Selection.activeGameObject = SceneSwitcher.Instance.GetGameObject(sceneIndex);
};
scrollView.Add(button);
}
}
+5 -1
View File
@@ -8,13 +8,17 @@ public class MyButton : MonoBehaviour, IPointerClickHandler, IPointerEnterHandle
[SerializeField]
private UnityEvent _onClick;
// references
[SerializeField]
private OutlineFx.OutlineFx _outlineFx;
[SerializeField]
public bool isActive = true;
public void SetActive(bool active)
{
isActive = active;
}
private void OnEnable()
{
+32
View File
@@ -31,12 +31,40 @@ public class SceneSwitcher : MonoBehaviour
}
}
[SerializeField]
private GameObject[] _deactivateChildrenOf;
public void SwitchScene(int sceneIndex)
{
for (var i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(i == sceneIndex);
}
foreach (var toDeactivate in _deactivateChildrenOf)
{
foreach (Transform child in toDeactivate.transform)
{
child.gameObject.SetActive(false);
}
}
}
public void SwitchToNext()
{
for (var i = 0; i < transform.childCount; i++)
{
if (transform.GetChild(i).gameObject.activeSelf)
{
var nextIndex = i + 1;
if (nextIndex >= transform.childCount)
{
nextIndex = 0;
}
SwitchScene(nextIndex);
return;
}
}
}
public List<(string name, int index)> GetScenes()
@@ -49,4 +77,8 @@ public class SceneSwitcher : MonoBehaviour
}
return scenes;
}
public GameObject GetGameObject(int sceneIndex)
{
return transform.GetChild(sceneIndex).gameObject;
}
}
-4
View File
@@ -1,10 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
#if UNITY_EDITOR
using UnityEditor;
+224
View File
@@ -0,0 +1,224 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Swizzles
{
public enum E4
{
X,
Y,
Z,
W,
Zero,
One
}
public enum E3
{
X,
Y,
Z,
Zero,
One
}
public enum E2
{
X,
Y,
Zero,
One
}
public static Vector2 Swiz(this Vector2 self, E2 newX, E2 newY)
{
return new Vector2(self.GetElement(newX), self.GetElement(newY));
}
public static Vector2 Swiz(this Vector2Int self, E2 newX, E2 newY)
{
return new Vector2(self.GetElement(newX), self.GetElement(newY));
}
public static Vector3 Swiz(this Vector2 self, E2 newX, E2 newY, E2 newZ)
{
return new Vector3(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ));
}
public static Vector3 Swiz(this Vector2Int self, E2 newX, E2 newY, E2 newZ)
{
return new Vector3(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ));
}
public static Vector4 Swiz(this Vector2 self, E2 newX, E2 newY, E2 newZ, E2 newW)
{
return new Vector4(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ), self.GetElement(newW));
}
public static Vector4 Swiz(this Vector2Int self, E2 newX, E2 newY, E2 newZ, E2 newW)
{
return new Vector4(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ), self.GetElement(newW));
}
public static Vector2 Swiz(this Vector3 self, E3 newX, E3 newY)
{
return new Vector2(self.GetElement(newX), self.GetElement(newY));
}
public static Vector2 Swiz(this Vector3Int self, E3 newX, E3 newY)
{
return new Vector2(self.GetElement(newX), self.GetElement(newY));
}
public static Vector3 Swiz(this Vector3 self, E3 newX, E3 newY, E3 newZ)
{
return new Vector3(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ));
}
public static Vector3 Swiz(this Vector3Int self, E3 newX, E3 newY, E3 newZ)
{
return new Vector3(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ));
}
public static Vector4 Swiz(this Vector3 self, E3 newX, E3 newY, E3 newZ, E3 newW)
{
return new Vector4(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ), self.GetElement(newW));
}
public static Vector4 Swiz(this Vector3Int self, E3 newX, E3 newY, E3 newZ, E3 newW)
{
return new Vector4(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ), self.GetElement(newW));
}
public static Vector2 Swiz(this Vector4 self, E4 newX, E4 newY)
{
return new Vector2(self.GetElement(newX), self.GetElement(newY));
}
public static Vector3 Swiz(this Vector4 self, E4 newX, E4 newY, E4 newZ)
{
return new Vector3(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ));
}
public static Vector4 Swiz(this Vector4 self, E4 newX, E4 newY, E4 newZ, E4 newW)
{
return new Vector4(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ), self.GetElement(newW));
}
public static Vector2Int SwizI(this Vector2Int self, E2 newX, E2 newY)
{
return new Vector2Int(self.GetElement(newX), self.GetElement(newY));
}
public static Vector2Int SwizI(this Vector2 self, E2 newX, E2 newY)
{
return new Vector2Int((int) self.GetElement(newX), (int) self.GetElement(newY));
}
public static Vector3Int SwizI(this Vector2Int self, E2 newX, E2 newY, E2 newZ)
{
return new Vector3Int(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ));
}
public static Vector3Int SwizI(this Vector2 self, E2 newX, E2 newY, E2 newZ)
{
return new Vector3Int((int) self.GetElement(newX), (int) self.GetElement(newY), (int) self.GetElement(newZ));
}
public static Vector2Int SwizI(this Vector3Int self, E3 newX, E3 newY)
{
return new Vector2Int(self.GetElement(newX), self.GetElement(newY));
}
public static Vector2Int SwizI(this Vector3 self, E3 newX, E3 newY)
{
return new Vector2Int((int) self.GetElement(newX), (int) self.GetElement(newY));
}
public static Vector3Int SwizI(this Vector3Int self, E3 newX, E3 newY, E3 newZ)
{
return new Vector3Int(self.GetElement(newX), self.GetElement(newY), self.GetElement(newZ));
}
public static Vector3Int SwizI(this Vector3 self, E3 newX, E3 newY, E3 newZ)
{
return new Vector3Int((int) self.GetElement(newX), (int) self.GetElement(newY), (int) self.GetElement(newZ));
}
public static Vector2Int SwizI(this Vector4 self, E4 newX, E4 newY)
{
return new Vector2Int((int) self.GetElement(newX), (int) self.GetElement(newY));
}
public static Vector3Int SwizI(this Vector4 self, E4 newX, E4 newY, E4 newZ)
{
return new Vector3Int((int) self.GetElement(newX), (int) self.GetElement(newY), (int) self.GetElement(newZ));
}
private static float GetElement(this Vector2 self, E2 e)
{
return e switch
{
E2.X => self.x,
E2.Y => self.y,
E2.Zero => 0f,
E2.One => 1f,
_ => throw new ArgumentOutOfRangeException(nameof(e), e, "Invalid element")
};
}
private static float GetElement(this Vector3 self, E3 e)
{
return e switch
{
E3.X => self.x,
E3.Y => self.y,
E3.Z => self.z,
E3.Zero => 0f,
E3.One => 1f,
_ => throw new ArgumentOutOfRangeException(nameof(e), e, "Invalid element")
};
}
private static float GetElement(this Vector4 self, E4 e)
{
return e switch
{
E4.X => self.x,
E4.Y => self.y,
E4.Z => self.z,
E4.W => self.w,
E4.Zero => 0f,
E4.One => 1f,
_ => throw new ArgumentOutOfRangeException(nameof(e), e, "Invalid element")
};
}
private static int GetElement(this Vector2Int self, E2 e)
{
return e switch
{
E2.X => self.x,
E2.Y => self.y,
E2.Zero => 0,
E2.One => 1,
_ => throw new ArgumentOutOfRangeException(nameof(e), e, null)
};
}
public static int GetElement(this Vector3Int self, E3 e)
{
return e switch
{
E3.X => self.x,
E3.Y => self.y,
E3.Z => self.z,
E3.Zero => 0,
E3.One => 1,
_ => throw new ArgumentOutOfRangeException(nameof(e), e, null)
};
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fa617336c000b7e4c81296bdaa3eace1
@@ -6,8 +6,10 @@ public class MyButtonTrackMixer : PlayableBehaviour
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
var myButton = playerData as MyButton;
if(!myButton){return;}
myButton!.isActive = false;
myButton.isActive = false;
for (var i = 0; i < playable.GetInputCount(); i++)
{
@@ -0,0 +1,14 @@
using TMPro;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
[TrackBindingType(typeof(TextMeshProUGUI))]
[TrackClipType(typeof(SubtitleTrackClip))]
public class SubtitleTrack : TrackAsset
{
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
{
return ScriptPlayable<SubtitleTrackMixer>.Create(graph, inputCount);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: cf966904c89cec546b53a94cd9de7805
@@ -0,0 +1,7 @@
using UnityEngine;
using UnityEngine.Playables;
public class SubtitleTrackBehaviour : PlayableBehaviour
{
public string subtitleText;
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1b3d76d457153a040aacb9ede466c956
@@ -0,0 +1,17 @@
using UnityEngine;
using UnityEngine.Playables;
public class SubtitleTrackClip : PlayableAsset
{
public string subtitleText;
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
{
var playable = ScriptPlayable<SubtitleTrackBehaviour>.Create(graph);
var subtitleTrackBehaviour = playable.GetBehaviour();
subtitleTrackBehaviour.subtitleText = subtitleText;
return playable;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1d30b6f2f1cc7954e9c7fed4e91c53a2
@@ -0,0 +1,31 @@
using TMPro;
using UnityEngine;
using UnityEngine.Playables;
public class SubtitleTrackMixer : PlayableBehaviour
{
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
var text = playerData as TextMeshProUGUI;
var currentText = "";
if (!text) { return; }
for (var i = 0; i < playable.GetInputCount(); i++)
{
if (playable.GetInputWeight(i) <=0)
continue;
var inputPlayable = (ScriptPlayable<SubtitleTrackBehaviour>)playable.GetInput(i);
var input = inputPlayable.GetBehaviour();
if (input.subtitleText != "")
{
currentText = input.subtitleText;
}
}
text.text = currentText;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ce87fa1edd37b85438c2c455cbaf4f70