x89rt2 3 сар өмнө
parent
commit
6f4b455b60

+ 13 - 0
Assets/Scripts/Script/AnimatorExtensions.cs

@@ -0,0 +1,13 @@
+using UnityEngine;
+
+public static class AnimatorExtensions
+{
+    public static void SafeSetInt(this Animator anim, int hash, int value)
+    {
+        if (anim == null) return;
+        if (!anim.isActiveAndEnabled) return;
+        if (anim.runtimeAnimatorController == null) return;
+
+        anim.SetInteger(hash, value);
+    }
+}

+ 11 - 0
Assets/Scripts/Script/AnimatorExtensions.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 19926c65995e049498de3d0c6804a1f5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 7
Assets/Scripts/Script/CardImagePanel.cs

@@ -7,6 +7,9 @@ using UnityEngine.Events;
 
 public class CardImagePanel : OffAnimation
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
+    private static WaitForSeconds _waitForSeconds0_25 = new WaitForSeconds(0.25f);
     [SerializeField] TextMeshProUGUI _infoText;
     [SerializeField] TMP_InputField _cardIDsInput;
     [SerializeField] GameObject _lackCardImagesObject;
@@ -41,13 +44,13 @@ public class CardImagePanel : OffAnimation
     {
         _isOpen = true;
         gameObject.SetActive(true);
-        _anim.SetInteger("Open", 1);
-        _anim.SetInteger("Close", 0);
-        _lackCardImagesObject.gameObject.SetActive(false);
+        _anim.SafeSetInt(OpenHash, 1);
+        _anim.SafeSetInt(CloseHash, 0);
+        _lackCardImagesObject.SetActive(false);
         _infoText.text = "";
         _cardIDsInput.text = "";
 
-        yield return new WaitForSeconds(0.25f);
+        yield return _waitForSeconds0_25;
 
         List<CEntity_Base> lackCardImageCardEntities = ContinuousController.instance.CardList
         .Filter(cEntity_Base => !StreamingAssetsUtility.IsCardExists(cEntity_Base)).ToList();
@@ -59,7 +62,7 @@ public class CardImagePanel : OffAnimation
                                 JpnMessage: $"以下の {lackCardImageCardEntities.Count}枚の\nカード画像がセットされていません。"
                             );
 
-            _lackCardImagesObject.gameObject.SetActive(true);
+            _lackCardImagesObject.SetActive(true);
 
             _cardIDsInput.text = string.Join(", ", lackCardImageCardEntities.Map(cEntity_Base => cEntity_Base.CardSpriteName));
         }
@@ -106,8 +109,8 @@ public class CardImagePanel : OffAnimation
             }
         }
 
-        _anim.SetInteger("Open", 0);
-        _anim.SetInteger("Close", 1);
+        _anim.SafeSetInt(OpenHash, 0);
+        _anim.SafeSetInt(CloseHash, 1);
     }
 
     public void OnClickCopyButton()

+ 2 - 2
Assets/Scripts/Script/DeckInfoPanel.cs

@@ -49,8 +49,8 @@ public class DeckInfoPanel : MonoBehaviour
         {
             if (GetComponent<Animator>() != null)
             {
-                GetComponent<Animator>().SetInteger(OpenHash, 1);
-                GetComponent<Animator>().SetInteger(CloseHash, 0);
+                GetComponent<Animator>().SafeSetInt(OpenHash, 1);
+                GetComponent<Animator>().SafeSetInt(CloseHash, 0);
             }
 
             ShowingDeckData = deckData;

+ 6 - 4
Assets/Scripts/Script/DeckListPanel.cs

@@ -9,6 +9,8 @@ using System.Linq;
 
 public class DeckListPanel : MonoBehaviour
 {
+    private static readonly int OpenHash = Animator.StringToHash("Open");
+    private static readonly int CloseHash = Animator.StringToHash("Close");
     public Animator anim;
 
     public CardPrefab_CreateDeck cardPrefab_CreateDeckPrefab;
@@ -107,15 +109,15 @@ public class DeckListPanel : MonoBehaviour
     public void Open()
     {
         On();
-        anim.SetInteger("Open", 1);
-        anim.SetInteger("Close", 0);
+        anim.SafeSetInt(OpenHash, 1);
+        anim.SafeSetInt(CloseHash, 0);
     }
 
     public void Close()
     {
         //OffDetailCard();
-        anim.SetInteger("Open", 0);
-        anim.SetInteger("Close", 1);
+        anim.SafeSetInt(OpenHash, 0);
+        anim.SafeSetInt(CloseHash, 1);
     }
 
     public void On()

+ 6 - 4
Assets/Scripts/Script/GameplayOption.cs

@@ -3,6 +3,8 @@ using UnityEngine;
 using UnityEngine.UI;
 public class GameplayOption : OffAnimation
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
     [SerializeField] Animator _anim;
     [SerializeField] Toggle _reverseOpponentsCardsToggle;
     [SerializeField] Toggle _showCutInAnimationToggle;
@@ -37,8 +39,8 @@ public class GameplayOption : OffAnimation
             }
         }
 
-        _anim.SetInteger("Open", 0);
-        _anim.SetInteger("Close", 1);
+        _anim.SafeSetInt(OpenHash, 0);
+        _anim.SafeSetInt(CloseHash, 1);
     }
 
     public void Init()
@@ -127,8 +129,8 @@ public class GameplayOption : OffAnimation
         }
 
         gameObject.SetActive(true);
-        _anim.SetInteger("Open", 1);
-        _anim.SetInteger("Close", 0);
+        _anim.SafeSetInt(OpenHash, 1);
+        _anim.SafeSetInt(CloseHash, 0);
     }
 
     #region Show cut in animation

+ 4 - 7
Assets/Scripts/Script/GraphicsOptionPanel.cs

@@ -1,8 +1,5 @@
-using System.Collections;
-using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
-using UnityEngine.Events;
 
 
 public class GraphicsOptionPanel : OffAnimation
@@ -32,8 +29,8 @@ public class GraphicsOptionPanel : OffAnimation
             }
         }
 
-        _anim.SetInteger(OpenHash, 0);
-        _anim.SetInteger(CloseHash, 1);
+        _anim.SafeSetInt(OpenHash, 0);
+        _anim.SafeSetInt(CloseHash, 1);
     }
 
     public void Init()
@@ -53,8 +50,8 @@ public class GraphicsOptionPanel : OffAnimation
         }
 
         gameObject.SetActive(true);
-        _anim.SetInteger(OpenHash, 1);
-        _anim.SetInteger(CloseHash, 0);
+        _anim.SafeSetInt(OpenHash, 1);
+        _anim.SafeSetInt(CloseHash, 0);
     }
 
     #region Auto select mode

+ 2 - 4
Assets/Scripts/Script/HomeMode.cs

@@ -62,10 +62,8 @@ public class HomeMode : MonoBehaviour
         Opening.instance.deck.deckListPanel.Close();
 
         for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
-        {
-            CreateNewDeckButton createNewDeckButton = Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<CreateNewDeckButton>();
-
-            if (createNewDeckButton != null)
+        {    
+            if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).TryGetComponent<CreateNewDeckButton>(out var createNewDeckButton))
             {
                 createNewDeckButton.CreateNewDeckWayObject.Off();
                 break;

+ 7 - 5
Assets/Scripts/Script/LanguagePanel.cs

@@ -6,6 +6,8 @@ using UnityEngine.Events;
 
 public class LanguagePanel : OffAnimation
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
     [SerializeField] Animator _anim;
     [SerializeField] List<LanguageToggle> _languageToggles = new();
 
@@ -29,8 +31,8 @@ public class LanguagePanel : OffAnimation
             }
         }
 
-        _anim.SetInteger("Open", 0);
-        _anim.SetInteger("Close", 1);
+        _anim.SafeSetInt(OpenHash, 0);
+        _anim.SafeSetInt(CloseHash, 1);
     }
 
     public void Init()
@@ -44,7 +46,7 @@ public class LanguagePanel : OffAnimation
         {
             foreach (LanguageToggle languageToggle in _languageToggles)
             {
-                void OnToggleChange(Language language)
+                static void OnToggleChange(Language language)
                 {
                     ContinuousController.instance.language = language;
                     ContinuousController.instance.SaveLanguage();
@@ -57,7 +59,7 @@ public class LanguagePanel : OffAnimation
         }
 
         gameObject.SetActive(true);
-        _anim.SetInteger("Open", 1);
-        _anim.SetInteger("Close", 0);
+        _anim.SafeSetInt(OpenHash, 1);
+        _anim.SafeSetInt(CloseHash, 0);
     }
 }

+ 4 - 2
Assets/Scripts/Script/OptionPanel.cs

@@ -6,6 +6,8 @@ using UnityEngine.Events;
 
 public class OptionPanel : OffAnimation
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
     [SerializeField] VolumePanel _volumePanel;
     [SerializeField] ResizeWindow _resizeWindowPanel;
     [SerializeField] GameplayOption _gameplayOption;
@@ -187,8 +189,8 @@ public class OptionPanel : OffAnimation
             }
         }
 
-        _anim.SetInteger("Open", 0);
-        _anim.SetInteger("Close", 1);
+        _anim.SafeSetInt(OpenHash, 0);
+        _anim.SafeSetInt(CloseHash, 1);
     }
 
     public void Init()

+ 2 - 2
Assets/Scripts/Script/ResizeWindow.cs

@@ -56,8 +56,8 @@ public class ResizeWindow : MonoBehaviour
             }
         }
 
-        anim.SetInteger(OpenHash, 0);
-        anim.SetInteger(CloseHash, 1);
+        anim.SafeSetInt(OpenHash, 0);
+        anim.SafeSetInt(CloseHash, 1);
     }
 
     public void SetUpWindowSize(string resolution)

+ 1 - 1
Assets/Scripts/Script/SelectBattleDeck.cs

@@ -145,7 +145,7 @@ public class SelectBattleDeck : MonoBehaviour
 
         SelectDeckObject.SetActive(true);
 
-        anim.SetInteger(OpenHash, 1);
+        anim.SafeSetInt(OpenHash, 1);
         anim.SetInteger(CloseHash, 0);
 
         ContinuousController.instance.StartCoroutine(SetDeckList(true));

+ 4 - 5
Assets/Scripts/Script/SelectDeck.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
-using System;
 using UnityEngine.Events;
 
 public class SelectDeck : OffAnimation
@@ -29,8 +28,8 @@ public class SelectDeck : OffAnimation
     public void OffSelectDeck()
     {
         anim.enabled = true;
-        anim.SetInteger(OpenHash, 0);
-        anim.SetInteger(CloseHash, 1);
+        anim.SafeSetInt(OpenHash, 1);
+        anim.SafeSetInt(CloseHash, 0);
 
         isOpen = false;
     }
@@ -70,8 +69,8 @@ public class SelectDeck : OffAnimation
 
         SelectDeckObject.SetActive(true);
 
-        anim.SetInteger(OpenHash, 1);
-        anim.SetInteger(CloseHash, 0);
+        anim.SafeSetInt(OpenHash, 1);
+        anim.SafeSetInt(CloseHash, 0);
 
         if (ContinuousController.instance.DeckDatas.Count > 0)
         {

+ 6 - 4
Assets/Scripts/Script/ServerRegionPanel.cs

@@ -6,6 +6,8 @@ using UnityEngine.Events;
 using UnityEngine.UI;
 public class ServerRegionPanel : OffAnimation
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
     [SerializeField] Animator _anim;
     [SerializeField] List<ServerRegionToggle> _serverRegionToggles = new();
 
@@ -29,8 +31,8 @@ public class ServerRegionPanel : OffAnimation
             }
         }
 
-        _anim.SetInteger("Open", 0);
-        _anim.SetInteger("Close", 1);
+        _anim.SafeSetInt(OpenHash, 0);
+        _anim.SafeSetInt(CloseHash, 1);
     }
 
     public void Init()
@@ -57,7 +59,7 @@ public class ServerRegionPanel : OffAnimation
         }
 
         gameObject.SetActive(true);
-        _anim.SetInteger("Open", 1);
-        _anim.SetInteger("Close", 0);
+        _anim.SafeSetInt(OpenHash, 1);
+        _anim.SafeSetInt(CloseHash, 0);
     }
 }

+ 6 - 4
Assets/Scripts/Script/TrialDraw.cs

@@ -6,6 +6,8 @@ using UnityEngine.EventSystems;
 
 public class TrialDraw : MonoBehaviour
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
     public CardPrefab_CreateDeck cardPrefab_CreateDeckPrefab;
     public Animator anim;
 
@@ -122,15 +124,15 @@ public class TrialDraw : MonoBehaviour
     public void Open()
     {
         On();
-        anim.SetInteger("Open", 1);
-        anim.SetInteger("Close", 0);
+        anim.SafeSetInt(OpenHash, 1);
+        anim.SafeSetInt(CloseHash, 0);
     }
 
     public void Close()
     {
         //OffDetailCard();
-        anim.SetInteger("Open", 0);
-        anim.SetInteger("Close", 1);
+        anim.SafeSetInt(OpenHash, 0);
+        anim.SafeSetInt(CloseHash, 1);
     }
 
     public void On()

+ 4 - 2
Assets/Scripts/Script/VolumePanel.cs

@@ -6,6 +6,8 @@ using UnityEngine.UI;
 
 public class VolumePanel : MonoBehaviour
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
     [Header("SEスライダー")]
     public Slider SESlier;
 
@@ -69,8 +71,8 @@ public class VolumePanel : MonoBehaviour
             }
         }
 
-        anim.SetInteger("Open", 0);
-        anim.SetInteger("Close", 1);
+        anim.SafeSetInt(OpenHash, 0);
+        anim.SafeSetInt(CloseHash, 1);
     }
 
     float ConvertPlayerPrefsValueToSliderValue(float playerPrefsValue, Slider slider)

+ 7 - 7
Assets/Scripts/Script/YesNoObject.cs

@@ -1,12 +1,12 @@
-using System.Collections;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Events;
-using UnityEngine.EventSystems;
 
 public class YesNoObject : MonoBehaviour
 {
+    private static readonly int CloseHash = Animator.StringToHash("Close");
+    private static readonly int OpenHash = Animator.StringToHash("Open");
     public Text InfoText;
 
     public List<CommandButton> Buttons;
@@ -73,8 +73,8 @@ public class YesNoObject : MonoBehaviour
     public void Open()
     {
         this.gameObject.SetActive(true);
-        anim.SetInteger("Open", 1);
-        anim.SetInteger("Close", 0);
+        anim.SafeSetInt(OpenHash, 1);
+        anim.SafeSetInt(CloseHash, 0);
     }
 
     public void Close()
@@ -89,7 +89,7 @@ public class YesNoObject : MonoBehaviour
             Opening.instance.PlayCancelSE();
         }
 
-        anim.SetInteger("Open", 0);
-        anim.SetInteger("Close", 1);
+        anim.SafeSetInt(OpenHash, 0);
+        anim.SafeSetInt(CloseHash, 1);
     }
 }