You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.6 KiB
85 lines
2.6 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
/// <summary> |
|
/// 克隆物体对象名生成工具 |
|
/// </summary> |
|
public class CloneObjNameTool |
|
{ |
|
private static CloneObjNameTool instance; |
|
private Dictionary<string, Dictionary<CloneObjType, int>> cloneObjectNumber; |
|
|
|
private CloneObjNameTool() |
|
{ |
|
cloneObjectNumber = new Dictionary<string, Dictionary<CloneObjType, int>>(); |
|
} |
|
|
|
public static CloneObjNameTool Instance() |
|
{ |
|
if (instance == null) |
|
{ |
|
instance = new CloneObjNameTool(); |
|
} |
|
return instance; |
|
} |
|
|
|
/// <summary> |
|
/// 获取克隆对象的编号 |
|
/// </summary> |
|
/// <param name="deptName">组织机构名</param> |
|
/// <param name="cloneObjType">克隆类型</param> |
|
/// <returns></returns> |
|
public int GetCloneObjectNumber(string deptName, CloneObjType cloneObjType) |
|
{ |
|
int number = 1; |
|
if (cloneObjectNumber.ContainsKey(deptName)) |
|
{//如果已存在这个组织机构 |
|
var cloneObjTypes = cloneObjectNumber[deptName];//获取这个组织机构下已经克隆的类型数组 |
|
if (cloneObjTypes.ContainsKey(cloneObjType)) |
|
{ |
|
//如果存在克隆对象类型返回+1值 |
|
number = ++cloneObjTypes[cloneObjType]; |
|
} |
|
else |
|
{ |
|
//如果没有克隆对象类型添加这个类型 |
|
cloneObjTypes.Add(cloneObjType, number); |
|
} |
|
} |
|
else |
|
{ |
|
//如果没有这个组织机构,创建克隆对象类型,将克隆对象类型添加到组织机构 |
|
var cloneObjTypes = new Dictionary<CloneObjType, int>(); |
|
cloneObjTypes.Add(cloneObjType, number); |
|
cloneObjectNumber.Add(deptName, cloneObjTypes); |
|
} |
|
return number; |
|
} |
|
|
|
/// <summary> |
|
/// 获取克隆对象的对象名称 |
|
/// </summary> |
|
public string GetCloneObjectName(CloneObjType cloneObjType) |
|
{ |
|
string name = ""; |
|
var deptName = ""; |
|
if (GameSettings.othersSettings.mode != Mode.DisasterManagement) |
|
{ |
|
deptName = CurrentUserInfo.organization.DisplayName; |
|
} |
|
else |
|
{ |
|
deptName = "灾情"; |
|
} |
|
|
|
var cloneObjTypeName = cloneObjType.ToString(); |
|
var number = GetCloneObjectNumber(deptName, cloneObjType); |
|
name = deptName + "-" + cloneObjTypeName + "-" + number; |
|
return name; |
|
} |
|
public void ResertCloneObjNameTool() |
|
{ |
|
cloneObjectNumber.Clear(); |
|
} |
|
}
|
|
|