@@ -76,192 +76,140 @@ public void Preload<T>(string packageName, string[] assetNames, Progression prog
7676
7777 public async UniTask < T > LoadWithCloneAsync < T > ( string packageName , string assetName , Transform parent = null , uint priority = 0 , Progression progression = null ) where T : CPBase , new ( )
7878 {
79- GameObject go = await this . LoadGameObjectAsync ( packageName , assetName , priority , progression ) ;
80- if ( go == null ) return null ;
81-
82- GameObject instGo = GameObject . Instantiate ( go , parent ) ;
83-
84- // 激活檢查, 如果主體 Active 為 false 必須打開
85- bool active ;
86- if ( ! instGo . activeSelf )
87- {
88- active = instGo . activeSelf ;
89- instGo . SetActive ( true ) ;
90- }
91- else active = instGo . activeSelf ;
92-
93- T cpBase = instGo . GetComponent < T > ( ) ;
94- if ( cpBase == null ) return null ;
95-
96- cpBase . SetNames ( assetName ) ;
97- cpBase . OnCreate ( ) ;
98- cpBase . InitFirst ( ) ;
99- // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
100- if ( active ) cpBase . Display ( null ) ;
79+ return await this . _LoadWithCloneAsync < T > ( packageName , assetName , parent , priority , progression , null , null ) ;
80+ }
10181
102- // 最後還原本身預製體的 Active
103- instGo . SetActive ( active ) ;
82+ public async UniTask < T > LoadWithCloneAsync < T > ( string packageName , string assetName , Transform parent , bool worldPositionStays , uint priority = 0 , Progression progression = null ) where T : CPBase , new ( )
83+ {
84+ return await this . _LoadWithCloneAsync < T > ( packageName , assetName , parent , priority , progression , worldPositionStays , null ) ;
85+ }
10486
105- return cpBase ;
87+ public async UniTask < T > LoadWithCloneAsync < T > ( string packageName , string assetName , Vector3 position , Quaternion rotation , Transform parent = null , Vector3 ? scale = null , uint priority = 0 , Progression progression = null ) where T : CPBase , new ( )
88+ {
89+ return await this . _LoadWithCloneAsync < T > ( packageName , assetName , parent , priority , progression , null , scale , position , rotation ) ;
10690 }
10791
108- public async UniTask < T > LoadWithCloneAsync < T > ( string packageName , string assetName , Transform parent , bool worldPositionStays , uint priority = 0 , Progression progression = null ) where T : CPBase , new ( )
92+ private async UniTask < T > _LoadWithCloneAsync < T > ( string packageName , string assetName , Transform parent , uint priority , Progression progression , bool ? worldPositionStays , Vector3 ? scale = null , Vector3 ? position = null , Quaternion ? rotation = null ) where T : CPBase , new ( )
10993 {
11094 GameObject go = await this . LoadGameObjectAsync ( packageName , assetName , priority , progression ) ;
111- if ( go == null ) return null ;
95+ if ( go == null )
96+ return null ;
11297
113- GameObject instGo = GameObject . Instantiate ( go , parent , worldPositionStays ) ;
98+ GameObject instGo ;
99+ if ( position . HasValue && rotation . HasValue )
100+ {
101+ instGo = GameObject . Instantiate ( go , position . Value , rotation . Value , parent ) ;
102+ }
103+ else if ( worldPositionStays . HasValue )
104+ {
105+ instGo = GameObject . Instantiate ( go , parent , worldPositionStays . Value ) ;
106+ }
107+ else
108+ {
109+ instGo = GameObject . Instantiate ( go , parent ) ;
110+ }
114111
115- // 激活檢查, 如果主體 Active 為 false 必須打開
116- bool active ;
117- if ( ! instGo . activeSelf )
112+ if ( scale . HasValue )
118113 {
119- active = instGo . activeSelf ;
120- instGo . SetActive ( true ) ;
114+ instGo . transform . localScale = scale . Value ;
121115 }
122- else active = instGo . activeSelf ;
123116
124117 T cpBase = instGo . GetComponent < T > ( ) ;
125- if ( cpBase == null ) return null ;
126-
127- cpBase . SetNames ( assetName ) ;
128- cpBase . OnCreate ( ) ;
129- cpBase . InitFirst ( ) ;
130- // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
131- if ( active ) cpBase . Display ( null ) ;
132-
133- // 最後還原本身預製體的 Active
134- instGo . SetActive ( active ) ;
135-
136- return cpBase ;
137- }
138-
139- public async UniTask < T > LoadWithCloneAsync < T > ( string packageName , string assetName , Vector3 position , Quaternion rotation , Transform parent = null , Vector3 ? scale = null , uint priority = 0 , Progression progression = null ) where T : CPBase , new ( )
140- {
141- GameObject go = await this . LoadGameObjectAsync ( packageName , assetName , priority , progression ) ;
142- if ( go == null ) return null ;
143-
144- GameObject instGo = GameObject . Instantiate ( go , position , rotation , parent ) ;
118+ if ( cpBase == null )
119+ return null ;
145120
146121 // 激活檢查, 如果主體 Active 為 false 必須打開
147- bool active ;
148- if ( ! instGo . activeSelf )
122+ bool active = instGo . activeSelf ;
123+ if ( ! active )
149124 {
150- active = instGo . activeSelf ;
125+ cpBase . initFirstByMono = cpBase . monoDrive ;
151126 instGo . SetActive ( true ) ;
152127 }
153- else active = instGo . activeSelf ;
154-
155- Vector3 localScale = ( scale == null ) ? instGo . transform . localScale : ( Vector3 ) scale ;
156- instGo . transform . localScale = localScale ;
157-
158- T cpBase = instGo . GetComponent < T > ( ) ;
159- if ( cpBase == null ) return null ;
160128
161129 cpBase . SetNames ( assetName ) ;
162- cpBase . OnCreate ( ) ;
163- cpBase . InitFirst ( ) ;
164- // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
165- if ( active ) cpBase . Display ( null ) ;
130+ if ( ! cpBase . monoDrive )
131+ {
132+ cpBase . OnCreate ( ) ;
133+ cpBase . InitFirst ( ) ;
134+
135+ // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
136+ if ( active )
137+ cpBase . Display ( null ) ;
138+ }
166139
167140 // 最後還原本身預製體的 Active
168141 instGo . SetActive ( active ) ;
142+ cpBase . initFirstByMono = false ;
169143
170144 return cpBase ;
171145 }
172146
173147 public T LoadWithClone < T > ( string packageName , string assetName , Transform parent = null , Progression progression = null ) where T : CPBase , new ( )
174148 {
175- GameObject go = this . LoadGameObject ( packageName , assetName , progression ) ;
176- if ( go == null ) return null ;
177-
178- GameObject instGo = GameObject . Instantiate ( go , parent ) ;
179-
180- // 激活檢查, 如果主體 Active 為 false 必須打開
181- bool active ;
182- if ( ! instGo . activeSelf )
183- {
184- active = instGo . activeSelf ;
185- instGo . SetActive ( true ) ;
186- }
187- else active = instGo . activeSelf ;
188-
189- T cpBase = instGo . GetComponent < T > ( ) ;
190- if ( cpBase == null ) return null ;
191-
192- cpBase . SetNames ( assetName ) ;
193- cpBase . OnCreate ( ) ;
194- cpBase . InitFirst ( ) ;
195- // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
196- if ( active ) cpBase . Display ( null ) ;
149+ return this . _LoadWithClone < T > ( packageName , assetName , parent , progression , null , null ) ;
150+ }
197151
198- // 最後還原本身預製體的 Active
199- instGo . SetActive ( active ) ;
152+ public T LoadWithClone < T > ( string packageName , string assetName , Transform parent , bool worldPositionStays , Progression progression = null ) where T : CPBase , new ( )
153+ {
154+ return this . _LoadWithClone < T > ( packageName , assetName , parent , progression , worldPositionStays , null ) ;
155+ }
200156
201- return cpBase ;
157+ public T LoadWithClone < T > ( string packageName , string assetName , Vector3 position , Quaternion rotation , Transform parent = null , Vector3 ? scale = null , Progression progression = null ) where T : CPBase , new ( )
158+ {
159+ return this . _LoadWithClone < T > ( packageName , assetName , parent , progression , null , scale , position , rotation ) ;
202160 }
203161
204- public T LoadWithClone < T > ( string packageName , string assetName , Transform parent , bool worldPositionStays , Progression progression = null ) where T : CPBase , new ( )
162+ private T _LoadWithClone < T > ( string packageName , string assetName , Transform parent , Progression progression , bool ? worldPositionStays = null , Vector3 ? scale = null , Vector3 ? position = null , Quaternion ? rotation = null ) where T : CPBase , new ( )
205163 {
206164 GameObject go = this . LoadGameObject ( packageName , assetName , progression ) ;
207- if ( go == null ) return null ;
165+ if ( go == null )
166+ return null ;
208167
209- GameObject instGo = GameObject . Instantiate ( go , parent , worldPositionStays ) ;
168+ GameObject instGo ;
169+ if ( position . HasValue && rotation . HasValue )
170+ {
171+ instGo = GameObject . Instantiate ( go , position . Value , rotation . Value , parent ) ;
172+ }
173+ else if ( worldPositionStays . HasValue )
174+ {
175+ instGo = GameObject . Instantiate ( go , parent , worldPositionStays . Value ) ;
176+ }
177+ else
178+ {
179+ instGo = GameObject . Instantiate ( go , parent ) ;
180+ }
210181
211- // 激活檢查, 如果主體 Active 為 false 必須打開
212- bool active ;
213- if ( ! instGo . activeSelf )
182+ if ( scale . HasValue )
214183 {
215- active = instGo . activeSelf ;
216- instGo . SetActive ( true ) ;
184+ instGo . transform . localScale = scale . Value ;
217185 }
218- else active = instGo . activeSelf ;
219186
220187 T cpBase = instGo . GetComponent < T > ( ) ;
221- if ( cpBase == null ) return null ;
222-
223- cpBase . SetNames ( assetName ) ;
224- cpBase . OnCreate ( ) ;
225- cpBase . InitFirst ( ) ;
226- // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
227- if ( active ) cpBase . Display ( null ) ;
228-
229- // 最後還原本身預製體的 Active
230- instGo . SetActive ( active ) ;
231-
232- return cpBase ;
233- }
234-
235- public T LoadWithClone < T > ( string packageName , string assetName , Vector3 position , Quaternion rotation , Transform parent = null , Vector3 ? scale = null , Progression progression = null ) where T : CPBase , new ( )
236- {
237- GameObject go = this . LoadGameObject ( packageName , assetName , progression ) ;
238- if ( go == null ) return null ;
239-
240- GameObject instGo = GameObject . Instantiate ( go , position , rotation , parent ) ;
188+ if ( cpBase == null )
189+ return null ;
241190
242191 // 激活檢查, 如果主體 Active 為 false 必須打開
243- bool active ;
244- if ( ! instGo . activeSelf )
192+ bool active = instGo . activeSelf ;
193+ if ( ! active )
245194 {
246- active = instGo . activeSelf ;
195+ cpBase . initFirstByMono = cpBase . monoDrive ;
247196 instGo . SetActive ( true ) ;
248197 }
249- else active = instGo . activeSelf ;
250-
251- Vector3 localScale = ( scale == null ) ? instGo . transform . localScale : ( Vector3 ) scale ;
252- instGo . transform . localScale = localScale ;
253-
254- T cpBase = instGo . GetComponent < T > ( ) ;
255- if ( cpBase == null ) return null ;
256198
257199 cpBase . SetNames ( assetName ) ;
258- cpBase . OnCreate ( ) ;
259- cpBase . InitFirst ( ) ;
260- // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
261- if ( active ) cpBase . Display ( null ) ;
200+ if ( ! cpBase . monoDrive )
201+ {
202+ cpBase . OnCreate ( ) ;
203+ cpBase . InitFirst ( ) ;
204+
205+ // 預製體如果製作時, 本身主體 Active 為 true 才調用 Display => OnShow
206+ if ( active )
207+ cpBase . Display ( null ) ;
208+ }
262209
263210 // 最後還原本身預製體的 Active
264211 instGo . SetActive ( active ) ;
212+ cpBase . initFirstByMono = false ;
265213
266214 return cpBase ;
267215 }
0 commit comments