Make work with astra

This commit is contained in:
Andras Schmelczer 2026-09-14 08:01:49 +01:00
commit c8ee5045e2
51 changed files with 6338 additions and 4613 deletions

View file

@ -0,0 +1,95 @@
using System;
using UnityEngine;
using Object = UnityEngine.Object;
namespace UnityStandardAssets.Utility
{
public class ActivateTrigger : MonoBehaviour
{
// A multi-purpose script which causes an action to occur when
// a trigger collider is entered.
public enum Mode
{
Trigger = 0, // Just broadcast the action on to the target
Replace = 1, // replace target with source
Activate = 2, // Activate the target GameObject
Enable = 3, // Enable a component
Animate = 4, // Start animation on target
Deactivate = 5 // Decativate target GameObject
}
public Mode action = Mode.Activate; // The action to accomplish
public Object target; // The game object to affect. If none, the trigger work on this game object
public GameObject source;
public int triggerCount = 1;
public bool repeatTrigger = false;
private void DoActivateTrigger()
{
triggerCount--;
if (triggerCount == 0 || repeatTrigger)
{
Object currentTarget = target ?? gameObject;
Behaviour targetBehaviour = currentTarget as Behaviour;
GameObject targetGameObject = currentTarget as GameObject;
if (targetBehaviour != null)
{
targetGameObject = targetBehaviour.gameObject;
}
switch (action)
{
case Mode.Trigger:
if (targetGameObject != null)
{
targetGameObject.BroadcastMessage("DoActivateTrigger");
}
break;
case Mode.Replace:
if (source != null)
{
if (targetGameObject != null)
{
Instantiate(source, targetGameObject.transform.position,
targetGameObject.transform.rotation);
DestroyObject(targetGameObject);
}
}
break;
case Mode.Activate:
if (targetGameObject != null)
{
targetGameObject.SetActive(true);
}
break;
case Mode.Enable:
if (targetBehaviour != null)
{
targetBehaviour.enabled = true;
}
break;
case Mode.Animate:
if (targetGameObject != null)
{
targetGameObject.GetComponent<Animation>().Play();
}
break;
case Mode.Deactivate:
if (targetGameObject != null)
{
targetGameObject.SetActive(false);
}
break;
}
}
}
private void OnTriggerEnter(Collider other)
{
DoActivateTrigger();
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c8634e062924929664361c08745211fb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,58 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class AlphaButtonClickMask : MonoBehaviour, ICanvasRaycastFilter
{
protected Image _image;
public void Start()
{
_image = GetComponent<Image>();
Texture2D tex = _image.sprite.texture as Texture2D;
bool isInvalid = false;
if (tex != null)
{
try
{
tex.GetPixels32();
}
catch (UnityException e)
{
Debug.LogError(e.Message);
isInvalid = true;
}
}
else
{
isInvalid = true;
}
if (isInvalid)
{
Debug.LogError("This script need an Image with a readbale Texture2D to work.");
}
}
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(_image.rectTransform, sp, eventCamera, out localPoint);
Vector2 pivot = _image.rectTransform.pivot;
Vector2 normalizedLocal = new Vector2(pivot.x + localPoint.x / _image.rectTransform.rect.width, pivot.y + localPoint.y / _image.rectTransform.rect.height);
Vector2 uv = new Vector2(
_image.sprite.rect.x + normalizedLocal.x * _image.sprite.rect.width,
_image.sprite.rect.y + normalizedLocal.y * _image.sprite.rect.height );
uv.x /= _image.sprite.texture.width;
uv.y /= _image.sprite.texture.height;
//uv are inversed, as 0,0 or the rect transform seem to be upper right, then going negativ toward lower left...
Color c = _image.sprite.texture.GetPixelBilinear(uv.x, uv.y);
return c.a> 0.1f;
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 971f44ba24a74294294daed00507d80e
timeCreated: 1436868016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityStandardAssets.Utility
{
public class AutoMobileShaderSwitch : MonoBehaviour
{
[SerializeField] private ReplacementList m_ReplacementList;
// Use this for initialization
private void OnEnable()
{
#if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_TIZEN
var renderers = FindObjectsOfType<Renderer>();
Debug.Log (renderers.Length+" renderers");
var oldMaterials = new List<Material>();
var newMaterials = new List<Material>();
int materialsReplaced = 0;
int materialInstancesReplaced = 0;
foreach(ReplacementDefinition replacementDef in m_ReplacementList.items)
{
foreach(var r in renderers)
{
Material[] modifiedMaterials = null;
for(int n=0; n<r.sharedMaterials.Length; ++n)
{
var material = r.sharedMaterials[n];
if (material.shader == replacementDef.original)
{
if (modifiedMaterials == null)
{
modifiedMaterials = r.materials;
}
if (!oldMaterials.Contains(material))
{
oldMaterials.Add(material);
Material newMaterial = (Material)Instantiate(material);
newMaterial.shader = replacementDef.replacement;
newMaterials.Add(newMaterial);
++materialsReplaced;
}
Debug.Log ("replacing "+r.gameObject.name+" renderer "+n+" with "+newMaterials[oldMaterials.IndexOf(material)].name);
modifiedMaterials[n] = newMaterials[oldMaterials.IndexOf(material)];
++materialInstancesReplaced;
}
}
if (modifiedMaterials != null)
{
r.materials = modifiedMaterials;
}
}
}
Debug.Log (materialInstancesReplaced+" material instances replaced");
Debug.Log (materialsReplaced+" materials replaced");
for(int n=0; n<oldMaterials.Count; ++n)
{
Debug.Log (oldMaterials[n].name+" ("+oldMaterials[n].shader.name+")"+" replaced with "+newMaterials[n].name+" ("+newMaterials[n].shader.name+")");
}
#endif
}
[Serializable]
public class ReplacementDefinition
{
public Shader original = null;
public Shader replacement = null;
}
[Serializable]
public class ReplacementList
{
public ReplacementDefinition[] items = new ReplacementDefinition[0];
}
}
}
namespace UnityStandardAssets.Utility.Inspector
{
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof (AutoMobileShaderSwitch.ReplacementList))]
public class ReplacementListDrawer : PropertyDrawer
{
const float k_LineHeight = 18;
const float k_Spacing = 4;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
float x = position.x;
float y = position.y;
float inspectorWidth = position.width;
// Don't make child fields be indented
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
var items = property.FindPropertyRelative("items");
var titles = new string[] {"Original", "Replacement", ""};
var props = new string[] {"original", "replacement", "-"};
var widths = new float[] {.45f, .45f, .1f};
const float lineHeight = 18;
bool changedLength = false;
if (items.arraySize > 0)
{
for (int i = -1; i < items.arraySize; ++i)
{
var item = items.GetArrayElementAtIndex(i);
float rowX = x;
for (int n = 0; n < props.Length; ++n)
{
float w = widths[n]*inspectorWidth;
// Calculate rects
Rect rect = new Rect(rowX, y, w, lineHeight);
rowX += w;
if (i == -1)
{
// draw title labels
EditorGUI.LabelField(rect, titles[n]);
}
else
{
if (props[n] == "-" || props[n] == "^" || props[n] == "v")
{
if (GUI.Button(rect, props[n]))
{
switch (props[n])
{
case "-":
items.DeleteArrayElementAtIndex(i);
items.DeleteArrayElementAtIndex(i);
changedLength = true;
break;
case "v":
if (i > 0)
{
items.MoveArrayElement(i, i + 1);
}
break;
case "^":
if (i < items.arraySize - 1)
{
items.MoveArrayElement(i, i - 1);
}
break;
}
}
}
else
{
SerializedProperty prop = item.FindPropertyRelative(props[n]);
EditorGUI.PropertyField(rect, prop, GUIContent.none);
}
}
}
y += lineHeight + k_Spacing;
if (changedLength)
{
break;
}
}
}
// add button
var addButtonRect = new Rect((x + position.width) - widths[widths.Length - 1]*inspectorWidth, y,
widths[widths.Length - 1]*inspectorWidth, lineHeight);
if (GUI.Button(addButtonRect, "+"))
{
items.InsertArrayElementAtIndex(items.arraySize);
}
y += lineHeight + k_Spacing;
// Set indent back to what it was
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
SerializedProperty items = property.FindPropertyRelative("items");
float lineAndSpace = k_LineHeight + k_Spacing;
return 40 + (items.arraySize*lineAndSpace) + lineAndSpace;
}
}
#endif
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9c4978ff6447f9040b84acc89b0bbdc8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,41 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
public class AutoMoveAndRotate : MonoBehaviour
{
public Vector3andSpace moveUnitsPerSecond;
public Vector3andSpace rotateDegreesPerSecond;
public bool ignoreTimescale;
private float m_LastRealTime;
private void Start()
{
m_LastRealTime = Time.realtimeSinceStartup;
}
// Update is called once per frame
private void Update()
{
float deltaTime = Time.deltaTime;
if (ignoreTimescale)
{
deltaTime = (Time.realtimeSinceStartup - m_LastRealTime);
m_LastRealTime = Time.realtimeSinceStartup;
}
transform.Translate(moveUnitsPerSecond.value*deltaTime, moveUnitsPerSecond.space);
transform.Rotate(rotateDegreesPerSecond.value*deltaTime, moveUnitsPerSecond.space);
}
[Serializable]
public class Vector3andSpace
{
public Vector3 value;
public Space space = Space.Self;
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a1347817507220a4384f3ff6f7c24546
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,58 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
public class CameraRefocus
{
public Camera Camera;
public Vector3 Lookatpoint;
public Transform Parent;
private Vector3 m_OrigCameraPos;
private bool m_Refocus;
public CameraRefocus(Camera camera, Transform parent, Vector3 origCameraPos)
{
m_OrigCameraPos = origCameraPos;
Camera = camera;
Parent = parent;
}
public void ChangeCamera(Camera camera)
{
Camera = camera;
}
public void ChangeParent(Transform parent)
{
Parent = parent;
}
public void GetFocusPoint()
{
RaycastHit hitInfo;
if (Physics.Raycast(Parent.transform.position + m_OrigCameraPos, Parent.transform.forward, out hitInfo,
100f))
{
Lookatpoint = hitInfo.point;
m_Refocus = true;
return;
}
m_Refocus = false;
}
public void SetFocusPoint()
{
if (m_Refocus)
{
Camera.transform.LookAt(Lookatpoint);
}
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d1e2e7a54dcc8694ab1eca46d072f264
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,54 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
[Serializable]
public class CurveControlledBob
{
public float HorizontalBobRange = 0.33f;
public float VerticalBobRange = 0.33f;
public AnimationCurve Bobcurve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.5f, 1f),
new Keyframe(1f, 0f), new Keyframe(1.5f, -1f),
new Keyframe(2f, 0f)); // sin curve for head bob
public float VerticaltoHorizontalRatio = 1f;
private float m_CyclePositionX;
private float m_CyclePositionY;
private float m_BobBaseInterval;
private Vector3 m_OriginalCameraPosition;
private float m_Time;
public void Setup(Camera camera, float bobBaseInterval)
{
m_BobBaseInterval = bobBaseInterval;
m_OriginalCameraPosition = camera.transform.localPosition;
// get the length of the curve in time
m_Time = Bobcurve[Bobcurve.length - 1].time;
}
public Vector3 DoHeadBob(float speed)
{
float xPos = m_OriginalCameraPosition.x + (Bobcurve.Evaluate(m_CyclePositionX)*HorizontalBobRange);
float yPos = m_OriginalCameraPosition.y + (Bobcurve.Evaluate(m_CyclePositionY)*VerticalBobRange);
m_CyclePositionX += (speed*Time.deltaTime)/m_BobBaseInterval;
m_CyclePositionY += ((speed*Time.deltaTime)/m_BobBaseInterval)*VerticaltoHorizontalRatio;
if (m_CyclePositionX > m_Time)
{
m_CyclePositionX = m_CyclePositionX - m_Time;
}
if (m_CyclePositionY > m_Time)
{
m_CyclePositionY = m_CyclePositionY - m_Time;
}
return new Vector3(xPos, yPos, 0f);
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 492f54f4accf00440828ffcb9e4fcc19
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,96 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
public class DragRigidbody : MonoBehaviour
{
const float k_Spring = 50.0f;
const float k_Damper = 5.0f;
const float k_Drag = 10.0f;
const float k_AngularDrag = 5.0f;
const float k_Distance = 0.2f;
const bool k_AttachToCenterOfMass = false;
private SpringJoint m_SpringJoint;
private void Update()
{
// Make sure the user pressed the mouse down
if (!Input.GetMouseButtonDown(0))
{
return;
}
var mainCamera = FindCamera();
// We need to actually hit an object
RaycastHit hit = new RaycastHit();
if (
!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin,
mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100,
Physics.DefaultRaycastLayers))
{
return;
}
// We need to hit a rigidbody that is not kinematic
if (!hit.rigidbody || hit.rigidbody.isKinematic)
{
return;
}
if (!m_SpringJoint)
{
var go = new GameObject("Rigidbody dragger");
Rigidbody body = go.AddComponent<Rigidbody>();
m_SpringJoint = go.AddComponent<SpringJoint>();
body.isKinematic = true;
}
m_SpringJoint.transform.position = hit.point;
m_SpringJoint.anchor = Vector3.zero;
m_SpringJoint.spring = k_Spring;
m_SpringJoint.damper = k_Damper;
m_SpringJoint.maxDistance = k_Distance;
m_SpringJoint.connectedBody = hit.rigidbody;
StartCoroutine("DragObject", hit.distance);
}
private IEnumerator DragObject(float distance)
{
var oldDrag = m_SpringJoint.connectedBody.drag;
var oldAngularDrag = m_SpringJoint.connectedBody.angularDrag;
m_SpringJoint.connectedBody.drag = k_Drag;
m_SpringJoint.connectedBody.angularDrag = k_AngularDrag;
var mainCamera = FindCamera();
while (Input.GetMouseButton(0))
{
var ray = mainCamera.ScreenPointToRay(Input.mousePosition);
m_SpringJoint.transform.position = ray.GetPoint(distance);
yield return null;
}
if (m_SpringJoint.connectedBody)
{
m_SpringJoint.connectedBody.drag = oldDrag;
m_SpringJoint.connectedBody.angularDrag = oldAngularDrag;
m_SpringJoint.connectedBody = null;
}
}
private Camera FindCamera()
{
if (GetComponent<Camera>())
{
return GetComponent<Camera>();
}
return Camera.main;
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 58650e15a2607e44daa0f150e0061d89
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,51 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
public class DynamicShadowSettings : MonoBehaviour
{
public Light sunLight;
public float minHeight = 10;
public float minShadowDistance = 80;
public float minShadowBias = 1;
public float maxHeight = 1000;
public float maxShadowDistance = 10000;
public float maxShadowBias = 0.1f;
public float adaptTime = 1;
private float m_SmoothHeight;
private float m_ChangeSpeed;
private float m_OriginalStrength = 1;
private void Start()
{
m_OriginalStrength = sunLight.shadowStrength;
}
// Update is called once per frame
private void Update()
{
Ray ray = new Ray(Camera.main.transform.position, -Vector3.up);
RaycastHit hit;
float height = transform.position.y;
if (Physics.Raycast(ray, out hit))
{
height = hit.distance;
}
if (Mathf.Abs(height - m_SmoothHeight) > 1)
{
m_SmoothHeight = Mathf.SmoothDamp(m_SmoothHeight, height, ref m_ChangeSpeed, adaptTime);
}
float i = Mathf.InverseLerp(minHeight, maxHeight, m_SmoothHeight);
QualitySettings.shadowDistance = Mathf.Lerp(minShadowDistance, maxShadowDistance, i);
sunLight.shadowBias = Mathf.Lerp(minShadowBias, maxShadowBias, 1 - ((1 - i)*(1 - i)));
sunLight.shadowStrength = Mathf.Lerp(m_OriginalStrength, 0, i);
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8566902b50d5bfb4fb7f8b89f9cdbe8b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,21 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
public class EventSystemChecker : MonoBehaviour
{
//public GameObject eventSystem;
// Use this for initialization
void Awake ()
{
if(!FindObjectOfType<EventSystem>())
{
//Instantiate(eventSystem);
GameObject obj = new GameObject("EventSystem");
obj.AddComponent<EventSystem>();
obj.AddComponent<StandaloneInputModule>().forceModuleActive = true;
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9c0578910bbe00d43919a92c7b9893fe
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -0,0 +1,73 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
[Serializable]
public class FOVKick
{
public Camera Camera; // optional camera setup, if null the main camera will be used
[HideInInspector] public float originalFov; // the original fov
public float FOVIncrease = 3f; // the amount the field of view increases when going into a run
public float TimeToIncrease = 1f; // the amount of time the field of view will increase over
public float TimeToDecrease = 1f; // the amount of time the field of view will take to return to its original size
public AnimationCurve IncreaseCurve;
public void Setup(Camera camera)
{
CheckStatus(camera);
Camera = camera;
originalFov = camera.fieldOfView;
}
private void CheckStatus(Camera camera)
{
if (camera == null)
{
throw new Exception("FOVKick camera is null, please supply the camera to the constructor");
}
if (IncreaseCurve == null)
{
throw new Exception(
"FOVKick Increase curve is null, please define the curve for the field of view kicks");
}
}
public void ChangeCamera(Camera camera)
{
Camera = camera;
}
public IEnumerator FOVKickUp()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t < TimeToIncrease)
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToIncrease)*FOVIncrease);
t += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
}
public IEnumerator FOVKickDown()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t > 0)
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToDecrease)*FOVIncrease);
t -= Time.deltaTime;
yield return new WaitForEndOfFrame();
}
//make sure that fov returns to the original size
Camera.fieldOfView = originalFov;
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6045a93fb05b9c74884821030da2c46c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

Some files were not shown because too many files have changed in this diff Show more