Categorii: Tot - texture

realizată de Mike Ton 8 ani în urmă

930

Unity 3D : Scriptable Object

In the realm of Unity development, creating and managing assets often involves the use of Scriptable Objects and various Editor utilities. One such utility is the PreviewRenderUtility, which allows developers to render previews of game objects within the editor.

Unity 3D : Scriptable Object

Scriptable Object

Asset

(Icons)
Unity

(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.cs

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

(Coroutine)
(MonoBehaviour)

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);

(AudioEvent)
/Editor

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;

(ScriptableObject)

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);

(Attribute)

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;

Editor

(preview)
PreviewRenderUtility

DrawRenderPreview (Rect r, GameObject previewObject ) { ... }

var mPrevRender = new PreviewRenderUtility();

AssetPreview

(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;

GUILayout
// buttons
EditorGUI
EditorUtility
// Create Project Objects/Components