/// <summary> /// creates an item for level. /// reads an item information file(.spec) and configures the item class. /// The read item class is stored in the list. /// </summary> /// <param name="info">item information for level</param> /// <param name="sceneParent">3D scene parent node</param> /// <returns>item class for the game</returns> protected GameItemBox CreateItemBox(ref ItemInLevel info, NodeBase sceneParent) { ItemBoxSpec spec = LoadItemSpec(ref info); GameItemBox item = new GameItemBox(spec); item.WorldTransform = Matrix.CreateTranslation(info.Position); item.SetRootAxis(Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); // creates a collision data. Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.ModelRadius, 0.0f), Matrix.Invert(item.RootAxis)); CollideSphere collide = new CollideSphere(centerPos, spec.ModelRadius); item.SetCollide(collide); item.EnableCulling = true; item.ActiveFog = true; item.ActiveLighting = false; // adds item to the list. itemList.Add(item); // adds item to parent scene node. sceneParent.AddChild(item); return(item); }
private void DrawLinkButtons(NodeBase node) { if (linkingParentNode == null) { if (GUILayout.Button("link")) { linkingParentNode = node; } } else if (linkingParentNode == node) { if (GUILayout.Button("cancel")) { linkingParentNode = null; } } else if (linkingParentNode.GetChildren().Contains(node.name)) { if (GUILayout.Button("unlink")) { linkingParentNode.RemoveChild(node.name); linkingParentNode = null; } } else { if (GUILayout.Button("child")) { Undo.RecordObject(selectedDialogue, "Add Dialogue Link"); linkingParentNode.AddChild(node.name); linkingParentNode = null; } } }
/// <summary> /// Adds a new particle to the storage /// </summary> /// <param name="entryName">particle name in the game</param> /// <param name="particleFile">particle file (.Particle)</param> /// <param name="maxCount">instance count</param> /// <param name="sceneParent">parent scene node</param> /// <returns>an index of new particle</returns> public int AddParticle(string entryName, string particleFile, int maxCount, NodeBase sceneParent) { if (particleOn == false) { return(-1); } ParticleStorage storage = null; ParticleSequenceInfo particleInfo = null; // checks a registerd particle. int index = FindParticleIndexByName(entryName); if (index != -1) { storage = particleSequencesList[index]; } else { storage = new ParticleStorage(); storage.entryName = entryName; particleSequencesList.Add(storage); } // makes a resource path. string resourcePath = Path.GetDirectoryName(particleFile); particleInfo = FindParticleInfo(particleFile); if (particleInfo == null) { particleInfo = LoadParticleSequenceInfo(particleFile); } if (particleInfo == null) { throw new ArgumentException( "failed to load particle : " + particleFile); } ParticleSequence source = new ParticleSequence(ref particleInfo, resourcePath); // makes and stores a particle instance. for (int i = 0; i < maxCount; i++) { ParticleSequence instance = ParticleSequence.CreateInstance(ref source); instance.Name = entryName; storage.list.Add(instance); // adds particle to render scene. sceneParent.AddChild(instance); } return(particleSequencesList.IndexOf(storage)); }
// 创建一个并行节点 static int CreateParallel(int parentId) { NodeBase parent = BTNormalNodes[parentId]; var node = new Parallel(parent); parent.AddChild(node); BTNormalNodes[BTCurrentIndex] = node; return(BTCurrentIndex++); }
// 创建一个优先选择节点 static int CreateSelectorPriority(int parentId) { NodeBase parent = BTNormalNodes[parentId]; var node = new SelectorPriority(parent); parent.AddChild(node); BTNormalNodes[BTCurrentIndex] = node; return(BTCurrentIndex++); }
private void Reload() { Tag = this; Header = this.Name; foreach (var program in this.Programs) { var node = new NodeBase(program.Name); AddChild(node); int variationIndex = 0; foreach (var variation in program.VariationMacroData.symbols) { foreach (var val in variation.Values) { int binaryIndex = program.BaseIndex + variationIndex * (program.HasGeometryShader() ? 3 : 2); var vertexBinary = this.Binaries[binaryIndex].GetGX2Shader(); var fragBinary = this.Binaries[binaryIndex + 1].GetGX2Shader(); var shaderNode = new NodeBase($"Variation: {variation.Name}_{val}"); var wrapper = new SHARCFBProgramWrapper(vertexBinary, fragBinary); shaderNode.Tag = wrapper; node.AddChild(shaderNode); variationIndex += 1; } } if (variationIndex == 0) { int binaryIndex = program.BaseIndex; var vertexBinary = this.Binaries[binaryIndex].GetGX2Shader(); var fragBinary = this.Binaries[binaryIndex + 1].GetGX2Shader(); var shaderNode = new NodeBase($"Shader Data"); var wrapper = new SHARCFBProgramWrapper(vertexBinary, fragBinary); shaderNode.Tag = wrapper; node.AddChild(shaderNode); } } }
// 创建一个action节点 static int CreateAction(int parentId, System.Action dyOnEnter, Func <TickStatus> dyOnExecute, Action <TickStatus> dyOnExit) { NodeBase parent = BTNormalNodes[parentId]; Action nodeBase = new Action(parent); parent.AddChild(nodeBase); nodeBase.SetDyOnEnter(dyOnEnter); nodeBase.SetDyOnExit(dyOnExit); nodeBase.SetDyOnExecute(dyOnExecute); BTNormalNodes[BTCurrentIndex] = nodeBase; return(BTCurrentIndex++); }
public override NodeBase CreateNodeHierachy() { var animNode = new NodeBase(this.Name); animNode.Tag = this; foreach (MaterialAnimGroup group in this.AnimGroups) { var materials = GetMaterials(group.Name); var material = materials.FirstOrDefault(); animNode.AddChild(CreateGroupHierachy(material, group)); } return(animNode); }
static void ProcessTree(NodeBase parent, ArchiveFileInfo file, string[] paths, int index) { string currentPath = paths[index]; if (paths.Length - 1 == index) { var fileNode = new NodeBase(currentPath); string ext = Toolbox.Core.Utils.GetExtension(currentPath); fileNode.Tag = file; parent.AddChild(fileNode); return; } var node = FindFolderNode(parent, currentPath); if (node == null) { node = new NodeBase(currentPath); parent.AddChild(node); } ProcessTree(node, file, paths, index + 1); }
/// <summary> /// sticks to the owner as a child. /// Will depend on owner as a child. /// </summary> /// <param name="owner"></param> public void AttachOwner(NodeBase owner) { DetachOwner(); if (specData.ModelAlone) { for (int i = 0; i < specData.ModelCount; i++) { // New parent is owner now this.AddChild(modelWeapon[i]); modelWeapon[i].SetRootAxis(Matrix.Identity); } } owner.AddChild(this); }
private NodeBase CreateGroupHierachy(FMAT material, STAnimGroup group) { if (group is ParamAnimGroup) { return(CreateParamNodeHierachy(material, (ParamAnimGroup)group)); } var groupNode = new NodeBase(group.Name); groupNode.Tag = group; //Params have their own sub group for each parameter //The X, Y, Z values being individual tracks foreach (STAnimGroup subGroup in group.SubAnimGroups) { groupNode.AddChild(CreateGroupHierachy(material, subGroup)); } var tracks = group.GetTracks(); return(groupNode); }
/// <summary> /// Parses a function definition (_functionDefintionSyntaxRegex) /// </summary> /// <param name="tokenCount"></param> private void ParseFunctionDefinition(int tokenCount) { if (_locationStack.Peek() != Location.Program || _currentNode != Program) { throw new ParsingException("[BUG] Function definition parsing should not be reachable outside of a program location."); } if (tokenCount < 5) { throw new ParsingException("[BUG] Function definition parsing requires a minimum of five tokens."); } var tokens = _remainingTokens.GetRange(0, tokenCount); _remainingTokens.RemoveRange(0, tokenCount); int index = 0; var returnType = (TypeKeywordToken)tokens[index++]; var functionName = (IdentifierToken)tokens[index++]; var openParen = (OpenParenToken)tokens[index++]; var parameters = new List <FunctionParameter>(); // handle the parameters if (tokenCount == 5) { // no parameters => TypeKeyword Identifier OpenParen CloseParen OpenBrace // nothing to do here } else if (tokenCount == 7) { // one parameter => TypeKeyword Identifier OpenParen TypeKeyword Identifier CloseParen OpenBrace var paramType = (TypeKeywordToken)tokens[index++]; var paramName = (IdentifierToken)tokens[index++]; parameters.Add(new FunctionParameter { Type = paramType.Contents, Name = paramName.Contents }); } else { // many parameters => TypeKeyword Identifier OpenParen TypeKeyword Identifier (Comma TypeKeyword Identifier)+ CloseParen OpenBrace if ((tokenCount - 7) % 3 != 0) { throw new ParsingException("[BUG] Invalid function parameters in function definition."); } int paramCount = (tokenCount - 7) / 3; var firstParamType = (TypeKeywordToken)tokens[index++]; var firstParamName = (IdentifierToken)tokens[index++]; parameters.Add(new FunctionParameter { Type = firstParamType.Contents, Name = firstParamName.Contents }); for (int p = 0; p < paramCount - 1; p++) { var comma = (CommaToken)tokens[index++]; var paramType = (TypeKeywordToken)tokens[index++]; var paramName = (IdentifierToken)tokens[index++]; parameters.Add(new FunctionParameter { Type = paramType.Contents, Name = paramName.Contents }); } } var closeParen = (CloseParenToken)tokens[index++]; var openBrace = (OpenBraceToken)tokens[index++]; var functionNode = new FunctionNode(Program, functionName.Contents, parameters); _currentNode.AddChild(functionNode); _currentNode = functionNode; _locationStack.Push(Location.Function); }
/// <summary> /// creates a player character. /// </summary> /// <param name="specFileName">player spec file(.spec)</param> /// <param name="sceneParent">3D scene parent node</param> protected void CreatePlayer(string specFileName, NodeBase sceneParent) { GamePlayerSpec spec = new GamePlayerSpec(); spec = (GamePlayerSpec)GameDataSpecManager.Load(specFileName, spec.GetType()); GamePlayer player = null; switch (GameLevel.PlayerCountInLevel) { case 0: { player = new GamePlayer(ref spec, PlayerIndex.One); RobotGameGame.SinglePlayer = player; FrameworkCore.GameEventManager.TargetScene = player; } break; case 1: { player = new GamePlayer(ref spec, PlayerIndex.Two); } break; default: throw new InvalidOperationException( "Added player count is overflow"); } // Entry enemies in 3D Scene root node sceneParent.AddChild(player); // Create rotation axis Matrix rot = Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)); player.SetRootAxis(rot); // Set material RenderMaterial material = new RenderMaterial(); material.alpha = 1.0f; material.diffuseColor = new Color(210, 210, 210); material.specularColor = new Color(60, 60, 60); material.emissiveColor = new Color(30, 30, 30); material.specularPower = 24; material.vertexColorEnabled = false; material.preferPerPixelLighting = false; player.Material = material; player.ActiveFog = true; player.ActiveLighting = true; // Create collision data Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.MechRadius, 0.0f), Matrix.Invert(rot)); CollideSphere collide = new CollideSphere(centerPos, spec.MechRadius); player.EnableCulling = true; player.SetCollide(collide); player.ActionIdle(); // Add collide RobotGameGame.CurrentGameLevel.CollisionVersusTeam[ GameLevel.PlayerCountInLevel].AddCollide(collide); RobotGameGame.CurrentGameLevel.CollisionLayerAllMech.AddCollide(collide); // Set the respawn position if (player.PlayerIndex == PlayerIndex.One) { int count = GameLevel.Info.RespawnInLevelList.Count; int rndIndex = HelperMath.Randomi(0, count); RespawnInLevel respawn = GameLevel.Info.RespawnInLevelList[rndIndex]; player.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(respawn.SpawnAngle)) * Matrix.CreateTranslation(respawn.SpawnPoint); } else if (player.PlayerIndex == PlayerIndex.Two) { GamePlayer gamePlayerOne = GameLevel.GetPlayerInLevel(0); RespawnInLevel respawn = GameLevel.FindRespawnMostFar(gamePlayerOne.SpawnPoint.Translation); player.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(respawn.SpawnAngle)) * Matrix.CreateTranslation(respawn.SpawnPoint); } GameLevel.AddPlayer(player); }
private NodeBase CreateParamNodeHierachy(FMAT material, ParamAnimGroup group) { var groupNode = new NodeBase(group.Name); groupNode.Tag = group; var tracks = group.GetTracks(); if (material != null) { List <ParamTrack> paramTracks = new List <ParamTrack>(); var param = material.ShaderParams[group.Name]; switch (param.Type) { case ShaderParamType.TexSrt: case ShaderParamType.TexSrtEx: var texSrt = ((TexSrt)param.DataValue); paramTracks.Add(new ParamTrack(0, (float)texSrt.Mode, "Mode")); paramTracks.Add(new ParamTrack(4, (float)texSrt.Scaling.X, "Scale.X")); paramTracks.Add(new ParamTrack(8, (float)texSrt.Scaling.Y, "Scale.Y")); paramTracks.Add(new ParamTrack(12, (float)texSrt.Rotation, "Rotate")); paramTracks.Add(new ParamTrack(16, (float)texSrt.Translation.X, "Position.X")); paramTracks.Add(new ParamTrack(20, (float)texSrt.Translation.Y, "Position.X")); break; case ShaderParamType.Float: paramTracks.Add(new ParamTrack(0, (float)param.DataValue, "Value")); break; case ShaderParamType.Float2: case ShaderParamType.Float3: case ShaderParamType.Float4: var values = ((float[])param.DataValue); string[] channel = new string[4] { "X", "Y", "Z", "W" }; for (int i = 0; i < values.Length; i++) { paramTracks.Add(new ParamTrack((uint)i * 4, values[i], channel[i])); } break; } for (int i = 0; i < paramTracks.Count; i++) { var targetTrack = group.Tracks.FirstOrDefault(x => ((ParamTrack)x).ValueOffset == paramTracks[i].ValueOffset); if (targetTrack == null) { group.Tracks.Add(paramTracks[i]); } else { targetTrack.Name = paramTracks[i].Name; } } } foreach (ParamTrack track in group.Tracks.OrderBy(x => ((ParamTrack)x).ValueOffset)) { track.ChannelIndex = ((int)track.ValueOffset / 4); var trackNode = new NodeBase(track.Name); trackNode.Tag = track; groupNode.AddChild(trackNode); } return(groupNode); }
/// <summary> /// creates a player for level. /// reads an player information file(.spec) and configures the player class. /// The read player class is stored in the list. /// </summary> /// <param name="info">player information for level</param> /// <param name="sceneParent">3D scene parent node</param> /// <returns>player class for the game</returns> protected GamePlayer CreatePlayer(ref PlayerInLevel info, NodeBase sceneParent) { GamePlayer player = null; GamePlayerSpec spec = LoadPlayerSpec(ref info); switch (PlayerCountInLevel) { case 0: player = new GamePlayer(ref spec, PlayerIndex.One); break; case 1: player = new GamePlayer(ref spec, PlayerIndex.Two); break; default: throw new InvalidOperationException( "Added player count is overflow"); } // adds a player to list. AddPlayer(player); // entries a player in parent scene node. sceneParent.AddChild(player); // sets to rotation axis. Matrix rot = Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)); player.SetRootAxis(rot); // sets the material. RenderMaterial material = new RenderMaterial(); material.alpha = 1.0f; material.diffuseColor = new Color((byte)info.MaterialDiffuseColor.X, (byte)info.MaterialDiffuseColor.Y, (byte)info.MaterialDiffuseColor.Z); material.specularColor = new Color((byte)info.MaterialSpecularColor.X, (byte)info.MaterialSpecularColor.Y, (byte)info.MaterialSpecularColor.Z); material.emissiveColor = new Color((byte)info.MaterialEmissiveColor.X, (byte)info.MaterialEmissiveColor.Y, (byte)info.MaterialEmissiveColor.Z); material.specularPower = info.MaterialSpecularPower; material.vertexColorEnabled = false; material.preferPerPixelLighting = false; player.Material = material; player.ActiveFog = true; player.ActiveLighting = true; // creates a collision data. Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.MechRadius, 0.0f), Matrix.Invert(rot)); CollideSphere collide = new CollideSphere(centerPos, spec.MechRadius); player.EnableCulling = true; player.SetCollide(collide); player.ActionIdle(); player.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(info.SpawnAngle)) * Matrix.CreateTranslation(info.SpawnPoint); return(player); }
/// <summary> /// creates an enemy for level. /// reads an enemy information file(.spec) and configures the enemy class. /// The read enemy class is stored in the list. /// </summary> /// <param name="info">enemy information for level</param> /// <param name="sceneParent">3D scene parent node</param> protected void CreateSpawnEnemy(ref EnemyInLevel info, NodeBase sceneParent) { GameEnemy enemy = null; GameEnemySpec spec = LoadEnemySpec(ref info); // creates an enemy by unit type switch (spec.UnitClass) { case UnitClassId.Tank: enemy = new EnemyTank(ref spec); break; case UnitClassId.LightMech: case UnitClassId.HeavyMech: enemy = new EnemyMech(ref spec); break; case UnitClassId.Boss: enemy = new EnemyBoss(ref spec); break; default: throw new NotSupportedException( "Not supported unit type : " + spec.UnitType); } // sets the material RenderMaterial material = new RenderMaterial(); material.alpha = 1.0f; material.diffuseColor = new Color((byte)info.MaterialDiffuseColor.X, (byte)info.MaterialDiffuseColor.Y, (byte)info.MaterialDiffuseColor.Z); material.specularColor = new Color((byte)info.MaterialSpecularColor.X, (byte)info.MaterialSpecularColor.Y, (byte)info.MaterialSpecularColor.Z); material.emissiveColor = new Color((byte)info.MaterialEmissiveColor.X, (byte)info.MaterialEmissiveColor.Y, (byte)info.MaterialEmissiveColor.Z); material.specularPower = info.MaterialSpecularPower; material.vertexColorEnabled = false; material.preferPerPixelLighting = false; enemy.Material = material; enemy.ActiveFog = true; enemy.ActiveLighting = true; // adds this to the list. enemyList.Add(enemy); // entries this in parent scene node. sceneParent.AddChild(enemy); // sets to rotate axis. if (spec.UnitType == UnitTypeId.Tiger) { enemy.SetRootAxis( Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)) * Matrix.CreateRotationZ(MathHelper.ToRadians(90.0f))); } else { enemy.SetRootAxis(Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } // sets to stage spawn position. enemy.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(info.SpawnAngle)) * Matrix.CreateTranslation(info.SpawnPoint); // activate draw culling. enemy.EnableCulling = true; // creates a collision data. { Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.MechRadius, 0.0f), Matrix.Invert(enemy.RootAxis)); CollideSphere collide = new CollideSphere(centerPos, spec.MechRadius); enemy.SetCollide(collide); } // creates a game event. switch (info.SpawnType) { case SpawnTypeId.Time: { FrameworkCore.GameEventManager.AddEvent( new GameTimeEvent(info.SpawnTime, enemy, false)); } break; case SpawnTypeId.Area: { FrameworkCore.GameEventManager.AddEvent( new GameAreaEvent(info.SpawnPoint, info.SpawnRadius, enemy, false)); } break; } // sets start A.I. enemy.SetStartAI(info.StartAi, info.StartAiTime); }