protected void GetController() { if (!controller) { controller = GetComponent <RexController>(); } if (controller) { controller.AddState(this); } }
//Swaps out the current RexController for another; most commonly used if the actor has multiple RexControllers, i.e. one for land, one for water, one for air, etc. public void SetController(RexController _controller) { if (slots.controller) { slots.controller.EndAllStates(); slots.controller.isEnabled = false; slots.controller.gameObject.SetActive(false); slots.controller.CancelTurn(); slots.controller.StopAllCoroutines(); slots.controller.SetAxis(new Vector2(0.0f, 0.0f)); } _controller.gameObject.SetActive(true); _controller.isEnabled = true; _controller.SetStateToDefault(true); _controller.CancelTurn(); _controller.direction = slots.controller.direction; _controller.AnimateEnable(); _controller.SetAxis(new Vector2(0.0f, 0.0f)); _controller.direction = slots.controller.direction; slots.controller = _controller; BoxCollider2D controllerCollider = slots.controller.GetComponent <BoxCollider2D>(); if (controllerCollider != null && slots.collider != null) { BoxCollider2D boxCollider = GetComponent <BoxCollider2D>(); if (boxCollider != null) { float originalColliderSizeY = boxCollider.size.y; boxCollider.size = controllerCollider.bounds.size; float difference = originalColliderSizeY - controllerCollider.bounds.size.y; SetPosition(new Vector2(transform.position.x, transform.position.y - difference * 0.5f)); } } if (slots.physicsObject) { if (_controller.overrideMaxFallSpeed != 0.0f) { slots.physicsObject.gravitySettings.maxFallSpeed = _controller.overrideMaxFallSpeed; } } OnControllerChanged(_controller); }
private static GameObject GetSelectGameObject() { GameObject selectedObject = Selection.activeGameObject; RexController rexController = null; if (selectedObject) { rexController = selectedObject.GetComponent <RexController>(); } if (selectedObject && rexController) { return(selectedObject); } else { EditorUtility.DisplayDialog("Ruh-roh!", "Please select a GameObject with a RexController component to attach this ability to first.", "Got it!"); return(null); } }
protected virtual void OnControllerChanged(RexController _newController) { } //This can be used to trigger specific effects when the controller changes
private static void FillRexActorSlots() { GameObject selectedObject = Selection.activeGameObject; RexActor actor = null; if (selectedObject) { actor = selectedObject.GetComponent <RexActor>(); } if (actor != null) { actor.slots.physicsObject = actor.GetComponent <RexPhysics>(); actor.slots.anim = actor.GetComponent <Animator>(); actor.slots.controller = actor.GetComponentInChildren <RexController>(); actor.slots.input = actor.GetComponent <RexInput>(); actor.slots.jitter = actor.GetComponent <Jitter>(); actor.slots.spriteHolder = actor.transform.Find("SpriteHolder"); actor.slots.spriteRenderer = actor.transform.Find("SpriteHolder").GetComponentInChildren <SpriteRenderer>(); if (actor.damagedProperties.spritesToFlash == null) { actor.damagedProperties.spritesToFlash = new List <SpriteRenderer>(); } actor.damagedProperties.spritesToFlash.Add(actor.slots.spriteRenderer); actor.slots.collider = actor.GetComponent <BoxCollider2D>(); RexPhysics physicsObject = actor.GetComponent <RexPhysics>(); if (physicsObject != null) { physicsObject.rexObject = actor; } RexController controller = actor.slots.controller; if (controller) { controller.slots.actor = actor; actor.waterProperties.landController = controller; } Energy[] energy = actor.GetComponentsInChildren <Energy>(); if (energy.Length > 0) { for (int i = 0; i < energy.Length; i++) { if (energy[i].gameObject.name == "HP") { actor.hp = energy[i]; } else if (energy[i].gameObject.name == "MP") { actor.mp = energy[i]; } } if (actor.hp == null) { actor.hp = energy[0]; } } Attack[] attacks = actor.GetComponentsInChildren <Attack>(); for (int i = 0; i < attacks.Length; i++) { attacks[i].slots.actor = actor; } EditorUtility.DisplayDialog("Yeah!", "The RexActor was successfully slotted!", "Yay!"); } else { EditorUtility.DisplayDialog("Ruh-roh!", "Please select a GameObject with a RexActor component first.", "Got it!"); } }