private void GenerateOrDeleteObject(IVRiscuitObjectSet objset, IVRiscuitObjectSet globalTable) { if (isGenerateOrDeleteObject == false) { return; } foreach (var kvp in _genDelTable) { var val = kvp.Value; if (val < 0) { var objs = objset.TypeTable[kvp.Key]; if (objs.Count < -val) { Debug.LogError("Error: 必要な数のオブジェクトがありません。"); if (globalTable != null) { foreach (var obj in objs) { globalTable.Delete(obj); objset.Delete(obj); } } return; } for (int i = 0; i < -val; i++) { if (globalTable != null) { globalTable.Delete(objs[0]); } objset.Delete(objs[0]); } } else if (val > 0) { var first = objset.First(); var generated = new List <CalculateObject>(); for (int i = 0; i < val; i++) { var pos = new Vector3(first.Position.x + 1, first.Position.y, first.Position.z); var rot = Quaternion.Euler(first.Rotation.eulerAngles.x, first.Rotation.eulerAngles.y, first.Rotation.eulerAngles.z); var o = new CalculateObject(pos, rot, kvp.Key); objset.Add(o); generated.Add(o); } _generatedObjects = generated; } } }
/// <summary> /// ルールの適用 /// </summary> /// <param name="objectsTable"></param> void IRule.Apply(IVRiscuitObjectSet objectsTable, IVRiscuitObjectSet globalTable) { var beforeTable = new VRiscuitObjectSet(objectsTable); GenerateOrDeleteObject(objectsTable, globalTable); DescentMethod(objectsTable, beforeTable, _afterObjectSet, _beforeObjectSet); // 追加されたオブジェクトをmanagerのobjectSetに追加 if (_generatedObjects == null) { return; } foreach (var obj in _generatedObjects) { if (IsDebug) { globalTable.Add(obj); continue; } } _generatedObjects = null; }