Commit 6067f46c authored by Soraphis's avatar Soraphis
Browse files

added scriptablevariables as thirdparty library

and a sample object in the sample scene
parent c1cf4197
Soraphis @ e14d6e55
Subproject commit dcd3a2334efe304dc7325cd026d63c066fa75f8a Subproject commit e14d6e55f2c577c51ddee8f1a7e40c6d1064aae2
fileFormatVersion: 2
guid: 7143f22f1cb11224a90afc0f76c6afea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
https://github.com/roboryantron/Unite2017
\ No newline at end of file
fileFormatVersion: 2
guid: a3bb4b72d9e32514fa135ffbb5dcb7fc
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4a5bdb027158a714287a1c12dcb6e5e7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 27ab28222d2618249be384a893fb4f4c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
// ----------------------------------------------------------------------------
// Unite 2017 - Game Architecture with Scriptable Objects
//
// Author: Ryan Hipple
// Date: 10/04/17
// ----------------------------------------------------------------------------
using UnityEngine;
namespace RoboRyanTron.Unite2017.Variables
{
/// <summary>
/// Takes a FloatVariable and sends its value to an Animator parameter
/// every frame on Update.
/// </summary>
public class AnimatorParameterSetter : MonoBehaviour
{
[Tooltip("Variable to read from and send to the Animator as the specified parameter.")]
public FloatVariable Variable;
[Tooltip("Animator to set parameters on.")]
public Animator Animator;
[Tooltip("Name of the parameter to set with the value of Variable.")]
public string ParameterName;
/// <summary>
/// Animator Hash of ParameterName, automatically generated.
/// </summary>
[SerializeField] private int parameterHash;
private void OnValidate()
{
parameterHash = Animator.StringToHash(ParameterName);
}
private void Update()
{
Animator.SetFloat(parameterHash, Variable.Value);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: e771fa5f5e2e3f940b9bc241fbcba99f
timeCreated: 1506481786
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// ----------------------------------------------------------------------------
// Unite 2017 - Game Architecture with Scriptable Objects
//
// Author: Ryan Hipple
// Date: 10/04/17
// ----------------------------------------------------------------------------
using UnityEngine;
using UnityEngine.Audio;
namespace RoboRyanTron.Unite2017.Variables
{
/// <summary>
/// Takes a FloatVariable and sends a curve filtered version of its value
/// to an exposed audio mixer parameter every frame on Update.
/// </summary>
public class AudioParameterSetter : MonoBehaviour
{
[Tooltip("Mixer to set the parameter in.")]
public AudioMixer Mixer;
[Tooltip("Name of the parameter to set in the mixer.")]
public string ParameterName = "";
[Tooltip("Variable to send to the mixer parameter.")]
public FloatVariable Variable;
[Tooltip("Minimum value of the Variable that is mapped to the curve.")]
public FloatReference Min;
[Tooltip("Maximum value of the Variable that is mapped to the curve.")]
public FloatReference Max;
[Tooltip("Curve to evaluate in order to look up a final value to send as the parameter.\n" +
"T=0 is when Variable == Min\n" +
"T=1 is when Variable == Max")]
public AnimationCurve Curve;
private void Update()
{
float t = Mathf.InverseLerp(Min.Value, Max.Value, Variable.Value);
float value = Curve.Evaluate(Mathf.Clamp01(t));
Mixer.SetFloat(ParameterName, value);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 299bff7d6e35c954e8ea2552c85925d7
timeCreated: 1506874288
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// ----------------------------------------------------------------------------
// Unite 2017 - Game Architecture with Scriptable Objects
//
// Author: Ryan Hipple
// Date: 10/04/17
// ----------------------------------------------------------------------------
using UnityEngine;
using UnityEngine.Audio;
namespace RoboRyanTron.Unite2017.Variables
{
public class AudioVolumeSetter : MonoBehaviour
{
public AudioMixer Mixer;
public string ParameterName = "";
public FloatVariable Variable;
private void Update()
{
float dB = Variable.Value > 0.0f ?
20.0f * Mathf.Log10(Variable.Value) :
-80.0f;
Mixer.SetFloat(ParameterName, dB);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8418a429d33f6b7499247e83eebdbc93
timeCreated: 1505450514
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// ----------------------------------------------------------------------------
// Unite 2017 - Game Architecture with Scriptable Objects
//
// Author: Ryan Hipple
// Date: 10/04/17
// ----------------------------------------------------------------------------
using UnityEngine;
namespace RoboRyanTron.Unite2017.Variables
{
public class DamageDealer : MonoBehaviour
{
public FloatReference DamageAmount;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 3870d1a7207a5f94db08d1cefcf78825
timeCreated: 1506871845
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 85b9c3e407230c841a6c0ec9ed29c438
folderAsset: yes
timeCreated: 1507522382
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
// ----------------------------------------------------------------------------
// Unite 2017 - Game Architecture with Scriptable Objects
//
// Author: Ryan Hipple
// Date: 10/04/17
// ----------------------------------------------------------------------------
using UnityEditor;
using UnityEngine;
namespace RoboRyanTron.Unite2017.Variables
{
[CustomPropertyDrawer(typeof(FloatReference))]
public class FloatReferenceDrawer : PropertyDrawer
{
/// <summary>
/// Options to display in the popup to select constant or variable.
/// </summary>
private readonly string[] popupOptions =
{ "Use Constant", "Use Variable" };
/// <summary> Cached style to use to draw the popup button. </summary>
private GUIStyle popupStyle;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (popupStyle == null)
{
popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"));
popupStyle.imagePosition = ImagePosition.ImageOnly;
}
label = EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, label);
EditorGUI.BeginChangeCheck();
// Get properties
SerializedProperty useConstant = property.FindPropertyRelative("UseConstant");
SerializedProperty constantValue = property.FindPropertyRelative("ConstantValue");
SerializedProperty variable = property.FindPropertyRelative("Variable");
// Calculate rect for configuration button
Rect buttonRect = new Rect(position);
buttonRect.yMin += popupStyle.margin.top;
buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
position.xMin = buttonRect.xMax;
// Store old indent level and set it to 0, the PrefixLabel takes care of it
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
int result = EditorGUI.Popup(buttonRect, useConstant.boolValue ? 0 : 1, popupOptions, popupStyle);
useConstant.boolValue = result == 0;
EditorGUI.PropertyField(position,
useConstant.boolValue ? constantValue : variable,
GUIContent.none);
if (EditorGUI.EndChangeCheck())
property.serializedObject.ApplyModifiedProperties();
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 1b4b8b2d9f5a4d447a3dbb595a41291e
timeCreated: 1505271762
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// ----------------------------------------------------------------------------
// Unite 2017 - Game Architecture with Scriptable Objects
//
// Author: Ryan Hipple
// Date: 10/04/17
// ----------------------------------------------------------------------------
using UnityEngine;
using UnityEngine.UI;
namespace RoboRyanTron.Unite2017.Variables
{
/// <summary>
/// Sets an Image component's fill amount to represent how far Variable is
/// between Min and Max.
/// </summary>
public class ImageFillSetter : MonoBehaviour
{
[Tooltip("Value to use as the current ")]
public FloatReference Variable;
[Tooltip("Min value that Variable to have no fill on Image.")]
public FloatReference Min;
[Tooltip("Max value that Variable can be to fill Image.")]
public FloatReference Max;
[Tooltip("Image to set the fill amount on." )]
public Image Image;
private void Update()
{
Image.fillAmount = Mathf.Clamp01(
Mathf.InverseLerp(Min, Max, Variable));
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: a8acea44d44a5ec4ea472404164e8497
timeCreated: 1505887264
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// ----------------------------------------------------------------------------
// Unite 2017 - Game Architecture with Scriptable Objects
//
// Author: Ryan Hipple
// Date: 10/04/17
// ----------------------------------------------------------------------------
using System;
using UnityEngine;
namespace RoboRyanTron.Unite2017.Variables
{
public class KeyboardMover : MonoBehaviour
{
[Serializable]
public class MoveAxis
{
public KeyCode Positive;
public KeyCode Negative;
public MoveAxis(KeyCode positive, KeyCode negative)
{
Positive = positive;
Negative = negative;
}
public static implicit operator float(MoveAxis axis)
{
return (Input.GetKey(axis.Positive)
? 1.0f : 0.0f) -
(Input.GetKey(axis.Negative)
? 1.0f : 0.0f);
}
}
public FloatVariable MoveRate;
public MoveAxis Horizontal = new MoveAxis(KeyCode.D, KeyCode.A);
public MoveAxis Vertical = new MoveAxis(KeyCode.W, KeyCode.S);
private void Update()
{
Vector3 moveNormal = new Vector3(Horizontal, Vertical, 0.0f).normalized;
transform.position += moveNormal*Time.deltaTime*MoveRate.Value;
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment