Skip to content

Commit

Permalink
feat: Add random texture action
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Aug 20, 2023
1 parent 7e88dad commit 5988e6b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/JCSUnity/Scripts/Actions/Texture.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Assets/JCSUnity/Scripts/Actions/Texture/JCS_RandomTextureAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* $File: JCS_RandomTextureAction.cs $
* $Date: 2023-08-19 06:10:05 $
* $Revision: $
* $Creator: Jen-Chieh Shen $
* $Notice: See LICENSE.txt for modification and distribution information
* Copyright (c) 2023 by Shen, Jen-Chieh $
*/
using System.Collections.Generic;
using UnityEngine;
using MyBox;

namespace JCSUnity
{
public class JCS_RandomTextureAction : MonoBehaviour
{
/* Variables */

private Renderer mRenderer = null;

[Separator("Initialize Variables (JCS_RandomTextureAction)")]

[Tooltip("List of textures to use.")]
[SerializeField]
public List<Texture> textures = null;

/* Setter & Getter */

/* Functions */

private void Awake()
{
this.mRenderer = this.GetComponent<Renderer>();

UpdateTexture();
}

/// <summary>
/// Randomly update the texture once.
/// </summary>
public void UpdateTexture()
{
SetTexture(textures);
}

/// <summary>
/// Update current texture with list of textures.
/// </summary>
public void SetTexture(List<Texture> textures)
{
Texture tex = JCS_Random.ChooseOne(textures);
mRenderer.material.SetTexture("_MainTex", tex);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions docs/ScriptReference/Actions/Texture/JCS_RandomTextureAction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# JCS_RandomTextureAction

Trigger an event while the time is reached.

## Variables

| Name | Description |
|:---------|:-------------------------|
| textures | List of textures to use. |

## Functions

| Name | Description |
|:--------------|:----------------------------------------------|
| UpdateTexture | Randomly update the texture once. |
| SetTexture | Update current texture with list of textures. |

0 comments on commit 5988e6b

Please sign in to comment.