diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Audio/SoundNames.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Audio/SoundNames.cs deleted file mode 100644 index 23447705ed2..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Audio/SoundNames.cs +++ /dev/null @@ -1,89 +0,0 @@ -public static class SoundNames -{ - public const string add_diamond = "sfx_add_diamond"; - public const string bbq_begin = "sfx_bbq_begin"; - public const string bbq_burnt = "sfx_bbq_burnt"; - public const string bbq_end = "sfx_bbq_end"; - public const string bbq_work = "sfx_bbq_work"; - public const string button_l = "sfx_button_l"; - public const string button_m = "sfx_button_m"; - public const string button_s = "sfx_button_s"; - public const string cardbag_close = "sfx_cardbag_close"; - public const string cardbag_get = "sfx_cardbag_get"; - public const string cardbag_open = "sfx_cardbag_open"; - public const string coin_add = "sfx_coin_add"; - public const string combo3 = "sfx_combo3"; - public const string combo4 = "sfx_combo4"; - public const string combo5 = "sfx_combo5"; - public const string combo6 = "sfx_combo6"; - public const string combo7 = "sfx_combo7"; - public const string combomaster_activated = "sfx_combomaster_activated"; - public const string combomaster_fail = "sfx_combomaster_fail"; - public const string combomaster_openbox = "sfx_combomaster_openbox"; - public const string combomaster_pop = "sfx_combomaster_pop"; - public const string combomaster_success = "sfx_combomaster_success"; - public const string cut_begin = "sfx_cut_begin"; - public const string cut_end = "sfx_cut_end"; - public const string cut_work = "sfx_cut_work"; - public const string cut_work2 = "sfx_cut_work2"; - public const string cut_work3 = "sfx_cut_work3"; - public const string cut_work_loop = "sfx_cut_work_loop"; - public const string deepfry_begin = "sfx_deepfry_begin"; - public const string deepfry_burnt = "sfx_deepfry_burnt"; - public const string deepfry_end = "sfx_deepfry_end"; - public const string deepfry_work = "sfx_deepfry_work"; - public const string drink_begin = "sfx_drink_begin"; - public const string drink_end = "sfx_drink_end"; - public const string drink_work = "sfx_drink_work"; - public const string easter_egg_open = "sfx_easter_egg_open"; - public const string endless_box_open = "sfx_endless_box_open"; - public const string endless_wave_tip = "sfx_endless_wave_tip"; - public const string food_frozen = "sfx_food_frozen"; - public const string fry_begin = "sfx_fry_begin"; - public const string fry_burnt = "sfx_fry_burnt"; - public const string fry_end = "sfx_fry_end"; - public const string fry_work = "sfx_fry_work"; - public const string gain_diamond = "sfx_gain_diamond"; - public const string get_bowl = "sfx_get_bowl"; - public const string get_coin = "sfx_get_coin"; - public const string get_dish = "sfx_get_dish"; - public const string get_glass = "sfx_get_glass"; - public const string get_like = "sfx_get_like"; - public const string get_plate = "sfx_get_plate"; - public const string get_spoon = "sfx_get_spoon"; - public const string get_sugar = "sfx_get_sugar"; - public const string get_wood = "sfx_get_wood"; - public const string ingredient_meat = "sfx_ingredient_meat"; - public const string ingredient_sauce = "sfx_ingredient_sauce"; - public const string ingredient_veg = "sfx_ingredient_veg"; - public const string lose = "sfx_lose"; - public const string machine_begin = "sfx_machine_begin"; - public const string machine_end = "sfx_machine_end"; - public const string machine_work = "sfx_machine_work"; - public const string newmap_unlock = "sfx_newmap_unlock"; - public const string open_keybox = "sfx_open_keybox"; - public const string order_get = "sfx_order_get"; - public const string order_show = "sfx_order_show"; - public const string oven_begin = "sfx_oven_begin"; - public const string oven_end = "sfx_oven_end"; - public const string oven_work = "sfx_oven_work"; - public const string panel_in = "sfx_panel_in"; - public const string panel_out = "sfx_panel_out"; - public const string piggybank_getreward = "sfx_piggybank_getreward"; - public const string piggybank_shake = "sfx_piggybank_shake"; - public const string piggybank_smash = "sfx_piggybank_smash"; - public const string pot_begin = "sfx_pot_begin"; - public const string pot_burnt = "sfx_pot_burnt"; - public const string pot_work = "sfx_pot_work"; - public const string purchase_success = "sfx_purchase_success"; - public const string spin_end = "sfx_spin_end"; - public const string spin_go = "sfx_Spin_Go"; - public const string spin_idle = "sfx_Spin_Idle"; - public const string tap_food = "sfx_tap_food"; - public const string trash = "sfx_trash"; - public const string upgrade = "sfx_upgrade"; - public const string upgrade_confirm = "sfx_upgrade_confirm"; - public const string upgrade_locked = "sfx_upgrade_locked"; - public const string upgrade_unlock = "sfx_upgrade_unlock"; - public const string win = "sfx_win"; -} diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Audio/SoundNames.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Audio/SoundNames.cs.meta deleted file mode 100644 index c9ec545f1f7..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Audio/SoundNames.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1edf6f32253b442ba959f68754d8f8c5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Condition/ConditionManager.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Condition/ConditionManager.cs index c3f1fb2de21..b588b5755d2 100644 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Condition/ConditionManager.cs +++ b/ProjectNLD/Assets/Code/Scripts/Framework/Condition/ConditionManager.cs @@ -1,10 +1,7 @@ using System; using System.Collections.Generic; -using System.Reflection; using cfg; -using cfg.ActorCfg; using PhxhSDK; -using Utils; using static Framework.EventManager; namespace Framework.Condition diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/GameObjectFactory.cs b/ProjectNLD/Assets/Code/Scripts/Framework/GameObjectFactory.cs deleted file mode 100644 index b3709283792..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/GameObjectFactory.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using UnityEngine; -using Object = UnityEngine.Object; - -namespace Framework -{ - /// - /// gameobject对象工厂,封装了gameobject的创建和销毁 - /// - public static class GameObjectFactory - { - private static Transform _defaultRoot; - - - public static GameObject Create(bool dontDestroyOnLoad) - { - try - { - var go = new GameObject(); - // if(dontDestroyOnLoad)GameObject.DontDestroyOnLoad(go); - go.transform.parent = GetDefaultRoot(); - return go; - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - return null; - } - - public static void Destroy(Object go) - { - try - { - Object.Destroy(go); - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - } - - public static GameObject Clone(GameObject templateGo,GameObject parObj=null) - { - try - { - if (templateGo!=null) - { - Transform parent = null; - if (parObj != null && parObj.transform != null) - { - parent = parObj.transform; - } - - if (parent == null) - { - parent = templateGo.transform.parent; - } - - if (parent == null) - { - return Object.Instantiate(templateGo); - } - - return Object.Instantiate(templateGo, parent, true); - } - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - - return null; - } - - public static Transform GetDefaultRoot() - { - try - { - if (_defaultRoot == null) - { - GameObject gameObj = new GameObject("GameObjectFactoryRoot"); - // Object.DontDestroyOnLoad(gameObj); - _defaultRoot = gameObj.transform; - } - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - return _defaultRoot; - } - } -} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/GameObjectFactory.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/GameObjectFactory.cs.meta deleted file mode 100644 index 476dd83a448..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/GameObjectFactory.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f9758ce3398364147a7062443817aec7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/AnimatorUtils.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/AnimatorUtils.cs deleted file mode 100644 index 55786bb8f9a..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/AnimatorUtils.cs +++ /dev/null @@ -1,21 +0,0 @@ -using UnityEngine; - -public static class AnimatorUtils -{ - static public AnimationClip GetClipInfo(Animator animator, string clipName) - { - var clips = animator?.runtimeAnimatorController?.animationClips; - if (clips != null) - { - for (int i = 0; i < clips.Length; i++) - { - if (clips[i].name.Equals(clipName)) - { - return clips[i]; - } - } - } - - return default(AnimationClip); - } -} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/AnimatorUtils.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/AnimatorUtils.cs.meta deleted file mode 100644 index dd6a520a72c..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/AnimatorUtils.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 84697ceaf6763438fb9e2267f40be056 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/MaterialPropertyBlockVisitor.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/MaterialPropertyBlockVisitor.cs deleted file mode 100644 index 67a9ac84693..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/MaterialPropertyBlockVisitor.cs +++ /dev/null @@ -1,21 +0,0 @@ -using UnityEngine; - -namespace Framework -{ - public static class MaterialPropertyBlockVisitor - { - static private MaterialPropertyBlock _instance; - public static MaterialPropertyBlock Instance - { - get - { - if (_instance == null) - { - _instance = new MaterialPropertyBlock(); - } - _instance.Clear(); - return _instance; - } - } - } -} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/MaterialPropertyBlockVisitor.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/MaterialPropertyBlockVisitor.cs.meta deleted file mode 100644 index 52bfd6c4420..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/MaterialPropertyBlockVisitor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8c77f9fb6d14743aab406aeb20b85dd0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/ParticleSystemUtils.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/ParticleSystemUtils.cs deleted file mode 100644 index ca6b6f0ca7e..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/ParticleSystemUtils.cs +++ /dev/null @@ -1,39 +0,0 @@ -using UnityEngine; - -namespace Framework -{ - public class ParticleSystemUtils - { - public static void Play(ParticleSystem ps, bool withChildren) - { - ps?.Play(withChildren); - } - - public static void Play(ParticleSystem[] pss, bool withChildren) - { - if (pss != null) - { - for (int i = 0; i < pss.Length; i++) - { - pss[i].Play(withChildren); - } - } - } - - public static void Stop(ParticleSystem ps, bool withChildren) - { - ps?.Stop(withChildren); - } - - public static void Stop(ParticleSystem[] pss, bool withChildren) - { - if (pss != null) - { - for (int i = 0; i < pss.Length; i++) - { - pss[i].Stop(withChildren); - } - } - } - } -} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/ParticleSystemUtils.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/ParticleSystemUtils.cs.meta deleted file mode 100644 index 1b54dbbc7e2..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Graphic/ParticleSystemUtils.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5224ec2a94ce04cdf96a56ce9595679f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView.meta b/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView.meta deleted file mode 100644 index a461879c785..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 02d1d2393f5ae094ea9e3fb413a07567 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollView.cs b/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollView.cs deleted file mode 100644 index 8da931cae8a..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollView.cs +++ /dev/null @@ -1,837 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) AillieoTech. All rights reserved. -// -// ----------------------------------------------------------------------- - -namespace Framework -{ - using System; - using System.Collections; - using System.Collections.Generic; - using UnityEngine; - using UnityEngine.Serialization; - using UnityEngine.UI; - - [RequireComponent(typeof(RectTransform))] - [DisallowMultipleComponent] - public class PhxhScrollView : ScrollRect - { - [Tooltip("默认item尺寸")] - public Vector2 defaultItemSize; - - [Tooltip("item的模板")] - public RectTransform itemTemplate; - - // 0001 - protected const int flagScrollDirection = 1; - - [SerializeField] - [FormerlySerializedAs("m_layoutType")] - protected ItemLayoutType layoutType = ItemLayoutType.Vertical; - - // 只保存4个临界index - protected int[] criticalItemIndex = new int[4]; - - // callbacks for items - protected Action updateFunc; - protected Action bindButton; - - protected Func itemSizeFunc; - protected Func itemCountFunc; - protected Func itemGetFunc; - protected Action itemRecycleFunc; - - private readonly List managedItems = new List(); - - private Rect refRect; - - // resource management - private PhxhSimpleObjPool itemPool = null; - - private int dataCount = 0; - - [Tooltip("初始化时池内item数量")] - [SerializeField] - private int poolSize; - - // status - private bool initialized = false; - private int willUpdateData = 0; - - private Vector3[] viewWorldConers = new Vector3[4]; - private Vector3[] rectCorners = new Vector3[2]; - - // for hide and show - public enum ItemLayoutType - { - // 最后一位表示滚动方向 - Vertical = 0b0001, // 0001 - Horizontal = 0b0010, // 0010 - VerticalThenHorizontal = 0b0100, // 0100 - HorizontalThenVertical = 0b0101, // 0101 - } - - public virtual void SetUpdateFunc(Action func) - { - this.updateFunc = func; - } - - public virtual void SetItemSizeFunc(Func func) - { - this.itemSizeFunc = func; - } - - public virtual void SetItemCountFunc(Func func) - { - this.itemCountFunc = func; - } - - public void SetItemGetAndRecycleFunc(Func getFunc, Action recycleFunc) - { - if (getFunc != null && recycleFunc != null) - { - this.itemGetFunc = getFunc; - this.itemRecycleFunc = recycleFunc; - } - else - { - this.itemGetFunc = null; - this.itemRecycleFunc = null; - } - } - - public void ResetAllDelegates() - { - this.SetUpdateFunc(null); - this.SetItemSizeFunc(null); - this.SetItemCountFunc(null); - this.SetItemGetAndRecycleFunc(null, null); - } - - public void UpdateData(bool immediately = true) - { - if (immediately) - { - this.willUpdateData |= 3; // 0011 - this.InternalUpdateData(); - } - else - { - if (this.willUpdateData == 0 && this.IsActive()) - { - this.StartCoroutine(this.DelayUpdateData()); - } - - this.willUpdateData |= 3; - } - } - - public void UpdateDataIncrementally(bool immediately = true) - { - if (immediately) - { - this.willUpdateData |= 1; // 0001 - this.InternalUpdateData(); - } - else - { - if (this.willUpdateData == 0) - { - this.StartCoroutine(this.DelayUpdateData()); - } - - this.willUpdateData |= 1; - } - } - - public void ScrollTo(int index) - { - this.InternalScrollTo(index); - } - - protected override void OnEnable() - { - base.OnEnable(); - if (this.willUpdateData != 0) - { - this.StartCoroutine(this.DelayUpdateData()); - } - } - - protected override void OnDisable() - { - this.initialized = false; - base.OnDisable(); - } - - protected virtual void InternalScrollTo(int index) - { - index = Mathf.Clamp(index, 0, this.dataCount - 1); - this.EnsureItemRect(index); - Rect r = this.managedItems[index].rect; - var dir = (int)this.layoutType & flagScrollDirection; - if (dir == 1) - { - // vertical - var value = 1 - (-r.yMax / (this.content.sizeDelta.y - this.refRect.height)); - this.SetNormalizedPosition(value, 1); - } - else - { - // horizontal - var value = r.xMin / (this.content.sizeDelta.x - this.refRect.width); - this.SetNormalizedPosition(value, 0); - } - } - - protected override void SetContentAnchoredPosition(Vector2 position) - { - base.SetContentAnchoredPosition(position); - this.UpdateCriticalItems(); - } - - protected override void SetNormalizedPosition(float value, int axis) - { - base.SetNormalizedPosition(value, axis); - this.ResetCriticalItems(); - } - - protected void EnsureItemRect(int index) - { - if (!this.managedItems[index].rectDirty) - { - // 已经是干净的了 - return; - } - - ScrollItemWithRect firstItem = this.managedItems[0]; - if (firstItem.rectDirty) - { - Vector2 firstSize = this.GetItemSize(0); - firstItem.rect = CreateWithLeftTopAndSize(Vector2.zero, firstSize); - firstItem.rectDirty = false; - } - - // 当前item之前的最近的已更新的rect - var nearestClean = 0; - for (var i = index; i >= 0; --i) - { - if (!this.managedItems[i].rectDirty) - { - nearestClean = i; - break; - } - } - - // 需要更新 从 nearestClean 到 index 的尺寸 - Rect nearestCleanRect = this.managedItems[nearestClean].rect; - Vector2 curPos = GetLeftTop(nearestCleanRect); - Vector2 size = nearestCleanRect.size; - this.MovePos(ref curPos, size); - - for (var i = nearestClean + 1; i <= index; i++) - { - size = this.GetItemSize(i); - this.managedItems[i].rect = CreateWithLeftTopAndSize(curPos, size); - this.managedItems[i].rectDirty = false; - this.MovePos(ref curPos, size); - } - - var range = new Vector2(Mathf.Abs(curPos.x), Mathf.Abs(curPos.y)); - switch (this.layoutType) - { - case ItemLayoutType.VerticalThenHorizontal: - range.x += size.x; - range.y = this.refRect.height; - break; - case ItemLayoutType.HorizontalThenVertical: - range.x = this.refRect.width; - if (curPos.x != 0) - { - range.y += size.y; - } - - break; - default: - break; - } - - this.content.sizeDelta = range; - } - - protected override void OnDestroy() - { - if (this.itemPool != null) - { - this.itemPool.Purge(); - } - } - - protected Rect GetItemLocalRect(int index) - { - if (index >= 0 && index < this.dataCount) - { - this.EnsureItemRect(index); - return this.managedItems[index].rect; - } - - return (Rect)default; - } - -#if UNITY_EDITOR - protected override void OnValidate() - { - var dir = (int)this.layoutType & flagScrollDirection; - if (dir == 1) - { - // vertical - if (this.horizontalScrollbar != null) - { - this.horizontalScrollbar.gameObject.SetActive(false); - this.horizontalScrollbar = null; - } - } - else - { - // horizontal - if (this.verticalScrollbar != null) - { - this.verticalScrollbar.gameObject.SetActive(false); - this.verticalScrollbar = null; - } - } - - base.OnValidate(); - } -#endif - - private static Vector2 GetLeftTop(Rect rect) - { - Vector2 ret = rect.position; - ret.y += rect.size.y; - return ret; - } - - private static Rect CreateWithLeftTopAndSize(Vector2 leftTop, Vector2 size) - { - Vector2 leftBottom = leftTop - new Vector2(0, size.y); - return new Rect(leftBottom, size); - } - - private IEnumerator DelayUpdateData() - { - yield return new WaitForEndOfFrame(); - this.InternalUpdateData(); - } - - private void InternalUpdateData() - { - if (!this.IsActive()) - { - this.willUpdateData |= 3; - return; - } - - if (!this.initialized) - { - this.InitScrollView(); - } - - var newDataCount = 0; - var keepOldItems = (this.willUpdateData & 2) == 0; - - if (this.itemCountFunc != null) - { - newDataCount = this.itemCountFunc(); - } - - if (newDataCount != this.managedItems.Count) - { - if (this.managedItems.Count < newDataCount) - { - // 增加 - if (!keepOldItems) - { - foreach (var itemWithRect in this.managedItems) - { - // 重置所有rect - itemWithRect.rectDirty = true; - } - } - - while (this.managedItems.Count < newDataCount) - { - this.managedItems.Add(new ScrollItemWithRect()); - } - } - else - { - // 减少 保留空位 避免GC - for (int i = 0, count = this.managedItems.Count; i < count; ++i) - { - if (i < newDataCount) - { - // 重置所有rect - if (!keepOldItems) - { - this.managedItems[i].rectDirty = true; - } - - if (i == newDataCount - 1) - { - this.managedItems[i].rectDirty = true; - } - } - - // 超出部分 清理回收item - if (i >= newDataCount) - { - this.managedItems[i].rectDirty = true; - if (this.managedItems[i].item != null) - { - this.RecycleOldItem(this.managedItems[i].item); - this.managedItems[i].item = null; - } - } - } - } - } - else - { - if (!keepOldItems) - { - for (int i = 0, count = this.managedItems.Count; i < count; ++i) - { - // 重置所有rect - this.managedItems[i].rectDirty = true; - } - } - } - - this.dataCount = newDataCount; - - this.ResetCriticalItems(); - - this.willUpdateData = 0; - } - - private void ResetCriticalItems() - { - bool hasItem, shouldShow; - int firstIndex = -1, lastIndex = -1; - - for (var i = 0; i < this.dataCount; i++) - { - hasItem = this.managedItems[i].item != null; - shouldShow = this.ShouldItemSeenAtIndex(i); - - if (shouldShow) - { - if (firstIndex == -1) - { - firstIndex = i; - } - - lastIndex = i; - } - - if (hasItem && shouldShow) - { - // 应显示且已显示 - this.SetDataForItemAtIndex(this.managedItems[i].item, i); - continue; - } - - if (hasItem == shouldShow) - { - // 不应显示且未显示 - // if (firstIndex != -1) - // { - // // 已经遍历完所有要显示的了 后边的先跳过 - // break; - // } - continue; - } - - if (hasItem && !shouldShow) - { - // 不该显示 但是有 - this.RecycleOldItem(this.managedItems[i].item); - this.managedItems[i].item = null; - continue; - } - - if (shouldShow && !hasItem) - { - // 需要显示 但是没有 - RectTransform item = this.GetNewItem(i); - this.OnGetItemForDataIndex(item, i); - this.managedItems[i].item = item; - continue; - } - } - - // content.localPosition = Vector2.zero; - this.criticalItemIndex[CriticalItemType.UpToHide] = firstIndex; - this.criticalItemIndex[CriticalItemType.DownToHide] = lastIndex; - this.criticalItemIndex[CriticalItemType.UpToShow] = Mathf.Max(firstIndex - 1, 0); - this.criticalItemIndex[CriticalItemType.DownToShow] = Mathf.Min(lastIndex + 1, this.dataCount - 1); - } - - private RectTransform GetCriticalItem(int type) - { - var index = this.criticalItemIndex[type]; - if (index >= 0 && index < this.dataCount) - { - return this.managedItems[index].item; - } - - return null; - } - - private void UpdateCriticalItems() - { - var dirty = true; - - while (dirty) - { - dirty = false; - - for (int i = CriticalItemType.UpToHide; i <= CriticalItemType.DownToShow; i++) - { - if (i <= CriticalItemType.DownToHide) - { - // 隐藏离开可见区域的item - dirty = dirty || this.CheckAndHideItem(i); - } - else - { - // 显示进入可见区域的item - dirty = dirty || this.CheckAndShowItem(i); - } - } - } - } - - private bool CheckAndHideItem(int criticalItemType) - { - RectTransform item = this.GetCriticalItem(criticalItemType); - var criticalIndex = this.criticalItemIndex[criticalItemType]; - if (item != null && !this.ShouldItemSeenAtIndex(criticalIndex)) - { - this.RecycleOldItem(item); - this.managedItems[criticalIndex].item = null; - - if (criticalItemType == CriticalItemType.UpToHide) - { - // 最上隐藏了一个 - this.criticalItemIndex[criticalItemType + 2] = Mathf.Max(criticalIndex, this.criticalItemIndex[criticalItemType + 2]); - this.criticalItemIndex[criticalItemType]++; - } - else - { - // 最下隐藏了一个 - this.criticalItemIndex[criticalItemType + 2] = Mathf.Min(criticalIndex, this.criticalItemIndex[criticalItemType + 2]); - this.criticalItemIndex[criticalItemType]--; - } - - this.criticalItemIndex[criticalItemType] = Mathf.Clamp(this.criticalItemIndex[criticalItemType], 0, this.dataCount - 1); - - if (this.criticalItemIndex[CriticalItemType.UpToHide] > this.criticalItemIndex[CriticalItemType.DownToHide]) - { - // 偶然的情况 拖拽超出一屏 - this.ResetCriticalItems(); - return false; - } - - return true; - } - - return false; - } - - private bool CheckAndShowItem(int criticalItemType) - { - RectTransform item = this.GetCriticalItem(criticalItemType); - var criticalIndex = this.criticalItemIndex[criticalItemType]; - - if (item == null && this.ShouldItemSeenAtIndex(criticalIndex)) - { - RectTransform newItem = this.GetNewItem(criticalIndex); - this.OnGetItemForDataIndex(newItem, criticalIndex); - this.managedItems[criticalIndex].item = newItem; - - if (criticalItemType == CriticalItemType.UpToShow) - { - // 最上显示了一个 - this.criticalItemIndex[criticalItemType - 2] = Mathf.Min(criticalIndex, this.criticalItemIndex[criticalItemType - 2]); - this.criticalItemIndex[criticalItemType]--; - } - else - { - // 最下显示了一个 - this.criticalItemIndex[criticalItemType - 2] = Mathf.Max(criticalIndex, this.criticalItemIndex[criticalItemType - 2]); - this.criticalItemIndex[criticalItemType]++; - } - - this.criticalItemIndex[criticalItemType] = Mathf.Clamp(this.criticalItemIndex[criticalItemType], 0, this.dataCount - 1); - - if (this.criticalItemIndex[CriticalItemType.UpToShow] >= this.criticalItemIndex[CriticalItemType.DownToShow]) - { - // 偶然的情况 拖拽超出一屏 - this.ResetCriticalItems(); - return false; - } - - return true; - } - - return false; - } - - private bool ShouldItemSeenAtIndex(int index) - { - if (index < 0 || index >= this.dataCount) - { - return false; - } - - this.EnsureItemRect(index); - return new Rect(this.refRect.position - this.content.anchoredPosition, this.refRect.size).Overlaps(this.managedItems[index].rect); - } - - private bool ShouldItemFullySeenAtIndex(int index) - { - if (index < 0 || index >= this.dataCount) - { - return false; - } - - this.EnsureItemRect(index); - return this.IsRectContains(new Rect(this.refRect.position - this.content.anchoredPosition, this.refRect.size), this.managedItems[index].rect); - } - - private bool IsRectContains(Rect outRect, Rect inRect, bool bothDimensions = false) - { - if (bothDimensions) - { - var xContains = (outRect.xMax >= inRect.xMax) && (outRect.xMin <= inRect.xMin); - var yContains = (outRect.yMax >= inRect.yMax) && (outRect.yMin <= inRect.yMin); - return xContains && yContains; - } - else - { - var dir = (int)this.layoutType & flagScrollDirection; - if (dir == 1) - { - // 垂直滚动 只计算y向 - return (outRect.yMax >= inRect.yMax) && (outRect.yMin <= inRect.yMin); - } - else - { - // = 0 - // 水平滚动 只计算x向 - return (outRect.xMax >= inRect.xMax) && (outRect.xMin <= inRect.xMin); - } - } - } - - private void InitPool() - { - var poolNode = new GameObject("POOL"); - poolNode.SetActive(false); - poolNode.transform.SetParent(this.transform, false); - this.itemPool = new PhxhSimpleObjPool( - this.poolSize, - (RectTransform item) => - { - item.transform.SetParent(poolNode.transform, false); - }, - () => - { - GameObject itemObj = Instantiate(this.itemTemplate.gameObject); - RectTransform item = itemObj.GetComponent(); - itemObj.transform.SetParent(poolNode.transform, false); - if (this.bindButton != null) - { - this.bindButton(itemObj); - } - item.anchorMin = Vector2.up; - item.anchorMax = Vector2.up; - item.pivot = Vector2.zero; - - itemObj.SetActive(true); - return item; - }); - } - - private void OnGetItemForDataIndex(RectTransform item, int index) - { - this.SetDataForItemAtIndex(item, index); - item.transform.SetParent(this.content, false); - } - - private void SetDataForItemAtIndex(RectTransform item, int index) - { - if (this.updateFunc != null) - { - this.updateFunc(index, item); - } - - this.SetPosForItemAtIndex(item, index); - } - - private void SetPosForItemAtIndex(RectTransform item, int index) - { - this.EnsureItemRect(index); - Rect r = this.managedItems[index].rect; - item.localPosition = r.position; - item.sizeDelta = r.size; - } - - private Vector2 GetItemSize(int index) - { - if (index >= 0 && index <= this.dataCount) - { - if (this.itemSizeFunc != null) - { - return this.itemSizeFunc(index); - } - } - - return this.defaultItemSize; - } - - private RectTransform GetNewItem(int index) - { - RectTransform item; - if (this.itemGetFunc != null) - { - item = this.itemGetFunc(index); - } - else - { - item = this.itemPool.Get(); - } - - return item; - } - - private void RecycleOldItem(RectTransform item) - { - if (this.itemRecycleFunc != null) - { - this.itemRecycleFunc(item); - } - else - { - this.itemPool.Recycle(item); - } - } - - private void InitScrollView() - { - this.initialized = true; - - // 根据设置来控制原ScrollRect的滚动方向 - var dir = (int)this.layoutType & flagScrollDirection; - this.vertical = dir == 1; - this.horizontal = dir == 0; - - this.content.pivot = Vector2.up; - this.content.anchorMin = Vector2.up; - this.content.anchorMax = Vector2.up; - this.content.anchoredPosition = Vector2.zero; - - this.InitPool(); - this.UpdateRefRect(); - } - - // refRect是在Content节点下的 viewport的 rect - private void UpdateRefRect() - { - /* - * WorldCorners - * - * 1 ------- 2 - * | | - * | | - * 0 ------- 3 - * - */ - - if (!CanvasUpdateRegistry.IsRebuildingLayout()) - { - Canvas.ForceUpdateCanvases(); - } - - this.viewRect.GetWorldCorners(this.viewWorldConers); - this.rectCorners[0] = this.content.transform.InverseTransformPoint(this.viewWorldConers[0]); - this.rectCorners[1] = this.content.transform.InverseTransformPoint(this.viewWorldConers[2]); - this.refRect = new Rect((Vector2)this.rectCorners[0] - this.content.anchoredPosition, this.rectCorners[1] - this.rectCorners[0]); - } - - private void MovePos(ref Vector2 pos, Vector2 size) - { - // 注意 所有的rect都是左下角为基准 - switch (this.layoutType) - { - case ItemLayoutType.Vertical: - // 垂直方向 向下移动 - pos.y -= size.y; - break; - case ItemLayoutType.Horizontal: - // 水平方向 向右移动 - pos.x += size.x; - break; - case ItemLayoutType.VerticalThenHorizontal: - pos.y -= size.y; - if (pos.y - size.y < -this.refRect.height) - { - pos.y = 0; - pos.x += size.x; - } - - break; - case ItemLayoutType.HorizontalThenVertical: - - pos.x += size.x; - if (pos.x + size.x > this.refRect.width) - { - pos.x = 0; - pos.y -= size.y; - } - - break; - default: - break; - } - } - public void SetButton(Action action) - { - this.bindButton = action; - } - - // const int 代替 enum 减少 (int)和(CriticalItemType)转换 - protected static class CriticalItemType - { - public static byte UpToHide = 0; - public static byte DownToHide = 1; - public static byte UpToShow = 2; - public static byte DownToShow = 3; - } - - private class ScrollItemWithRect - { - // scroll item 身上的 RectTransform组件 - public RectTransform item; - - // scroll item 在scrollview中的位置 - public Rect rect; - - // rect 是否需要更新 - public bool rectDirty = true; - } - } -} diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollView.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollView.cs.meta deleted file mode 100644 index 57ada5f8e6f..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollView.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 9f9de67925f950347af7cb5c19023db8 -timeCreated: 1533042733 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollViewEx.cs b/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollViewEx.cs deleted file mode 100644 index 7f47f7de0a3..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollViewEx.cs +++ /dev/null @@ -1,245 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) AillieoTech. All rights reserved. -// -// ----------------------------------------------------------------------- - -namespace Framework -{ - using System; - using UnityEngine; - using UnityEngine.EventSystems; - using UnityEngine.Serialization; - - [RequireComponent(typeof(RectTransform))] - [DisallowMultipleComponent] - public class PhxhScrollViewEx : PhxhScrollView - { - [SerializeField] - [FormerlySerializedAs("m_pageSize")] - private int pageSize = 50; - - private int startOffset = 0; - - private Func realItemCountFunc; - - private Vector2 lastPosition; - - private bool reloadFlag = false; - - public override void SetUpdateFunc(Action func) - { - if (func != null) - { - var f = func; - func = (index, rect) => - { - f(index + this.startOffset, rect); - }; - } - - base.SetUpdateFunc(func); - } - - public override void SetItemSizeFunc(Func func) - { - if (func != null) - { - var f = func; - func = (index) => - { - return f(index + this.startOffset); - }; - } - - base.SetItemSizeFunc(func); - } - - public override void SetItemCountFunc(Func func) - { - this.realItemCountFunc = func; - if (func != null) - { - var f = func; - func = () => Mathf.Min(f(), this.pageSize); - } - - base.SetItemCountFunc(func); - } - - public override void OnDrag(PointerEventData eventData) - { - if (this.reloadFlag) - { - this.reloadFlag = false; - this.OnEndDrag(eventData); - this.OnBeginDrag(eventData); - - return; - } - - base.OnDrag(eventData); - } - - protected override void Awake() - { - base.Awake(); - - this.lastPosition = Vector2.up; - this.onValueChanged.AddListener(this.OnValueChanged); - } - - protected override void InternalScrollTo(int index) - { - var count = 0; - if (this.realItemCountFunc != null) - { - count = this.realItemCountFunc(); - } - - index = Mathf.Clamp(index, 0, count - 1); - this.startOffset = Mathf.Clamp(index - (this.pageSize / 2), 0, count - this.itemCountFunc()); - this.UpdateData(true); - base.InternalScrollTo(index - this.startOffset); - } - - private void OnValueChanged(Vector2 position) - { - int toShow; - int critical; - bool downward; - int pin; - - Vector2 delta = position - this.lastPosition; - this.lastPosition = position; - - this.reloadFlag = false; - - if (((int)this.layoutType & flagScrollDirection) == 1) - { - // 垂直滚动 只计算y向 - if (delta.y < 0) - { - // 向上 - toShow = this.criticalItemIndex[CriticalItemType.DownToShow]; - critical = this.pageSize - 1; - if (toShow < critical) - { - return; - } - - pin = critical - 1; - downward = false; - } - else if (delta.y > 0) - { - // 向下 - toShow = this.criticalItemIndex[CriticalItemType.UpToShow]; - critical = 0; - if (toShow > critical) - { - return; - } - - pin = critical + 1; - downward = true; - } - else - { - return; - } - } - else - { - // = 0 - // 水平滚动 只计算x向 - if (delta.x > 0) - { - // 向右 - toShow = this.criticalItemIndex[CriticalItemType.UpToShow]; - critical = 0; - if (toShow > critical) - { - return; - } - - pin = critical + 1; - downward = true; - } - else if (delta.x < 0) - { - // 向左 - toShow = this.criticalItemIndex[CriticalItemType.DownToShow]; - critical = this.pageSize - 1; - if (toShow < critical) - { - return; - } - - pin = critical - 1; - downward = false; - } - else - { - return; - } - } - - // 该翻页了 翻半页吧 - var old = this.startOffset; - if (downward) - { - this.startOffset -= this.pageSize / 2; - } - else - { - this.startOffset += this.pageSize / 2; - } - - var realDataCount = 0; - if (this.realItemCountFunc != null) - { - realDataCount = this.realItemCountFunc(); - } - - this.startOffset = Mathf.Clamp(this.startOffset, 0, Mathf.Max(realDataCount - this.pageSize, 0)); - - if (old != this.startOffset) - { - this.reloadFlag = true; - - // 记录 原先的速度 - Vector2 oldVelocity = this.velocity; - - // 计算 pin元素的世界坐标 - Rect rect = this.GetItemLocalRect(pin); - - Vector2 oldWorld = this.content.TransformPoint(rect.position); - var dataCount = 0; - if (this.itemCountFunc != null) - { - dataCount = this.itemCountFunc(); - } - - if (dataCount > 0) - { - this.EnsureItemRect(0); - if (dataCount > 1) - { - this.EnsureItemRect(dataCount - 1); - } - } - - // 根据 pin元素的世界坐标 计算出content的position - var pin2 = pin + old - this.startOffset; - Rect rect2 = this.GetItemLocalRect(pin2); - Vector2 newWorld = this.content.TransformPoint(rect2.position); - Vector2 deltaWorld = newWorld - oldWorld; - Vector2 deltaLocal = this.content.InverseTransformVector(deltaWorld); - this.SetContentAnchoredPosition(this.content.anchoredPosition - deltaLocal); - this.UpdateData(true); - this.velocity = oldVelocity; - } - } - } -} diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollViewEx.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollViewEx.cs.meta deleted file mode 100644 index 493a317046e..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhScrollViewEx.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 990bec45166081c4087bc378d32950f1 -timeCreated: 1533042733 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhSimpleObjPool.cs b/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhSimpleObjPool.cs deleted file mode 100644 index cbd4b2d014c..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhSimpleObjPool.cs +++ /dev/null @@ -1,76 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) AillieoTech. All rights reserved. -// -// ----------------------------------------------------------------------- - -namespace Framework -{ - using System; - using System.Collections.Generic; - - public class PhxhSimpleObjPool - { - private readonly Stack stack; - private readonly Func ctor; - private readonly Action onRecycle; - private int size; - private int usedCount; - - public PhxhSimpleObjPool(int max = 5, Action onRecycle = null, Func ctor = null) - { - this.stack = new Stack(max); - this.size = max; - this.onRecycle = onRecycle; - this.ctor = ctor; - } - - public T Get() - { - T item; - if (this.stack.Count == 0) - { - if (this.ctor != null) - { - item = this.ctor(); - } - else - { - item = Activator.CreateInstance(); - } - } - else - { - item = this.stack.Pop(); - } - - this.usedCount++; - return item; - } - - public void Recycle(T item) - { - if (this.onRecycle != null) - { - this.onRecycle.Invoke(item); - } - - if (this.stack.Count < this.size) - { - this.stack.Push(item); - } - - this.usedCount--; - } - - public void Purge() - { - // TODO - } - - public override string ToString() - { - return $"SimpleObjPool: item=[{typeof(T)}], inUse=[{this.usedCount}], restInPool=[{this.stack.Count}/{this.size}] "; - } - } -} diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhSimpleObjPool.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhSimpleObjPool.cs.meta deleted file mode 100644 index c6f125ce123..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/ScrollView/PhxhSimpleObjPool.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 05ad16b4d0f8b4c37a1cadc920b0b045 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIButtonEx.cs b/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIButtonEx.cs index 547c85e4381..7e47d831a8c 100644 --- a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIButtonEx.cs +++ b/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIButtonEx.cs @@ -1,9 +1,7 @@ using System; using UnityEngine; using UnityEngine.UI; -using UnityEditor; using UnityEngine.EventSystems; -using UnityEngine.InputSystem; [RequireComponent(typeof(Button))] public class UIButtonEx: Button diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIList.cs b/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIList.cs deleted file mode 100644 index 53e7851bd43..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIList.cs +++ /dev/null @@ -1 +0,0 @@ -using System; using System.Collections.Generic; //using DG.Tweening; using Framework; using Framework.Wrapper; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using Object = UnityEngine.Object; /// /// 列表单项的基类 /// /// 与UI列表单项对应的数据类 public abstract class UIListItem { protected UIGameObjectWrapper _go; protected object _context; protected int _index; public void Init(GameObject go, object context) { _go = new UIGameObjectWrapper(go); _go.SetActive(true); _context = context; InitUI(_go); } public GameObject GetGameObject() { return _go.GameObject; } public void SetScale(float scale) { _go.SetScale(scale); } public void SetParent(Transform parent) { _go.SetParent(parent, false); } public void SetActive(bool active) { _go.SetActive(active); } public void Dispose() { OnDispose(); } public void ReUse(D data) { OnBindData(data); } public void SetSelected(bool selected) { OnSelected(selected); } public void SetIndex(int index) { _index = index; } public void DistancePercentFromViewCenter(float percent) { OnDistancePercentFromViewCenter(percent); } public void Release() { Dispose(); if (_go != null) { GameObjectFactory.Destroy(_go.GameObject); _go = null; } } /// /// item 初始化,缓存界面元素等; /// /// code example /// /// _image = go.GetItem("xxxx/xxxx/xxxx"); /// _title = go.GetItem("xxxx/xxxx/xxxx"); /// /// /// /// 列表下的单项 gameobject 对应的包装类 protected abstract void InitUI(UIGameObjectWrapper go); /// /// item释放资源 (离开可视区域或者界面销毁时) /// /// code example /// /// res.Dispose(); /// _image.sprite = null; /// _title = null; /// button.onClick.RemoveAllListeners(); // 注意:由于UIListItem是复用的,button 一定要清理listener /// /// protected abstract void OnDispose(); /// /// item 加载资源,更新表现 (进入可视区域时) /// /// code example /// /// _image.sprite = LoadSprite(); /// button.onClick.RemoveAllListeners(); // 注意:由于UIListItem是复用的,button 一定要清理listener,再绑定新的数据 /// button.onClick.AddListener({}); /// /// /// 用于更新 列表单项表现 的数据类 protected abstract void OnBindData(D data); /// /// 被选中时的表现 /// /// protected abstract void OnSelected(bool selected); /// /// 距离中心的比例 /// /// cell的size与距离中心的比例 (cellsize/delta) protected virtual void OnDistancePercentFromViewCenter(float percent) { } } public class UIList : UIGameObjectWrapper where T : UIListItem, new() { protected object _context; protected GameObject _itemTemplate; private GameObject _slotTemplate; private ScrollRect _scrollRect; private RectTransform _contentRectTransform; private RectTransform _viewportRectTransform; private RectTransform _itemRect; private UIListLayout _layout; private float _cellSize; private float _spacing; private float _padding; private int _groupCount; private List> _slots = new List>(); private Stack> _itemPool = new Stack>(16); private List _datas; private bool _needUpdate; private float _updateInterval = 0.1f; private float _currentTime = 0f; private int _currentSelect = -1; private float _scrollRectSize; /// /// /// /// list从属的 带有scrollview组件的game object /// 列表单项在 scrollview下的transform路径 /// 布局方式:行,列,格 /// 如果需要的话, 可以传入上下文,比如一些界面里记的状态, 在UIListItem单项里使用 public UIList(GameObject scrollView, string itemUnderScrollView, UIListLayout layout, object context) : base(scrollView) { try { _context = context; _scrollRect = GetItem(scrollView); _itemTemplate = GetItem($"{itemUnderScrollView}"); _slotTemplate = _BuildTemplateSlot(_itemTemplate); var contentTransform = _itemTemplate.transform.parent; _contentRectTransform = contentTransform.GetComponent(); _viewportRectTransform = contentTransform.parent.GetComponent(); _itemRect = _itemTemplate.GetComponent(); _itemTemplate.SetActive(false); _scrollRectSize = _scrollRect.GetComponent().sizeDelta.x; _layout = layout; switch (_layout) { case UIListLayout.Vertical: var verticalLayoutGroup = contentTransform.GetComponent(); _cellSize = _itemRect.rect.height; _spacing = verticalLayoutGroup.spacing; _padding = verticalLayoutGroup.padding.top; _groupCount = 1; break; case UIListLayout.Horizontal: var horizontalLayoutGroup = contentTransform.GetComponent(); _cellSize = _itemRect.rect.width; _spacing = horizontalLayoutGroup.spacing; _padding = horizontalLayoutGroup.padding.left; _groupCount = 1; break; case UIListLayout.Grid: var gridLayoutGroup = contentTransform.GetComponent(); _cellSize = gridLayoutGroup.cellSize.y; _spacing = gridLayoutGroup.spacing.y; _padding = gridLayoutGroup.padding.top; if (gridLayoutGroup.constraint == GridLayoutGroup.Constraint.Flexible) { gridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount; gridLayoutGroup.constraintCount = Mathf.FloorToInt( (_viewportRectTransform.rect.width - gridLayoutGroup.padding.left - gridLayoutGroup.padding.right + gridLayoutGroup.spacing.x) / (gridLayoutGroup.spacing.x + gridLayoutGroup.cellSize.x)); } _groupCount = gridLayoutGroup.constraintCount; break; default: break; } } catch (Exception e) { DebugUtil.LogError(e); } } public ScrollRect ScrollRect { get { return _scrollRect; } } public List> Slots { get { return _slots; } } public float CellSize { get { return _cellSize; } } public float Spacing => _spacing; /// /// 必须调用:把数据传给列表 /// /// public void SetDatas(List datas) { _datas = datas; _BuildAllSlots(); _UpdateContentSize(); } public void AddDataRange(IEnumerable datas) { _datas?.AddRange(datas); _UpdateContentSize(); } public void ClearDatas() { SetDatas(null); } public void ApplyData() { for (int i = 0; i < _slots.Count; i++) { var item = _slots[i].GetItem(); if (item != null && i < _GetDataCount()) { item.ReUse(_datas[i]); } } } /// /// 必须调用:动态列表必需update /// public void Update() { _currentTime += Time.deltaTime; while (_currentTime >= _updateInterval) { _currentTime -= _updateInterval; _needUpdate = true; } if (_needUpdate) { _UpdateContent(); } } /// /// 必须调用,列表正确地销毁 /// public void Dispose() { if (_slotTemplate) { Object.Destroy(_slotTemplate); _slotTemplate = null; } var count = _GetDataCount(); if (_slots != null) { for (int i = 0; i < _slots.Count; i++) { _RemoveItem(_slots[i]); GameObjectFactory.Destroy(_slots[i].GameObject); } _slots.Clear(); } var e = _itemPool.GetEnumerator(); while (e.MoveNext()) { e.Current.Release(); } _itemPool.Clear(); _datas = null; } public void ScrollTo(int index, float duration = -1) { var itemPos = GetItemPosition(index); var newPos = _contentRectTransform.localPosition; if (_layout == UIListLayout.Horizontal) { newPos.x = itemPos; } else { newPos.y = itemPos; } if (duration > 0) { //_contentRectTransform.DOLocalMove(newPos, duration); } else { _contentRectTransform.localPosition = newPos; } } public float GetItemPosition(int index) { return _padding + Mathf.FloorToInt((float)index / _groupCount) * (_cellSize + _spacing); } public void ScrollTo(float position, float duration = -1) { var newPos = _contentRectTransform.localPosition; if (_layout == UIListLayout.Horizontal) { newPos.x = - position; } else { newPos.y = - position; } if (duration > 0) { //_contentRectTransform.DOLocalMove(newPos, duration); } else { _contentRectTransform.localPosition = newPos; } } public float GetScrollPos() { if (_layout == UIListLayout.Horizontal) { return -_contentRectTransform.localPosition.x; } else { return -_contentRectTransform.localPosition.y; } } public void Select(int index) { if (_slots != null) { if (_currentSelect >= 0 && _currentSelect < _slots.Count) { var item = _slots[_currentSelect].GetItem(); item?.SetSelected(false); } _currentSelect = index; if (_currentSelect >= 0 && _currentSelect < _slots.Count) { var item = _slots[_currentSelect].GetItem(); item?.SetSelected(true); } } } public bool GetSelectedData(out D data) { if (_currentSelect >= 0 && _currentSelect < _datas.Count) { data = _datas[_currentSelect]; return true; } data = default(D); return false; } public void Bind(UnityAction onScrollPosChanged) { _scrollRect.onValueChanged.AddListener(onScrollPosChanged); } public float GetViewportSize() { if (_layout == UIListLayout.Horizontal) { return _viewportRectTransform.rect.width; } else { return _viewportRectTransform.rect.height; } } public bool TryGetItem(int index, out T item) { if (index >= 0 && index < _slots.Count) { if (_slots[index].HasItem()) { item = _slots[index].GetItem() as T; if (item != null) { return true; } } } item = null; return false; } private GameObject _BuildTemplateSlot(GameObject template) { var rectTransform = template.GetComponent(); var slot = new GameObject("Slot"); slot.layer = template.layer; slot.transform.SetParent(template.transform.parent, false); var slotRect = slot.AddComponent(); slotRect.pivot = rectTransform.pivot; slotRect.anchorMax = rectTransform.anchorMax; slotRect.anchorMin = rectTransform.anchorMin; slotRect.offsetMax = rectTransform.offsetMax; slotRect.offsetMin = rectTransform.offsetMin; slotRect.sizeDelta = rectTransform.sizeDelta; slotRect.anchoredPosition = rectTransform.anchoredPosition; slotRect.anchoredPosition3D = rectTransform.anchoredPosition3D; var layoutElement = template.GetComponent(); if (layoutElement) { var slotLayoutElement = slot.AddComponent(); slotLayoutElement.minWidth = layoutElement.minWidth; slotLayoutElement.minHeight = layoutElement.minWidth; slotLayoutElement.ignoreLayout = layoutElement.ignoreLayout; slotLayoutElement.flexibleWidth = layoutElement.flexibleWidth; slotLayoutElement.flexibleHeight = layoutElement.flexibleHeight; slotLayoutElement.layoutPriority = layoutElement.layoutPriority; slotLayoutElement.preferredWidth = layoutElement.preferredWidth; slotLayoutElement.preferredHeight = layoutElement.preferredHeight; Object.Destroy(layoutElement); } slot.SetActive(false); return slot; } private void _BuildAllSlots() { var count = _GetDataCount(); if (count > 0) { if (_slots == null) { _slots = new List>(count); } int i = 0; for (; i < count; i++) { _OpenSlot(i); } for (; i < _slots.Count; i++) { _CloseSlot(i); } } else { if (_slots != null) { for (int i = 0; i < _slots.Count; i++) { _CloseSlot(i); } } } _needUpdate = true; } private void _UpdateContent() { var count = _GetDataCount(); int startHide, endHide, startShow, endShow; _GetShowSlotRange(out startShow, out endShow, out startHide, out endHide); for (int i = 0; i < count; i++) { var slot = _slots[i]; if (slot.HasItem()) { if (i < startHide || i > endHide) { _RemoveItem(slot); } } else { if (i >= startShow && i <= endShow) { _AddItem(slot, _datas[i], i); } } if (slot.HasItem()) { var delta = 0f; if (_layout == UIListLayout.Horizontal) { delta = slot.LocalPosition.x - Mathf.Abs(_contentRectTransform.localPosition.x); } else { delta = slot.LocalPosition.y - _contentRectTransform.localPosition.y; } delta = Mathf.Abs(delta); var percent = 1f - delta / _scrollRectSize / 2f; slot.GetItem().DistancePercentFromViewCenter(percent); } } } private void _UpdateContentSize() { var size = _padding + (_slots.Count/(float)_groupCount) * (_cellSize + _spacing); if (_layout == UIListLayout.Horizontal) { _contentRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size); } else { _contentRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size); } } public float GetContentSize() { if (_layout == UIListLayout.Horizontal) { return _contentRectTransform.rect.width; } else { return _contentRectTransform.rect.height; } } private UIListSlot _CreateSlot() { var go = GameObjectFactory.Clone(_slotTemplate); return new UIListSlot(go); } private int _GetDataCount() { return _datas?.Count ?? 0; } private void _CloseSlot(int index) { var slot = _slots[index]; _RemoveItem(slot); slot.SetActive(false); } private void _OpenSlot(int index) { var more = index - (_slots.Count - 1); if (more > 0) { for (int i = 0; i < more; i++) { var slot = _CreateSlot(); slot.SetActive(true); _slots.Add(slot); } } else { _RemoveItem(_slots[index]); _slots[index].SetActive(true); } } private void _RemoveItem(UIListSlot slot) { var c = slot.GetItem(); if (c != null) { c.Dispose(); slot.RemoveItem(); _itemPool.Push(c); c.SetParent(GameObjectFactory.GetDefaultRoot()); } } private void _AddItem(UIListSlot slot, D data, int index) { UIListItem c = null; if (_itemPool.Count > 0) { c = _itemPool.Pop(); } else { c = new T(); c.Init(GameObjectFactory.Clone(_itemTemplate), _context); } if (c != null) { slot.AddItem(c); c.SetIndex(index); c.SetSelected(index == _currentSelect); c.ReUse(data); } } // pos = _padding + math.floor(index / _groupCount) * (_cellSize + _spacing) private void _GetShowSlotRange(out int startShowIndex, out int endShowIndex, out int startHideIndex, out int endHideIndex) { var rectStartPos = 0f; var rectEndPos = 0f; if (_layout == UIListLayout.Horizontal) { rectStartPos = Mathf.Abs(_contentRectTransform.localPosition.x); rectEndPos = rectStartPos + _viewportRectTransform.rect.width; } else { rectStartPos = _contentRectTransform.localPosition.y; rectEndPos = rectStartPos + _viewportRectTransform.rect.height; } var startIndex = Mathf.FloorToInt((rectStartPos - _padding) / (_cellSize + _spacing)) * _groupCount; var endIndex = Mathf.FloorToInt((rectEndPos - _padding) / (_cellSize + _spacing)) * _groupCount; startShowIndex = startIndex - _groupCount; endShowIndex = endIndex + _groupCount; startHideIndex = startIndex - 2 * _groupCount; endHideIndex = endIndex + 2 * _groupCount; } } public enum UIListLayout { Vertical, Horizontal, Grid, } public class UIListSlot : UIGameObjectWrapper { public UIListSlot(GameObject go) : base(go) { _slot = go; } private GameObject _slot; private UIListItem _item; public void AddItem(UIListItem go) { if (_item != null) { DebugUtil.LogError("UIListSlot.AddItem: already has item"); return; } go.SetParent(_slot.transform); go.SetActive(true); _item = go; } public UIListItem RemoveItem() { var ret = _item; _item = null; ret?.SetParent(null); ret?.SetActive(false); return ret; } public bool HasItem() { return _item != null; } public UIListItem GetItem() { return _item; } public Vector3 LocalPosition { get { return _slot.transform.localPosition; } } } \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIList.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIList.cs.meta deleted file mode 100644 index c97aa208524..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIList.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 45075e6d297604846a12a334871735f9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIReuseable.cs b/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIReuseable.cs index 58d49396d52..69bf47b8052 100644 --- a/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIReuseable.cs +++ b/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIReuseable.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Framework; +using PhxhSDK; using UnityEngine; public class UIReuseable : MonoBehaviour @@ -27,7 +27,7 @@ public class UIReuseable : MonoBehaviour GameObject cell = null; if (_cellPoolList.Count == 0) { - cell = GameObjectFactory.Clone(template, parent); + cell = Utils.Clone(template, parent); cell.SetActive(true); } else diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/GameObjectWrapper.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/GameObjectWrapper.cs deleted file mode 100644 index b5a5899afaa..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/GameObjectWrapper.cs +++ /dev/null @@ -1,394 +0,0 @@ -using System; -using UnityEngine; - -namespace Framework.Wrapper -{ - /// - /// gameobject 和 transform 操作的封装类 - /// - public class GameObjectWrapper - { - protected GameObject _gameObject; - - public GameObjectWrapper(GameObject go) - { - if (go == null) - { - DebugUtil.LogError("GameObjectWrapper: gameObject is null"); - } - _gameObject = go; - } - - public string Name - { - get - { - return _gameObject != null ? _gameObject.name : null; - } - set - { - if (_gameObject != null) _gameObject.name = value; - } - } - - private Transform Transform => _gameObject != null ? _gameObject.transform : null; - - public int GetInstanceID() - { - return _gameObject != null ? _gameObject.GetInstanceID() : 0; - } - - public string GetNameMark() - { - return _gameObject != null ? (_gameObject.name + _gameObject.transform.parent.name) : string.Empty; - } - - public bool GetActive() - { - return _gameObject != null && _gameObject.activeSelf; - } - - public void SetActive(bool active) - { - if (_gameObject != null) _gameObject.SetActive(active); - } - - public bool IsActive() - { - return _gameObject != null && _gameObject.activeSelf; - } - - public Vector3 GetPosition(Space relativeTo = Space.World) - { - return Transform != null - ? relativeTo == Space.World ? Transform.position : Transform.localPosition - : Vector3.zero; - } - - public void SetPosition(Vector3 position, Space relativeTo = Space.World) - { - if (Transform == null) return; - if (relativeTo == Space.World) - { - Transform.position = position; - } - else - { - Transform.localPosition = position; - } - } - - public Quaternion GetRotation(Space relativeTo = Space.World) - { - if (Transform == null) - { - return Quaternion.identity; - } - return relativeTo == Space.World ? Transform.rotation : Transform.localRotation; - } - - public void SetRotationH(Vector3 dir) - { - Quaternion rotation; - if (TransformUtil.ToRotationH(dir, out rotation)) - { - SetRotation(rotation); - } - } - - public void SetRotation(Vector3 dir, Vector3 up) - { - Quaternion rotation; - if (TransformUtil.ToRotation(dir, up, out rotation)) - { - SetRotation(rotation); - } - } - - public void SetRotation(Quaternion rotation, Space relativeTo = Space.World) - { - try - { - if (Transform == null) return; - if (relativeTo == Space.World) - { - Transform.rotation = rotation; - } - else - { - Transform.localRotation = rotation; - } - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - } - - public Vector3 GetEulerAngles(Space relativeTo = Space.World) - { - return GetRotation(relativeTo).eulerAngles; - } - - public void SetEulerAngles(Vector3 eulerAngles, Space relativeTo = Space.World) - { - Quaternion rotation = Quaternion.Euler(eulerAngles); - SetRotation(rotation, relativeTo); - } - - public Vector3 GetRight() - { - return Transform != null ? Transform.right : Vector3.zero; - } - - public Vector3 GetForward() - { - return Transform != null ? Transform.forward : Vector3.zero; - } - - public Vector3 GetUp() - { - return Transform != null ? Transform.up : Vector3.zero; - } - - public float GetAngleH() - { - return TransformUtil.GetAngleH(GetRotation()); - } - - public void SetAngleH(float angle) - { - SetRotation(Quaternion.AngleAxis(angle, Vector3.up)); - } - - public Vector3 GetScale(Space relativeTo = Space.Self) - { - if (Transform == null) - { - return Vector3.one; - } - return relativeTo == Space.World ? Transform.lossyScale : Transform.localScale; - } - - public void SetScale(float scale) - { - if (scale > 0.0f) - { - SetScale(Vector3.one * scale); - } - } - - public void SetScale(Vector3 scale, Space relativeTo = Space.Self) - { - try - { - var transform = Transform; - if (transform == null) - { - return; - } - if (scale.x > 0.0f && scale.y > 0.0f && scale.z > 0.0f) - { - if (relativeTo == Space.World) - { - if (Transform.parent == null) - { - Transform.localScale = scale; - } - else - { - Vector3 parentScale = Transform.parent.lossyScale; - if (parentScale.x > 0.0f && - parentScale.y > 0.0f && - parentScale.z > 0.0f) - { - Transform.localScale = new Vector3(scale.x / parentScale.x, - scale.y / parentScale.y, - scale.z / parentScale.z); - } - } - } - else - { - Transform.localScale = scale; - } - } - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - } - - public Matrix4x4 GetLocalToWorldMatrix() - { - return Transform != null ? Transform.localToWorldMatrix : Matrix4x4.identity; - } - - public Matrix4x4 GetWorldToLocalMatrix() - { - return Transform != null ? Transform.worldToLocalMatrix : Matrix4x4.identity; - } - - public Transform GetParent() - { - return Transform != null ? Transform.parent : null; - } - - - public void SetParent(GameObjectWrapper parent, bool worldPositionStays = true) - { - SetParent(parent?.Transform, worldPositionStays); - } - - public void SetParent(Transform parent, bool worldPositionStays = true) - { - var transform = Transform; - if (transform == null) - { - return; - } - Transform.SetParent(parent, worldPositionStays); - if (!worldPositionStays) - { - Transform.localPosition = Vector3.zero; - Transform.localRotation = Quaternion.identity; - } - } - - public int GetChildCount() - { - return Transform != null ? Transform.childCount : 0; - } - - public void AttachChild(Transform child) - { - AttachChild(child, Vector3.zero, rotation: Quaternion.identity); - } - - public void AttachChild(Transform child, Vector3 position) - { - AttachChild(child, position, rotation: Quaternion.identity); - } - - public void AttachChild(Transform child, Vector3 position, Quaternion rotation) => AttachChild(child, position, rotation, Vector3.one); - - public void AttachChild(Transform child, Vector3 position, Quaternion rotation, Vector3 scale) - { - try - { - if (child != null && Transform != null) - { - child.SetParent(Transform, false); - child.localPosition = position; - child.localRotation = rotation; - child.localScale = scale; - } - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - } - - public void DetachChild(Transform child) - { - if (child != null) - { - child.SetParent(null); - } - } - - public void AttachChild(GameObjectWrapper child) - { - AttachChild(child, position: Vector3.zero, rotation: Quaternion.identity, scale: Vector3.one); - } - - public void AttachChild(GameObjectWrapper child, Vector3 position) - { - AttachChild(child, position, Quaternion.identity, Vector3.one); - } - - public void AttachChild(GameObjectWrapper child, Vector3 position, Quaternion rotation) - { - AttachChild(child, position, rotation, Vector3.one); - } - - public void AttachChild(GameObjectWrapper child, Vector3 position, Quaternion rotation, Vector3 scale) - { - try - { - if (Transform == null) - { - return; - } - child.SetParent(Transform, false); - child.SetPosition(position, Space.Self); - child.SetRotation(rotation, Space.Self); - child.SetScale(scale); - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - } - - public void DetachChild(GameObjectWrapper child) - { - try - { - if (child != null) - { - DetachChild(child.Transform); - } - } - catch (Exception e) - { - DebugUtil.LogError(e); - } - } - - public virtual void SetLayer(int layer) - { - if (_gameObject != null) _gameObject.layer = layer; - } - - public int GetLayer() - { - return _gameObject != null ? _gameObject.layer : 0; - } - - public GameObject GameObject - { - get { return _gameObject; } - } - - public Transform transform - { - get - { - return _gameObject.transform; - } - } - - public Vector3 TransformPoint(Vector3 position) - { - return _gameObject.transform.TransformPoint(position); - } - - public Vector3 InverseTransformVector(Vector3 position) - { - return _gameObject.transform.InverseTransformVector(position); - } - - public Vector3 InverseTransformPoint(Vector3 position) - { - return _gameObject.transform.InverseTransformPoint(position); - } - - public Vector3 TransformVector(Vector3 position) - { - return _gameObject.transform.TransformVector(position); - } - } -} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/GameObjectWrapper.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/GameObjectWrapper.cs.meta deleted file mode 100644 index cf99306186e..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/GameObjectWrapper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f0271496c285e437aa515e0c872eb926 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/Node.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/Node.cs deleted file mode 100644 index 2c9d4e5fa4c..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/Node.cs +++ /dev/null @@ -1 +0,0 @@ -using System; using UnityEngine; namespace Framework.Wrapper { /// /// 空的游戏物体 /// public sealed class Node : GameObjectWrapper, IDisposable { public Node():base(GameObjectFactory.Create(false)) { } public static Node Root = new Node(); /// /// 需要显式调用Dispose,销毁game object,editor模式下,系统会帮你检查node的泄漏问题 /// public void Dispose() { Dispose(true); #if UNITY_EDITOR GC.SuppressFinalize(this); //自己释放了,不需要gc帮我调用析构函数 #endif } #if UNITY_EDITOR ~Node() { Dispose(false); } #endif private void ReleaseUnmanagedResources() { GameObjectFactory.Destroy(_gameObject); } private void Dispose(bool disposing) { if (!disposing) { DebugUtil.LogError( "Node should call dispose method,or the inner game object wont destroy. node name: {0}", Name); } ReleaseUnmanagedResources(); if (disposing) { } } } } \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/Node.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/Node.cs.meta deleted file mode 100644 index cf7f6792ba8..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/Node.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a300f7b978bde4ed9a02fb89a2608cf9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/RendererWrapper.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/RendererWrapper.cs deleted file mode 100644 index e6ec5394e03..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/RendererWrapper.cs +++ /dev/null @@ -1,98 +0,0 @@ - -using UnityEngine; - -namespace Framework.Wrapper -{ - public class RendererWrapper - { - private readonly Renderer[] _renderers; - private Material[][] _originalMaterials; - private Shader[] _originalShaders; - - - public RendererWrapper(Renderer[] renderers) - { - if (renderers == null) - { - DebugUtil.LogError("RendererWrapper: renderer is null"); - } - _renderers = renderers; - - if (_renderers.Length > 0) - { - _originalMaterials = new Material[_renderers.Length][]; - for (int i = 0; i < _renderers.Length; i++) - { - _originalMaterials[i] = _renderers[i].sharedMaterials; - } - } - } - - public void SetVisible(bool visible) - { - if (_renderers != null) - { - foreach (var renderer in _renderers) - { - if (renderer != null) - { - renderer.enabled = visible; - } - } - } - } - - public void SetMaterialProperty(string name, Color value) - { - if (_renderers != null) - { - foreach (var renderer in _renderers) - { - if (renderer != null) - { - var mpb = MaterialPropertyBlockVisitor.Instance; - mpb.SetColor(name, value); - renderer.SetPropertyBlock(mpb); - } - } - } - } - - public void SetMaterial(Material material) - { - if (_renderers != null) - { - foreach (var renderer in _renderers) - { - if (renderer != null) - { - if (renderer.materials != null && renderer.sharedMaterials.Length > 0) - { - var mats = new Material[renderer.sharedMaterials.Length]; - for (int i = 0; i < mats.Length; i++) - { - mats[i] = material; - } - renderer.sharedMaterials = mats; - } - } - } - } - } - - public void ResetMaterial() - { - if (_originalMaterials != null && _renderers != null && _originalMaterials.Length != _renderers.Length) - { - DebugUtil.LogError( - "{0}.ResetMaterial, _originalMaterials.Length {1} != _renderers.Length {2}", GetType(), - _originalMaterials.Length, _renderers.Length); - return; - } - for (int i = 0; i < _originalMaterials.Length; i++) - { - _renderers[i].sharedMaterials = _originalMaterials[i]; - } - } - } -} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/RendererWrapper.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/RendererWrapper.cs.meta deleted file mode 100644 index bce89feb23b..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/RendererWrapper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8372e28a48792474c8e63275532eb6a9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/TransformUtil.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/TransformUtil.cs deleted file mode 100644 index ce69184e85a..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/TransformUtil.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System.Collections; -using UnityEngine; - -namespace Framework -{ - public static class TransformUtil - { - public static bool ToRotationH(Vector3 dir, out Quaternion rotation) - { - dir.y = 0.0f; - if (dir.sqrMagnitude > Constants.DOUBLE_EPSILON) - { - dir.Normalize(); - rotation = Quaternion.LookRotation(dir, Vector3.up); - return true; - } - - rotation = Quaternion.identity; - return false; - } - - public static bool ToRotation(Vector3 dir, Vector3 up, out Quaternion rotation) - { - if (dir.sqrMagnitude > Constants.DOUBLE_EPSILON && - up.sqrMagnitude > Constants.DOUBLE_EPSILON) - { - rotation = Quaternion.LookRotation(dir, up); - return true; - } - - rotation = Quaternion.identity; - return false; - } - - public static float GetAngleH(Quaternion rotation) - { - var angle = 0.0f; - var axis = Vector3.zero; - rotation.ToAngleAxis(out angle, out axis); - return angle * axis.y; - } - - public static void CopyTransform(Transform src, Transform dst) - { - dst.parent = src.parent; - dst.position = src.position; - dst.rotation = src.rotation; - dst.localPosition = src.localPosition; - dst.localRotation = src.localRotation; - dst.localScale = src.localScale; - } - - // public static IEnumerator Easing(Transform o, Transform startPos, Transform endPos, float duration) - // { - // var current = 0f; - // while ((current += Time.deltaTime) < duration) - // { - // var start = startPos.position; - // var change = endPos.position - start; - // var x = EasingEquationsDouble.Linear(current, start.x, change.x, duration); - // var y = EasingEquationsDouble.Linear(current, start.y, change.y, duration); - // var z = EasingEquationsDouble.Linear(current, start.z, change.z, duration); - // o.position = new Vector3((float)x,(float)y,(float)z); - // yield return null; - // } - // o.transform.position = endPos.position; - // } - } -} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/TransformUtil.cs.meta b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/TransformUtil.cs.meta deleted file mode 100644 index 8296652facd..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/TransformUtil.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c6634bff59b374ac19cd5c020ef71ee1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/UIGameObjectWrapper.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/UIGameObjectWrapper.cs deleted file mode 100644 index ae980d6c5ef..00000000000 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Wrapper/UIGameObjectWrapper.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using JetBrains.Annotations; -using UnityEngine; -using UnityEngine.Events; -using UnityEngine.UI; - -namespace Framework.Wrapper -{ - public class UIGameObjectWrapper : GameObjectWrapper - { - - public UIGameObjectWrapper(GameObject go) : base(go) - { - } - - public GameObject TryGetItem(string key) - { - if (key == null) - { - return null; - } - if (string.IsNullOrEmpty(key)) - { - return _gameObject; - } - var obj = _gameObject.transform.Find(key)?.gameObject; - return obj; - } - - public T TryGetItem(string key) where T : Component - { - var child = TryGetItem(key); - return TryGetItem(child); - } - - public T TryGetItem() where T : Component - { - return TryGetItem(_gameObject); - } - - public T TryGetItem(GameObject go) where T : Component - { - return go?.GetComponent(); - } - - public GameObject GetItem(string key) - { - var obj = TryGetItem(key); - if (obj == null) - { - DebugUtil.LogError("GetItem failed, window controller name : {0}, key = {1}", GetType(), key); - } - - return obj; - } - - public T GetItem(string key) where T : Component - { - var child = GetItem(key); - return GetItem(child); - } - - public T GetItem() where T : Component - { - return GetItem(_gameObject); - } - - public T GetItem(GameObject go) where T : Component - { - if (go != null) - { - var com = TryGetItem(go); - if (com == null) - { - DebugUtil.LogError("GetItem failed, window controller name : {0}, game object name = {1}, Component type:{2}",GetType(),go.name,typeof(T)); - } - - return com; - } - - return default(T); - } - - public Button BindButton(string key, UnityAction action) - { - Button button = GetItem