public static GameObject InstantiateEffectOverOwner(Transform p_owner, GameObject p_effect, bool p_forceLocalScale = true, bool p_instantiateInOwnerParent = true, bool p_keepOriginalRotation = false) { GameObject v_effectObject = null; if (p_effect != null) { if (p_owner != null) { v_effectObject = GameObject.Instantiate(p_effect) as GameObject; v_effectObject.transform.position = p_owner.position; v_effectObject.transform.rotation = p_owner.rotation; v_effectObject.transform.parent = p_instantiateInOwnerParent? p_owner.parent : p_owner; v_effectObject.transform.Rotate(p_effect.transform.localEulerAngles); //Force Scale to original one if (p_forceLocalScale) { v_effectObject.transform.localScale = p_effect.transform.localScale; } else { KiltUtils.SetLossyScale(v_effectObject.transform, p_effect.transform.localScale); } if (p_keepOriginalRotation) { v_effectObject.transform.eulerAngles = p_effect.transform.localEulerAngles; } } else { v_effectObject = GameObject.Instantiate(p_effect) as GameObject; } } return(v_effectObject); }
protected virtual void RecalcSize(bool p_force = false) { if (p_force || _needRecalc) { _needRecalc = false; _lastWidth = Screen.width; _lastHeight = Screen.height; //Recalc if (CameraThatDrawThisObject != null) { Vector3 v_middlePoint = CameraThatDrawThisObject.ScreenToWorldPoint(new Vector2(_lastWidth / 2.0f, _lastHeight / 2.0f)); Vector3 v_topLeftPoint = CameraThatDrawThisObject.ScreenToWorldPoint(new Vector2(0, 0)); Vector3 v_scale = new Vector3(Mathf.Abs(v_middlePoint.x - v_topLeftPoint.x) * 2.05f, Mathf.Abs(v_middlePoint.y - v_topLeftPoint.y) * 2.05f, 1); KiltUtils.SetLossyScale(this.transform, v_scale); transform.position = new Vector3(v_middlePoint.x, v_middlePoint.y, transform.position.z); } } }
protected virtual void StartCollisionEffects(Vector2 p_collisionLocation) { Vector2 v_directionVector = VectorHelper.Direction(p_collisionLocation, this.transform.position); float v_angle = Vector2.Angle(Vector2.right, v_directionVector) + 180; if (CollisionEffectObject != null) { GameObject v_effectObject = GameObject.Instantiate(CollisionEffectObject) as GameObject; v_effectObject.transform.position = p_collisionLocation; v_effectObject.transform.rotation = Quaternion.Euler(Vector3.zero); v_effectObject.transform.parent = this.transform.parent; //Force Scale to original one //v_effectObject.transform.rotation = CollisionEffectObject.transform.rotation; //v_effectObject.transform.localScale = DestroyEffectObject.transform.localScale; if (DestroyEffectObject != null) { KiltUtils.SetLossyScale(v_effectObject.transform, DestroyEffectObject.transform.localScale); } v_effectObject.transform.Rotate(new Vector3(0, 0, v_angle)); } }
/*protected override void OnPingFinish() * { * SetAmountToScale(true, 1f); * } * * protected override void OnPongFinish() * { * SetAmountToScale(false, 1f); * }*/ #endregion #region Other Methods private void CheckIfCanClampInitialValues(bool p_isPing) { if (Owner != null) { if (UseVectorsToClampInitialValues && ScaleTypeOption != ScaleTypeOptionEnum.ScaleBy && ScaleTypeOption != ScaleTypeOptionEnum.ScalePercentBy) { if (p_isPing) { if (IsLocalScale) { Vector3 v_vectorLocal = new Vector3(Owner.transform.localScale.x, Owner.transform.localScale.y, Owner.transform.localScale.z); v_vectorLocal.x = EnumHelper.ContainsLongFlag((long)ScaleTypeOption, (long)ScaleTypeOptionEnum.ScaleToX)? ScaleBackVector.x : v_vectorLocal.x; v_vectorLocal.y = EnumHelper.ContainsLongFlag((long)ScaleTypeOption, (long)ScaleTypeOptionEnum.ScaleToY)? ScaleBackVector.y : v_vectorLocal.y; v_vectorLocal.z = EnumHelper.ContainsLongFlag((long)ScaleTypeOption, (long)ScaleTypeOptionEnum.ScaleToZ)? ScaleBackVector.z : v_vectorLocal.z; Owner.transform.localScale = v_vectorLocal; } else { Vector3 v_vectorGlobal = new Vector3(Owner.transform.lossyScale.x, Owner.transform.lossyScale.y, Owner.transform.lossyScale.z); v_vectorGlobal.x = EnumHelper.ContainsLongFlag((long)ScaleTypeOption, (long)ScaleTypeOptionEnum.ScaleToX)? ScaleBackVector.x : v_vectorGlobal.x; v_vectorGlobal.y = EnumHelper.ContainsLongFlag((long)ScaleTypeOption, (long)ScaleTypeOptionEnum.ScaleToY)? ScaleBackVector.y : v_vectorGlobal.y; v_vectorGlobal.z = EnumHelper.ContainsLongFlag((long)ScaleTypeOption, (long)ScaleTypeOptionEnum.ScaleToZ)? ScaleBackVector.z : v_vectorGlobal.z; KiltUtils.SetLossyScale(Owner.transform, v_vectorGlobal); } } else if (UseScaleBackVector) { if (IsLocalScale) { Owner.transform.localScale = ScaleVector; } else { KiltUtils.SetLossyScale(Owner.transform, ScaleVector); } } } } }
protected virtual void SetAmountToScale(bool p_isPing, float p_timeScale) { if (Owner != null) { float v_timeScale = p_timeScale; Vector3 v_timeScaleVector = new Vector3(ScaleValueBy.x * v_timeScale, ScaleValueBy.y * v_timeScale, ScaleValueBy.z * v_timeScale); Vector3 v_vectorToAdd = new Vector3(v_timeScaleVector.x - CurrentScaledValueBy.x, v_timeScaleVector.y - CurrentScaledValueBy.y, v_timeScaleVector.z - CurrentScaledValueBy.z); CurrentScaledValueBy = v_timeScaleVector; if (!p_isPing && !UseScaleBackVector && ScaleTypeOption != ScaleTypeOptionEnum.ScalePercentBy) { v_vectorToAdd = new Vector3(-v_vectorToAdd.x, -v_vectorToAdd.y, -v_vectorToAdd.z); } if (m_isLocalScale) { Owner.transform.localScale = new Vector3(Owner.transform.localScale.x + v_vectorToAdd.x, Owner.transform.localScale.y + v_vectorToAdd.y, Owner.transform.localScale.z + v_vectorToAdd.z); } else { Vector3 v_newLossyScale = new Vector3(Owner.transform.lossyScale.x + v_vectorToAdd.x, Owner.transform.lossyScale.y + v_vectorToAdd.y, Owner.transform.lossyScale.z + v_vectorToAdd.z); KiltUtils.SetLossyScale(this.transform, v_newLossyScale); } } }