protected virtual void Awake() { CacheMonoObject(); binder = gameObject.GetComponent <PrefabBinder>(); SetPrefabBinder(binder); }
public T WrapperScriptBehaviour <T>(GameObject gameObject, string scriptResourcePath = "", string scriptName = null) where T : ScriptBehaviour { GameObject resourceGo = null; if (string.IsNullOrEmpty(scriptResourcePath) == false) { resourceGo = gameObject; } else { resourceGo = GameObjectUtility.Find(scriptResourcePath, gameObject); } if (string.IsNullOrEmpty(scriptName) == false) { PrefabBinder prefabBinder = GameObjectUtility.GetIfNotAdd <PrefabBinder>(resourceGo); prefabBinder.scriptPath = scriptName; } bool isActive = resourceGo.activeSelf; if (!isActive) { resourceGo.SetActive(true); //保证active状态为false的时候也能获取到组件 } T behaviour = GameObjectUtility.GetIfNotAdd <T>(resourceGo); if (!isActive) { resourceGo.SetActive(false); } return(behaviour); }
public void SetPrefabBinder(PrefabBinder prefabBinder) { binder = prefabBinder; if (binder != null) { binder.Initialize(); LoadScript(); } }