import Chroma
import ComponentUtil
import PyBehaviour
import PyScript

class TestReload(object):

	def __init__(self):
		self.chroma = Chroma(Color.red)

		self.manager = None

	def Update(self):
		self.chroma.shiftHue(Time.deltaTime * 20)
		self.chroma.shiftSaturation(Time.deltaTime * 15)
		self.gameObject.renderer.material.color = self.chroma.getColor()

		if self.manager == None:
			self.manager = GameObject.Find("BlubManager")
			if self.manager == None:
				blub = GameObject("BlubManager")
				blub.AddScript("BlubManager")
				self.manager = blub

	def OnMouseDown(self):
		if self.manager != None:
			self.manager.selected = self.gameObject

	def OnGUI(self):
		if self.manager == None or self.manager.selected != self.gameObject:
			return
		GUI.Label(Rect(50, 50, 500, 500), self.gameObject.name)
		if GUI.Button(Rect(70, 70, 80, 20), "Reset"):
			pb = ComponentUtil.findInLineage[PyBehaviour](self.gameObject)
			pb.reset()
		if GUI.Button(Rect(70, 90, 80, 20), "Clone"):
			another = Object.Instantiate(self.gameObject,
					self.gameObject.transform.position + Random.onUnitSphere * 3,
					Quaternion.identity)
			another.name = "stuff %f" % Random.Range(0, 1)
		if GUI.Button(Rect(70, 110, 80, 20), "FULL"):
			PyScript.fullReset()
		if GUI.Button(Rect(70, 140, 80, 20), "Light"):
			glight = GameObject("Light")
			glight.transform.position = Vector3(-100, 100, 100)
			light = glight.AddComponent("Light")
			light.type = LightType.Directional

	def OnMouseUp(self):
		self.gameObject.transform.Rotate(15, 0, 0)
		cam = GameObject.FindWithTag("MainCamera")
		if cam != None:
			cam.transform.Rotate(15, 0, 0)
