UnityEngine.Component.GetComponent()

Here are the examples of the csharp api UnityEngine.Component.GetComponent() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1498 Examples 7

19 Source : ActiveAnimation.cs
with GNU General Public License v3.0
from aelariane

public static ActiveAnimation Play(Animation anim, string clipName, Direction playDirection, EnableCondition enableBeforePlay, DisableCondition disableCondition)
    {
        if (!NGUITools.GetActive(anim.gameObject))
        {
            if (enableBeforePlay != EnableCondition.EnableThenPlay)
            {
                return null;
            }
            NGUITools.SetActive(anim.gameObject, true);
            UIPanel[] componentsInChildren = anim.gameObject.GetComponentsInChildren<UIPanel>();
            int i = 0;
            int num = componentsInChildren.Length;
            while (i < num)
            {
                componentsInChildren[i].Refresh();
                i++;
            }
        }
        ActiveAnimation activeAnimation = anim.GetComponent<ActiveAnimation>();
        if (activeAnimation == null)
        {
            activeAnimation = anim.gameObject.AddComponent<ActiveAnimation>();
        }
        activeAnimation.mAnim = anim;
        activeAnimation.mDisableDirection = (Direction)disableCondition;
        activeAnimation.eventReceiver = null;
        activeAnimation.callWhenFinished = null;
        activeAnimation.onFinished = null;
        activeAnimation.Play(clipName, playDirection);
        return activeAnimation;
    }

19 Source : AnimatedAlpha.cs
with GNU General Public License v3.0
from aelariane

private void Awake()
    {
        this.mWidget = base.GetComponent<UIWidget>();
        this.mPanel = base.GetComponent<UIPanel>();
        this.Update();
    }

19 Source : UILocalize.cs
with GNU General Public License v3.0
from aelariane

public void Localize()
    {
        Localization instance = Localization.instance;
        UIWidget component = base.GetComponent<UIWidget>();
        UILabel uilabel = component as UILabel;
        UISprite uisprite = component as UISprite;
        if (string.IsNullOrEmpty(this.mLanguage) && string.IsNullOrEmpty(this.key) && uilabel != null)
        {
            this.key = uilabel.text;
        }
        string text = (!string.IsNullOrEmpty(this.key)) ? instance.Get(this.key) : string.Empty;
        if (uilabel != null)
        {
            UIInput uiinput = NGUITools.FindInParents<UIInput>(uilabel.gameObject);
            if (uiinput != null && uiinput.label == uilabel)
            {
                uiinput.defaultText = text;
            }
            else
            {
                uilabel.text = text;
            }
        }
        else if (uisprite != null)
        {
            uisprite.spriteName = text;
            uisprite.MakePixelPerfect();
        }
        this.mLanguage = instance.currentLanguage;
    }

19 Source : UIPanel.cs
with GNU General Public License v3.0
from aelariane

private static void SetChildLayer(Transform t, int layer)
    {
        for (int i = 0; i < t.childCount; i++)
        {
            Transform child = t.GetChild(i);
            if (child.GetComponent<UIPanel>() == null)
            {
                if (child.GetComponent<UIWidget>() != null)
                {
                    child.gameObject.layer = layer;
                }
                UIPanel.SetChildLayer(child, layer);
            }
        }
    }

19 Source : UIPanel.cs
with GNU General Public License v3.0
from aelariane

public static UIPanel Find(Transform trans, bool createIfMissing)
    {
        Transform y = trans;
        UIPanel uipanel = null;
        while (uipanel == null && trans != null)
        {
            uipanel = trans.GetComponent<UIPanel>();
            if (uipanel != null)
            {
                break;
            }
            if (trans.parent == null)
            {
                break;
            }
            trans = trans.parent;
        }
        if (createIfMissing && uipanel == null && trans != y)
        {
            uipanel = trans.gameObject.AddComponent<UIPanel>();
            UIPanel.SetChildLayer(uipanel.cachedTransform, uipanel.cachedGameObject.layer);
        }
        return uipanel;
    }

19 Source : UIPanel.cs
with GNU General Public License v3.0
from aelariane

public bool ConstrainTargetToBounds(Transform target, ref Bounds targetBounds, bool immediate)
    {
        Vector3 b = this.CalculateConstrainOffset(targetBounds.min, targetBounds.max);
        if (b.magnitude > 0f)
        {
            if (immediate)
            {
                target.localPosition += b;
                targetBounds.center += b;
                SpringPosition component = target.GetComponent<SpringPosition>();
                if (component != null)
                {
                    component.enabled = false;
                }
            }
            else
            {
                SpringPosition springPosition = SpringPosition.Begin(target.gameObject, target.localPosition + b, 13f);
                springPosition.ignoreTimeScale = true;
                springPosition.worldSpace = false;
            }
            return true;
        }
        return false;
    }

19 Source : UISpriteAnimation.cs
with GNU General Public License v3.0
from aelariane

private void RebuildSpriteList()
    {
        if (this.mSprite == null)
        {
            this.mSprite = base.GetComponent<UISprite>();
        }
        this.mSpriteNames.Clear();
        if (this.mSprite != null && this.mSprite.atlas != null)
        {
            List<UIAtlas.Sprite> spriteList = this.mSprite.atlas.spriteList;
            int i = 0;
            int count = spriteList.Count;
            while (i < count)
            {
                UIAtlas.Sprite sprite = spriteList[i];
                if (string.IsNullOrEmpty(this.mPrefix) || sprite.name.StartsWith(this.mPrefix))
                {
                    this.mSpriteNames.Add(sprite.name);
                }
                i++;
            }
            this.mSpriteNames.Sort();
        }
    }

19 Source : AnimatedColor.cs
with GNU General Public License v3.0
from aelariane

private void Awake()
    {
        this.mWidget = base.GetComponent<UIWidget>();
    }

19 Source : CheckBoxCamera.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        if (PlayerPrefs.HasKey("cameraType"))
        {
            if (this.camera.ToString().ToUpper() == PlayerPrefs.GetString("cameraType").ToUpper())
            {
                base.GetComponent<UICheckbox>().isChecked = true;
            }
            else
            {
                base.GetComponent<UICheckbox>().isChecked = false;
            }
        }
    }

19 Source : NGUITools.cs
with GNU General Public License v3.0
from aelariane

public static void MakePixelPerfect(Transform t)
    {
        UIWidget component = t.GetComponent<UIWidget>();
        if (component != null)
        {
            component.MakePixelPerfect();
        }
        else
        {
            t.localPosition = NGUITools.Round(t.localPosition);
            t.localScale = NGUITools.Round(t.localScale);
            int i = 0;
            int childCount = t.childCount;
            while (i < childCount)
            {
                NGUITools.MakePixelPerfect(t.GetChild(i));
                i++;
            }
        }
    }

19 Source : BTN_Connect_To_Server_On_List.cs
with GNU General Public License v3.0
from aelariane

private void OnClick()
    {
        base.transform.parent.parent.GetComponent<PanelMultiJoin>().connectToIndex(this.index, this.roomName);
    }

19 Source : LanguageChangeListener.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        if (Language.type == -1)
        {
            if (PlayerPrefs.HasKey("language"))
            {
                Language.type = PlayerPrefs.GetInt("language");
            }
            else
            {
                PlayerPrefs.SetInt("language", 0);
                Language.type = 0;
            }
            Language.init();
            base.GetComponent<UIPopupList>().selection = Language.GetLang(Language.type);
        }
        else
        {
            base.GetComponent<UIPopupList>().selection = Language.GetLang(Language.type);
        }
    }

19 Source : TitanBase.cs
with GNU General Public License v3.0
from aelariane

protected override void Cache()
        {
            base.Cache();
            if (baseT == null && (baseT = transform) == null)
            {
                return;
            }
            AABB = baseT.Find(AABBPath);
            Core = baseT.Find(CorePath);
            Chest = baseT.Find(ChestPath);
            Transform snd;
            if (snd = baseT.Find(FootAudioPath))
            {
                FootAudio = snd.GetComponent<AudioSource>();
            }
            if ((Hand_L_001 = baseT.Find(Hand_L_001Path)) && (Hand_L_001Sphere = Hand_L_001.GetComponent<SphereCollider>()))
            {
                Hand_L_001SphereT = Hand_L_001Sphere.transform;
            }
            if ((Hand_R_001 = baseT.Find(Hand_R_001Path)) && (Hand_R_001Sphere = Hand_R_001.GetComponent<SphereCollider>()))
            {
                Hand_R_001SphereT = Hand_R_001Sphere.transform;
            }
            Head = baseT.Find(HeadPath);
            Hip = baseT.Find(HipPath);
            Neck = baseT.Find(NeckPath);
            chkFrontRight = baseT.Find("chkFrontRight");
            chkFrontLeft = baseT.Find("chkFrontLeft");
            chkBackRight = baseT.Find("chkBackRight");
            chkBackLeft = baseT.Find("chkBackLeft");
            chkOverHead = baseT.Find("chkOverHead");
            chkFront = baseT.Find("chkFront");
            chkAeLeft = baseT.Find("chkAeLeft");
            chkAeLLeft = baseT.Find("chkAeLLeft");
            chkAeRight = baseT.Find("chkAeRight");
            chkAeLRight = baseT.Find("chkAeLRight");
            ap_front_ground = baseT.Find("ap_front_ground");
        }

19 Source : PopListCamera.cs
with GNU General Public License v3.0
from aelariane

private void Awake()
    {
        if (PlayerPrefs.HasKey("cameraType"))
        {
            base.GetComponent<UIPopupList>().selection = PlayerPrefs.GetString("cameraType");
        }
    }

19 Source : PopListCamera.cs
with GNU General Public License v3.0
from aelariane

private void OnSelectionChange()
    {
        if (base.GetComponent<UIPopupList>().selection == "ORIGINAL")
        {
            IN_GAME_MAIN_CAMERA.CameraMode = CameraType.ORIGINAL;
        }
        if (base.GetComponent<UIPopupList>().selection == "WOW")
        {
            IN_GAME_MAIN_CAMERA.CameraMode = CameraType.WOW;
        }
        if (base.GetComponent<UIPopupList>().selection == "TPS")
        {
            IN_GAME_MAIN_CAMERA.CameraMode = CameraType.TPS;
        }
        PlayerPrefs.SetString("cameraType", base.GetComponent<UIPopupList>().selection);
    }

19 Source : PopuplistCharacterSelection.cs
with GNU General Public License v3.0
from aelariane

private void onCharacterChange()
    {
        string selection = base.GetComponent<UIPopupList>().selection;
        HeroStat heroStat;
        if (selection == "Set 1" || selection == "Set 2" || selection == "Set 3")
        {
            HeroCostume heroCostume = CostumeConeveter.LocalDataToHeroCostume(selection.ToUpper());
            if (heroCostume == null)
            {
                heroStat = new HeroStat();
            }
            else
            {
                heroStat = heroCostume.stat;
            }
        }
        else
        {
            heroStat = HeroStat.getInfo(base.GetComponent<UIPopupList>().selection);
        }
        this.SPD.transform.localScale = new Vector3((float)heroStat.Spd, 20f, 0f);
        this.GAS.transform.localScale = new Vector3((float)heroStat.Gas, 20f, 0f);
        this.BLA.transform.localScale = new Vector3((float)heroStat.Bla, 20f, 0f);
        this.ACL.transform.localScale = new Vector3((float)heroStat.Acl, 20f, 0f);
    }

19 Source : EffectController.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        this.EffectCache = this.ObjectCache.GetComponent<XffectCache>();
    }

19 Source : PhotonView.cs
with GNU General Public License v3.0
from aelariane

public static PhotonView Get(Component component)
    {
        return component.GetComponent<PhotonView>();
    }

19 Source : PickupItem.cs
with GNU General Public License v3.0
from aelariane

public void OnTriggerEnter(Collider other)
    {
        PhotonView component = other.GetComponent<PhotonView>();
        if (this.PickupOnTrigger && component != null && component.IsMine)
        {
            this.Pickup();
        }
    }

19 Source : PickupItemSimple.cs
with GNU General Public License v3.0
from aelariane

public void OnTriggerEnter(Collider other)
    {
        PhotonView component = other.GetComponent<PhotonView>();
        if (this.PickupOnCollide && component != null && component.IsMine)
        {
            this.Pickup();
        }
    }

19 Source : XffectCache.cs
with GNU General Public License v3.0
from aelariane

private void Awake()
    {
        foreach (object obj in base.transform)
        {
            Transform transform = (Transform)obj;
            this.ObjectDic[transform.name] = new ArrayList();
            this.ObjectDic[transform.name].Add(transform);
            Xffect component = transform.GetComponent<Xffect>();
            if (component != null)
            {
                component.Initialize();
            }
            transform.gameObject.SetActive(false);
        }
    }

19 Source : XffectCache.cs
with GNU General Public License v3.0
from aelariane

protected Transform AddObject(string name)
    {
        Transform transform = base.transform.Find(name);
        if (transform == null)
        {
            Debug.Log("object:" + name + "doesn't exist!");
            return null;
        }
        Transform transform2 = UnityEngine.Object.Instantiate(transform, Vectors.zero, Quaternion.idenreplacedy) as Transform;
        this.ObjectDic[name].Add(transform2);
        transform2.gameObject.SetActive(false);
        Xffect component = transform2.GetComponent<Xffect>();
        if (component != null)
        {
            component.Initialize();
        }
        return transform2;
    }

19 Source : Cannon.cs
with GNU General Public License v3.0
from aelariane

public void Awake()
    {
        bool flag = BasePV != null;
        if (flag)
        {
            BasePV.observed = this;
            this.barrel = base.transform.Find("Barrel");
            this.correctPlayerPos = base.transform.position;
            this.correctPlayerRot = base.transform.rotation;
            this.correctBarrelRot = this.barrel.rotation;
            bool isMine = BasePV.IsMine;
            if (isMine)
            {
                this.firingPoint = this.barrel.Find("FiringPoint");
                this.ballPoint = this.barrel.Find("BallPoint");
                this.myCannonLine = this.ballPoint.GetComponent<LineRenderer>();
                bool flag2 = base.gameObject.name.Contains("CannonGround");
                if (flag2)
                {
                    this.isCannonGround = true;
                }
            }
            bool isMasterClient = PhotonNetwork.IsMasterClient;
            if (isMasterClient)
            {
                PhotonPlayer owner = BasePV.owner;
                bool flag3 = RCManager.allowedToCannon.ContainsKey(owner.ID);
                if (flag3)
                {
                    this.settings = RCManager.allowedToCannon[owner.ID].settings;
                    BasePV.RPC("SetSize", PhotonTargets.All, new object[]
                    {
                        this.settings
                    });
                    int viewID = RCManager.allowedToCannon[owner.ID].viewID;
                    RCManager.allowedToCannon.Remove(owner.ID);
                    CannonPropRegion component = PhotonView.Find(viewID).gameObject.GetComponent<CannonPropRegion>();
                    bool flag4 = component != null;
                    if (flag4)
                    {
                        component.disabled = true;
                        component.destroyed = true;
                        PhotonNetwork.Destroy(component.gameObject);
                    }
                }
                else
                {
                    bool flag5 = !owner.IsLocal;// && !FengGameManagerMKII.instance.restartingMC;
                    if (flag5)
                    {
                        //TO DO
                        //FengGameManagerMKII.instance.kickPlayerRC(owner, false, "spawning cannon without request.");
                    }
                }
            }
        }
    }

19 Source : CheckBoxEnableSS.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        this.init = true;
        if (PlayerPrefs.HasKey("EnableSS"))
        {
            if (PlayerPrefs.GetInt("EnableSS") == 1)
            {
                base.GetComponent<UICheckbox>().isChecked = true;
            }
            else
            {
                base.GetComponent<UICheckbox>().isChecked = false;
            }
        }
        else
        {
            base.GetComponent<UICheckbox>().isChecked = true;
            PlayerPrefs.SetInt("EnableSS", 1);
        }
    }

19 Source : CheckBoxShowSSInGame.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        this.init = true;
        if (PlayerPrefs.HasKey("showSSInGame"))
        {
            if (PlayerPrefs.GetInt("showSSInGame") == 1)
            {
                base.GetComponent<UICheckbox>().isChecked = true;
            }
            else
            {
                base.GetComponent<UICheckbox>().isChecked = false;
            }
        }
        else
        {
            base.GetComponent<UICheckbox>().isChecked = true;
            PlayerPrefs.SetInt("showSSInGame", 1);
        }
    }

19 Source : LanguageChangeListener.cs
with GNU General Public License v3.0
from aelariane

private void OnSelectionChange()
    {
        Language.type = Language.GetLangIndex(base.GetComponent<UIPopupList>().selection);
        PlayerPrefs.SetInt("language", Language.type);
    }

19 Source : Graph_3D.cs
with MIT License
from alchemz

void Start()
    {
        CreatePoints();
        m_system = GetComponent<ParticleSystem>();
    }

19 Source : connectLine.cs
with MIT License
from alchemz

void Update()
    {

        LineRenderer lineRenderer = GetComponent<LineRenderer>();
        var t = Time.time;
        for (int i = 0; i < lengthOfLineRenderer; i++)
        {
            lineRenderer.SetPosition(i, new Vector3(i * 0.5f, Mathf.Sin(i + t), 0.0f));
        }
    }

19 Source : FPSDisplay.cs
with MIT License
from alchemz

void Awake()
    {
        fpsCounter = GetComponent<FPSCounter>();
    }

19 Source : Nucleon.cs
with MIT License
from alchemz

void Awake()
    {
        body = GetComponent<Rigidbody>();
        lineRenderer =GetComponent<LineRenderer>();
     
        material= new Material(Shader.Find("Standard"));
        lineRenderer.material = material;


    }

19 Source : PlayerInfoDisplay.cs
with MIT License
from andruzzzhka

void Awake()
        {
            playerPlaceText = CustomExtensions.CreateWorldText(transform, "");
            playerPlaceText.rectTransform.ancreplaceddPosition = new Vector2(42.5f, -47.5f);
            playerPlaceText.fontSize = 8f;

            playerNameText = CustomExtensions.CreateWorldText(transform, "");
            playerNameText.rectTransform.ancreplaceddPosition = new Vector2(44f, -47.5f);
            playerNameText.fontSize = 7f;

            playerScoreText = CustomExtensions.CreateWorldText(transform, "");
            playerScoreText.rectTransform.ancreplaceddPosition = new Vector2(55f, -47.5f);
            playerScoreText.fontSize = 8f;

            playerSpeakerIcon = new GameObject("Player Speaker Icon", typeof(Canvas), typeof(CanvasRenderer)).AddComponent<Image>();
            playerSpeakerIcon.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
            playerSpeakerIcon.rectTransform.SetParent(transform);
            playerSpeakerIcon.rectTransform.localScale = new Vector3(0.008f, 0.008f, 1f);
            playerSpeakerIcon.rectTransform.pivot = new Vector2(0.5f, 0.5f);
            playerSpeakerIcon.rectTransform.ancreplaceddPosition3D = new Vector3(-8.5f, 2f, 0f);
            playerSpeakerIcon.sprite = Sprites.speakerIcon;
        }

19 Source : DifficultySelectionViewController.cs
with MIT License
from andruzzzhka

[UIAction("#post-parse")]
        public void SetupViewController()
        {
            playButtonGlow = playButton.GetComponent<Glowable>();

            levelDetailsRect.gameObject.AddComponent<Mask>();

            Image maskImage = levelDetailsRect.gameObject.AddComponent<Image>();

            maskImage.material = Sprites.NoGlowMat;
            maskImage.sprite = Resources.FindObjectsOfTypeAll<Sprite>().First(x => x.name == "RoundRectPanel");
            maskImage.type = Image.Type.Sliced;
            maskImage.color = new Color(0f, 0f, 0f, 0.25f);

            levelCoverImage.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);

            progressBarBG.color = new Color(1f, 1f, 1f, 0.2f);
            progressBarTop.color = new Color(1f, 1f, 1f, 1f);

            charactertisticControlBlocker.color = new Color(1f, 1f, 1f, 0f);
            difficultyControlBlocker.color = new Color(1f, 1f, 1f, 0f);

            cancellationToken = new CancellationTokenSource();

            _defaultArtworkTexture = Resources.FindObjectsOfTypeAll<Texture2D>().First(x => x.name == "DefaultSongArtwork");

            _playerDataModel = Resources.FindObjectsOfTypeAll<PlayerDataModel>().First();
        }

19 Source : PlayingNowViewController.cs
with MIT License
from andruzzzhka

[UIAction("#post-parse")]
        public void SetupViewController()
        {
            playNowButtonGlow = playNowButton.GetComponent<Glowable>();

            levelDetailsRect.gameObject.AddComponent<Mask>();

            Image maskImage = levelDetailsRect.gameObject.AddComponent<Image>();

            maskImage.material = Sprites.NoGlowMat;
            maskImage.sprite = Resources.FindObjectsOfTypeAll<Sprite>().First(x => x.name == "RoundRectPanel");
            maskImage.type = Image.Type.Sliced;
            maskImage.color = new Color(0f, 0f, 0f, 0.25f);

            levelCoverImage.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);

            progressBarBG.color = new Color(1f, 1f, 1f, 0.2f);
            progressBarTop.color = new Color(1f, 1f, 1f, 1f);

            //_beatmapLevelsModel = Resources.FindObjectsOfTypeAll<BeatmapLevelsModel>().First();

            _defaultArtworkTexture = Resources.FindObjectsOfTypeAll<Texture2D>().First(x => x.name == "DefaultSongArtwork");

            _playerDataModel = Resources.FindObjectsOfTypeAll<PlayerDataModel>().First();

            leaderboardTableView.GetComponent<TableView>().RemoveReusableCells("Cell");

            if (selectedLevel != null)
                SetSong(selectedLevel, selectedBeatmapCharacteristic, selectedDifficulty);
        }

19 Source : AvatarController.cs
with MIT License
from andruzzzhka

void InitializeAvatarController()
        {
#if DEBUG
            Plugin.log.Info("Spawning avatar");
#endif
            centerAdjust = GameObject.FindObjectOfType<VRCenterAdjust>();

            avatarInput = new MultiplayerAvatarInput();

            avatar = AvatarManager.SpawnAvatar(defaultAvatarInstance, avatarInput);

            /*
            exclusionScript = avatar.GameObject.GetComponentsInChildren<AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
            if (exclusionScript != null)
                exclusionScript.SetVisible();
            */

            playerNameText = CustomExtensions.CreateWorldText(transform, "INVALID");
            playerNameText.rectTransform.ancreplaceddPosition3D = new Vector3(0f, 0.25f, 0f);
            playerNameText.alignment = TextAlignmentOptions.Center;
            playerNameText.fontSize = 2.5f;

            playerSpeakerIcon = new GameObject("Player Speaker Icon", typeof(Canvas), typeof(CanvasRenderer)).AddComponent<Image>();
            playerSpeakerIcon.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
            playerSpeakerIcon.rectTransform.SetParent(transform);
            playerSpeakerIcon.rectTransform.localScale = new Vector3(0.004f, 0.004f, 1f);
            playerSpeakerIcon.rectTransform.pivot = new Vector2(0.5f, 0.5f);
            playerSpeakerIcon.rectTransform.ancreplaceddPosition3D = new Vector3(0f, 0.65f, 0f);
            playerSpeakerIcon.sprite = Sprites.speakerIcon;

            avatar.eventsPlayer.gameObject.transform.SetParent(centerAdjust.transform, false);
            transform.SetParent(centerAdjust.transform, false);

            if (ModelSaberAPI.cachedAvatars.Any(x => x.Value.fullPath == avatar.customAvatar.fullPath))
            {
                currentAvatarHash = ModelSaberAPI.cachedAvatars.First(x => x.Value.fullPath == avatar.customAvatar.fullPath).Key;
            }
            else
            {
                currentAvatarHash = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
            }
        }

19 Source : StarsUIControl.cs
with MIT License
from andruzzzhka

private void TransformButton(int index)
        {
            
            if (viewControllersContainer == null)
            {
                viewControllersContainer = FindObjectsOfType<RectTransform>().First(x => x.name == "ViewControllers");
                practiceButtonTemplate = viewControllersContainer.GetComponentsInChildren<Button>(true).First(x => x.name == "PracticeButton");
            }

            _starButtons[index] = Instantiate(practiceButtonTemplate, transform as RectTransform, false);
            _starButtons[index].gameObject.SetActive(true);
            _starButtons[index].onClick = new Button.ButtonClickedEvent();
            _starButtons[index].onClick.AddListener(() => { HandleStarPressedEvent(index + 1); });
            _starButtons[index].name = "CustomUIButton";
            _starButtons[index].SetButtonText("");
            _starButtons[index].SetButtonIcon(Sprites.StarEmpty);

            (_starButtons[index].transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f);
            (_starButtons[index].transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f);
            (_starButtons[index].transform as RectTransform).ancreplaceddPosition = new Vector2(10f * index, 0f);
            (_starButtons[index].transform as RectTransform).sizeDelta = new Vector2(10f, 10f);

            RectTransform iconTransform = _starButtons[index].GetComponentsInChildren<RectTransform>(true).First(x => x.name == "Icon");
            iconTransform.gameObject.SetActive(true);
            Destroy(iconTransform.parent.GetComponent<HorizontalLayoutGroup>());
            iconTransform.sizeDelta = new Vector2(8f, 8f);
            iconTransform.ancreplaceddPosition = new Vector2(5f, -4.8f);

            _starButtons[index].GetComponentsInChildren<Image>().First(x => x.name == "Stroke").enabled = false;
            
        }

19 Source : RequestBotListViewController.cs
with GNU Lesser General Public License v3.0
from angturil

protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling)
        {
            if (firstActivation)
            {
                if (!SongCore.Loader.AreSongsLoaded)
                {
                    SongCore.Loader.SongsLoadedEvent += SongLoader_SongsLoadedEvent;
                }

                Plugin.Log("DidActivate 001");

                // get table cell instance
                _requestListTableCellInstance = Resources.FindObjectsOfTypeAll<LevelListTableCell>().First((LevelListTableCell x) => x.name == "LevelListTableCell");

                // initialize Yes/No modal
                YesNoModal.instance.Setup();

                Plugin.Log("DidActivate 002");

                _songPreviewPlayer = Resources.FindObjectsOfTypeAll<SongPreviewPlayer>().FirstOrDefault();

                RectTransform container = new GameObject("RequestBotContainer", typeof(RectTransform)).transform as RectTransform;
                container.SetParent(rectTransform, false);

                #region TableView Setup and Initialization
                var go = new GameObject("SongRequestTableView", typeof(RectTransform));
                go.SetActive(false);

                go.AddComponent<ScrollRect>();
                go.AddComponent<Touchable>();
                go.AddComponent<EventSystemListener>();

                ScrollView scrollView = go.AddComponent<ScrollView>();

                _songListTableView = go.AddComponent<TableView>();
                go.AddComponent<RectMask2D>();
                _songListTableView.transform.SetParent(container, false);

                _songListTableView.SetField("_preallocatedCells", new TableView.CellsGroup[0]);
                _songListTableView.SetField("_isInitialized", false);
                _songListTableView.SetField("_scrollView", scrollView);

                var viewport = new GameObject("Viewport").AddComponent<RectTransform>();
                viewport.SetParent(go.GetComponent<RectTransform>(), false);
                go.GetComponent<ScrollRect>().viewport = viewport;
                (viewport.transform as RectTransform).sizeDelta = new Vector2(70f, 70f);

                RectTransform content = new GameObject("Content").AddComponent<RectTransform>();
                content.SetParent(viewport, false);

                scrollView.SetField("_contentRectTransform", content);
                scrollView.SetField("_viewport", viewport);

                _songListTableView.SetDataSource(this, false);

                _songListTableView.LazyInit();

                go.SetActive(true);

                (_songListTableView.transform as RectTransform).sizeDelta = new Vector2(70f, 70f);
                (_songListTableView.transform as RectTransform).ancreplaceddPosition = new Vector2(3f, 0f);

                _songListTableView.didSelectCellWithIdxEvent += DidSelectRow;

                _pageUpButton = UIHelper.CreateUIButton("SRMPageUpButton",
                    container,
                    "PracticeButton",
                    new Vector2(0f, 38.5f),
                    new Vector2(15f, 7f),
                    () => { scrollView.PageUpButtonPressed(); },
                    "˄");
                Destroy(_pageUpButton.GetComponentsInChildren<ImageView>().FirstOrDefault(x => x.name == "Underline"));

                _pageDownButton = UIHelper.CreateUIButton("SRMPageDownButton",
                    container,
                    "PracticeButton",
                    new Vector2(0f, -38.5f),
                    new Vector2(15f, 7f),
                    () => { scrollView.PageDownButtonPressed(); },
                    "˅");
                Destroy(_pageDownButton.GetComponentsInChildren<ImageView>().FirstOrDefault(x => x.name == "Underline"));
                #endregion

                CenterKeys = new KEYBOARD(container, "", false, -15, 15);

#if UNRELEASED
                // BUG: Need additional modes disabling one shot buttons
                // BUG: Need to make sure the buttons are usable on older headsets

                Plugin.Log("DidActivate 005");

                _CurrentSongName = BeatSaberUI.CreateText(container, "", new Vector2(-35, 37f));
                _CurrentSongName.fontSize = 3f;
                _CurrentSongName.color = Color.cyan;
                _CurrentSongName.alignment = TextAlignmentOptions.Left;
                _CurrentSongName.enableWordWrapping = false;
                _CurrentSongName.text = "";

                _CurrentSongName2 = BeatSaberUI.CreateText(container, "", new Vector2(-35, 34f));
                _CurrentSongName2.fontSize = 3f;
                _CurrentSongName2.color = Color.cyan;
                _CurrentSongName2.alignment = TextAlignmentOptions.Left;
                _CurrentSongName2.enableWordWrapping = false;
                _CurrentSongName2.text = "";

                //CenterKeys.AddKeys(SONGLISTKEY);
                if (!RequestBot.AddKeyboard(CenterKeys, "mainpanel.kbd"))
                {
                    CenterKeys.AddKeys(SONGLISTKEY);
                }

                ColorDeckButtons(CenterKeys, Color.white, Color.magenta);
#endif

                RequestBot.AddKeyboard(CenterKeys, "CenterPanel.kbd");

                CenterKeys.DefaultActions();

                #region History button
                // History button
                _historyButton = UIHelper.CreateUIButton("SRMHistory", container, "PracticeButton", new Vector2(53f, 30f),
                    new Vector2(25f, 15f),
                    () =>
                    {
                        isShowingHistory = !isShowingHistory;
                        RequestBot.Setreplacedle(isShowingHistory ? "Song Request History" : "Song Request Queue");
                        if (NumberOfCells() > 0)
                        {
                            _songListTableView.ScrollToCellWithIdx(0, TableView.ScrollPositionType.Beginning, false);
                            _songListTableView.SelectCellWithIdx(0);
                            _selectedRow = 0;
                        }
                        else
                        {
                            _selectedRow = -1;
                        }
                        UpdateRequestUI(true);
                        SetUIInteractivity();
                        _lastSelection = -1;
                    }, "History");

                _historyButton.ToggleWordWrapping(false);
                _historyHintText = UIHelper.AddHintText(_historyButton.transform as RectTransform, "");
                #endregion

                #region Blacklist button
                // Blacklist button
                _blacklistButton = UIHelper.CreateUIButton("SRMBlacklist", container, "PracticeButton", new Vector2(53f, 10f),
                    new Vector2(25f, 15f),
                    () =>
                    {
                        if (NumberOfCells() > 0)
                        {
                            void _onConfirm()
                            {
                                RequestBot.Blacklist(_selectedRow, isShowingHistory, true);
                                if (_selectedRow > 0)
                                    _selectedRow--;
                                confirmDialogActive = false;
                            }

                            // get song
                            var song = SongInfoForRow(_selectedRow).song;

                            // indicate dialog is active
                            confirmDialogActive = true;

                            // show dialog
                            YesNoModal.instance.ShowDialog("Blacklist Song Warning", $"Blacklisting {song["songName"].Value} by {song["authorName"].Value}\r\nDo you want to continue?", _onConfirm, () => { confirmDialogActive = false; });
                        }
                    }, "Blacklist");

                _blacklistButton.ToggleWordWrapping(false);
                UIHelper.AddHintText(_blacklistButton.transform as RectTransform, "Block the selected request from being queued in the future.");
                #endregion

                #region Skip button
                // Skip button
                _skipButton = UIHelper.CreateUIButton("SRMSkip", container, "PracticeButton", new Vector2(53f, 0f),
                    new Vector2(25f, 15f),
                    () =>
                    {
                        if (NumberOfCells() > 0)
                        {
                            // get song
                            var song = SongInfoForRow(_selectedRow).song;

                            void _onConfirm()
                            {
                                // get selected song
                                currentsong = SongInfoForRow(_selectedRow);

                                // skip it
                                RequestBot.Skip(_selectedRow);

                                // select previous song if not first song
                                if (_selectedRow > 0)
                                {
                                    _selectedRow--;
                                }

                                // indicate dialog is no longer active
                                confirmDialogActive = false;
                            }

                            // indicate dialog is active
                            confirmDialogActive = true;

                            // show dialog
                            YesNoModal.instance.ShowDialog("Skip Song Warning", $"Skipping {song["songName"].Value} by {song["authorName"].Value}\r\nDo you want to continue?", _onConfirm, () => { confirmDialogActive = false; });
                        }
                    }, "Skip");

                _skipButton.ToggleWordWrapping(false);
                UIHelper.AddHintText(_skipButton.transform as RectTransform, "Remove the selected request from the queue.");
                #endregion

                #region Play button
                // Play button
                _playButton = UIHelper.CreateUIButton("SRMPlay", container, "ActionButton", new Vector2(53f, -10f),
                    new Vector2(25f, 15f),
                    () =>
                    {
                        if (NumberOfCells() > 0)
                        {
                            currentsong = SongInfoForRow(_selectedRow);
                            RequestBot.played.Add(currentsong.song);
                            RequestBot.WriteJSON(RequestBot.playedfilename, ref RequestBot.played);

                            SetUIInteractivity(false);
                            RequestBot.Process(_selectedRow, isShowingHistory);
                            _selectedRow = -1;
                        }
                    }, "Play");

                ((RectTransform)_playButton.transform).localScale = Vector3.one;
                _playButton.GetComponent<NoTransitionsButton>().enabled = true;

                _playButton.ToggleWordWrapping(false);
                _playButton.interactable = ((isShowingHistory && RequestHistory.Songs.Count > 0) || (!isShowingHistory && RequestQueue.Songs.Count > 0));
                UIHelper.AddHintText(_playButton.transform as RectTransform, "Download and scroll to the currently selected request.");
                #endregion

                #region Queue button
                // Queue button
                _queueButton = UIHelper.CreateUIButton("SRMQueue", container, "PracticeButton", new Vector2(53f, -30f),
                    new Vector2(25f, 15f),
                    () =>
                    {
                        RequestBotConfig.Instance.RequestQueueOpen = !RequestBotConfig.Instance.RequestQueueOpen;
                        RequestBotConfig.Instance.Save();
                        RequestBot.WriteQueueStatusToFile(RequestBotConfig.Instance.RequestQueueOpen ? "Queue is open." : "Queue is closed.");
                        RequestBot.Instance.QueueChatMessage(RequestBotConfig.Instance.RequestQueueOpen ? "Queue is open." : "Queue is closed.");
                        UpdateRequestUI();
                    }, RequestBotConfig.Instance.RequestQueueOpen ? "Queue Open" : "Queue Closed");

                _queueButton.ToggleWordWrapping(true);
                _queueButton.SetButtonUnderlineColor(RequestBotConfig.Instance.RequestQueueOpen ? Color.green : Color.red);
                _queueButton.SetButtonTextSize(3.5f);
                UIHelper.AddHintText(_queueButton.transform as RectTransform, "Open/Close the queue.");
                #endregion

                // Set default RequestFlowCoordinator replacedle
                RequestBot.Setreplacedle(isShowingHistory ? "Song Request History" : "Song Request Queue");
            }
            base.DidActivate(firstActivation, addedToHierarchy, screenSystemEnabling);

            if (addedToHierarchy)
            {
                _selectedRow = -1;
                _songListTableView.ClearSelection();
            }

            UpdateRequestUI();
            SetUIInteractivity(true);
        }

19 Source : ResourceRegen.cs
with MIT License
from ArchonInteractive

[UsedImplicitly]
        protected virtual void Awake()
        {
            if (_target == null)
                _target = GetComponent<ResourcePool<TSource, TArgs>>();
        }

19 Source : GravitationalEntity.cs
with MIT License
from ArchonInteractive

[UsedImplicitly]
        private void Awake()
        {
            _rigidbody = GetComponent<Rigidbody>();
        }

19 Source : GravitationalEntity2D.cs
with MIT License
from ArchonInteractive

[UsedImplicitly]
        private void Awake()
        {
            _rigidbody = GetComponent<Rigidbody2D>();
        }

19 Source : PlaneDiscoveryGuide.cs
with GNU General Public License v3.0
from ARPOISE

private void _UpdateUI()
        {
            if (Session.Status == SessionStatus.LostTracking && Session.LostTrackingReason != LostTrackingReason.None)
            {
                // The session has lost tracking.
                m_FeaturePoints.SetActive(false);
                m_HandAnimation.enabled = false;
                m_SnackBar.SetActive(true);
                switch (Session.LostTrackingReason)
                {
                    case LostTrackingReason.InsufficientLight:
                        m_SnackBarText.text = "Too dark. Try moving to a well-lit area.";
                        break;
                    case LostTrackingReason.InsufficientFeatures:
                        m_SnackBarText.text = "Aim device at a surface with more texture or color.";
                        break;
                    case LostTrackingReason.ExcessiveMotion:
                        m_SnackBarText.text = "Moving too fast. Slow down.";
                        break;
                    default:
                        m_SnackBarText.text = "Motion tracking is lost.";
                        break;
                }

                m_OpenButton.SetActive(false);
                m_IsLostTrackingDisplayed = true;
                return;
            }
            else if (m_IsLostTrackingDisplayed)
            {
                // The session has moved from the lost tracking state.
                m_SnackBar.SetActive(false);
                m_IsLostTrackingDisplayed = false;
            }

            if (m_NotDetectedPlaneElapsed > DisplayGuideDelay)
            {
                // The session has been tracking but no planes have been found by 'DisplayGuideDelay'.
                m_FeaturePoints.SetActive(true);

                if (!m_HandAnimation.enabled)
                {
                    m_HandAnimation.GetComponent<CanvasRenderer>().SetAlpha(0f);
                    m_HandAnimation.CrossFadeAlpha(1f, k_AnimationFadeDuration, false);
                }

                m_HandAnimation.enabled = true;
                m_SnackBar.SetActive(true);

                if (m_NotDetectedPlaneElapsed > OfferDetailedInstructionsDelay)
                {
                    m_SnackBarText.text = "Need Help?";
                    m_OpenButton.SetActive(true);
                }
                else
                {
                    m_SnackBarText.text = "Point your camera to where you want to place an object.";
                    m_OpenButton.SetActive(false);
                }
            }
            else if (m_NotDetectedPlaneElapsed > 0f || m_DetectedPlaneElapsed > k_HideGuideDelay)
            {
                // The session is tracking but no planes have been found in less than 'DisplayGuideDelay' or
                // at least one plane has been tracking for more than 'k_HideGuideDelay'.
                m_FeaturePoints.SetActive(false);
                m_SnackBar.SetActive(false);
                m_OpenButton.SetActive(false);

                if (m_HandAnimation.enabled)
                {
                    m_HandAnimation.GetComponent<CanvasRenderer>().SetAlpha(1f);
                    m_HandAnimation.CrossFadeAlpha(0f, k_AnimationFadeDuration, false);
                }

                m_HandAnimation.enabled = false;
            }
        }

19 Source : UpgradePanel.cs
with MIT License
from arran-nz

private Vector3 GetAttributeSpawnPos(int count, Transform clone)
    {
        return new Vector3(
                clone.position.x,
                clone.position.y - (count * (STAT_SPACING + clone.GetComponent<RectTransform>().rect.height)));
    }

19 Source : WorkerBase.cs
with MIT License
from arran-nz

protected virtual void Awake()
    {
        carryValueText = gameObject.GetComponentInChildren<TextMesh>();
        CarryValueTextRenderer = carryValueText.GetComponent<MeshRenderer>();
        WorkerSprite = gameObject.GetComponentInChildren<SpriteRenderer>();
        MyArea = gameObject.GetComponentInParent<WorkingAreaBase>();

        UpdateCarryAmountText(0);
        ChangeState(WorkerStates.ReceiveOrders);
    }

19 Source : AreaAttributeDisplay.cs
with MIT License
from arran-nz

public void UpdateAttributeDisplay(string statName, string currentValue, string additionalValue, Vector3 position)
    {
        statNameDisplay.text = statName;
        currentValueDisplay.text = currentValue;
        additionalValueDisplay.text = "+ " + additionalValue;

        RectTransform rT = GetComponent<RectTransform>();
        rT.position = position;
    }

19 Source : NotificationMessage.cs
with MIT License
from arran-nz

private void Awake()
    {
        image = GetComponent<Image>();
        textDisplay = GetComponentInChildren<Text>();
    }

19 Source : Cell.cs
with MIT License
from ArtemOnigiri

void OnJointBreak2D(Joint2D joint)
    {
        Rigidbody2D connectedBody = joint.connectedBody;
        if(connectedBody)
        {
            Cell cell = connectedBody.GetComponent<Cell>();
            BreakLink(cell);
        }
    }

19 Source : TMP_SubMeshUI.cs
with MIT License
from ashishgopalhattimare

Material GetSharedMaterial()
        {
            if (m_canvasRenderer == null)
                m_canvasRenderer = GetComponent<CanvasRenderer>();

            return m_canvasRenderer.GetMaterial();
        }

19 Source : SuitcaseMoneyBehaviour.cs
with GNU General Public License v3.0
from Athlon007

void OnEnable()
        {
            if (!triggered)
            {
                GetComponent<PlayMakerFSM>().Fsm.RestartOnEnable = false;
                triggered = true;
            }
        }

19 Source : SatsumaSeatsManager.cs
with GNU General Public License v3.0
from Athlon007

void Awake()
        {
            rb = GetComponent<Rigidbody>();
            tightness = gameObject.GetPlayMakerFSM("BoltCheck").FsmVariables.GetFsmFloat("Tightness");

            defaultMreplaced = rb.mreplaced;
            lastTightnessValue = tightness.Value;

            rb.mreplaced = tightness.Value > 7 ? defaultMreplaced : 1;
        }

19 Source : GameFixes.cs
with GNU General Public License v3.0
from Athlon007

public void MainFixes()
        {
            // GT Grille resetting fix.
            try
            {
                PlayMakerFSM[] gtGrille = GameObject.Find("grille gt(Clone)").GetComponents<PlayMakerFSM>();
                foreach (var fsm in gtGrille)
                    fsm.Fsm.RestartOnEnable = false;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "GT_GRILLE_ERROR");
            }

            // Random fixes.
            try
            {
                Transform buildings = GameObject.Find("Buildings").transform;

                // Find house of Teimo and detach it from Perajarvi, so it can be loaded and unloaded separately
                GameObject perajarvi = GameObject.Find("PERAJARVI");
                perajarvi.transform.Find("HouseRintama4").parent = buildings;
                // Same for chicken house.
                perajarvi.transform.Find("ChickenHouse").parent = buildings;

                // Chicken house (barn) close to player's house
                buildings.Find("ChickenHouse").parent = null;

                // Fix for church wall. Changing it's parent to NULL, so it will not be loaded or unloaded.
                // It used to be attached to CHURCH gameobject,
                // but the Amis cars (yellow and grey cars) used to end up in the graveyard area.
                GameObject.Find("CHURCHWALL").transform.parent = null;

                // Fix for old house on the way from Perajarvi to Ventti's house (HouseOld5)
                perajarvi.transform.Find("HouseOld5").parent = buildings;

                // Fix for houses behind Teimo's
                perajarvi.transform.Find("HouseRintama3").parent = buildings;
                perajarvi.transform.Find("HouseSmall3").parent = buildings;

                // Perajarvi fixes for multiple objects with the same name.
                // Instead of being the part of Perajarvi, we're changing it to be the part of Buildings.
                Transform[] perajarviChilds = perajarvi.GetComponentsInChildren<Transform>();
                for (int i = 0; i < perajarviChilds.Length; i++)
                {
                    // Fix for disappearing grain processing plant
                    // https://my-summer-car.fandom.com/wiki/Grain_processing_plant
                    if (perajarviChilds[i].gameObject.name.Contains("silo"))
                    {
                        perajarviChilds[i].parent = buildings;
                        continue;
                    }

                    // Fix for Ventti's and Teimo's mailboxes (and pretty much all mailboxes that are inside of Perajarvi)
                    if (perajarviChilds[i].gameObject.name == "MailBox")
                    {
                        perajarviChilds[i].parent = buildings;
                        continue;
                    }

                    // Fix for greenhouses on the road from Perajarvi to Ventti's house
                    if (perajarviChilds[i].name == "Greenhouse")
                    {
                        perajarviChilds[i].parent = buildings;
                        continue;
                    }
                }

                // Fix for floppies at Jokke's new house
                while (perajarvi.transform.Find("TerraceHouse/diskette(itemx)") != null)
                {
                    Transform diskette = perajarvi.transform.Find("TerraceHouse/diskette(itemx)");
                    if (diskette != null && diskette.parent != null)
                        diskette.parent = null;
                }

                // Fix for Jokke's house furnitures clipping through floor
                perajarvi.transform.Find("TerraceHouse/Colliders").parent = null;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "PERAJARVI_FIXES_ERROR");
            }

            // Fix for cottage items disappearing when moved
            try
            {
                GameObject.Find("coffee pan(itemx)").transform.parent = null;
                GameObject.Find("lantern(itemx)").transform.parent = null;
                GameObject.Find("coffee cup(itemx)").transform.parent = null;
                GameObject.Find("camera(itemx)").transform.parent = null;
                GameObject.Find("COTTAGE/ax(itemx)").transform.parent = null;

                GameObject.Find("fireworks bag(itemx)").transform.parent = null;

                // Fix for fishing areas
                GameObject.Find("FishAreaAVERAGE").transform.parent = null;
                GameObject.Find("FishAreaBAD").transform.parent = null;
                GameObject.Find("FishAreaGOOD").transform.parent = null;
                GameObject.Find("FishAreaGOOD2").transform.parent = null;

                // Fix for strawberry field mailboxes
                GameObject.Find("StrawberryField").transform.Find("LOD/MailBox").parent = null;
                GameObject.Find("StrawberryField").transform.Find("LOD/MailBox").parent = null;

                // Fix for items left on cottage chimney clipping through it on first load of cottage
                GameObject.Find("COTTAGE").transform.Find("MESH/Cottage_chimney").parent = null;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "ITEMS_FIXES_ERROR");
            }

            // Applying a script to vehicles that can pick up and drive the player as a preplacedanger to his house.
            // This script makes it so when the player enters the car, the parent of the vehicle is set to null.
            try
            {
                GameObject fittan = GameObject.Find("TRAFFIC").transform.Find("VehiclesDirtRoad/Rally/FITTAN").gameObject;
                GameObject kuski = GameObject.Find("NPC_CARS").transform.Find("KUSKI").gameObject;
                FsmHook.FsmInject(fittan.transform.Find("PlayerTrigger/DriveTrigger").gameObject, "Player in car", () => fittan.transform.parent = null);
                FsmHook.FsmInject(kuski.transform.Find("PlayerTrigger/DriveTrigger").gameObject, "Player in car", () => kuski.transform.parent = null);

            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, true, "TAXI_MANAGERS_ERROR");
            }

            // Fixed Ventii bet resetting to default on cabin load.
            try
            {
                GameObject.Find("CABIN").transform.Find("Cabin/Ventti/Table/GameManager").GetPlayMakerFSM("Use").Fsm.RestartOnEnable = false;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "VENTII_FIX_ERROR");
            }

            // Junk cars - setting Load game to null.
            int junkCarCounter = 1;
            try
            {
                for (junkCarCounter = 1; GameObject.Find($"JunkCar{junkCarCounter}") != null; junkCarCounter++)
                {
                    GameObject junk = GameObject.Find($"JunkCar{junkCarCounter}");
                    junk.GetComponent<PlayMakerFSM>().Fsm.RestartOnEnable = false;

                    WorldObjectManager.Instance.Add(junk, DisableOn.Distance);
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, $"JUNK_CARS_{junkCarCounter}_ERROR");;
            }

            // Toggle Humans (apart from Farmer and Fighter2).
            try
            {
                GameObject humans = GameObject.Find("HUMANS");
                foreach (Transform t in GameObject.Find("HUMANS").GetComponentsInChildren<Transform>().Where(t => t.parent == humans.transform))
                {
                    if (t.gameObject.name.EqualsAny("HUMANS", "Fighter2", "Farmer", "FighterPub"))
                        continue;

                    WorldObjectManager.Instance.Add(t.gameObject, DisableOn.Distance);
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "HUMANS_ERROR");
            }

            // Fixes wasp hives resetting to on load values.
            try
            {
                GameObject[] wasphives = Resources.FindObjectsOfTypeAll<GameObject>().Where(g => g.name == "WaspHive").ToArray();
                foreach (GameObject wasphive in wasphives)
                {
                    wasphive.GetComponent<PlayMakerFSM>().Fsm.RestartOnEnable = false;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "WASPHIVES_ERROR");
            }

            // Disabling the script that sets the kinematic state of Satsuma to False.
            try
            {
                GameObject hand = GameObject.Find("PLAYER/Pivot/AnimPivot/Camera/FPSCamera/1Hand_replacedemble/Hand");
                PlayMakerFSM pickUp = hand.GetPlayMakerFSM("PickUp");

                pickUp.GetState("Drop part").RemoveAction(0);
                pickUp.GetState("Drop part 2").RemoveAction(0);
                pickUp.GetState("Tool picked").RemoveAction(2);
                pickUp.GetState("Drop tool").RemoveAction(0);
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, true, "SATSUMA_HAND_BS_FIX");
            }

            // Preventing mattres from being disabled.
            try
            {
                Transform mattres = GameObject.Find("DINGONBIISI").transform.Find("mattres");
                if (mattres != null)
                    mattres.parent = null;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "MANSION_MATTRES_ERROR");
            }

            // Item anti clip for cottage.
            try
            {
                GameObject area = new GameObject("MOP_ItemAntiClip");
                area.transform.position = new Vector3(-848.3f, -5.4f, 505.5f);
                area.transform.eulerAngles = new Vector3(0, 343.0013f, 0);
                area.AddComponent<ItemAntiClip>();
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, true, "ITEM_ANTICLIP_ERROR");
            }

            // Z-fighting fix for wrisreplacedch.
            try
            {
                GameObject player = GameObject.Find("PLAYER");

                if (player)
                {
                    Transform hour = player.transform.Find("Pivot/AnimPivot/Camera/FPSCamera/FPSCamera/Watch/Animate/BreathAnim/WrisreplacedchHand/Clock/Pivot/Hour/hour");
                    if (hour)
                    {
                        hour.GetComponent<Renderer>().material.renderQueue = 3001;
                    }

                    Transform minute = player.transform.Find("Pivot/AnimPivot/Camera/FPSCamera/FPSCamera/Watch/Animate/BreathAnim/WrisreplacedchHand/Clock/Pivot/Minute/minute");
                    if (minute)
                    {
                        minute.GetComponent<Renderer>().material.renderQueue = 3002;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "HANDWATCH_RENDERER_QUEUE_ERROR");
            }

            // Adds roll fix to the bus.
            try
            {
                GameObject bus = GameObject.Find("BUS");
                if (bus)
                {
                    bus.AddComponent<BusRollFix>();
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "BUS_ROLL_FIX_ERROR");
            }

            // Fixes bedroom window wrap resetting to default value.
            try
            {
                Transform triggerWindowWrap = GameObject.Find("YARD").transform.Find("Building/BEDROOM1/trigger_window_wrap");
                if (triggerWindowWrap != null)
                    triggerWindowWrap.GetComponent<PlayMakerFSM>().Fsm.RestartOnEnable = false;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "TRIGGER_WINDOW_WRAP_ERROR");
            }

            // Fixes diskette ejecting not wokring.
            try
            {
                Resources.FindObjectsOfTypeAll<GameObject>().First(g => g.name == "TriggerDiskette")
                    .GetPlayMakerFSM("replacedembly").Fsm.RestartOnEnable = false;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "TRIGGER_DISKETTE_ERROR");
            }

            // Fixed computer memory resetting.
            try
            {
                Resources.FindObjectsOfTypeAll<GameObject>().First(g => g.name == "TriggerPlayMode").GetPlayMakerFSM("PlayerTrigger").Fsm.RestartOnEnable = false;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "TRIGGER_DISKETTE_ERROR");
            }

            // Fixes berry picking skill resetting to default.
            try
            {
                GameObject.Find("JOBS").transform.Find("StrawberryField").gameObject.GetComponent<PlayMakerFSM>().Fsm.RestartOnEnable = false;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "STRAWBERRY_FIELD_FSM");
            }

            // GrandmaHiker fixes.
            try
            {
                GameObject grandmaHiker = GameObject.Find("GrannyHiker");
                if (grandmaHiker)
                {
                    GameObject skeleton = grandmaHiker.transform.Find("Char/skeleton").gameObject;

                    PlayMakerFSM logicFSM = grandmaHiker.GetPlayMakerFSM("Logic");

                    FsmState openDoorFsmState = logicFSM.GetState("Open door");
                    List<FsmStateAction> openDoorActions = openDoorFsmState.Actions.ToList();
                    openDoorActions.Add(new GrandmaHiker(skeleton, false));
                    openDoorFsmState.Actions = openDoorActions.ToArray();

                    FsmState setMreplaced2State = logicFSM.GetState("Set mreplaced 2");
                    List<FsmStateAction> setMreplaced2Actions = setMreplaced2State.Actions.ToList();
                    setMreplaced2Actions.Add(new GrandmaHiker(skeleton, true));
                    setMreplaced2State.Actions = setMreplaced2Actions.ToArray();
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "GRANDMA_HIKER_FIXES");
            }

            // Cabin door resetting fix.
            try
            {
                GameObject.Find("CABIN").transform.Find("Cabin/Door/Pivot/Handle").gameObject.GetComponent<PlayMakerFSM>().Fsm.RestartOnEnable = false;
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "CABIN_DOOR_RESET_FIX_ERROR");
            }

            // Construction site
            try
            {
                Transform construction = GameObject.Find("PERAJARVI").transform.Find("ConstructionSite");
                if (construction)
                {
                    construction.parent = null;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "PERAJARVI_CONSTRUCTION_ERROR");
            }

            // Satsuma parts trigger fix.
            try
            {
                gameObject.AddComponent<SatsumaTriggerFixer>();
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "SATSUMA_TRIGGER_FIXER_ERROR");
            }

            // MailBox fix
            try
            {
                foreach (var g in Resources.FindObjectsOfTypeAll<GameObject>().Where(g => g.name == "MailBox"))
                {
                    Transform hatch = g.transform.Find("BoxHatch");
                    if (hatch)
                    {
                        hatch.GetComponent<PlayMakerFSM>().Fsm.RestartOnEnable = false;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "MAILBOX_ERROR");
            }

            ModConsole.Log("[MOP] Finished applying fixes");
        }

19 Source : FramerateRecorder.cs
with GNU General Public License v3.0
from Athlon007

internal void Initialize()
        {
            try
            {
                instance = this;

                fpsMesh = GameObject.Find("GUI").transform.Find("HUD/FPS/HUDValue").GetComponent<TextMesh>();
                if (samples == null) samples = new List<float>();

                currentFrameRateWait = FrameWait();
                StartCoroutine(currentFrameRateWait);
            }
            catch (Exception ex)
            {
                ModConsole.LogError(ex.ToString());
            }
        }

See More Examples