/// <summary> /// Create an uninitialized RTSAgent /// </summary> /// <returns>The raw agent.</returns> /// <param name="agentCode">Agent code.</param> /// <param name="isBare">If set to <c>true</c> is bare.</param> public static RTSAgent CreateRawAgent(string agentCode, Vector2d startPosition = default(Vector2d), Vector2d startRotation = default(Vector2d)) { if (!GameResourceManager.IsValidAgentCode(agentCode)) { throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode)); } FastStack <RTSAgent> cache = CachedAgents[agentCode]; RTSAgent curAgent = null; if (cache.IsNotNull() && cache.Count > 0) { curAgent = cache.Pop(); ushort agentCodeID = GameResourceManager.GetAgentCodeIndex(agentCode); Debug.Log(curAgent.TypeIndex); TypeAgentsActive[agentCodeID][curAgent.TypeIndex] = true; } else { IAgentData interfacer = GameResourceManager.AgentCodeInterfacerMap[agentCode]; Vector3 pos = startPosition.ToVector3(); Quaternion rot = new Quaternion(0, startRotation.y, 0, startRotation.x); curAgent = GameObject.Instantiate(GameResourceManager.GetAgentTemplate(agentCode).gameObject, pos, rot).GetComponent <RTSAgent>(); curAgent.Setup(interfacer); RegisterRawAgent(curAgent); } return(curAgent); }
//integrate into LSF public void CalculateBounds() { _selectionBounds = new Bounds(_position.ToVector3(), Vector3.zero); foreach (Renderer r in Agent.GetComponentsInChildren <Renderer>()) { _selectionBounds.Encapsulate(r.bounds); } }
public short[,] Scan(int scanLayers) { int widthPeriods = Size.x.Div(Interval).CeilToInt(); int heightPeriods = Size.y.Div(Interval).CeilToInt(); short[,] heightMap = new short[widthPeriods, heightPeriods]; Vector3 startPos = _bottomLeft.ToVector3(HeightBounds.y.ToFloat()); Vector3 scanPos = startPos; float dist = (HeightBounds.y - HeightBounds.x).ToFloat(); float fRes = Interval.ToFloat(); for (int x = 0; x < widthPeriods; x++) { scanPos.z = startPos.z; for (int y = 0; y < heightPeriods; y++) { RaycastHit hit; long height; if (Physics.Raycast(scanPos, Vector3.down, out hit, dist, scanLayers, QueryTriggerInteraction.UseGlobal)) { height = FixedMath.Create(hit.point.y); } else { height = HeightBounds.x; } heightMap [x, y] = Compress(height); scanPos.z += fRes; } scanPos.x += fRes; } return(heightMap); }
public void Initialize(Vector3d StartPosition, Vector2d StartRotation, bool isDynamic = true) { Active = true; PositionalTransform = _positionalTransform; RotationalTransform = _rotationalTransform; if (!Setted) { this.Setup(null); } this.RaycastVersion = 0; this.HeightPosChanged = true; CheckVariables(); PositionChanged = true; RotationChanged = true; VelocityChanged = true; PositionChangedBuffer = true; RotationChangedBuffer = true; Priority = BasePriority; Velocity = Vector2d.zero; VelocityMagnitude = 0; LastPosition = _position = StartPosition.ToVector2d(); _heightPos = StartPosition.z; _rotation = StartRotation; ForwardNeedsSet = true; FastRadius = this.Radius * this.Radius; XMin = 0; XMax = 0; YMin = 0; YMax = 0; PastGridXMin = int.MaxValue; PastGridXMax = int.MaxValue; PastGridYMin = int.MaxValue; PastGridYMax = int.MaxValue; if (Shape != ColliderType.None) { BuildPoints(); BuildBounds(); } ID = PhysicsManager.Assimilate(this, isDynamic); Partition.PartitionObject(this); if (PositionalTransform != null) { CanSetVisualPosition = true; _visualPosition = _position.ToVector3(HeightPos.ToFloat()); lastVisualPos = _visualPosition; PositionalTransform.position = _visualPosition; } else { CanSetVisualPosition = false; } if (RotationalTransform != null) { CanSetvisualRotation = Agent.MyAgentType != AgentType.Building ? true : false; if (Forward != Vector2d.zero) { visualRotation = GetVisualRotation(); } lastvisualRotationation = visualRotation; } else { CanSetvisualRotation = false; } SetVisuals(); velocityPosition = Vector3.zero; this.ImmovableCollisionDirection = Vector2d.zero; PartitionChanged = true; }