You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using SiegeSong;
|
|
|
|
namespace SiegeSong
|
|
{
|
|
public class InstanceManager : MonoBehaviour
|
|
{
|
|
public string CurrentPlayerInstanceID;
|
|
public GameObject[] Instances;
|
|
public string[] InstanceIDs;
|
|
public int[] ActorIDs;
|
|
|
|
public RuntimeManager RuntimeManager;
|
|
|
|
public int LastGeneratedInstanceIndex;
|
|
|
|
public int MaxInstanceIDLength = 5;
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public string GenerateInstanceID()
|
|
{
|
|
LastGeneratedInstanceIndex++;
|
|
var instanceIndex = LastGeneratedInstanceIndex.ToString();
|
|
var newInstanceID = "";
|
|
for (var i = 0; i < MaxInstanceIDLength; i++)
|
|
{
|
|
if (i >= instanceIndex.Length)
|
|
{
|
|
newInstanceID += "A";
|
|
}
|
|
else
|
|
{
|
|
newInstanceID += "BCDEFGHIJK"[int.Parse(instanceIndex[i].ToString())];
|
|
}
|
|
}
|
|
return newInstanceID;
|
|
}
|
|
|
|
public GameObject GetInstanceByID(string instanceID)
|
|
{
|
|
for(var i = 0; i < Instances.Length; i++)
|
|
{
|
|
if (InstanceIDs[i].ToLower() == instanceID.ToLower())
|
|
{
|
|
return Instances[i];
|
|
}
|
|
}
|
|
return new GameObject();
|
|
}
|
|
|
|
public void AddInstance(string instanceID, GameObject newInstance)
|
|
{
|
|
var newInstanceArray = new GameObject[Instances.Length + 1];
|
|
var newInstanceIDArray = new string[InstanceIDs.Length + 1];
|
|
Instances.CopyTo(newInstanceArray, 0);
|
|
InstanceIDs.CopyTo(newInstanceIDArray, 0);
|
|
newInstanceArray[newInstanceArray.Length - 1] = newInstance;
|
|
newInstanceIDArray[newInstanceIDArray.Length - 1] = instanceID;
|
|
Instances = newInstanceArray;
|
|
InstanceIDs = newInstanceIDArray;
|
|
}
|
|
|
|
public void RemoveInstance(string instanceID)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|