void OnValidate() { if (Hidable == null) { Hidable = GetComponent <Colorable>(); } }
// Update is called once per frame void Update() { Colorable temp = null; float minDistance = Mathf.Infinity; foreach (Colorable c in colorables) { // Iterate through the distance between the player and each square to find the closest value. float distance = c.GetDistanceFromPosition(player.transform.position); if (distance < minDistance) { // If previous min distance but no longer, change to default color. if (temp != null) { temp.ChangeColor(false); } temp = c; minDistance = distance; } else { // If not the min distance, change to default color. c.ChangeColor(false); } } // Change the closest object to be colored. temp.ChangeColor(true); }
public void AbsorbObject(Colorable colorable) { audioSource.PlayOneShot(absorbSound); SetColor(colorable.Color); Destroy(colorable.gameObject); absorbParticles.Play(); }
public ColorableInstance AddColorableInstance(GameObject obj, Colorable colorable) { ColorableInstance instance = obj.AddComponent <ColorableInstance>(); instance.Colorable = colorable; return(instance); }
void ToggleSelected() { if (selected != null) { Colorable selectedColorable = selected.GetComponent <Colorable>(); selectedColorable.ToggleSelector(false); } }
private void OnTriggerExit(Collider other) { Colorable colorable = other.GetComponent <Colorable>(); if (colorable != null) { machine.RemoveTarget(colorable); } }
private void OnTriggerEnter(Collider other) { Colorable colorable = other.GetComponent <Colorable>(); if (colorable != null) { machine.AbsorbObject(colorable); } }
void OnValidate() { if (Colorable == null) { Colorable = GetComponent <Colorable>(); } if (ColorSwapable == null) { ColorSwapable = GetComponent <ColorSwapable>(); } }
private Sprite[] GetSectionColorLayers(Colorable colorable) { ColorableSection[] sections = colorable.Sections; Sprite[] sprites = new Sprite[sections.Length]; for (int i = 0; i < sections.Length; i++) { sprites[i] = sections[i].ColorLayer; } return(sprites); }
public Colorable ColorableForActorId(int actorId) { List <Actor> a = this.ActorsWithId(actorId); if (a.Count == 0) { return(null); } GameObject g = a[0].gameObject; Colorable c = g.GetComponent <Colorable> (); return(c); }
// FIXME: ContextMenu doesn't work. //[ContextMenu("Initialize targetObj & targetCC")] protected void InitTargets() { if (targetCC == null) { if (targetObj == null) { targetObj = gameObject; } targetCC = Colorable.GetComponent(targetObj); } UnityEngine.Assertions.Assert.IsNotNull( targetCC, "No suitable Colorable Component was found in " + gameObject.name + " to be used by " + this.GetType().FullName ); }
void DetectColorableType() { text = GetComponent<Text>(); if (text != null) { colorableType = Colorable.Text; } else { spriteRenderer = GetComponent<SpriteRenderer>(); if (spriteRenderer != null) { colorableType = Colorable.Sprite; } else { image = GetComponent<Image>(); if (image != null) { colorableType = Colorable.Image; } else { Debug.LogError("Must have a Text or Sprite to be colored dynamically"); } } } }
private GameObject[] AddLayers(ColorableInstance colorableInstance, GameObject originalObject, int startDepth) { Colorable colorable = colorableInstance.Colorable; // Get all layers Sprite[] layers = colorable.GetAllLayers(); GameObject[] layerObjects = new GameObject[layers.Length]; // Z axis depth int depth = startDepth; for (int i = 0; i < layers.Length; i++) { if (layers[i] == null) { layerObjects[i] = null; continue; } GameObject gameObject = new GameObject(); gameObject.name = "Layer" + i; // Add the sprite renderer SpriteRenderer spriteRenderer = gameObject.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = layers[i]; gameObject.transform.parent = originalObject.transform; // Change the depth Vector3 newPosition = gameObject.transform.localPosition; newPosition.z = depth; depth--; gameObject.transform.localPosition = newPosition; layerObjects[i] = gameObject; } return(layerObjects); }
public void SetupWithInstructionSet(InstructionSet _instructionSet) { this.instructionSet = _instructionSet; this.actorRenderer.sprite = BoardManager.Instance().SpriteForActorId(this.instructionSet.actorId); this.actorBackgroundRenderer.sprite = BoardManager.Instance().BackgroundSpriteForActorId(this.instructionSet.actorId); Colorable colorable = BoardManager.Instance().ColorableForActorId(this.instructionSet.actorId); if (colorable != null && this.actorBackgroundRenderer != null && this.actorBackgroundRenderer.sprite != null) { this.actorBackgroundRenderer.color = colorable.GetSelectedColor(); } for (int i = 0; i < this.directionContainers.Length; i++) { this.directionContainers [i].SetActive(false); } switch (this.instructionSet.direction) { case Direction.Up: this.directionContainers [0].SetActive(true); break; case Direction.Down: this.directionContainers [1].SetActive(true); break; case Direction.Left: this.directionContainers [2].SetActive(true); break; case Direction.Right: this.directionContainers [3].SetActive(true); break; default: break; } }
private void InitializeSections(ColorableInstance colorableInstance, GameObject colorableObject) { int depth = 10; Sprite[] sectionColorLayers = GetSectionColorLayers(colorableInstance.Colorable); GameObject[] layerObjects = new GameObject[sectionColorLayers.Length]; Colorable colorable = colorableInstance.Colorable; List <ColorableSectionInstance> sectionInstances = new List <ColorableSectionInstance>(); SectionSelector sectionSelector = null; for (int i = 0; i < sectionColorLayers.Length; i++) { if (sectionColorLayers[i] == null) { layerObjects[i] = null; continue; } GameObject gameObject = new GameObject(); gameObject.name = "Section: " + i; gameObject.AddComponent <ColorChanger>(); // Create the 2D box collider, add it to Collision Sprite Renderer /*if (i == 0) * { * sectionSelector = gameObject.AddComponent<SectionSelector>(); * }*/ // Create sprite renderer SpriteRenderer spriteRenderer = gameObject.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = sectionColorLayers[i]; gameObject.transform.parent = colorableObject.transform; ColorableSectionInstance sectionInstance = gameObject.AddComponent <ColorableSectionInstance>(); sectionInstance.ColorableSection = colorableInstance.Colorable.Sections[i]; sectionInstances.Add(sectionInstance); // Collision object GameObject collisionGameObject = new GameObject(); collisionGameObject.name = "Collision: " + i; // Create sprite renderer SpriteRenderer collisionSpriteRenderer = collisionGameObject.AddComponent <SpriteRenderer>(); collisionSpriteRenderer.sprite = colorableInstance.Colorable.Sections[i].SelectionLayer; collisionGameObject.transform.parent = gameObject.transform; collisionSpriteRenderer.enabled = false; BoxCollider2D meshCollider = collisionGameObject.AddComponent <BoxCollider2D>(); // Change the depth Vector3 newPosition = gameObject.transform.localPosition; newPosition.z = depth; depth--; gameObject.transform.localPosition = newPosition; layerObjects[i] = gameObject; } colorableInstance.InitializeSectionInstances(sectionInstances.ToArray()); }
public void AddTarget(Colorable target) { targets.Add(target); }
public void RemoveTarget(Colorable target) { targets.Remove(target); }