浏览代码

Added Support for Game Saves in Factory / Added SetInstigatorFromFactoryLogic Option continue for null instigator / Tweaked UI of GameSaveSetValueAction

/main
peeweek 5 年前
当前提交
086aeacb
共有 3 个文件被更改,包括 59 次插入6 次删除
  1. 50
      Runtime/Ingredients/Factory/Factory.cs
  2. 12
      Runtime/LevelScripting/Actions/GameSaveSetValueAction.cs
  3. 3
      Runtime/LevelScripting/Logic/SetInstigatorFromFactoryLogic.cs

50
Runtime/Ingredients/Factory/Factory.cs


{
Random,
Sequential,
Shuffle
Shuffle,
GameSave
}
public enum SpawnTargetSelection

DontDestroyOnLoad
}
[Header("Blueprint")]
public BlueprintSelectionMode blueprintSelecionMode = BlueprintSelectionMode.Random;
[ShowIf("usesGameSave")]
public GameSaveManager.Location gameSaveLocation = GameSaveManager.Location.User;
[ShowIf("usesGameSave")]
public string gameSaveVariableName = "FactoryBPIndex";
[ShowIf("usesGameSave")]
public int defaultGameSaveIndex = 0;
[Header("Spawn Target")]
public SpawnLocation spawnLocation = SpawnLocation.SameSceneAsTarget;
public BlueprintSelectionMode blueprintSelecionMode = BlueprintSelectionMode.Random;
[Header("Reap and Respawn")]
public SpawnLocation spawnLocation = SpawnLocation.SameSceneAsTarget;
public float RespawnDelay = 3.0f;
public bool ReapInstancesOnDestroy = true;

}
}
bool usesGameSave()
{
return blueprintSelecionMode == BlueprintSelectionMode.GameSave;
}
public void SetTarget(GameObject target)
{
if(target != null)

public GameObject GetInstance(int index)
{
if (m_Instances.Count > index)
if (m_Instances != null && m_Instances.Count > index)
return m_Instances[index];
else
return null;

private GameObject SelectBlueprint()
{
if(FactoryBlueprints == null || FactoryBlueprints.Length == 0)
{
Debug.LogError($"Factory '{gameObject.name}' could not spawn anything as there are no blueprints set up");
return null;
}
default:
case BlueprintSelectionMode.Random:
currentBlueprintIndex = Random.Range(0, FactoryBlueprints.Length);
break;

case BlueprintSelectionMode.Shuffle:
currentBlueprintIndex = Shuffle(currentBlueprintIndex);
break;
case BlueprintSelectionMode.GameSave:
currentBlueprintIndex = GetFromGameSave();
break;
}
return FactoryBlueprints[currentBlueprintIndex];
}

shuffleIndices = Enumerable.Range(0, FactoryBlueprints.Length).OrderBy(x => Random.value).ToList();
}
return shuffleIndices[(shuffleIndices.IndexOf(i) + 1) % shuffleIndices.Count];
}
private int GetFromGameSave()
{
var gsm = Manager.Get<GameSaveManager>();
int index = -1;
if(gsm.HasInt(gameSaveVariableName, gameSaveLocation))
{
index = gsm.GetInt(gameSaveVariableName, gameSaveLocation);
}
else
{
index = defaultGameSaveIndex;
}
return Mathf.Clamp(index, 0, FactoryBlueprints.Length - 1);
}
}
}

12
Runtime/LevelScripting/Actions/GameSaveSetValueAction.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public string Key = "SomeKey";
public GameSaveManager.Location saveLocation = GameSaveManager.Location.System;
public GameSaveManager.ValueType valueType = GameSaveManager.ValueType.String;
[ShowIf("isString")]
[ShowIf("isInt")]
[ShowIf("isBool")]
[ShowIf("isFloat")]
public float FloatValue;
public override void Execute(GameObject instigator = null)

case GameSaveManager.ValueType.String: gsm.SetString(Key, saveLocation, StringValue); break;
}
}
bool isString() { return valueType == GameSaveManager.ValueType.String; }
bool isBool() { return valueType == GameSaveManager.ValueType.Bool; }
bool isInt() { return valueType == GameSaveManager.ValueType.Int; }
bool isFloat() { return valueType == GameSaveManager.ValueType.Float; }
}
}

3
Runtime/LevelScripting/Logic/SetInstigatorFromFactoryLogic.cs


[NonNullCheck]
public Factory Factory;
public int FactoryIndex = 0;
public bool ContinueEvenIfNull = false;
public override void Execute(GameObject instigator = null)
{

if (instance != null)
if(instance != null || ContinueEvenIfNull)
Call(Next, instance);
}
}

正在加载...
取消
保存