forked from keijiro/Reaktion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Keijiro Takahashi
authored and
Keijiro Takahashi
committed
Aug 5, 2014
1 parent
2645484
commit 1657adf
Showing
6 changed files
with
237 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// Reaktion - An audio reactive animation toolkit for Unity. | ||
// | ||
// Copyright (C) 2013, 2014 Keijiro Takahashi | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections; | ||
|
||
namespace Reaktion { | ||
|
||
// Custom editor UI for InjectorLink. | ||
[CustomPropertyDrawer(typeof(InjectorLink))] | ||
class InjectorLinkDrawer : PropertyDrawer | ||
{ | ||
// Labels and values for the mode selector. | ||
static GUIContent[] modeLabels = { | ||
new GUIContent("Not Bound"), | ||
new GUIContent("Auto Bind"), | ||
new GUIContent("Bind By Reference"), | ||
new GUIContent("Bind By Name") | ||
}; | ||
static int[] modeValues = { 0, 1, 2, 3 }; | ||
|
||
int GetRowCount(SerializedProperty property) | ||
{ | ||
// Fully expand if it has multiple mode values. | ||
var propMode = property.FindPropertyRelative("_mode"); | ||
if (propMode.hasMultipleDifferentValues) return 3; | ||
|
||
// Expand when by-reference and by-name mode. | ||
var mode = (InjectorLink.Mode)propMode.enumValueIndex; | ||
if (mode == InjectorLink.Mode.ByReference || | ||
mode == InjectorLink.Mode.ByName) return 2; | ||
|
||
// Just one line. | ||
return 1; | ||
} | ||
|
||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) | ||
{ | ||
var rowCount = GetRowCount(property); | ||
return EditorGUIUtility.singleLineHeight * rowCount + | ||
EditorGUIUtility.standardVerticalSpacing * (rowCount - 1); | ||
} | ||
|
||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
EditorGUI.BeginProperty(position, label, property); | ||
|
||
position.height = EditorGUIUtility.singleLineHeight; | ||
|
||
// First line: mode selector. | ||
var propMode = property.FindPropertyRelative("_mode"); | ||
EditorGUI.IntPopup(position, propMode, modeLabels, modeValues, label); | ||
position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; | ||
|
||
// Indent the line. | ||
position.width -= 16; | ||
position.x += 16; | ||
EditorGUIUtility.labelWidth -= 16; | ||
|
||
// Reference box. | ||
var mode = (InjectorLink.Mode)propMode.enumValueIndex; | ||
if (propMode.hasMultipleDifferentValues || mode == InjectorLink.Mode.ByReference) | ||
{ | ||
EditorGUI.PropertyField(position, property.FindPropertyRelative("_reference")); | ||
position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; | ||
} | ||
|
||
// Name box. | ||
if (propMode.hasMultipleDifferentValues || mode == InjectorLink.Mode.ByName) | ||
EditorGUI.PropertyField(position, property.FindPropertyRelative("_name")); | ||
|
||
// Update the link when it gets updated. | ||
if (GUI.changed) property.FindPropertyRelative("_forceUpdate").boolValue = true; | ||
|
||
EditorGUI.EndProperty(); | ||
} | ||
} | ||
|
||
} // namespace Reaktion |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// | ||
// Reaktion - An audio reactive animation toolkit for Unity. | ||
// | ||
// Copyright (C) 2013, 2014 Keijiro Takahashi | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
namespace Reaktion { | ||
|
||
// A class used to reference an Injector from Reaktors. | ||
[System.Serializable] | ||
public class InjectorLink | ||
{ | ||
// Link mode. | ||
public enum Mode { Null, Automatic, ByReference, ByName } | ||
|
||
[SerializeField] Mode _mode = Mode.Automatic; | ||
|
||
public Mode mode { | ||
get { return _mode; } | ||
set { _mode = value; Update(); } | ||
} | ||
|
||
// Link-by-reference mode information. | ||
[SerializeField] InjectorBase _reference; | ||
|
||
public InjectorBase reference { | ||
get { return _reference; } | ||
set { _reference = value; Update(); } | ||
} | ||
|
||
// Link-by-name mode information. | ||
[SerializeField] string _name; | ||
|
||
public string name { | ||
get { return _name; } | ||
set { _name = value; Update(); } | ||
} | ||
|
||
// "Update the link" flag (exposed only for Editor). | ||
[SerializeField] bool _forceUpdate; | ||
|
||
// Master script. | ||
MonoBehaviour master; | ||
|
||
// Linked Injector. | ||
InjectorBase injector; | ||
|
||
// Get a output dB level from the Injector. | ||
public float DbLevel { | ||
get { | ||
if (_forceUpdate) Update(); | ||
return injector ? injector.DbLevel : -1e12f; | ||
} | ||
} | ||
|
||
// Initialization (should be called from the master script). | ||
public void Initialize(MonoBehaviour master) | ||
{ | ||
this.master = master; | ||
Update(); | ||
} | ||
|
||
// Update the link. | ||
public void Update() | ||
{ | ||
injector = FindInjector(); | ||
_forceUpdate = false; | ||
} | ||
|
||
// Find the linked injector. | ||
InjectorBase FindInjector() | ||
{ | ||
if (_mode == Mode.Automatic && master) | ||
{ | ||
var r = master.GetComponent<InjectorBase>(); | ||
if (r) return r; | ||
|
||
r = master.GetComponentInParent<InjectorBase>(); | ||
if (r) return r; | ||
|
||
r = master.GetComponentInChildren<InjectorBase>(); | ||
if (r) return r; | ||
|
||
return Object.FindObjectOfType<InjectorBase>(); | ||
} | ||
|
||
if (_mode == Mode.ByReference) return _reference; | ||
|
||
if (_mode == Mode.ByName) | ||
{ | ||
var go = GameObject.Find(_name); | ||
if (go) return go.GetComponent<InjectorBase>(); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
} // namespace Reaktion |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters