Skip to content

Commit 5988e6b

Browse files
committed
feat: Add random texture action
1 parent 7e88dad commit 5988e6b

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

Assets/JCSUnity/Scripts/Actions/Texture.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* $File: JCS_RandomTextureAction.cs $
3+
* $Date: 2023-08-19 06:10:05 $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright (c) 2023 by Shen, Jen-Chieh $
8+
*/
9+
using System.Collections.Generic;
10+
using UnityEngine;
11+
using MyBox;
12+
13+
namespace JCSUnity
14+
{
15+
public class JCS_RandomTextureAction : MonoBehaviour
16+
{
17+
/* Variables */
18+
19+
private Renderer mRenderer = null;
20+
21+
[Separator("Initialize Variables (JCS_RandomTextureAction)")]
22+
23+
[Tooltip("List of textures to use.")]
24+
[SerializeField]
25+
public List<Texture> textures = null;
26+
27+
/* Setter & Getter */
28+
29+
/* Functions */
30+
31+
private void Awake()
32+
{
33+
this.mRenderer = this.GetComponent<Renderer>();
34+
35+
UpdateTexture();
36+
}
37+
38+
/// <summary>
39+
/// Randomly update the texture once.
40+
/// </summary>
41+
public void UpdateTexture()
42+
{
43+
SetTexture(textures);
44+
}
45+
46+
/// <summary>
47+
/// Update current texture with list of textures.
48+
/// </summary>
49+
public void SetTexture(List<Texture> textures)
50+
{
51+
Texture tex = JCS_Random.ChooseOne(textures);
52+
mRenderer.material.SetTexture("_MainTex", tex);
53+
}
54+
}
55+
}

Assets/JCSUnity/Scripts/Actions/Texture/JCS_RandomTextureAction.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# JCS_RandomTextureAction
2+
3+
Trigger an event while the time is reached.
4+
5+
## Variables
6+
7+
| Name | Description |
8+
|:---------|:-------------------------|
9+
| textures | List of textures to use. |
10+
11+
## Functions
12+
13+
| Name | Description |
14+
|:--------------|:----------------------------------------------|
15+
| UpdateTexture | Randomly update the texture once. |
16+
| SetTexture | Update current texture with list of textures. |

0 commit comments

Comments
 (0)