浏览代码

Random Manager (#37)

* Base Commit : Random Manager

* Cleanup

* Updated Changelog
/main
GitHub 4 年前
当前提交
8e73fbca
共有 7 个文件被更改,包括 132 次插入0 次删除
  1. 1
      CHANGELOG.md
  2. 47
      Resources/Default_RandomManager.prefab
  3. 7
      Resources/Default_RandomManager.prefab.meta
  4. 28
      Runtime/LevelScripting/Actions/SetRandomSeedAction.cs
  5. 11
      Runtime/LevelScripting/Actions/SetRandomSeedAction.cs.meta
  6. 27
      Runtime/Managers/Implementations/RandomManager.cs
  7. 11
      Runtime/Managers/Implementations/RandomManager.cs.meta

1
CHANGELOG.md


* Added generic `bool Manager.TryGet<T>(out T manager)`
* Added `SimplePlayerInput` to supersede `KeyboardGamepadPlayerInput`
* Added new **RandomManager** and **SetRandomSeedAction**: Enables setting seeds for the `UnityEngine.Random`
#### Fixed

47
Resources/Default_RandomManager.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8867789534852015449
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5022597271667052788}
- component: {fileID: 7880544412867005628}
m_Layer: 0
m_Name: Default_RandomManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5022597271667052788
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8867789534852015449}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &7880544412867005628
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8867789534852015449}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ab445608acddfb94c903461bb0614295, type: 3}
m_Name:
m_EditorClassIdentifier:
setInitialSeed: 0
initialSeed: 0

7
Resources/Default_RandomManager.prefab.meta


fileFormatVersion: 2
guid: 79e039f1d121ce8428a86d5bca9c4e38
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

28
Runtime/LevelScripting/Actions/SetRandomSeedAction.cs


using NaughtyAttributes;
using System;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class SetRandomSeedAction : ActionBase
{
[Tooltip("Whether to set a new random seed, or a fixed seed")]
public bool newRandomSeed;
[DisableIf("newRandomSeed")]
[Tooltip("If New Random Seed is False. the new Random seed to apply")]
public int newSeed;
public override void Execute(GameObject instigator = null)
{
if(Manager.TryGet(out RandomManager randomManager))
{
if (newRandomSeed)
randomManager.SetRandomSeed(new System.Random((int)(DateTime.Now.Ticks - new DateTime(2021,1,1).Ticks)).Next());
else
randomManager.SetRandomSeed(newSeed);
}
}
}
}

11
Runtime/LevelScripting/Actions/SetRandomSeedAction.cs.meta


fileFormatVersion: 2
guid: 20fcb6e5b4b442543bccb6f484e4c688
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

27
Runtime/Managers/Implementations/RandomManager.cs


using UnityEngine;
namespace GameplayIngredients
{
[ManagerDefaultPrefab("RandomManager")]
public class RandomManager : Manager
{
public bool setInitialSeed = false;
public int initialSeed = 0;
public int currentSeed { get; private set; }
void Awake()
{
if (setInitialSeed)
SetRandomSeed(initialSeed);
}
public void SetRandomSeed(int seed)
{
Random.InitState(seed);
currentSeed = seed;
}
}
}

11
Runtime/Managers/Implementations/RandomManager.cs.meta


fileFormatVersion: 2
guid: ab445608acddfb94c903461bb0614295
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存