/// <inheritdoc cref="BowWeaponItem"/> public override void Attack() { if (Projectile == null || !CanAttack) { return; } var projectile = MonoUtil.Load(Projectile); projectile.transform.position = Util.GetCharacterTransform().position; projectile.transform.right = Util.GetDirectionTowardsCursor(projectile.transform); // Updates texture for dagger try { projectile.transform.GetChild(0).GetChild(0).GetComponent <SpriteRenderer>().sprite = Info.Prefabs[0].transform.GetChild(0).GetComponent <SpriteRenderer>().sprite; } catch (Exception) { // ignored } SetCollDown(); MonoUtil.Remove(projectile, 6); Durability -= EquipableData.DurabilityReducer; }
/// <summary> /// Setup the log4net and define appenders. /// </summary> private void SetupLogger() { Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); hierarchy.Root.Level = Level.Debug; hierarchy.RaiseConfigurationChanged(EventArgs.Empty); AppenderSkeleton consoleAppender, fileAppender; if (MonoUtil.IsRunningOnMono()) { consoleAppender = new ConsoleAppender(); } else { consoleAppender = new ColoredConsoleAppender(); } consoleAppender.Layout = new PatternLayout(@"[%date][%c][%level] %message %newline"); consoleAppender.Threshold = Level.Debug; consoleAppender.ActivateOptions(); // fileAppender = new FileAppender(); // fileAppender.AppendToFile = true; // fileAppender.Layout = new PatternLayout(@"[%date][%c][%level] %message %newline"); // fileAppender.Threshold = Level.Debug; // fileAppender.File = "log.txt"; // fileAppender.ActivateOptions(); BasicConfigurator.Configure(consoleAppender); // BasicConfigurator.Configure(FileAppender); }
/// <summary> /// Destroys object that was loaded into game world when mounted, /// called on dismount /// </summary> /// <returns>Whether or not item was successfully dismounted</returns> protected override bool OnDismount() { if (_cachedInstance != null) { MonoUtil.Remove(_cachedInstance); } return(base.OnDismount()); }
/// <inheritdoc cref="SimpleItem"/> public override void Use() { base.Use(); var particle = MonoUtil.Load(Info.Prefabs[0]); var parent = GameObject.FindGameObjectWithTag("Player"); particle.transform.parent = parent.transform; particle.transform.localPosition = Vector3.zero; }
private static IPersistenceConfigurer GetSQLite() { if (MonoUtil.IsRunningOnMono()) { return(MonoSQLiteConfiguration.Standard .UsingFile(DatabaseSettings.Instance.Name + ".sqlite").ShowSql()); } else { return(SQLiteConfiguration.Standard.UsingFile(DatabaseSettings.Instance.Name + ".sqlite").ShowSql()); } }
/// <summary> /// Loads object into game world when mounted /// </summary> /// <returns>Whether or not item was successfully mounted</returns> protected override bool OnMount() { if (Info.Prefabs.Length > 1) { _cachedInstance = MonoUtil.Load(Info.Prefabs[1]); _cachedInstance.transform.parent = Camera.main.transform; _cachedInstance.GetComponent <InstantiableWeaponController>().Item = this; _cachedInstance.transform.localPosition = new Vector3(0, 0, _cachedInstance.transform.localPosition.z); } return(base.OnMount()); }
/// <summary> /// Adds visual effect onto player when used /// TODO: Better effect fetcher /// </summary> protected virtual void LoadEffect() { var effectName = "healing"; if (PotionInfo.EffectAmount.Magic > 0) { effectName = "healing_mp"; } var effectPrefab = Resources.Load <GameObject>($"Prefabs/Player/Effects/prefab_player_effect_{effectName}"); var effect = MonoUtil.Load(effectPrefab); effect.transform.position = Util.GetCharacterTransform().position; effect.transform.parent = Camera.main.transform; MonoUtil.Remove(effect, 3); }
/// <summary> /// Initiates projectile towards mouse /// </summary> public override void Attack() { if (Projectile == null || !CanAttack) { return; } var projectile = MonoUtil.Load(Projectile); projectile.transform.position = Util.GetCharacterTransform().position; projectile.transform.right = Util.GetDirectionTowardsCursor(projectile.transform); MonoUtil.Remove(projectile, 12); SetCollDown(); base.Attack(); }
/// <inheritdoc cref="WeaponItem"/> public override void Attack() { if (AttackPrefab == null || !CanAttack) { return; } // Loads attack animation var attack = MonoUtil.Load(AttackPrefab); attack.transform.position = Util.GetCharacterTransform().position; attack.transform.right = Util.GetDirectionTowardsCursor(attack.transform); attack.transform.parent = Camera.main.transform; // Moves character toward mouse direction var character = Util.GetCharacter; character.GetComponent <Rigidbody2D>().AddForce(Util.GetDirectionTowardsCursor(character.transform) * 50); if (!_usedDefault) { return; } // Updates texture of sword for default attack try { attack.transform.GetChild(0).GetChild(0).GetComponent <SpriteRenderer>().sprite = Info.Prefabs[0].transform.GetChild(0).GetComponent <SpriteRenderer>().sprite; } catch (Exception) { // Ignored } SetCollDown(); base.Attack(); }
/// make async request for data type result private void CallWWW_resultData_async <T>(string address, WWWForm data, OnUserDataResultDelegate <T> callback, RequestType type) where T : class { MonoUtil.GetMainObj().StartCoroutine(CallWWW_resultData_asyncCR <T>(address, data, callback, type)); }
/// make async request for boolean type result private void CallWWW_result_async(string address, WWWForm data, OnResultDelegate callback, RequestType type) { MonoUtil.GetMainObj().StartCoroutine(CallWWW_result_asyncCR(address, data, callback, type)); }
void Awake() { MonoUtil.instance = this; }
IEnumerator PlayAnim(float delay, UIAnimData animData, System.Action onPlayEnd) { if (delay > 0) { yield return(new WaitForSeconds(delay)); } for (int i = 0; i < animData.m_frames.Count; i++) { UIAnimFrame curFrame = animData.m_frames[i]; switch (curFrame.m_type) { case E_UIAnimType.Empty: { yield return(new WaitForSeconds(animData.m_frames[i].m_duration)); } break; case E_UIAnimType.Set: { GameObject[] targets = animData.GetTargets(); for (int t = 0; t < targets.Length; t++) { if (curFrame.HasTween(E_TweenType.Position)) { SetPosition(targets[t], curFrame.m_position); } if (curFrame.HasTween(E_TweenType.Rotation)) { SetRotation(targets[t], Quaternion.Euler(curFrame.m_rotation)); } if (curFrame.HasTween(E_TweenType.Scale)) { SetScale(targets[t], curFrame.m_scale); } if (curFrame.HasTween(E_TweenType.Color)) { SetColor(targets[t], curFrame.m_color); } if (curFrame.HasTween(E_TweenType.Alpha)) { SetAlpha(targets[t], curFrame.m_alpha); } } } break; case E_UIAnimType.PlaySFX: { //AudioSource audioSrc = AudioManager.ins.PlaySFX(curFrame.m_audioName, Random.Range(curFrame.m_duration, curFrame.m_alpha), curFrame.m_particleParent); //if (audioSrc != null) //{ // float pitch = Random.Range(curFrame.m_scale.x, curFrame.m_scale.y); // audioSrc.pitch = pitch; //} // if (curFrame.m_audioName != null) // SoundMgr.GetSingle().play_se(curFrame.m_audioName); } break; case E_UIAnimType.PlayBGM: //if (string.IsNullOrEmpty(curFrame.m_audioName)) //{ // AudioManager.ins.StopBGM(); //} //else //{ // AudioManager.ins.PlayBGM(curFrame.m_audioName); //} break; case E_UIAnimType.PlayVOX: { //AudioManager.ins.StopAllVOX(); //AudioManager.ins.PlayVOX(curFrame.m_audioName); } break; case E_UIAnimType.AddParticle: { GameObject prefab = Resources.Load(curFrame.m_particlePath) as GameObject; Transform particleTrans = MonoUtil.CreatePrefab(prefab, "particle", curFrame.m_particleParent, curFrame.m_position); if (curFrame.m_particleDestroyAfterPlay) { particleTrans.gameObject.AddComponent <OneShotParticle>(); } } break; case E_UIAnimType.Tween: { bool isTweening = true; bool assignedOnTweenEnd = false; EventDelegate.Callback onTweenEnd = () => { isTweening = false; }; UITweener tw = null; GameObject[] targets = animData.GetTargets(); for (int t = 0; t < targets.Length; t++) { if (curFrame.HasTween(E_TweenType.Position)) { tw = TweenPosition.Begin(targets[t], curFrame.m_duration, curFrame.m_position); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Rotation)) { tw = TweenRotation.Begin(targets[t], curFrame.m_duration, Quaternion.Euler(curFrame.m_rotation)); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Scale)) { tw = TweenScale.Begin(targets[t], curFrame.m_duration, curFrame.m_scale); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Color)) { tw = TweenColor.Begin(targets[t], curFrame.m_duration, curFrame.m_color); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Alpha)) { tw = TweenAlpha.Begin(targets[t], curFrame.m_duration, curFrame.m_alpha); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } } while (assignedOnTweenEnd && isTweening) { yield return(null); } } break; case E_UIAnimType.SubAnim: if (curFrame.m_animPlayer != null) { bool isPlaying = true; curFrame.m_animPlayer.Play(() => isPlaying = false, 0f); while (curFrame.m_particleDestroyAfterPlay && isPlaying) { yield return(null); } } break; case E_UIAnimType.SubAnimGroup: { if (curFrame.m_animPlayerGroup != null) { BaseAnimPlayer[] players = curFrame.m_animPlayerGroup.GetComponentsInImmediateChildren <BaseAnimPlayer>(false, Mathf.FloorToInt(curFrame.m_alpha)); if (players != null && players.Length > 0) { if (curFrame.m_duration >= 0f) { float duration = curFrame.m_duration; bool isPlaying = true; float maxLength = 0f; int maxLengthIdx = -1; for (int j = 0; j < players.Length; j++) { if (!players[j].gameObject.activeInHierarchy) { continue; } float curLength = players[j].Length + duration * j; if (curLength > maxLength) { maxLength = curLength; maxLengthIdx = j; } } if (maxLengthIdx == -1) { isPlaying = false; } for (int j = 0; j < players.Length; j++) { if (j == maxLengthIdx) { players[j].Play(() => isPlaying = false, duration * j); } else { players[j].Play(null, duration * j); } } while (curFrame.m_particleDestroyAfterPlay && isPlaying) { yield return(null); } } else { for (int j = 0; j < players.Length; j++) { bool isPlaying = true; players[j].Play(() => isPlaying = false, 0f); while (isPlaying) { yield return(null); } } } } } } break; case E_UIAnimType.EnableBehaviour: if (curFrame.m_behaviour != null) { curFrame.m_behaviour.enabled = curFrame.m_particleDestroyAfterPlay; } else { GameObject[] targets = animData.GetTargets(); for (int t = 0; t < targets.Length; t++) { targets[t].SetActive(curFrame.m_particleDestroyAfterPlay); } } break; case E_UIAnimType.PlayAnimation: if (!string.IsNullOrEmpty(curFrame.m_audioName)) { var animation = animData.m_target.GetComponent <Animation>(); var animator = animData.m_target.GetComponent <Animator>(); if (animation != null) { var clip = animation[curFrame.m_audioName]; clip.speed = 1; if (clip != null && curFrame.m_duration > 0) { clip.speed = clip.length / curFrame.m_duration; } animation.Stop(); animation.Play(curFrame.m_audioName); yield return(new WaitForSeconds(curFrame.m_duration)); } if (animator != null) { animator.Play(curFrame.m_audioName); } } break; case E_UIAnimType.SendEvent: if (!string.IsNullOrEmpty(curFrame.m_audioName)) { EventManager.Instance.SendEvent(curFrame.m_audioName); } break; default: break; } } if (onPlayEnd != null) { onPlayEnd(); } }