浏览代码

Added Timer Elements

/main
Thomas ICHÉ 5 年前
当前提交
204e6d25
共有 11 个文件被更改,包括 328 次插入0 次删除
  1. 3
      CHANGELOG.md
  2. 8
      Icons/Misc/ic-timer.png
  3. 91
      Icons/Misc/ic-timer.png.meta
  4. 8
      Runtime/Ingredients/Timer.meta
  5. 74
      Runtime/Ingredients/Timer/Timer.cs
  6. 11
      Runtime/Ingredients/Timer/Timer.cs.meta
  7. 69
      Runtime/Ingredients/Timer/TimerAction.cs
  8. 11
      Runtime/Ingredients/Timer/TimerAction.cs.meta
  9. 42
      Runtime/Ingredients/Timer/TimerDisplayRig.cs
  10. 11
      Runtime/Ingredients/Timer/TimerDisplayRig.cs.meta

3
CHANGELOG.md


* Added SetAnimatorParameterAction : Perform parameter setting on Animators
* Added Sacrifice Oldest option to Factory
* Added Folder Cosmetic Behavior (for view in Advanced HIerarchy View)
* Added Timer Component
* Added TimerAction to control Timer
* Added TimerDisplayRig
#### Changed

8
Icons/Misc/ic-timer.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 853 B

91
Icons/Misc/ic-timer.png.meta


fileFormatVersion: 2
guid: 4ad9148371bb28f44a21256b05f6ecae
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/Ingredients/Timer.meta


fileFormatVersion: 2
guid: 1ebdbde62aaa7554e927640949440236
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

74
Runtime/Ingredients/Timer/Timer.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients
{
public class Timer : MonoBehaviour
{
public bool StartOnEnable = false;
public uint Hours = 0;
[Range(0,59)]
public uint Minutes = 1;
[Range(0,59)]
public uint Seconds = 30;
[Range(0,999)]
public uint Milliseconds = 0;
public uint CurrentHours { get { return (uint)Mathf.Floor(m_TTL / 3600); } }
public uint CurrentMinutes { get { return (uint)Mathf.Floor(m_TTL / 60) % 60; } }
public uint CurrentSeconds { get { return (uint)Mathf.Floor(m_TTL) % 60; } }
public uint CurrentMilliseconds { get { return (uint)((m_TTL % 1.0f) * 1000); } }
[ReorderableList]
public Callable[] OnTimerFinished;
[ReorderableList]
public Callable[] OnTimerInterrupt;
[ReorderableList]
public Callable[] OnTimerStart;
float m_TTL = 0.0f;
public bool isRunning => m_TTL > 0.0f;
public void OnEnable()
{
if (StartOnEnable)
Restart();
else
m_TTL = 0.0f;
}
public void Restart(GameObject instigator = null)
{
m_TTL = Hours * 3600 + Minutes * 60 + Seconds + Milliseconds * 0.001f;
Callable.Call(OnTimerStart, instigator);
}
public void Update()
{
if(m_TTL > 0.0f)
{
m_TTL -= Time.deltaTime;
if (m_TTL <= 0.0f)
{
m_TTL = 0.0f;
Callable.Call(OnTimerFinished);
}
}
}
public void Interrupt(GameObject instigator = null)
{
if(m_TTL > 0.0f)
{
m_TTL = 0.0f;
Callable.Call(OnTimerInterrupt, instigator);
}
}
}
}

11
Runtime/Ingredients/Timer/Timer.cs.meta


fileFormatVersion: 2
guid: 3c7830caa27694f488f509f2dff31323
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 4ad9148371bb28f44a21256b05f6ecae, type: 3}
userData:
assetBundleName:
assetBundleVariant:

69
Runtime/Ingredients/Timer/TimerAction.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class TimerAction : ActionBase
{
public enum Action
{
Start,
SetTime,
Interrupt
}
[NonNullCheck]
public Timer timer;
public Action action = Action.Start;
[ShowIf("isSetTime")]
public uint Hours = 0;
[ShowIf("isSetTime"), Range(0,59)]
public uint Minutes = 1;
[ShowIf("isSetTime"), Range(0,59)]
public uint Seconds = 30;
[ShowIf("isSetTime"), Range(0, 999)]
public uint Milliseconds = 0;
[ShowIf("isSetTime")]
public bool Restart = false;
public override void Execute(GameObject instigator = null)
{
if(timer == null)
{
Debug.LogWarning($"{this.gameObject.name}:{this.name} : Null Timer");
}
else
{
switch (action)
{
default:
case Action.Start:
timer.Restart(instigator);
break;
case Action.SetTime:
if (timer.isRunning)
timer.Interrupt(instigator);
timer.Hours = Hours;
timer.Minutes = Minutes;
timer.Seconds = Seconds;
timer.Milliseconds = Milliseconds;
if (Restart)
timer.Restart(instigator);
break;
case Action.Interrupt:
timer.Interrupt(instigator);
break;
}
}
}
bool isSetTime() { return action == Action.SetTime; }
}
}

11
Runtime/Ingredients/Timer/TimerAction.cs.meta


fileFormatVersion: 2
guid: 198dc0c7b790e2240b7322b532cbdf83
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 4ad9148371bb28f44a21256b05f6ecae, type: 3}
userData:
assetBundleName:
assetBundleVariant:

42
Runtime/Ingredients/Timer/TimerDisplayRig.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using NaughtyAttributes;
namespace GameplayIngredients
{
public class TimerDisplayRig : MonoBehaviour
{
[NonNullCheck]
public Text text;
[NonNullCheck]
public TextMesh textMesh;
[NonNullCheck]
public Timer timer;
[InfoBox("Use the following wildcards:\n - %h : hours\n - %m : minutes\n - %s : seconds\n - %x : milliseconds", InfoBoxType.Normal)]
public string format = "%h:%m:%s:%x";
private void Update()
{
if (timer == null || (text == null && textMesh == null))
return;
var value = format;
value = value.Replace("%h", timer.CurrentHours.ToString("D2"));
value = value.Replace("%m", timer.CurrentMinutes.ToString("D2"));
value = value.Replace("%s", timer.CurrentSeconds.ToString("D2"));
value = value.Replace("%x", timer.CurrentMilliseconds.ToString("D3"));
if (text != null)
text.text = value;
if (textMesh != null)
textMesh.text = value;
}
}
}

11
Runtime/Ingredients/Timer/TimerDisplayRig.cs.meta


fileFormatVersion: 2
guid: e2522200da7627a458c971072a53bf5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 4ad9148371bb28f44a21256b05f6ecae, type: 3}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存