von Mike Ton Vor 8 Jahren
956
Mehr dazu
(gizmos)
Assets/Gizmos
"AudioItem Icon.png"
png named with a normal space between "AudioItem" - name of your class - and "Icon".
128x128
public class AudioItem : ScriptableObject { }
https://forum.unity3d.com/threads/custom-scriptableobject-icons-thumbnail.256246/#post-1693711
AttackShapeEditor : Editor { ... }
Texture2D
(Thumbnail)
RenderStaticPreview (string assetPath, Object[] subAssets, int texWidth, int texHeight) { ... }
staticPreview.Apply();
(draw)
staticPreview.SetPixel(sx+px, sy+py, col);
var staticPreview = new Texture2D (texWidth, texHeight);
bool
(PreviewGUI)
OnPreviewGUI (Rect r, GUIStyle background) { ... }
// 2D rect to draw in PreviewGUI window
HasPreviewGUI () {...}
return true;
// Default == false (off)
// Ensures Preview Window is displayed in Inspector
OnInspectorGUI () { ... }
if (Event.current.type == EventType.Layout) { ... }
return;
// What does this do???
AttackPattern.cs
Destructible.cs
TakeDamage(float damage) { ... }
if (Health < 0 && DestructionSequence) { ... }
StartCoroutine(DestructionSequence.SequenceCoroutine(this));
...
Destructible : MonoBehaviour { ... }
HideBehindEffect.cs
HideBehindEffect : DestructionSequence { ... }
SequenceCoroutine(MonoBehaviour runner) { ... }
Destroy(runner.gameObject);
yield return new WaitForSeconds(DestroyOriginalAfterTime);
Instantiate(Effect, runner.transform.position, runner.transform.rotation);
DestroyOriginalAfterTime = 1f;
GameObject
Effect;
[CreateAssetMenu(menuName="Destruction/Hide Behind Effect")]
DestructionSequence.cs
DestructionSequence : ScriptableObject { ... }
IEnumerator
SequenceCoroutine(MonoBehaviour runner);
AudioEventEditor.cs
(class)
AudioEventEditor : Editor { ... }
OnInspectorGUI() { ... }
if (GUILayout.Button("Preview")) { ... }
((AudioEvent) target).Play(_previewer);
// if Preview Button pressed, play audio
// If statement creates button !
DrawDefaultInspector();
OnDisable() { ... }
DestroyImmediate(_previewer.gameObject);
OnEnable() { ... }
_previewer = EditorUtility.CreateGameObjectWithHideFlags("Audio preview", HideFlags.HideAndDontSave, typeof(AudioSource)).GetComponent
private
AudioSource
_previewer;
[CustomEditor(typeof(AudioEvent), true)]
// ??? true == ???
using
UnityEditor;
SimpleAudioEvent.cs
SimpleAudioEvent : AudioEvent { ... }
override
Play(AudioSource source) { ... }
source.Play();
(config source)
source.pitch = Random.Range(pitch.minValue, pitch.maxValue);
source.volume = Random.Range(volume.minValue, volume.maxValue);
source.clip = clips[Random.Range(0, clips.Length)];
if (clips.Length == 0) return;
(var)
[MinMaxRange(0, 2)]
RangedFloat
volume;
pitch;
AudioClip[]
clips;
[CreateAssetMenu(menuName="Audio Events/Simple")]
AudioEvent.cs
abstract
AudioEvent : ScriptableObject { ... }
void
Play(AudioSource source);
RangedFloat.cs
struct
RangedFloat { ... }
maxValue;
minValue;
(attribute)
[Serializable]
MinMaxRangeAttribute.cs
public
class
MinMaxRangeAttribute : Attribute { ... }
float
Max { get; private set; }
Min { get; private set; }
MinMaxRangeAttribute(float min, float max) { ... }
Max = max;
Min = min;
DrawRenderPreview (Rect r, GameObject previewObject ) { ... }
var mPrevRender = new PreviewRenderUtility();
(func)
Texture
GenerateIcon(GameObject previewObject){ ... }
return
previewIcon;
previewIcon = AssetPreview.GetAssetPreview (previewObject);
previewObject.SetActive(true);
// ARGH! Must set to active to activate thumbnail
private Texture previewIcon;