protected override void ParseMessage(IncomingMessage inMessage)
 {
     base.ParseMessage(inMessage);
     name = inMessage.ReadString();
     location = inMessage.ReadIntVector();
     orientation = inMessage.ReadQuaternion();
     scale = inMessage.ReadVector();
     objectType = (ObjectNodeType)inMessage.ReadInt32();
     followTerrain = inMessage.ReadBool();
     try {
         direction = inMessage.ReadVector();
         lastInterp = inMessage.ReadTimestamp();
     } catch (System.IO.EndOfStreamException) {
         // ignore this - it means we got an old style response
     }
 }
Ejemplo n.º 2
0
        protected void Init(string name, SceneNode sceneNode, ObjectNodeType objType, WorldManager worldManager)
        {
            this.name = name;
            this.sceneNode = sceneNode;
            this.objType = objType;
            this.worldManager = worldManager;
            this.Targetable = false;

            attachmentPoints = new Dictionary<string, AttachmentPoint>();
            soundSources = new List<SoundSource>();

            base.Init();
        }
Ejemplo n.º 3
0
 public ObjectNode(long oid, string name, SceneNode sceneNode, ObjectNodeType objType, WorldManager worldManager)
     : base(oid)
 {
     Init(name, sceneNode, objType, worldManager);
 }
Ejemplo n.º 4
0
    public void Generate()
    {
        var sw = new System.Diagnostics.Stopwatch();

        sw.Restart();

        int        halfGridSize = grid.GridSize / 2;
        Vector2Int gridCenter   = new Vector2Int(halfGridSize, halfGridSize);

        List <GridTile> spawnedTiles = new List <GridTile>();

        for (int i = 0; i < objectsToSpawn; i++)
        {
            Vector2Int pos = new Vector2Int(Random.Range(0, grid.GridSize), Random.Range(0, grid.GridSize));

            while (grid.GetTile(pos.x, pos.y).NodeBase != null ||
                   Vector2Int.Distance(pos, gridCenter) < centerObjectSpawnSafezone ||
                   ObjectInDistance(pos, distanceBetweenObjects))
            {
                pos = new Vector2Int(Random.Range(0, grid.GridSize), Random.Range(0, grid.GridSize));
            }

            var tile = grid.GetTile(pos.x, pos.y);

            ObjectNodeType objectNodeType = ObjectNode.GetRandomObjectNodeType();
            GameObject     nodePrefab     = null;

            switch (objectNodeType)
            {
            case ObjectNodeType.Burner:
                nodePrefab = GameObject.Instantiate(burnerObjectNodePrefab);
                break;

            case ObjectNodeType.Connector:
                nodePrefab = GameObject.Instantiate(connectorObjectNodePrefab);
                break;

            case ObjectNodeType.ScoreMultiplier:
                nodePrefab = GameObject.Instantiate(scoreMultiplierObjectNodePrefab);
                break;
            }

            nodePrefab.GetComponent <NodeBase>().Randomize();

            tile.SetNodePrefab(nodePrefab);

            spawnedTiles.Add(tile);
        }

        spawnedTiles.ForEach(
            e => {
            for (int i = 0; i < 4; i++)
            {
                ConnectorPorts flag = (ConnectorPorts)(1 << i);

                if (e.NodeBase.ConnectorPorts.HasFlag(flag))
                {
                    Vector2Int pos = e.GridPos + GameManager.Instance.portDirections[i];
                    var otherNode  = MapGenerator.Instance.Grid.GetTile(pos.x, pos.y);
                    if (otherNode == null)
                    {
                        continue;
                    }

                    ConnectorPorts otherFlag = (ConnectorPorts)(1 << i + GameManager.Instance.portFlagLookup[i]);

                    if (otherNode.NodeBase != null &&
                        otherNode.NodeBase.PortsOpen &&
                        otherNode.NodeBase.ConnectedToRoot &&
                        otherNode.NodeBase.ConnectorPorts.HasFlag(otherFlag))
                    {
                        e.NodeBase.ConnectedNodes[i] = otherNode.NodeBase;
                        otherNode.NodeBase.ConnectedNodes[i + GameManager.Instance.portFlagLookup[i]] = e.NodeBase;
                    }
                }
            }
        }
            );

        sw.Stop();
        UnityEngine.Debug.Log($"Map Gen. Time: {sw.ElapsedMilliseconds} ms");
    }