protected override void SetPosition(VainDrawer drawinfo) { // Apply the rotation before calculations this.obj.transform.eulerAngles = drawinfo.ExitRotation; this.obj.transform.position = drawinfo.ExitPosition; // Caculate the centerpoint of the of this vain Vector3 VainExit = new Vector3(); if (drawinfo.DestinationExit == 0) { VainExit = new Vector3(this.obj.transform.position.x, this.obj.transform.position.y, this.obj.transform.position.z); } else if (drawinfo.DestinationExit == 1) { VainExit = new Vector3(this.obj.transform.position.x, this.obj.transform.position.y, this.obj.transform.position.z + (size.z * this.scale)); } // Check if there is a differance between the 2 coordinates Vector3 delta = drawinfo.ExitPosition - VainExit; if (delta.x == 0 && delta.y == 0 && delta.z == 0) { // Apply the new position to the vain this.obj.transform.position = VainExit; } else { this.obj.transform.position = drawinfo.ExitPosition + delta; } }
/// <summary> /// Sets the position and rotation of the new vain object to the correct parameters /// </summary> /// <param name="drawinfo">The information about how to rotate and position</param> protected virtual void SetPosition(VainDrawer drawinfo) { Debug.LogError("No method defined for subtype of vain: " + this.GetType().ToString() + " method: SetPosition()"); }
/// <summary> /// Draw the current vain to the gamescene /// </summary> /// <param name="parent">The parent transform for the vain to be part of</param> /// <param name="drawinfo">The information given by the CalculateNextPosition() method</param> /// <returns>Returns true if there is a second exit</returns> public virtual bool DrawMe(Transform parent, VainDrawer drawinfo) { // Check if the vain is already drawn. If it is drawn already, skip creating the object if (!isDrawn) { // Get the next available object from the object pool //this.obj = ObjectPool.GetInstance().GetObject(this.GetType()); this.obj = ObjectPool.INSTANCE.GetNext(this.GetType()); this.obj.SetActive(true); // Set the parent of the object to the VainBuilder this.obj.transform.parent = parent; this.obj.name = this.id.ToString(); // Set the scale of the object this.obj.transform.localScale = new Vector3(this.scale, this.scale, this.scale); // Set the flip of the object for (int i = 0; i < this.obj.transform.childCount; i++) { this.obj.transform.GetChild(i).eulerAngles = new Vector3(0, 180 - this.flip, this.zrotation * 30.0f); } // Remember that the vain is now drawn this.isDrawn = true; // Set the position and rotation of the vain if (!drawinfo.IsEmpty()) this.SetPosition(drawinfo); } // Return true if the vain has a second exit return this.HasSecondExit(); }