12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using PlaygroundSplines;
- using System.Threading;
- namespace ParticlePlayground {
-
-
-
-
-
- [ExecuteInEditMode()]
- public class PlaygroundC : MonoBehaviour {
-
-
-
- public static int meshQuantity;
- public static int particlesQuantity;
- public static float version = 2.26f;
- public static string specialVersion = " ";
-
-
-
-
-
-
-
-
- public static float globalTime;
-
-
-
- public static float lastTimeUpdated;
-
-
-
- public static float globalDeltaTime;
-
-
-
- public static float globalTimescale = 1.0f;
-
-
-
-
-
- public static Vector3 initialTargetPosition = new Vector3(0,-999.99f,0);
-
-
-
- public static int skinnedUpdateRate = 1;
-
-
-
- public static bool triggerSceneRepaint = true;
-
-
-
- public static float collisionSleepVelocity = .01f;
-
-
-
- public static int unsafeAutomaticThreadFrames = 20;
-
-
-
- public static Plane[] frustumPlanes;
-
-
-
-
-
-
-
- public static event OnPlaygroundParticle particleEventBirth;
- static bool particleEventBirthInitialized = false;
-
-
-
-
- public static event OnPlaygroundParticle particleEventDeath;
- static bool particleEventDeathInitialized = false;
-
-
-
-
-
- public static event OnPlaygroundParticle particleEventCollision;
- static bool particleEventCollisionInitialized = false;
-
-
-
-
-
- public static event OnPlaygroundParticle particleEventTime;
- static bool particleEventTimeInitialized = false;
-
-
-
-
-
- public static void SendParticleEventBirth (PlaygroundEventParticle eventParticle) {
- if (particleEventBirthInitialized)
- particleEventBirth(eventParticle);
- }
-
-
-
-
-
- public static void SendParticleEventDeath (PlaygroundEventParticle eventParticle) {
- if (particleEventDeathInitialized)
- particleEventDeath(eventParticle);
- }
-
-
-
-
-
- public static void SendParticleEventCollision (PlaygroundEventParticle eventParticle) {
- if (particleEventCollisionInitialized)
- particleEventCollision(eventParticle);
- }
-
-
-
-
-
- public static void SendParticleEventTime (PlaygroundEventParticle eventParticle) {
- if (particleEventTimeInitialized)
- particleEventTime(eventParticle);
- }
-
-
-
-
-
-
-
- public static PlaygroundC reference;
-
-
-
- public static Transform referenceTransform;
-
-
-
- public static GameObject referenceGameObject;
-
-
-
-
-
-
- [SerializeField]
- public List<PlaygroundParticlesC> particleSystems = new List<PlaygroundParticlesC>();
-
-
-
- [SerializeField]
- public List<ManipulatorObjectC> manipulators = new List<ManipulatorObjectC>();
-
-
-
- [HideInInspector] public int paintMaxPositions = 10000;
-
-
-
- [HideInInspector] public bool calculate = true;
-
-
-
- [HideInInspector] public PIXELMODEC pixelFilterMode = PIXELMODEC.Pixel32;
-
-
-
- [HideInInspector] public bool autoGroup = true;
-
-
-
- [HideInInspector] public bool buildZeroAlphaPixels = false;
-
-
-
- [HideInInspector] public bool drawGizmos = true;
-
-
-
- [HideInInspector] public bool drawSourcePositions = false;
-
-
-
- [HideInInspector] public bool showShuriken = false;
-
-
-
- [HideInInspector] public bool paintToolbox = true;
-
-
-
- [HideInInspector] public float collisionPlaneScale = .1f;
-
-
-
- [HideInInspector] public bool showSnapshotsInHierarchy = false;
-
-
-
- [HideInInspector] public bool drawWireframe = false;
- [HideInInspector] public bool drawSplinePreview = true;
-
-
-
-
-
-
-
- [HideInInspector] public ThreadMethod threadMethod = ThreadMethod.Automatic;
- [HideInInspector] public ThreadMethodComponent skinnedMeshThreadMethod = ThreadMethodComponent.InsideParticleCalculation;
- [HideInInspector] public ThreadMethodComponent turbulenceThreadMethod = ThreadMethodComponent.InsideParticleCalculation;
-
-
-
- [HideInInspector] public int maxThreads = 128;
- bool isDoneThread = true;
- bool isDoneThreadLocal = true;
- bool isDoneThreadSkinned = true;
- bool isDoneThreadTurbulence = true;
- int threads;
- static int processorCount;
- static int activeThreads = 0;
-
-
-
- static System.Random random = new System.Random();
- object locker = new object();
- object lockerLocal = new object();
-
-
-
-
-
-
-
- public static PlaygroundParticlesC Particle () {
- PlaygroundParticlesC playgroundParticles = ResourceInstantiate("Particle Playground System").GetComponent<PlaygroundParticlesC>();
- return playgroundParticles;
- }
-
-
-
-
-
- public static PlaygroundParticlesC ParticleNew () {
- PlaygroundParticlesC playgroundParticles = PlaygroundParticlesC.CreateParticleObject("Particle Playground System "+particlesQuantity,Vector3.zero,Quaternion.identity,1f,new Material(Shader.Find("Playground/Vertex Color")));
- playgroundParticles.particleCache = new ParticleSystem.Particle[playgroundParticles.particleCount];
- PlaygroundParticlesC.OnCreatePlaygroundParticles(playgroundParticles);
- return playgroundParticles;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Texture2D image, string name, Vector3 position, Quaternion rotation, Vector3 offset, float particleSize, float scale, Material material) {
- return PlaygroundParticlesC.CreatePlaygroundParticles(new Texture2D[]{image},name,position,rotation,offset,particleSize,scale,material);
- }
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Texture2D image) {
- return PlaygroundParticlesC.CreatePlaygroundParticles(new Texture2D[]{image},"Particle Playground System "+particlesQuantity,Vector3.zero,Quaternion.identity,Vector3.zero,1f,1f,new Material(Shader.Find("Playground/Vertex Color")));
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Texture2D[] images, string name, Vector3 position, Quaternion rotation, Vector3 offset, float particleSize, float scale, Material material) {
- return PlaygroundParticlesC.CreatePlaygroundParticles(images,name,position,rotation,offset,particleSize,scale,material);
- }
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Texture2D[] images) {
- return PlaygroundParticlesC.CreatePlaygroundParticles(images,"Particle Playground System "+particlesQuantity,Vector3.zero,Quaternion.identity,Vector3.zero,1f,1f,new Material(Shader.Find("Playground/Vertex Color")));
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Mesh mesh, Texture2D texture, string name, Vector3 position, Quaternion rotation, float particleScale, Vector3 offset, Material material) {
- return MeshParticles.CreateMeshParticles(new Mesh[]{mesh},new Texture2D[]{texture},null,name,position,rotation,particleScale,new Vector3[]{offset},material);
- }
-
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Mesh mesh, Texture2D texture) {
- return MeshParticles.CreateMeshParticles(new Mesh[]{mesh},new Texture2D[]{texture},null,"Particle Playground System "+particlesQuantity,Vector3.zero,Quaternion.identity,1f,new Vector3[]{Vector3.zero},new Material(Shader.Find("Playground/Vertex Color")));
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Mesh[] meshes, Texture2D[] textures, string name, Vector3 position, Quaternion rotation, float particleScale, Vector3[] offsets, Material material) {
- return MeshParticles.CreateMeshParticles(meshes,textures,null,name,position,rotation,particleScale,offsets,material);
- }
-
-
-
-
-
-
- public static PlaygroundParticlesC Particle (Mesh[] meshes, Texture2D[] textures) {
- return MeshParticles.CreateMeshParticles(meshes,textures,null,"Particle Playground System "+particlesQuantity,Vector3.zero,Quaternion.identity,1f,new Vector3[meshes.Length],new Material(Shader.Find("Playground/Vertex Color")));
- }
-
-
-
-
-
- public static int Emit (PlaygroundParticlesC playgroundParticles) {
- return playgroundParticles.Emit(playgroundParticles.scriptedEmissionPosition,playgroundParticles.scriptedEmissionVelocity,playgroundParticles.scriptedEmissionColor);
- }
-
-
-
-
-
-
-
-
- public static int Emit (PlaygroundParticlesC playgroundParticles, Vector3 position, Vector3 normal, Color color) {
- return playgroundParticles.Emit(position,normal,color);
- }
-
-
-
-
-
-
- public static void Emit (PlaygroundParticlesC playgroundParticles, bool setEmission) {
- playgroundParticles.Emit(setEmission);
- }
-
-
-
-
-
-
- public static void GetPosition (SkinnedWorldObject particleStateWorldObject, bool updateNormals) {
- PlaygroundParticlesC.GetPosition(particleStateWorldObject, updateNormals);
- }
-
-
-
-
-
-
- public static void GetPosition (Vector3[] vertices, WorldObject particleStateWorldObject) {
- PlaygroundParticlesC.GetPosition(vertices,particleStateWorldObject);
- }
-
-
-
-
-
-
- public static void GetNormals (Vector3[] normals, WorldObject particleStateWorldObject) {
- PlaygroundParticlesC.GetNormals(normals,particleStateWorldObject);
- }
-
-
-
-
-
-
- public static void SetColor (PlaygroundParticlesC playgroundParticles, int to) {
- PlaygroundParticlesC.SetColor(playgroundParticles,to);
- }
-
-
-
-
-
-
- public static void SetColor (PlaygroundParticlesC playgroundParticles, Color color) {
- PlaygroundParticlesC.SetColor(playgroundParticles,color);
- }
-
-
-
-
-
-
- public static void SetAlpha (PlaygroundParticlesC playgroundParticles, float alpha) {
- PlaygroundParticlesC.SetAlpha(playgroundParticles,alpha);
- }
-
-
-
-
-
-
- public static void SetSize (PlaygroundParticlesC playgroundParticles, float size) {
- PlaygroundParticlesC.SetSize(playgroundParticles,size);
- }
-
-
-
-
-
-
- public static void Translate (PlaygroundParticlesC playgroundParticles, Vector3 direction) {
- PlaygroundParticlesC.Translate(playgroundParticles,direction);
- }
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, ParticleStateC state) {
- PlaygroundParticlesC.Add(playgroundParticles,state);
- }
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Texture2D image, float scale, Vector3 offset, string stateName) {
- PlaygroundParticlesC.Add(playgroundParticles,image,scale,offset,stateName,null);
- }
-
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Texture2D image, float scale, Vector3 offset, string stateName, Transform stateTransform) {
- PlaygroundParticlesC.Add(playgroundParticles,image,scale,offset,stateName,stateTransform);
- }
-
-
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Texture2D image, Texture2D depthmap, float depthmapStrength, float scale, Vector3 offset, string stateName) {
- PlaygroundParticlesC.Add(playgroundParticles,image,depthmap,depthmapStrength,scale,offset,stateName,null);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Texture2D image, Texture2D depthmap, float depthmapStrength, float scale, Vector3 offset, string stateName, Transform stateTransform) {
- PlaygroundParticlesC.Add(playgroundParticles,image,depthmap,depthmapStrength,scale,offset,stateName,stateTransform);
- }
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Mesh mesh, float scale, Vector3 offset, string stateName) {
- MeshParticles.Add(playgroundParticles,mesh,scale,offset,stateName,null);
- }
-
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Mesh mesh, float scale, Vector3 offset, string stateName, Transform stateTransform) {
- MeshParticles.Add(playgroundParticles,mesh,scale,offset,stateName,stateTransform);
- }
-
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Mesh mesh, Texture2D texture, float scale, Vector3 offset, string stateName) {
- MeshParticles.Add(playgroundParticles,mesh,texture,scale,offset,stateName,null);
- }
-
-
-
-
-
-
-
-
-
-
-
- public static void Add (PlaygroundParticlesC playgroundParticles, Mesh mesh, Texture2D texture, float scale, Vector3 offset, string stateName, Transform stateTransform) {
- MeshParticles.Add(playgroundParticles,mesh,texture,scale,offset,stateName,stateTransform);
- }
-
-
-
-
-
-
- public static PlaygroundColliderC AddCollider (PlaygroundParticlesC playgroundParticles) {
- PlaygroundColliderC pCollider = new PlaygroundColliderC();
- playgroundParticles.colliders.Add(pCollider);
- return pCollider;
- }
-
-
-
-
-
-
-
- public static PlaygroundColliderC AddCollider (PlaygroundParticlesC playgroundParticles, Transform transform) {
- PlaygroundColliderC pCollider = new PlaygroundColliderC();
- pCollider.transform = transform;
- playgroundParticles.colliders.Add(pCollider);
- return pCollider;
- }
-
-
-
-
-
-
- public static void SetParticleCount (PlaygroundParticlesC playgroundParticles, int amount) {
- PlaygroundParticlesC.SetParticleCount(playgroundParticles,amount);
- }
-
-
-
-
-
-
- public static void SetLifetime (PlaygroundParticlesC playgroundParticles, float time) {
- PlaygroundParticlesC.SetLifetime(playgroundParticles,playgroundParticles.sorting,time);
- }
-
-
-
-
-
-
- public static void SetMaterial (PlaygroundParticlesC playgroundParticles, Material particleMaterial) {
- PlaygroundParticlesC.SetMaterial(playgroundParticles, particleMaterial);
- }
-
-
-
-
-
- public static void Destroy (PlaygroundParticlesC playgroundParticles) {
- PlaygroundParticlesC.Destroy(playgroundParticles);
- }
-
-
-
-
-
-
- public static WorldObject WorldObject (Transform meshTransform) {
- return PlaygroundParticlesC.NewWorldObject(meshTransform);
- }
-
-
-
-
-
-
- public static SkinnedWorldObject SkinnedWorldObject (Transform meshTransform) {
- return PlaygroundParticlesC.NewSkinnedWorldObject(meshTransform);
- }
-
-
-
-
-
-
-
-
-
-
- public static ManipulatorObjectC ManipulatorObject (MANIPULATORTYPEC type, LayerMask affects, Transform manipulatorTransform, float size, float strength) {
- return PlaygroundParticlesC.NewManipulatorObject(type,affects,manipulatorTransform,size,strength,null);
- }
-
-
-
-
-
-
- public static ManipulatorObjectC ManipulatorObject (Transform manipulatorTransform) {
- LayerMask layerMask = -1;
- return PlaygroundParticlesC.NewManipulatorObject(MANIPULATORTYPEC.Attractor,layerMask,manipulatorTransform,1f,1f,null);
- }
-
-
-
-
-
-
-
-
-
-
-
- public static ManipulatorObjectC ManipulatorObject (MANIPULATORTYPEC type, LayerMask affects, Transform manipulatorTransform, float size, float strength, PlaygroundParticlesC playgroundParticles) {
- return PlaygroundParticlesC.NewManipulatorObject(type,affects,manipulatorTransform,size,strength,playgroundParticles);
- }
-
-
-
-
-
-
-
- public static ManipulatorObjectC ManipulatorObject (Transform manipulatorTransform, PlaygroundParticlesC playgroundParticles) {
- LayerMask layerMask = -1;
- return PlaygroundParticlesC.NewManipulatorObject(MANIPULATORTYPEC.Attractor,layerMask,manipulatorTransform,1f,1f,playgroundParticles);
- }
-
-
-
-
-
-
- public static ManipulatorObjectC GetManipulator (int i) {
- if (reference.manipulators.Count>0 && reference.manipulators[i%reference.manipulators.Count]!=null)
- return reference.manipulators[i%reference.manipulators.Count];
- else return null;
- }
-
-
-
-
-
-
-
- public static ManipulatorObjectC GetManipulator (int i, PlaygroundParticlesC playgroundParticles) {
- if (playgroundParticles.manipulators.Count>0 && playgroundParticles.manipulators[i%playgroundParticles.manipulators.Count]!=null)
- return playgroundParticles.manipulators[i%playgroundParticles.manipulators.Count];
- else return null;
- }
-
-
-
-
-
-
-
- public static List<PlaygroundEventParticle> GetManipulatorParticles (int manipulator, PlaygroundParticlesC playgroundParticles) {
- if (manipulator<0 || manipulator>=playgroundParticles.manipulators.Count) return null;
- List<PlaygroundEventParticle> particles = new List<PlaygroundEventParticle>();
- PlaygroundEventParticle particle = new PlaygroundEventParticle();
- for (int i = 0; i<playgroundParticles.particleCount; i++) {
- if (playgroundParticles.manipulators[manipulator].Contains(playgroundParticles.playgroundCache.position[i], playgroundParticles.manipulators[manipulator].transform.position)) {
- playgroundParticles.UpdateEventParticle(particle, i);
- particles.Add (particle.Clone());
- }
- }
- return particles;
- }
-
-
-
-
-
-
- public static List<PlaygroundEventParticle> GetManipulatorParticles (int manipulator) {
- if (manipulator<0 || manipulator>=reference.manipulators.Count) return null;
- List<PlaygroundEventParticle> particles = new List<PlaygroundEventParticle>();
- PlaygroundEventParticle particle = new PlaygroundEventParticle();
- for (int s = 0; s<reference.particleSystems.Count; s++) {
- for (int i = 0; i<reference.particleSystems[s].particleCount; i++) {
- if (reference.particleSystems[s].manipulators[manipulator].Contains(reference.particleSystems[s].playgroundCache.position[i], reference.particleSystems[s].manipulators[manipulator].transform.position)) {
- reference.particleSystems[s].UpdateEventParticle(particle, i);
- particles.Add (particle.Clone());
- }
- }
- }
- return particles;
- }
-
- public static Transform CreateTransform () {
- return (Transform)new GameObject("Source Transform").transform;
- }
-
- public static Transform CreatePlaygroundTransform (PlaygroundParticlesC playgroundParticles) {
- Transform newTransform = CreateTransform();
- PlaygroundTransformC newPlaygroundTransform = new PlaygroundTransformC();
- newPlaygroundTransform.transform = newTransform;
- if (playgroundParticles.sourceTransforms.Count==1 && playgroundParticles.sourceTransforms[0].transform==null)
- playgroundParticles.sourceTransforms[0].transform = newTransform;
- else
- playgroundParticles.sourceTransforms.Add (newPlaygroundTransform);
- newTransform.parent = playgroundParticles.particleSystemTransform;
- newTransform.localPosition = Vector3.zero;
- newTransform.name += " "+playgroundParticles.sourceTransforms.Count.ToString();
- return newTransform;
- }
-
-
-
-
-
- public static PlaygroundSpline CreateSpline () {
- GameObject splineGO = new GameObject("Playground Spline", typeof(PlaygroundSpline));
- return (PlaygroundSpline)splineGO.GetComponent(typeof(PlaygroundSpline));
- }
-
-
-
-
-
-
-
- public static PlaygroundSpline CreateSpline (PlaygroundParticlesC playgroundParticles) {
- PlaygroundSpline spline = CreateSpline();
- spline.Reset();
- if (playgroundParticles.splines.Count==1 && playgroundParticles.splines[0]==null)
- playgroundParticles.splines[0] = spline;
- else
- playgroundParticles.splines.Add (spline);
- spline.transform.parent = playgroundParticles.particleSystemTransform;
- spline.transform.localPosition = Vector3.zero;
- spline.name += " "+playgroundParticles.splines.Count.ToString();
- spline.AddUser(playgroundParticles.particleSystemTransform);
- return spline;
- }
-
- public static PlaygroundSpline CreateSpline (ManipulatorPropertyC manipulatorProperty) {
- PlaygroundSpline spline = CreateSpline();
- spline.Reset();
- manipulatorProperty.splineTarget = spline;
- return spline;
- }
-
-
-
-
-
- public static PlaygroundEventC CreateEvent () {
- return new PlaygroundEventC();
- }
-
-
-
-
-
-
- public static PlaygroundEventC CreateEvent (PlaygroundParticlesC playgroundParticles) {
- if (playgroundParticles==null) return null;
- PlaygroundEventC playgroundEvent = new PlaygroundEventC();
- if (playgroundParticles.events==null)
- playgroundParticles.events = new List<PlaygroundEventC>();
- playgroundParticles.events.Add (playgroundEvent);
- return playgroundEvent;
- }
-
-
-
-
-
-
-
- public static PlaygroundEventC GetEvent (int i, PlaygroundParticlesC playgroundParticles) {
- if (playgroundParticles.events.Count>0 && playgroundParticles.events[i%playgroundParticles.events.Count]!=null)
- return playgroundParticles.events[i%playgroundParticles.events.Count];
- else return null;
- }
-
-
-
-
-
-
- public static void RemoveEvent (int i, PlaygroundParticlesC playgroundParticles) {
- i = i%playgroundParticles.events.Count;
- if (playgroundParticles.events.Count>0 && playgroundParticles.events[i]!=null) {
- if (playgroundParticles.events[i].target!=null) {
- for (int x = 0; x<playgroundParticles.events[i].target.eventControlledBy.Count; x++)
- if (playgroundParticles.events[i].target.eventControlledBy[x]==playgroundParticles)
- playgroundParticles.events[i].target.eventControlledBy.RemoveAt(x);
- }
- playgroundParticles.events.RemoveAt (i);
- }
- }
-
-
-
-
-
-
- public static PlaygroundParticlesC GetParticles (int i) {
- if (reference.particleSystems.Count>0 && reference.particleSystems[i%reference.particleSystems.Count]!=null)
- return reference.particleSystems[i%reference.particleSystems.Count];
- else return null;
- }
-
-
-
-
-
-
- public static ParticleProjectionC ParticleProjection (PlaygroundParticlesC playgroundParticles) {
- return PlaygroundParticlesC.NewProjectionObject(playgroundParticles);
- }
-
-
-
-
-
-
- public static PaintObjectC PaintObject (PlaygroundParticlesC playgroundParticles) {
- return PlaygroundParticlesC.NewPaintObject(playgroundParticles);
- }
-
-
-
-
-
-
-
-
-
- public static int Paint (PlaygroundParticlesC playgroundParticles, Vector3 position, Vector3 normal, Transform parent, Color32 color) {
- return playgroundParticles.paint.Paint(position,normal,parent,color);
- }
-
-
-
-
-
-
-
-
-
- public static void Paint (PaintObjectC paintObject, Vector3 position, Vector3 normal, Transform parent, Color32 color) {
- paintObject.Paint(position,normal,parent,color);
- }
-
-
-
-
-
-
-
- public static bool Erase (PlaygroundParticlesC playgroundParticles, Vector3 position, float radius) {
- return playgroundParticles.paint.Erase(position,radius);
- }
-
-
-
-
-
-
-
- public static bool Erase (PaintObjectC paintObject, Vector3 position, float radius) {
- return paintObject.Erase(position,radius);
- }
-
-
-
-
-
-
- public static bool Erase (PlaygroundParticlesC playgroundParticles, int index) {
- return playgroundParticles.paint.Erase(index);
- }
-
-
-
-
-
- public static void ClearPaint (PlaygroundParticlesC playgroundParticles) {
- if (playgroundParticles.paint!=null)
- playgroundParticles.paint.ClearPaint();
- }
-
-
-
-
-
-
- public static int GetPaintPositionLength (PlaygroundParticlesC playgroundParticles) {
- return playgroundParticles.paint.positionLength;
- }
-
-
-
-
-
-
- public static void SetInitialTargetPosition (PlaygroundParticlesC playgroundParticles, Vector3 position) {
- PlaygroundParticlesC.SetInitialTargetPosition(playgroundParticles,position, true);
- }
-
-
-
-
-
-
- public static void Emission (PlaygroundParticlesC playgroundParticles, bool emit) {
- PlaygroundParticlesC.Emission(playgroundParticles,emit,false);
- }
-
-
-
-
-
-
-
- public static void Emission (PlaygroundParticlesC playgroundParticles, bool emit, bool restEmission) {
- PlaygroundParticlesC.Emission(playgroundParticles,emit,restEmission);
- }
-
-
-
-
-
- public static void Clear (PlaygroundParticlesC playgroundParticles) {
- PlaygroundParticlesC.Clear(playgroundParticles);
- }
-
-
-
-
-
- public static void RefreshScatter (PlaygroundParticlesC playgroundParticles) {
- playgroundParticles.RefreshScatter();
- }
-
-
-
-
-
-
- public static PlaygroundParticlesC InstantiatePreset (string presetName) {
- GameObject presetGo = ResourceInstantiate("Presets/"+presetName);
- PlaygroundParticlesC presetParticles = presetGo.GetComponent<PlaygroundParticlesC>();
- if (presetParticles!=null) {
- if (reference==null)
- reference = PlaygroundC.ResourceInstantiate("Playground Manager").GetComponent<PlaygroundC>();
- if (reference) {
- if (reference.autoGroup && presetParticles.particleSystemTransform.parent==null)
- presetParticles.particleSystemTransform.parent = referenceTransform;
- particlesQuantity++;
- presetParticles.particleSystemId = particlesQuantity-1;
- }
- presetGo.name = presetName;
- return presetParticles;
- } else {
- if (presetGo.name.Contains("Presets/"))
- presetGo.name = presetGo.name.Remove(0, 8);
- return null;
- }
- }
-
-
-
-
-
- public bool IsDoneThread () {
- return isDoneThread;
- }
-
-
-
-
-
- public bool IsDoneThreadTurbulence () {
- return isDoneThreadTurbulence;
- }
-
-
-
-
-
- public bool IsDoneThreadSkinnedMeshes () {
- return isDoneThreadSkinned;
- }
-
-
-
-
-
- public bool IsFirstUnsafeAutomaticFrames () {
- return isFirstUnsafeAutomaticFrames;
- }
-
-
-
-
-
- public bool HasEnabledGlobalManipulators () {
- if (manipulators.Count>0) {
- for (int i = 0; i<manipulators.Count; i++) {
- if (manipulators[i].enabled && manipulators[i].transform!=null && manipulators[i].transform.transform!=null) {
- return true;
- }
- }
- }
- return false;
- }
-
-
-
-
-
-
-
-
-
- public static Color32[] GetPixels (Texture2D image) {
- if (image == null) return null;
- if (reference && reference.pixelFilterMode==PIXELMODEC.Bilinear) {
- Color32[] pixels = new Color32[image.width*image.height];
- for (int y = 0; y<image.height; y++) {
- for (int x = 0; x<image.width; x++) {
- pixels[(y*image.width)+x] = image.GetPixelBilinear((x*1f)/image.width, (y*1f)/image.height);
- }
- }
- return pixels;
- } else return image.GetPixels32();
- }
-
-
- public static Vector3 Offset (PLAYGROUNDORIGINC origin, int imageWidth, int imageHeight, float meshScale) {
- Vector3 offset = Vector3.zero;
- switch (origin) {
- case PLAYGROUNDORIGINC.TopLeft: offset.y = -imageHeight*meshScale; break;
- case PLAYGROUNDORIGINC.TopCenter: offset.y = -imageHeight*meshScale; offset.x = (-imageWidth*meshScale)/2; break;
- case PLAYGROUNDORIGINC.TopRight: offset.y = -imageHeight*meshScale; offset.x = (-imageWidth*meshScale); break;
- case PLAYGROUNDORIGINC.MiddleLeft: offset.y = -imageHeight*meshScale/2; break;
- case PLAYGROUNDORIGINC.MiddleCenter: offset.y = -imageHeight*meshScale/2; offset.x = (-imageWidth*meshScale)/2; break;
- case PLAYGROUNDORIGINC.MiddleRight: offset.y = -imageHeight*meshScale/2; offset.x = (-imageWidth*meshScale); break;
- case PLAYGROUNDORIGINC.BottomCenter: offset.x = (-imageWidth*meshScale)/2; break;
- case PLAYGROUNDORIGINC.BottomRight: offset.x = (-imageWidth*meshScale); break;
- }
- return offset;
- }
-
-
-
-
-
-
-
-
- public static Vector3[] RandomVector3 (int length, Vector3 min, Vector3 max) {
- Vector3[] v3 = new Vector3[length];
- for (int i = 0; i<length; i++) {
- v3[i] = new Vector3(
- PlaygroundParticlesC.RandomRange(random, min.x, max.x),
- PlaygroundParticlesC.RandomRange(random, min.y, max.y),
- PlaygroundParticlesC.RandomRange(random, min.z, max.z)
- );
- }
- return v3;
- }
-
-
-
-
-
-
-
-
- public static float[] RandomFloat (int length, float min, float max) {
- float[] f = new float[length];
- for (int i = 0; i<length; i++) {
- f[i] = PlaygroundParticlesC.RandomRange (random, min, max);
- }
- return f;
- }
-
-
-
-
-
- public static void ShuffleArray (float[] arr) {
- int r;
- float tmp;
- for (int i = arr.Length - 1; i > 0; i--) {
- r = random.Next(0,i);
- tmp = arr[i];
- arr[i] = arr[r];
- arr[r] = tmp;
- }
- }
-
-
-
-
-
- public static void ShuffleArray (int[] arr) {
- int r;
- int tmp;
- for (int i = arr.Length - 1; i > 0; i--) {
- r = random.Next(0,i);
- tmp = arr[i];
- arr[i] = arr[r];
- arr[r] = tmp;
- }
- }
-
-
-
-
-
- public static int Largest (int[] compare) {
- int largest = 0;
- for (int i = 0; i<compare.Length; i++)
- if (compare[i]>largest) largest = i;
- return largest;
- }
-
-
-
-
-
-
- public static int CountZeroAlphasInTexture (Texture2D image) {
- int alphaCount = 0;
- Color32[] pixels = image.GetPixels32();
- for (int x = 0; x<pixels.Length; x++)
- if (pixels[x].a==0)
- alphaCount++;
- return alphaCount;
- }
-
-
-
-
-
-
- public static GameObject ResourceInstantiate (string n) {
- GameObject res = UnityEngine.Resources.Load(n) as GameObject;
- if (!res)
- return null;
- GameObject go = Instantiate(res) as GameObject;
- go.name = n;
- return go;
- }
-
-
-
-
-
-
-
- public static void TimeReset () {
- globalDeltaTime = .0f;
- #if UNITY_EDITOR
- if (!UnityEditor.EditorApplication.isPlaying) {
- globalTime = 0f;
- } else
- globalTime = Time.timeSinceLevelLoad;
- #else
- globalTime = Time.timeSinceLevelLoad;
- #endif
- lastTimeUpdated = globalTime;
- }
-
-
-
-
- public IEnumerator InitializePlayground () {
-
-
- if (reference!=null && reference!=this) {
- yield return null;
- Debug.Log("There can only be one instance of the Playground Manager in the scene.");
-
-
- foreach (Transform child in transform)
- child.parent = null;
- DestroyImmediate(gameObject);
- yield break;
- } else if (reference==null)
- reference = this;
-
-
- CheckEvents();
-
-
- random = new System.Random();
-
-
- TimeReset();
-
-
- for (int i = 0; i<particleSystems.Count; i++) {
- if (particleSystems[i]!=null) {
- particleSystems[i].particleSystemId = i;
- } else {
- particleSystems.RemoveAt(i);
- i--;
- }
- }
-
-
- particlesQuantity = particleSystems.Count;
-
-
- #if UNITY_EDITOR
- PlaygroundSpline.drawSplinePreviews = drawSplinePreview;
- #endif
-
-
- frameCount = 0;
- threadAggregatorRuns = 0;
- isReady = true;
- isDoneThread = true;
- isDoneThreadLocal = true;
- isDoneThreadSkinned = true;
- isDoneThreadTurbulence = true;
- maxThreads = Mathf.Clamp (maxThreads, 1, 128);
- processorCount = SystemInfo.processorCount;
- threads = Mathf.Clamp (processorCount>1?processorCount-1:1, 1, maxThreads);
-
- }
- int frameCount = 0;
- bool isReady = false;
- public static bool IsReady () {
- return reference.isReady;
- }
-
-
-
-
- public static void SetTime () {
-
-
- #if UNITY_EDITOR
- if (!UnityEditor.EditorApplication.isPlaying)
- globalTime += (Time.realtimeSinceStartup-lastTimeUpdated)*globalTimescale;
- else
- globalTime += (Time.deltaTime)*globalTimescale;
- #else
- globalTime += (Time.deltaTime)*globalTimescale;
- #endif
-
-
- globalDeltaTime = globalTime-lastTimeUpdated;
-
-
- lastTimeUpdated = globalTime;
- }
-
- static void CheckEvents () {
- particleEventBirthInitialized = particleEventBirth!=null;
- particleEventDeathInitialized = particleEventDeath!=null;
- particleEventCollisionInitialized = particleEventCollision!=null;
- particleEventTimeInitialized = particleEventTime!=null;
- }
-
-
-
-
-
-
- void OnEnable () {
-
-
- referenceTransform = transform;
- referenceGameObject = gameObject;
-
-
- StartCoroutine(InitializePlayground());
- #if UNITY_EDITOR
- InvokeRepeating("RefreshHieararchy", 1f, 1f);
- #endif
- }
-
- void OnDisable () {
- #if UNITY_EDITOR
- CancelInvoke("RefreshHieararchy");
- #endif
- }
-
-
- void Start () {SetTime();}
-
-
-
-
-
- void LateUpdate () {
- activeThreads = 0;
- if (activeSystems.Count>0)
- activeSystems.Clear();
- frameCount++;
- isFirstUnsafeAutomaticFrames = frameCount<unsafeAutomaticThreadFrames||threadAggregatorRuns<unsafeAutomaticThreadFrames;
- if (reference!=this) {
- InitializePlayground();
- return;
- }
-
-
- SetTime();
-
-
- CheckEvents();
-
-
- for (int m = 0; m<manipulators.Count; m++)
- manipulators[m].Update();
-
-
- if (particleSystems.Count==0)
- return;
-
- hasActiveParticleSystems = false;
- hasLocalNoThreads = false;
- hasLocalOnePerSystem = false;
- hasLocalOneForAll = false;
- hasActiveSkinnedMeshes = false;
- hasActiveTurbulence = false;
- if (previousThreadMethod!=threadMethod) {
- isDoneThread = true;
- previousThreadMethod = threadMethod;
- }
- if (threadMethod!=ThreadMethod.OneForAll)
- isDoneThread = true;
- if (previousSkinnedMeshThreadMethod!=skinnedMeshThreadMethod) {
- isDoneThreadSkinned = true;
- previousSkinnedMeshThreadMethod = skinnedMeshThreadMethod;
- }
- if (previousTurbulenceThreadMethod!=turbulenceThreadMethod) {
- isDoneThreadTurbulence = true;
- previousTurbulenceThreadMethod = turbulenceThreadMethod;
- }
-
-
- Camera mainCamera = Camera.main;
- bool frustumPlanesSet = false;
- bool hasSourceUpdateNow = false;
- int currentParticleSystemCount = particleSystems.Count;
- for (int i = 0; i<particleSystems.Count; i++) {
- if (particleSystems[i]!=null &&
- !particleSystems[i].isSnapshot &&
- particleSystems[i].shurikenParticleSystem!=null &&
- particleSystems[i].particleSystemGameObject.activeInHierarchy &&
- particleSystems[i].Initialized() &&
- !particleSystems[i].IsSettingParticleCount() &&
- !particleSystems[i].IsSettingLifetime() &&
- !particleSystems[i].IsYieldRefreshing() &&
- !particleSystems[i].InTransition() &&
- !particleSystems[i].IsLoading() &&
- !particleSystems[i].IsPrewarming() &&
- !particleSystems[i].IsSettingParticleTime()) {
-
-
- if (Time.frameCount%particleSystems[i].updateRate!=0) {
- for (int p = 0; p<particleSystems[i].particleCount; p++)
- particleSystems[i].particleCache[p].remainingLifetime = (particleSystems[i].playgroundCache.death[p]-particleSystems[i].playgroundCache.birth[p])-particleSystems[i].playgroundCache.lifetimeSubtraction[p];
- particleSystems[i].isReadyForThreadedCalculations = false;
- continue;
- }
-
-
- if (currentParticleSystemCount > particleSystems.Count) {
- if (i>0) {
- i--;
- currentParticleSystemCount = particleSystems.Count;
- } else {hasActiveParticleSystems=false; return;}
- } else if (currentParticleSystemCount < particleSystems.Count) {
- currentParticleSystemCount = particleSystems.Count;
- }
- if (particleSystems.Count==0 || i>=particleSystems.Count) {hasActiveParticleSystems=false; return;}
-
-
- if (!frustumPlanesSet && particleSystems[i].pauseCalculationWhenInvisible && mainCamera!=null && mainCamera.enabled) {
- frustumPlanes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
- frustumPlanesSet = true;
- }
-
-
- if (particleSystems[i].onlySourcePositioning||particleSystems[i].onlyLifetimePositioning)
- if (!particleSystems[i].UpdateSystem())
- continue;
-
-
- if (particleSystems.Count>0 && i<particleSystems.Count) {
-
-
- particleSystems[i].isReadyForThreadedCalculations = particleSystems[i].PrepareThreadedCalculations();
- if (particleSystems[i].IsAlive()) {
- hasActiveParticleSystems = true;
- if (particleSystems[i].onlySourcePositioning||particleSystems[i].onlyLifetimePositioning)
- hasSourceUpdateNow = true;
- if (threadMethod==ThreadMethod.Automatic)
- activeSystems.Add (i);
- if (!particleSystems[i].forceSkinnedMeshUpdateOnMainThread && particleSystems[i].IsSkinnedWorldObjectReady() && particleSystems[i].calculate)
- hasActiveSkinnedMeshes = true;
- if (particleSystems[i].HasTurbulence() && particleSystems[i].calculate)
- hasActiveTurbulence = true;
-
- switch (particleSystems[i].threadMethod) {
- case ThreadMethodLocal.NoThreads:hasLocalNoThreads=true;break;
- case ThreadMethodLocal.OnePerSystem:hasLocalOnePerSystem=true;break;
- case ThreadMethodLocal.OneForAll:hasLocalOneForAll=true;break;
- }
- } else particleSystems[i].isReadyForThreadedCalculations = false;
- } else if (particleSystems.Count>0 && i<particleSystems.Count && particleSystems[i]!=null) {
- particleSystems[i].isReadyForThreadedCalculations = false;
- }
- } else if (particleSystems[i]!=null) {
- particleSystems[i].isReadyForThreadedCalculations = false;
- if (particleSystems[i].IsPrewarming()) {
- if (particleSystems[i].HasTurbulence()) {
- hasActiveTurbulence = true;
- hasActiveParticleSystems = true;
- }
- }
- }
-
- }
-
-
- if (hasActiveParticleSystems) {
-
-
- ThreadAggregator();
-
-
- if (hasSourceUpdateNow) {
- for (int i = 0; i<particleSystems.Count; i++) {
- if (particleSystems[i]!=null &&
- (particleSystems[i].onlySourcePositioning || particleSystems[i].onlyLifetimePositioning) &&
- particleSystems[i].isReadyForThreadedCalculations &&
- !particleSystems[i].InTransition() &&
- !particleSystems[i].IsLoading() &&
- particleSystems[i].IsReady()) {
- particleSystems[i].UpdateShuriken();
- }
- }
- }
- }
-
-
- #if UNITY_EDITOR
- PlaygroundParticlesC.didHierarchyRepaint = false;
- #endif
- }
-
-
-
-
-
- void Update () {
- int currentParticleSystemCount = particleSystems.Count;
- for (int i = 0; i<particleSystems.Count; i++) {
-
-
- if (currentParticleSystemCount > particleSystems.Count) {
- if (i>0) {
- i--;
- currentParticleSystemCount = particleSystems.Count;
- } else {hasActiveParticleSystems=false; return;}
- } else if (currentParticleSystemCount < particleSystems.Count) {
- currentParticleSystemCount = particleSystems.Count;
- }
- if (particleSystems.Count==0 || i>=particleSystems.Count) {hasActiveParticleSystems=false; return;}
-
- if (particleSystems[i]!=null &&
- !particleSystems[i].onlySourcePositioning &&
- !particleSystems[i].onlyLifetimePositioning &&
- particleSystems[i].UpdateSystem() &&
- particleSystems[i].isReadyForThreadedCalculations &&
- !particleSystems[i].InTransition() &&
- !particleSystems[i].IsLoading() &&
- !particleSystems[i].IsSettingParticleTime() &&
- particleSystems[i].IsReady()) {
- particleSystems[i].UpdateShuriken();
- }
- }
- }
-
- #if UNITY_EDITOR
- void RefreshHieararchy () {
- UnityEditor.EditorApplication.RepaintHierarchyWindow();
- }
- #endif
-
- bool hasActiveParticleSystems = false;
- bool hasLocalNoThreads = false;
- bool hasLocalOnePerSystem = false;
- bool hasLocalOneForAll = false;
- bool hasActiveSkinnedMeshes = false;
- bool hasActiveTurbulence = false;
- bool isFirstUnsafeAutomaticFrames = true;
- int threadAggregatorRuns = 0;
- List<int> activeSystems = new List<int>();
-
- ThreadMethod previousThreadMethod;
- ThreadMethodComponent previousSkinnedMeshThreadMethod;
- ThreadMethodComponent previousTurbulenceThreadMethod;
-
-
-
-
-
- public static int ActiveThreads () {
- return activeThreads;
- }
-
- public static int ProcessorCount () {
- return processorCount;
- }
-
-
-
-
- void ThreadAggregator () {
-
-
- if (hasActiveSkinnedMeshes) {
- switch (skinnedMeshThreadMethod) {
- case ThreadMethodComponent.InsideParticleCalculation:
-
-
- break;
- case ThreadMethodComponent.OnePerSystem:
- for(int i = 0; i<particleSystems.Count; i++) {
- if (!particleSystems[i].forceSkinnedMeshUpdateOnMainThread && particleSystems[i].IsSkinnedWorldObjectReady())
- particleSystems[i].skinnedWorldObject.UpdateOnNewThread();
- }
- break;
- case ThreadMethodComponent.OneForAll:
- if (isDoneThreadSkinned) {
- isDoneThreadSkinned = false;
- RunAsync (()=>{
- if (isDoneThreadSkinned) return;
- for(int i = 0; i<particleSystems.Count; i++)
- if (!particleSystems[i].forceSkinnedMeshUpdateOnMainThread && particleSystems[i].IsSkinnedWorldObjectReady())
- particleSystems[i].skinnedWorldObject.Update();
- isDoneThreadSkinned=true;
- });
- }
- break;
- }
- }
-
-
- if (hasActiveTurbulence && turbulenceThreadMethod==ThreadMethodComponent.OneForAll) {
- if (isDoneThreadTurbulence) {
- isDoneThreadTurbulence = false;
- RunAsync (()=>{
- if (isDoneThreadTurbulence) return;
- for(int i = 0; i<particleSystems.Count; i++) {
- if (particleSystems[i].HasTurbulence()) {
- for (int p = 0; p<particleSystems[i].particleCount; p++) {
- if (!particleSystems[i].playgroundCache.noForce[p])
- PlaygroundParticlesC.Turbulence (particleSystems[i], particleSystems[i].GetSimplex(), p, particleSystems[i].GetDeltaTime(), particleSystems[i].turbulenceType, particleSystems[i].turbulenceTimeScale, particleSystems[i].turbulenceScale/particleSystems[i].velocityScale, particleSystems[i].turbulenceStrength, particleSystems[i].turbulenceApplyLifetimeStrength, particleSystems[i].turbulenceLifetimeStrength);
- }
- }
- isDoneThreadTurbulence=true;
- }
- });
- }
- }
-
-
- if (hasLocalNoThreads) {
- for(int i = 0; i<particleSystems.Count; i++)
- if (particleSystems[i].isReadyForThreadedCalculations && particleSystems[i].threadMethod==ThreadMethodLocal.NoThreads)
- PlaygroundParticlesC.ThreadedCalculations(particleSystems[i]);
- }
- if (hasLocalOnePerSystem) {
- for(int i = 0; i<particleSystems.Count; i++)
- if (particleSystems[i].threadMethod==ThreadMethodLocal.OnePerSystem)
- PlaygroundParticlesC.NewCalculatedThread(particleSystems[i]);
- }
- if (hasLocalOneForAll || (isFirstUnsafeAutomaticFrames && threadMethod==ThreadMethod.Automatic)) {
- if (isDoneThreadLocal) {
- isDoneThreadLocal = false;
- RunAsync (()=>{
- if (isDoneThreadLocal) return;
- lock (lockerLocal) {
- for(int i = 0; i<particleSystems.Count; i++)
- if (particleSystems[i].isReadyForThreadedCalculations && (particleSystems[i].threadMethod==ThreadMethodLocal.OneForAll || isFirstUnsafeAutomaticFrames)) {
- particleSystems[i].IsDoneThread = true;
- PlaygroundParticlesC.ThreadedCalculations(particleSystems[i]);
- }
- isDoneThreadLocal=true;
- }
- });
- }
- }
-
-
- switch (threadMethod) {
- case ThreadMethod.NoThreads:
- for(int i = 0; i<particleSystems.Count; i++)
- if (particleSystems[i].isReadyForThreadedCalculations && particleSystems[i].threadMethod==ThreadMethodLocal.Inherit)
- PlaygroundParticlesC.ThreadedCalculations(particleSystems[i]);
- break;
- case ThreadMethod.OnePerSystem:
- for(int i = 0; i<particleSystems.Count; i++)
- if (particleSystems[i].threadMethod==ThreadMethodLocal.Inherit && particleSystems[i].isReadyForThreadedCalculations)
- PlaygroundParticlesC.NewCalculatedThread(particleSystems[i]);
- break;
- case ThreadMethod.OneForAll:
- if (isDoneThread) {
- isDoneThread = false;
- RunAsync (()=>{
- if (isDoneThread) return;
- lock (locker) {
- for(int i = 0; i<particleSystems.Count; i++)
- if (particleSystems[i].isReadyForThreadedCalculations && particleSystems[i].threadMethod==ThreadMethodLocal.Inherit) {
- PlaygroundParticlesC.ThreadedCalculations(particleSystems[i]);
- }
- isDoneThread=true;
- }
- });
- }
- break;
- case ThreadMethod.Automatic:
- if (!isFirstUnsafeAutomaticFrames) {
- maxThreads = Mathf.Clamp (maxThreads, 1, 128);
- threads = Mathf.Clamp (processorCount>1?processorCount-1:1, 1, maxThreads);
-
-
- if (activeSystems.Count<=threads) {
- for(int i = 0; i<particleSystems.Count; i++)
- if (particleSystems[i].isReadyForThreadedCalculations && particleSystems[i].threadMethod==ThreadMethodLocal.Inherit)
- PlaygroundParticlesC.NewCalculatedThread(particleSystems[i]);
-
-
- } else {
- int index = 0;
- float systemsPerBundle = (activeSystems.Count*1f/threads*1f);
- float currentSystems = 0;
- int oldSystems = 0;
- for (int i = 0; i<threads; i++) {
- currentSystems += systemsPerBundle;
- PlaygroundParticlesC[] systemBundle = new PlaygroundParticlesC[Mathf.RoundToInt(currentSystems-oldSystems)];
- oldSystems += systemBundle.Length;
- for (int s = 0; s<systemBundle.Length; s++) {
- if (index<activeSystems.Count)
- systemBundle[s] = particleSystems[activeSystems[index]];
- index++;
- }
- PlaygroundParticlesC.NewCalculatedThread(systemBundle);
- }
- }
- }
- break;
- }
-
- if (threadMethod!=ThreadMethod.NoThreads && activeThreads==0) activeThreads = 1;
- threadAggregatorRuns++;
- }
-
- #if UNITY_METRO && !UNITY_EDITOR
-
-
-
-
- public static void RunAsync (Action a) {
- activeThreads++;
- System.Threading.Tasks.Task.Run(() => a());
- }
- #else
-
-
-
-
- public static void RunAsync (Action a) {
- lock (a) {
- activeThreads++;
- ThreadPool.QueueUserWorkItem(RunAction, a);
- }
- }
- #endif
- private static void RunAction (object a) {
- try {
- ((Action)a)();
- } catch {}
- }
-
- #if UNITY_EDITOR
- public void OnApplicationPause (bool pauseStatus) {
- if (!pauseStatus && !UnityEditor.EditorApplication.isPlaying) {
- TimeReset();
- foreach(PlaygroundParticlesC p in particleSystems) {
- if (!p.isSnapshot && !p.IsLoading() && !p.IsYieldRefreshing()) {
- p.Start();
- }
- }
- }
- }
- #endif
- }
-
-
-
-
- [Serializable]
- public class PaintObjectC {
-
-
-
- [HideInInspector] public List<PaintPositionC> paintPositions;
-
-
-
- [HideInInspector] public int positionLength;
-
-
-
- [HideInInspector] public Vector3 lastPaintPosition;
-
-
-
- [HideInInspector] public COLLISIONTYPEC collisionType;
-
-
-
- public float minDepth = -1f;
-
-
-
- public float maxDepth = 1f;
-
-
-
- public float spacing;
-
-
-
- public LayerMask layerMask = -1;
-
-
-
- public PlaygroundBrushC brush;
-
-
-
- public bool exceedMaxStopsPaint;
-
-
-
- public bool initialized = false;
-
-
-
-
- public void Initialize () {
- paintPositions = new List<PaintPositionC>();
- brush = new PlaygroundBrushC();
- lastPaintPosition = PlaygroundC.initialTargetPosition;
- initialized = true;
- }
-
-
-
-
-
-
- public bool Paint (Ray ray, Color32 color) {
- if (collisionType==COLLISIONTYPEC.Physics3D) {
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, brush.distance, layerMask)) {
- Paint(hit.point, hit.normal, hit.transform, color);
- lastPaintPosition = hit.point;
- return true;
- }
- } else {
- RaycastHit2D hitInfo2D = Physics2D.Raycast(ray.origin, ray.direction, brush.distance, layerMask, minDepth, maxDepth);
- if (hitInfo2D.collider!=null) {
- Paint(hitInfo2D.point, hitInfo2D.normal, hitInfo2D.transform, color);
- lastPaintPosition = hitInfo2D.point;
- return true;
- }
- }
- return false;
- }
-
-
-
-
-
-
-
-
- public int Paint (Vector3 pos, Vector3 norm, Transform parent, Color32 color) {
- PaintPositionC pPos = new PaintPositionC();
-
- if (parent) {
- pPos.parent = parent;
- pPos.initialPosition = parent.InverseTransformPoint(pos);
- pPos.initialNormal = parent.InverseTransformDirection(norm);
- } else {
- pPos.initialPosition = pos;
- pPos.initialNormal = norm;
- }
-
- pPos.color = color;
- pPos.position = pPos.initialPosition;
-
- paintPositions.Add(pPos);
-
- positionLength = paintPositions.Count;
- if (!exceedMaxStopsPaint && positionLength>PlaygroundC.reference.paintMaxPositions) {
- paintPositions.RemoveAt(0);
- positionLength = paintPositions.Count;
- }
-
- return positionLength-1;
- }
-
-
-
-
-
-
- public bool Erase (Vector3 pos, float radius) {
- bool erased = false;
- if (paintPositions.Count==0) return false;
- for (int i = 0; i<paintPositions.Count; i++) {
- if (Vector3.Distance(paintPositions[i].position, pos)<radius) {
- paintPositions.RemoveAt(i);
- erased = true;
- }
- }
- positionLength = paintPositions.Count;
- return erased;
- }
-
-
-
-
-
- public bool Erase (int index) {
- if (index>=0 && index<positionLength) {
- paintPositions.RemoveAt(index);
- positionLength = paintPositions.Count;
- return true;
- } else return false;
- }
-
-
-
-
-
-
- public Vector3 GetPosition (int index) {
- index=index%positionLength;
- return paintPositions[index].position;
- }
-
-
-
-
-
-
- public Color32 GetColor (int index) {
- index=index%positionLength;
- return paintPositions[index].color;
- }
-
-
-
-
-
-
- public Vector3 GetNormal (int index) {
- index=index%positionLength;
- return paintPositions[index].initialNormal;
- }
-
-
-
-
-
-
- public Transform GetParent (int index) {
- index=index%positionLength;
- return paintPositions[index].parent;
- }
-
-
-
-
-
-
- public Quaternion GetRotation (int index) {
- index=index%positionLength;
- return paintPositions[index].parentRotation;
- }
-
-
-
-
-
- public void Update () {
- for (int i = 0; i<paintPositions.Count; i++) {
- if (paintPositions[i].parent==null)
- continue;
- else
- Update(i);
- }
- }
-
-
-
-
-
- public void Update (int thisPosition) {
- thisPosition = thisPosition%positionLength;
- paintPositions[thisPosition].position = paintPositions[thisPosition].parent.TransformPoint(paintPositions[thisPosition].initialPosition);
- paintPositions[thisPosition].parentRotation = paintPositions[thisPosition].parent.rotation;
- }
-
-
-
-
- public void RemoveNonParented () {
- for (int i = 0; i<paintPositions.Count; i++)
- if (paintPositions[i].parent==null) {
- paintPositions.RemoveAt(i);
- i--;
- }
- }
-
-
-
-
-
-
-
- public bool RemoveNonParented (int thisPosition) {
- thisPosition = thisPosition%positionLength;
- if (paintPositions[thisPosition].parent==null) {
- paintPositions.RemoveAt(thisPosition);
- return true;
- }
- return false;
- }
-
-
-
-
- public void ClearPaint () {
- paintPositions = new List<PaintPositionC>();
- positionLength = 0;
- }
-
-
-
-
- public PaintObjectC Clone () {
- PaintObjectC paintObject = new PaintObjectC();
- if (paintPositions!=null && paintPositions.Count>0) {
- paintObject.paintPositions = new List<PaintPositionC>();
- paintObject.paintPositions.AddRange(paintPositions);
- }
- paintObject.positionLength = positionLength;
- paintObject.lastPaintPosition = lastPaintPosition;
- paintObject.spacing = spacing;
- paintObject.layerMask = layerMask;
- paintObject.collisionType = collisionType;
- if (brush!=null)
- paintObject.brush = brush.Clone();
- else
- paintObject.brush = new PlaygroundBrushC();
- paintObject.exceedMaxStopsPaint = exceedMaxStopsPaint;
- paintObject.initialized = initialized;
- return paintObject;
- }
- }
-
-
-
-
- [Serializable]
- public class PaintPositionC {
-
-
-
- public Vector3 position;
-
-
-
- public Color32 color;
-
-
-
- public Transform parent;
-
-
-
- public Vector3 initialPosition;
-
-
-
- public Vector3 initialNormal;
-
-
-
- public Quaternion parentRotation;
- }
-
-
-
-
- [Serializable]
- public class PlaygroundBrushC {
-
-
-
- public Texture2D texture;
-
-
-
- public float scale = 1f;
-
-
-
- public BRUSHDETAILC detail = BRUSHDETAILC.High;
-
-
-
- public float distance = 10000;
-
-
-
- [HideInInspector] public Color32[] color;
-
-
-
- [HideInInspector] public int colorLength;
-
-
-
-
-
- public void SetTexture (Texture2D newTexture) {
- texture = newTexture;
- Construct();
- }
-
-
-
-
- public void Construct () {
- color = PlaygroundC.GetPixels(texture);
- if (color!=null)
- colorLength = color.Length;
- }
-
-
-
-
-
-
- public Color32 GetColor (int index) {
- index=index%colorLength;
- return color[index];
- }
-
-
-
-
-
-
- public void SetColor (Color32 c, int index) {
- color[index] = c;
- }
-
-
-
-
- public PlaygroundBrushC Clone () {
- PlaygroundBrushC playgroundBrush = new PlaygroundBrushC();
- playgroundBrush.texture = texture;
- playgroundBrush.scale = scale;
- playgroundBrush.detail = detail;
- playgroundBrush.distance = distance;
- if (playgroundBrush.color!=null)
- playgroundBrush.color = color.Clone() as Color32[];
- playgroundBrush.colorLength = colorLength;
- return playgroundBrush;
- }
- }
-
-
-
-
- [Serializable]
- public class ParticleStateC {
-
-
-
- [HideInInspector] Color32[] color;
-
-
-
- [HideInInspector] Vector3[] position;
-
-
-
- [HideInInspector] Vector3[] normals;
-
-
-
- public Texture2D stateTexture;
-
-
-
- public Texture2D stateDepthmap;
-
-
-
- public float stateDepthmapStrength = 1f;
-
-
-
- public Mesh stateMesh;
-
-
-
- public string stateName;
-
-
-
- public float stateScale = 1f;
-
-
-
- public Vector3 stateOffset;
-
-
-
- public Transform stateTransform;
- public Matrix4x4 stateTransformMx = new Matrix4x4();
-
-
-
- [NonSerialized] public bool initialized = false;
-
-
-
- [HideInInspector] public int colorLength;
-
-
-
- [HideInInspector] public int positionLength;
- [HideInInspector] public bool applyChromaKey;
- [HideInInspector] public Color32 chromaKey;
- [HideInInspector] public float chromaKeySpread;
- bool isInitializing = false;
-
-
-
-
-
- public bool IsInitializing () {
- return isInitializing;
- }
-
-
-
-
- public void Initialize () {
- isInitializing = true;
- if (stateMesh==null && stateTexture!=null) {
- ConstructParticles(stateTexture, stateScale, stateOffset, stateName, stateTransform);
- } else if (stateMesh!=null && stateTexture!=null) {
- ConstructParticles(stateMesh, stateTexture, stateScale, stateOffset, stateName, stateTransform);
- } else if (stateMesh!=null && stateTexture==null) {
- ConstructParticles(stateMesh, stateScale, stateOffset, stateName, stateTransform);
- } else Debug.Log("State Texture or State Mesh returned null. Please assign an object to State: "+stateName+".");
- initialized = position!=null && position.Length>0;
- isInitializing = false;
- }
-
- public void UpdateMatrix (bool isLocal) {
- stateTransformMx.SetTRS (isLocal?Vector3.zero:stateTransform.position, isLocal?Quaternion.identity:stateTransform.rotation, stateTransform.localScale);
- }
-
-
-
-
-
-
-
-
-
- public void ConstructParticles (Texture2D image, float scale, Vector3 offset, string newStateName, Transform newStateTransform) {
- List<Color32> tmpColor = new List<Color32>();
- List<Vector3> tmpPosition = new List<Vector3>();
- color = PlaygroundC.GetPixels(image);
- bool readAlpha = false;
- if (PlaygroundC.reference)
- readAlpha = PlaygroundC.reference.buildZeroAlphaPixels;
- bool readDepthmap = stateDepthmap!=null;
- Color32[] depthMapPixels = readDepthmap?PlaygroundC.GetPixels(stateDepthmap):null;
- int x = 0;
- int y = 0;
- float depthmapRatio = stateDepthmap!=null?((depthMapPixels.Length*1f) / (color.Length*1f)):0;
- byte cSpread = (byte)(chromaKeySpread*255f);
- for (int i = 0; i<color.Length; i++) {
- if (readAlpha || color[i].a!=0) {
- if (!applyChromaKey || applyChromaKey &&
- ((color[i].r<chromaKey.r-cSpread || color[i].r>chromaKey.r+cSpread) &&
- (color[i].g<chromaKey.g-cSpread || color[i].g>chromaKey.g+cSpread) &&
- (color[i].b<chromaKey.b-cSpread || color[i].b>chromaKey.b+cSpread)))
- {
- tmpColor.Add(color[i]);
- if (readDepthmap) {
-
- int iScaled = Mathf.FloorToInt (((i*1f) * depthmapRatio));
- float z = ((((depthMapPixels[iScaled].r*1f)+(depthMapPixels[iScaled].g*1f)+(depthMapPixels[iScaled].b*1f))/3)*((depthMapPixels[iScaled].a*1f)/255)*stateDepthmapStrength)/255;
- tmpPosition.Add(new Vector3(x,y,z));
- } else tmpPosition.Add(new Vector3(x,y,0));
- }
- }
- x++; x=x%image.width;
- if (x==0 && i!=0) y++;
- }
- color = tmpColor.ToArray() as Color32[];
- position = tmpPosition.ToArray() as Vector3[];
- tmpColor = null;
- tmpPosition = null;
- normals = new Vector3[position.Length];
- for (int n = 0; n<normals.Length; n++) normals[n] = Vector3.forward;
- stateTransform = newStateTransform;
- stateTexture = image;
- colorLength = color.Length;
- positionLength = position.Length;
- stateScale = scale;
- stateOffset = offset;
- stateName = newStateName;
- initialized = position.Length>0;
- }
-
-
-
-
-
-
-
-
-
-
- public void ConstructParticles (Mesh mesh, Texture2D texture, float scale, Vector3 offset, string newStateName, Transform newStateTransform) {
- position = mesh.vertices;
- normals = mesh.normals;
- if (normals==null || normals.Length==0) {
- normals = new Vector3[position.Length];
- for (int n = 0; n<normals.Length; n++) normals[n] = Vector3.forward;
- }
- Vector2[] uvs = mesh.uv;
- color = new Color32[uvs.Length];
- for (int i = 0; i<position.Length; i++)
- color[i] = texture.GetPixelBilinear(uvs[i].x, uvs[i].y);
- stateMesh = mesh;
- stateTransform = newStateTransform;
- colorLength = color.Length;
- positionLength = position.Length;
- stateScale = scale;
- stateOffset = offset;
- stateName = newStateName;
- initialized = position.Length>0;
- }
-
-
-
-
-
-
-
-
-
- public void ConstructParticles (Mesh mesh, float scale, Vector3 offset, string newStateName, Transform newStateTransform) {
- position = mesh.vertices;
- normals = mesh.normals;
- if (normals==null || normals.Length==0) {
- normals = new Vector3[position.Length];
- for (int n = 0; n<normals.Length; n++) normals[n] = Vector3.forward;
- }
- Vector2[] uvs = mesh.uv;
- color = new Color32[uvs.Length];
- stateMesh = mesh;
- stateTransform = newStateTransform;
- colorLength = color.Length;
- positionLength = position.Length;
- stateScale = scale;
- stateOffset = offset;
- stateName = newStateName;
- initialized = position.Length>0;
- }
-
-
-
-
-
-
- public Color32 GetColor (int index) {
- if (colorLength==0) return new Color32();
- index=index%colorLength;
- return color[index];
- }
-
-
-
-
-
-
- public Vector3 GetPosition (int index) {
- if (positionLength==0) return new Vector3();
- index=index%positionLength;
- return (position[index]+stateOffset)*stateScale;
- }
-
- public Vector3 GetLocalPosition (int index) {
- if (positionLength==0) return new Vector3();
- index=index%positionLength;
- return stateTransformMx.MultiplyPoint3x4((position[index]+stateOffset)*stateScale);
- }
-
-
-
-
-
-
- public Vector3 GetNormal (int index) {
- if (positionLength==0) return new Vector3();
- index=index%positionLength;
- return normals[index];
- }
-
- public Vector3 GetLocalNormal (int index) {
- if (positionLength==0) return new Vector3();
- index=index%positionLength;
- return stateTransformMx.MultiplyPoint3x4(normals[index]);
- }
-
-
-
-
-
- public Color32[] GetColors () {
- return color.Clone() as Color32[];
- }
-
-
-
-
-
- public Vector3[] GetPositions () {
- return position.Clone() as Vector3[];
- }
-
-
-
-
-
- public Vector3[] GetNormals () {
- return normals.Clone() as Vector3[];
- }
-
-
-
-
-
-
- public void SetColor (int index, Color32 c) {
- color[index] = c;
- }
-
-
-
-
-
-
- public void SetPosition (int index, Vector3 v) {
- position[index] = v;
- }
-
-
-
-
-
-
- public void SetNormal (int index, Vector3 v) {
- normals[index] = v;
- }
-
-
-
-
-
-
- public Vector3 GetParentedPosition (int thisPosition) {
- thisPosition = thisPosition%positionLength;
- return stateTransform.TransformPoint((position[thisPosition]+stateOffset)*stateScale);
- }
-
-
-
-
- public ParticleStateC Clone () {
- ParticleStateC particleState = new ParticleStateC();
- particleState.stateName = stateName;
- particleState.stateScale = stateScale;
- particleState.stateTexture = stateTexture;
- particleState.stateDepthmap = stateDepthmap;
- particleState.stateDepthmapStrength = stateDepthmapStrength;
- particleState.stateMesh = stateMesh;
- particleState.stateOffset = stateOffset;
- particleState.colorLength = colorLength;
- particleState.positionLength = positionLength;
- particleState.stateTransform = stateTransform;
- particleState.applyChromaKey = applyChromaKey;
- particleState.chromaKey = chromaKey;
- particleState.chromaKeySpread = chromaKeySpread;
- return particleState;
- }
- }
-
-
-
-
- [Serializable]
- public class ParticleProjectionC {
-
-
-
- [HideInInspector] private Color32[] sourceColors;
-
-
-
- [HideInInspector] private Vector3[] sourcePositions;
-
-
-
- [HideInInspector] private Vector3[] targetPositions;
-
-
-
- [HideInInspector] private Vector3[] targetNormals;
-
-
-
- [HideInInspector] private bool[] hasProjected;
-
-
-
- [HideInInspector] private Transform[] targetParents;
-
-
-
- public Texture2D projectionTexture;
-
-
-
- public Vector2 projectionOrigin;
-
-
-
- public Transform projectionTransform;
-
-
-
- public Matrix4x4 projectionMatrix;
-
-
-
- public Vector3 projectionPosition;
-
-
-
- public Vector3 projectionDirection;
-
-
-
- public Quaternion projectionRotation;
-
-
-
- public float projectionDistance = 1000f;
-
-
-
- public float projectionScale = .1f;
-
-
-
- public LayerMask projectionMask = -1;
-
-
-
- public COLLISIONTYPEC collisionType;
-
-
-
- public float minDepth = -1f;
-
-
-
- public float maxDepth = 1f;
-
-
-
- public float surfaceOffset = 0f;
-
-
-
- public bool liveUpdate = true;
-
-
-
- public bool hasRefreshed = false;
-
-
-
- [HideInInspector] public bool initialized = false;
-
-
-
- [HideInInspector] public int colorLength;
-
-
-
- [HideInInspector] public int positionLength;
-
-
-
-
- public void Initialize () {
- if (!projectionTexture) return;
- Construct(projectionTexture, projectionTransform);
- if (!liveUpdate) {
- UpdateSource();
- Update();
- }
- initialized = true;
- hasRefreshed = false;
- }
-
-
-
-
-
-
- public void Construct (Texture2D image, Transform transform) {
- List<Color32> tmpColor = new List<Color32>();
- List<Vector3> tmpPosition = new List<Vector3>();
- sourceColors = PlaygroundC.GetPixels(image);
- bool readAlpha = false;
- if (PlaygroundC.reference)
- readAlpha = PlaygroundC.reference.buildZeroAlphaPixels;
-
- int x = 0;
- int y = 0;
- for (int i = 0; i<sourceColors.Length; i++) {
- if (readAlpha || sourceColors[i].a!=0) {
- tmpColor.Add(sourceColors[i]);
- tmpPosition.Add(new Vector3(x*projectionScale,y*projectionScale,0));
- }
- x++; x=x%image.width;
- if (x==0 && i!=0) y++;
- }
- sourceColors = tmpColor.ToArray();
- sourcePositions = tmpPosition.ToArray();
- tmpColor = null;
- tmpPosition = null;
- targetPositions = new Vector3[sourcePositions.Length];
- targetNormals = new Vector3[sourcePositions.Length];
- targetParents = new Transform[sourcePositions.Length];
- hasProjected = new bool[sourcePositions.Length];
- positionLength = sourcePositions.Length;
- colorLength = sourceColors.Length;
- projectionTexture = image;
- projectionTransform = transform;
- projectionMatrix = new Matrix4x4();
- }
-
-
-
-
- public void UpdateSource () {
- projectionPosition = projectionTransform.position;
- projectionDirection = projectionTransform.forward;
- projectionRotation = projectionTransform.rotation;
- projectionMatrix.SetTRS(projectionPosition, projectionRotation, projectionTransform.localScale);
- }
-
-
-
-
- public void Update () {
- for (int i = 0; i<positionLength; i++)
- Update(i);
- }
-
-
-
-
-
- public void Update (int index) {
- index=index%positionLength;
- Vector3 sourcePosition = projectionMatrix.MultiplyPoint3x4(sourcePositions[index]+new Vector3(projectionOrigin.x, projectionOrigin.y, 0));
- if (collisionType==COLLISIONTYPEC.Physics3D) {
- RaycastHit hit;
- if (Physics.Raycast(sourcePosition, projectionDirection, out hit, projectionDistance, projectionMask)) {
- targetPositions[index] = hit.point+(hit.normal*surfaceOffset);
- targetNormals[index] = hit.normal;
- targetParents[index] = hit.transform;
- hasProjected[index] = true;
- } else {
- targetPositions[index] = PlaygroundC.initialTargetPosition;
- targetNormals[index] = Vector3.forward;
- hasProjected[index] = false;
- targetParents[index] = null;
- }
- } else {
- RaycastHit2D hit2d = Physics2D.Raycast (sourcePosition, projectionDirection, projectionDistance, projectionMask, minDepth, maxDepth);
- if (hit2d.collider!=null) {
- targetPositions[index] = hit2d.point+(hit2d.normal*surfaceOffset);
- targetNormals[index] = hit2d.normal;
- targetParents[index] = hit2d.transform;
- hasProjected[index] = true;
- } else {
- targetPositions[index] = PlaygroundC.initialTargetPosition;
- targetNormals[index] = Vector3.forward;
- hasProjected[index] = false;
- targetParents[index] = null;
- }
- }
- }
-
-
-
-
-
-
- public Color32 GetColor (int index) {
- index=index%colorLength;
- return sourceColors[index];
- }
-
-
-
-
-
-
- public Vector3 GetPosition (int index) {
- index=index%positionLength;
- return (targetPositions[index]);
- }
-
-
-
-
-
-
- public Vector3 GetNormal (int index) {
- index=index%positionLength;
- return targetNormals[index];
- }
-
-
-
-
-
-
- public Transform GetParent (int index) {
- index=index%positionLength;
- return targetParents[index];
- }
-
-
-
-
-
-
- public bool HasProjection (int index) {
- index=index%positionLength;
- return hasProjected[index];
- }
-
-
-
-
- public ParticleProjectionC Clone () {
- ParticleProjectionC particleProjection = new ParticleProjectionC();
- if (sourceColors!=null)
- particleProjection.sourceColors = (Color32[])sourceColors.Clone ();
- if (sourcePositions!=null)
- particleProjection.sourcePositions = (Vector3[])sourcePositions.Clone ();
- if (targetPositions!=null)
- particleProjection.targetPositions = (Vector3[])targetPositions.Clone ();
- if (targetNormals!=null)
- particleProjection.targetNormals = (Vector3[])targetNormals.Clone ();
- if (hasProjected!=null)
- particleProjection.hasProjected = (bool[])hasProjected.Clone ();
- if (targetParents!=null)
- particleProjection.targetParents = (Transform[])targetParents.Clone ();
- particleProjection.projectionTexture = projectionTexture;
- particleProjection.projectionOrigin = projectionOrigin;
- particleProjection.projectionTransform = projectionTransform;
- particleProjection.projectionMatrix = projectionMatrix;
- particleProjection.projectionPosition = projectionPosition;
- particleProjection.projectionDirection = projectionDirection;
- particleProjection.projectionRotation = projectionRotation;
- particleProjection.projectionDistance = projectionDistance;
- particleProjection.projectionScale = projectionScale;
- particleProjection.projectionMask = projectionMask;
- particleProjection.collisionType = collisionType;
- particleProjection.minDepth = minDepth;
- particleProjection.maxDepth = maxDepth;
- particleProjection.surfaceOffset = surfaceOffset;
- particleProjection.liveUpdate = liveUpdate;
- particleProjection.hasRefreshed = hasRefreshed;
- particleProjection.initialized = initialized;
- particleProjection.colorLength = colorLength;
- particleProjection.positionLength = positionLength;
- return particleProjection;
- }
- }
-
-
-
-
- [Serializable]
- public class Vector3AnimationCurveC {
- public AnimationCurve x;
- public AnimationCurve y;
- public AnimationCurve z;
-
- public float xRepeat = 1f;
- public float yRepeat = 1f;
- public float zRepeat = 1f;
-
-
-
-
-
- public Vector3 Evaluate (float time) {
- return Evaluate (time, 1f);
- }
-
-
-
-
-
-
- public Vector3 Evaluate (float time, float scale) {
- return new Vector3(x.Evaluate(time*(xRepeat)%1f), y.Evaluate(time*(yRepeat)%1f), z.Evaluate(time*(zRepeat)%1f))*scale;
- }
-
-
-
-
-
- public bool HasKeys () {
- CheckNull();
- return x.keys.Length>0||y.keys.Length>0||z.keys.Length>0;
- }
-
-
-
-
-
-
- public void SetKeyValues (int key, float value) {
- SetKeyValues(key, new Vector3(value, value, value), 0, 0);
- }
-
-
-
-
-
-
- public void SetKeyValues (int key, Vector3 value, float inTangent, float outTangent) {
- CheckNull();
- Keyframe[] xKeys = x.keys;
- Keyframe[] yKeys = y.keys;
- Keyframe[] zKeys = z.keys;
- if (key<x.keys.Length) {
- xKeys[key].value = value.x;
- xKeys[key].inTangent = inTangent;
- xKeys[key].outTangent = outTangent;
- }
- if (key<y.keys.Length) {
- yKeys[key].value = value.y;
- yKeys[key].inTangent = inTangent;
- yKeys[key].outTangent = outTangent;
- }
- if (key<z.keys.Length) {
- zKeys[key].value = value.z;
- zKeys[key].inTangent = inTangent;
- zKeys[key].outTangent = outTangent;
- }
- x.keys = xKeys;
- y.keys = yKeys;
- z.keys = zKeys;
- }
-
-
-
-
- public void Reset () {
- CheckNull();
- Keyframe[] reset = new Keyframe[2];
- reset[0].time = 0;
- reset[1].time = 1f;
- x.keys = reset;
- y.keys = reset;
- z.keys = reset;
- xRepeat = 1f;
- yRepeat = 1f;
- zRepeat = 1f;
- }
-
-
-
-
- public void Reset1 () {
- CheckNull();
- Keyframe[] reset = new Keyframe[2];
- reset[0].time = 0;
- reset[0].value = 1f;
- reset[1].time = 1f;
- reset[1].value = 1f;
- x.keys = reset;
- y.keys = reset;
- z.keys = reset;
- xRepeat = 1f;
- yRepeat = 1f;
- zRepeat = 1f;
- }
-
-
-
-
- public void ResetWithMidKey () {
- CheckNull();
- Keyframe[] reset = new Keyframe[3];
- reset[0].time = 0;
- reset[1].time = .5f;
- reset[2].time = 1f;
- x.keys = reset;
- y.keys = reset;
- z.keys = reset;
- xRepeat = 1f;
- yRepeat = 1f;
- zRepeat = 1f;
- }
-
- public void CheckNull () {
- if (x==null) x = new AnimationCurve();
- if (y==null) y = new AnimationCurve();
- if (z==null) z = new AnimationCurve();
- }
-
-
-
-
- public Vector3AnimationCurveC Clone () {
- Vector3AnimationCurveC vector3AnimationCurveClone = new Vector3AnimationCurveC();
- vector3AnimationCurveClone.x = new AnimationCurve(x.keys);
- vector3AnimationCurveClone.y = new AnimationCurve(y.keys);
- vector3AnimationCurveClone.z = new AnimationCurve(z.keys);
- vector3AnimationCurveClone.xRepeat = xRepeat;
- vector3AnimationCurveClone.yRepeat = yRepeat;
- vector3AnimationCurveClone.zRepeat = zRepeat;
- return vector3AnimationCurveClone;
- }
- }
-
-
-
-
- [Serializable]
- public class WorldObjectBaseC {
- public GameObject gameObject;
- [HideInInspector] public Transform transform;
- [HideInInspector] public Rigidbody rigidbody;
- [HideInInspector] public MeshFilter meshFilter;
- [HideInInspector] public Mesh mesh;
- [HideInInspector] public Vector3[] vertexPositions;
- [HideInInspector] public Vector3[] normals;
- [HideInInspector] public bool updateNormals = false;
- [NonSerialized] public int cachedId;
- [NonSerialized] public bool initialized = false;
- [HideInInspector] public Matrix4x4 transformMatrix = new Matrix4x4();
-
- public void UpdateMatrix (bool isLocal) {
- transformMatrix.SetTRS(isLocal?Vector3.zero:transform.position, isLocal?Quaternion.identity:transform.rotation, transform.localScale);
- }
- }
-
-
-
-
- [Serializable]
- public class WorldObject : WorldObjectBaseC {
- [HideInInspector] public Renderer renderer;
-
-
-
-
- public void Initialize () {
- gameObject = transform.gameObject;
- rigidbody = gameObject.GetComponent<Rigidbody>();
- renderer = transform.GetComponentInChildren<Renderer>();
- meshFilter = transform.GetComponentInChildren<MeshFilter>();
- if (meshFilter!=null) {
- mesh = meshFilter.sharedMesh;
- if (mesh!=null) {
- vertexPositions = mesh.vertices;
- normals = mesh.normals;
- initialized = true;
- } else {
- initialized = false;
- }
- }
- cachedId = gameObject.GetInstanceID();
- }
-
-
-
-
- public void Update () {
- if (mesh!=null) {
- vertexPositions = mesh.vertices;
- if (updateNormals)
- normals = mesh.normals;
- }
- }
-
-
-
-
- public WorldObject Clone () {
- WorldObject worldObject = new WorldObject();
- worldObject.gameObject = gameObject;
- worldObject.transform = transform;
- worldObject.rigidbody = rigidbody;
- worldObject.renderer = renderer;
- worldObject.meshFilter = meshFilter;
- worldObject.mesh = mesh;
- worldObject.updateNormals = updateNormals;
- return worldObject;
- }
- }
-
-
-
-
- [Serializable]
- public class SkinnedWorldObject : WorldObjectBaseC {
-
-
-
- public int downResolution = 1;
-
-
-
- [HideInInspector] public SkinnedMeshRenderer renderer;
-
-
-
- private Transform[] boneTransforms;
-
-
-
- private BoneWeight[] weights;
-
-
-
- private Matrix4x4[] bindPoses;
-
-
-
- private Matrix4x4[] boneMatrices;
-
-
-
- private Vector3[] vertices;
-
-
-
- private Vector3[] localVertices;
-
-
-
- [HideInInspector] public bool isDoneThread = true;
-
- private Mesh bakedMesh;
- private Matrix4x4 vertexMatrix = new Matrix4x4();
-
-
-
-
- public void Initialize () {
- gameObject = transform.gameObject;
- cachedId = gameObject.GetInstanceID();
- rigidbody = gameObject.GetComponent<Rigidbody>();
- renderer = transform.GetComponentInChildren<SkinnedMeshRenderer>();
- mesh = renderer.sharedMesh;
- if (mesh!=null) {
- normals = mesh.normals;
- vertices = new Vector3[mesh.vertices.Length];
- localVertices = mesh.vertices;
- weights = mesh.boneWeights;
- boneTransforms = renderer.bones;
- bindPoses = mesh.bindposes;
- boneMatrices = new Matrix4x4[boneTransforms.Length];
- vertexPositions = vertices;
- initialized = true;
- Update();
- } else {
- Debug.Log ("No mesh could be found in the assigned Skinned World Object. Make sure a mesh is assigned to your Skinned Mesh Renderer, if so - make sure the hierarchy under only have one Skinned Mesh Renderer component.", gameObject);
- }
- }
-
-
-
-
- public void MeshUpdate () {
- if (initialized) {
- if (boneMatrices!=null && boneMatrices.Length>0)
- localVertices = mesh.vertices;
- if (updateNormals)
- normals = mesh.normals;
- }
- }
-
-
-
-
- public void BoneUpdate () {
- if (initialized) {
- if (boneMatrices!=null && boneMatrices.Length>0) {
- for (int i = 0; i<boneMatrices.Length; i++) {
- if (boneTransforms[i]!=null)
- boneMatrices[i] = boneTransforms[i].localToWorldMatrix * bindPoses[i];
- }
- } else {
- if (bakedMesh==null)
- bakedMesh = new Mesh();
- renderer.BakeMesh(bakedMesh);
- localVertices = bakedMesh.vertices;
- vertexMatrix.SetTRS(renderer.transform.position, renderer.transform.rotation, renderer.transform.localScale);
- }
- }
- }
-
-
-
-
- public void Update () {
- if (initialized) {
- for (int i = 0; i<vertices.Length; i++) {
- if (boneMatrices.Length>0) {
- Matrix4x4 m0 = boneMatrices[weights[i].boneIndex0];
- Matrix4x4 m1 = boneMatrices[weights[i].boneIndex1];
- Matrix4x4 m2 = boneMatrices[weights[i].boneIndex2];
- Matrix4x4 m3 = boneMatrices[weights[i].boneIndex3];
-
- for (int n=0; n<16; n++) {
- vertexMatrix[n] =
- m0[n] * weights[i].weight0 +
- m1[n] * weights[i].weight1 +
- m2[n] * weights[i].weight2 +
- m3[n] * weights[i].weight3;
- }
- }
- vertices[i] = vertexMatrix.MultiplyPoint3x4(localVertices[i]);
- }
- vertexPositions = vertices;
- }
- isDoneThread = true;
- }
-
-
-
-
- public void UpdateOnNewThread () {
- if (isDoneThread) {
- isDoneThread = false;
- PlaygroundC.RunAsync (()=> {
- if (isDoneThread) return;
- Update();
- });
- }
- }
-
-
-
-
- public SkinnedWorldObject Clone () {
- SkinnedWorldObject skinnedWorldObject = new SkinnedWorldObject();
- skinnedWorldObject.downResolution = downResolution;
- skinnedWorldObject.gameObject = gameObject;
- skinnedWorldObject.transform = transform;
- skinnedWorldObject.rigidbody = rigidbody;
- skinnedWorldObject.renderer = renderer;
- skinnedWorldObject.meshFilter = meshFilter;
- skinnedWorldObject.mesh = mesh;
- skinnedWorldObject.updateNormals = updateNormals;
- return skinnedWorldObject;
- }
- }
-
-
-
-
- [Serializable]
- public class ManipulatorObjectC {
-
-
-
- public MANIPULATORTYPEC type;
-
-
-
- public ManipulatorPropertyC property = new ManipulatorPropertyC();
-
-
-
- public List<ManipulatorPropertyC> properties = new List<ManipulatorPropertyC>();
-
-
-
- public LayerMask affects;
-
-
-
- public PlaygroundTransformC transform = new PlaygroundTransformC();
-
-
-
- public MANIPULATORSHAPEC shape;
-
-
-
- public float size;
-
-
-
- public Bounds bounds;
-
-
-
- public float strength;
-
-
-
- public float strengthSmoothing = 1f;
-
-
-
- public float strengthDistanceEffect = 1f;
-
-
-
- public bool enabled = true;
-
-
-
- public bool inverseBounds = false;
-
-
-
- public int manipulatorId = 0;
-
-
-
- public bool applyLifetimeFilter = false;
-
-
-
- public float lifetimeFilterMinimum = 0f;
-
-
-
- public float lifetimeFilterMaximum = 1f;
-
-
-
- public bool applyParticleFilter = false;
-
-
-
- public float particleFilterMinimum = 0f;
-
-
-
- public float particleFilterMaximum = 1f;
-
-
-
- public PlaygroundAxisConstraintsC axisConstraints = new PlaygroundAxisConstraintsC();
- public bool unfolded = false;
-
-
-
-
- public bool trackParticles = false;
-
-
-
-
-
- public TrackingMethod trackingMethod = TrackingMethod.ManipulatorId;
-
-
-
- public bool sendEventEnter = true;
-
-
-
- public bool sendEventExit = true;
-
-
-
- public bool sendEventBirth = true;
-
-
-
- public bool sendEventDeath = true;
-
-
-
- public bool sendEventCollision = true;
- public bool sendEventsUnfolded = false;
-
-
-
- public event OnPlaygroundParticle particleEventEnter;
-
-
-
- public event OnPlaygroundParticle particleEventExit;
-
-
-
- public event OnPlaygroundParticle particleEventBirth;
-
-
-
- public event OnPlaygroundParticle particleEventDeath;
-
-
-
- public event OnPlaygroundParticle particleEventCollision;
-
-
-
- [NonSerialized] public List<ManipulatorParticle> particles = new List<ManipulatorParticle>();
-
-
-
- [NonSerialized] public List<ManipulatorParticle> nonAffectedParticles = new List<ManipulatorParticle>();
-
-
-
- public PlaygroundEventParticle manipulatorEventParticle = new PlaygroundEventParticle();
- [NonSerialized] bool initializedEventEnter = false;
- [NonSerialized] bool initializedEventExit = false;
- [NonSerialized] bool initializedEventBirth = false;
- [NonSerialized] bool initializedEventDeath = false;
- [NonSerialized] bool initializedEventCollision = false;
-
-
-
-
-
-
- public bool Contains (Vector3 position, Vector3 mPosition) {
- if (shape==MANIPULATORSHAPEC.Box) {
- if (!inverseBounds)
- return bounds.Contains(transform.inverseRotation*(position-mPosition));
- else
- return !bounds.Contains(transform.inverseRotation*(position-mPosition));
- } else {
- if (!inverseBounds)
- return (Vector3.Distance(position, mPosition)<=size);
- else
- return (Vector3.Distance(position, mPosition)>=size);
- }
- }
-
- public void SendParticleEventEnter () {
-
- if (initializedEventEnter)
- particleEventEnter(manipulatorEventParticle);
- }
- public void SendParticleEventExit () {
- if (initializedEventExit)
- particleEventExit(manipulatorEventParticle);
- }
- public void SendParticleEventBirth () {
- if (initializedEventBirth)
- particleEventBirth(manipulatorEventParticle);
- }
- public void SendParticleEventDeath () {
- if (initializedEventDeath)
- particleEventDeath(manipulatorEventParticle);
- }
- public void SendParticleEventCollision () {
- if (initializedEventCollision)
- particleEventCollision(manipulatorEventParticle);
- }
-
-
-
-
-
-
- public PlaygroundEventParticle GetParticle (int index) {
- if (particles==null || particles.Count==0 || index>particles.Count) return null;
- return GetParticle (particles[index].particleSystemId, particles[index].particleId);
- }
-
-
-
-
-
-
-
- public PlaygroundEventParticle GetParticle (int particleSystemId, int particleId) {
- PlaygroundEventParticle returnEventParticle = new PlaygroundEventParticle();
- if (PlaygroundC.reference.particleSystems[particleSystemId].UpdateEventParticle(returnEventParticle, particleId))
- return returnEventParticle;
- else return null;
- }
-
-
-
-
-
- public List<PlaygroundEventParticle> GetParticles () {
- List<PlaygroundEventParticle> returnEventParticles = new List<PlaygroundEventParticle>();
- for (int i = 0; i<particles.Count; i++) {
- if (PlaygroundC.reference.particleSystems[particles[i].particleSystemId].UpdateEventParticle(manipulatorEventParticle, particles[i].particleId))
- returnEventParticles.Add (manipulatorEventParticle.Clone());
- }
- return returnEventParticles;
- }
-
-
-
-
-
-
-
- public bool ContainsParticle (int particleSystemId, int particleId) {
- for (int i = 0; i<particles.Count; i++) {
- if (particles[i%particles.Count].particleSystemId==particleSystemId && particles[i%particles.Count].particleId==particleId)
- return true;
- }
- return false;
- }
-
-
-
-
-
-
- public bool IsSameId (int compareId) {
- if (manipulatorId==compareId)
- return true;
- return false;
- }
-
-
-
-
-
-
- public bool AddParticle (int particleSystemId, int particleId) {
- if (particles == null)
- return false;
- for (int i = 0; i<particles.Count; i++) {
- if (particles==null || particles[i]==null)
- return false;
- if (particles[i%particles.Count].particleSystemId==particleSystemId && particles[i%particles.Count].particleId==particleId)
- return false;
- }
- particles.Add (new ManipulatorParticle(particleSystemId, particleId));
- return true;
- }
-
-
-
-
-
-
-
- public bool RemoveParticle (int particleSystemId, int particleId) {
- if (particles == null)
- return false;
- bool didRemove = false;
- for (int i = 0; i<particles.Count; i++) {
- if (particles==null || particles[i]==null)
- return false;
- if (particles[i%particles.Count].particleSystemId==particleSystemId && particles[i%particles.Count].particleId==particleId) {
- particles.RemoveAt(i%particles.Count);
- didRemove = true;
- }
- }
- return didRemove;
- }
-
-
-
-
- public void KillAllParticles () {
- if (particles == null)
- return;
- for (int i = 0; i<particles.Count; i++) {
- if (i>=particles.Count || i<0) return;
- PlaygroundC.reference.particleSystems[particles[i].particleSystemId].Kill (particles[i].particleId);
- particles.RemoveAt(i);
- if (i>0) i--;
- }
- }
-
-
-
-
-
-
-
- public bool ContainsNonAffectedParticle (int particleSystemId, int particleId) {
- for (int i = 0; i<nonAffectedParticles.Count; i++) {
- if (nonAffectedParticles[i].particleSystemId==particleSystemId && nonAffectedParticles[i].particleId==particleId)
- return true;
- }
- return false;
- }
-
-
-
-
-
-
- public void AddNonAffectedParticle (int particleSystemId, int particleId) {
- nonAffectedParticles.Add (new ManipulatorParticle(particleSystemId, particleId));
- }
-
-
-
-
-
-
-
- public bool RemoveNonAffectedParticle (int particleSystemId, int particleId) {
- for (int i = 0; i<nonAffectedParticles.Count; i++) {
- if (nonAffectedParticles[i].particleSystemId==particleSystemId && nonAffectedParticles[i].particleId==particleId) {
- nonAffectedParticles.RemoveAt(i);
- return true;
- }
- }
- return false;
- }
-
-
-
-
-
-
-
- public bool LifetimeFilter (float life, float total) {
- if (!applyLifetimeFilter) return true;
- float normalizedLife = life/total;
- return (normalizedLife>=lifetimeFilterMinimum && normalizedLife<=lifetimeFilterMaximum);
- }
-
-
-
-
-
-
-
- public bool ParticleFilter (int p, int total) {
- if (!applyParticleFilter) return true;
- float normalizedP = (p*1f)/(total*1f);
- return (normalizedP>=particleFilterMinimum && normalizedP<=particleFilterMaximum);
- }
-
-
-
-
- public void Update () {
- if (enabled) {
- if (transform.Update()) {
- manipulatorId = transform.instanceID;
- if (trackParticles) {
- initializedEventEnter = (particleEventEnter!=null);
- initializedEventExit = (particleEventExit!=null);
- initializedEventBirth = (particleEventBirth!=null);
- initializedEventDeath = (particleEventDeath!=null);
- initializedEventCollision = (particleEventCollision!=null);
- } else {
- if (particles.Count>0)
- particles.Clear();
- }
- if (type==MANIPULATORTYPEC.Property || type==MANIPULATORTYPEC.Combined) {
- property.Update();
- property.SetLocalVelocity(transform.rotation, property.velocity);
- if (property.type == MANIPULATORPROPERTYTYPEC.Math)
- property.UpdateMathProperty(transform.position);
- for (int i = 0; i<properties.Count; i++) {
- properties[i].Update();
- properties[i].SetLocalVelocity(transform.rotation, properties[i].velocity);
- if (properties[i].type == MANIPULATORPROPERTYTYPEC.Math)
- properties[i].UpdateMathProperty(transform.position);
- }
- }
- }
- }
- }
-
- public void SetLocalTargetsPosition (Transform otherTransform) {
- property.SetLocalTargetsPosition(otherTransform);
- for (int i = 0; i<properties.Count; i++)
- properties[i].SetLocalTargetsPosition (otherTransform);
- }
-
-
-
-
- public ManipulatorObjectC Clone () {
- ManipulatorObjectC manipulatorObject = new ManipulatorObjectC();
- manipulatorObject.type = type;
- manipulatorObject.property = property.Clone();
- manipulatorObject.affects = affects;
- manipulatorObject.transform = transform.Clone();
- manipulatorObject.size = size;
- manipulatorObject.shape = shape;
- manipulatorObject.bounds = bounds;
- manipulatorObject.strength = strength;
- manipulatorObject.strengthSmoothing = strengthSmoothing;
- manipulatorObject.strengthDistanceEffect = strengthDistanceEffect;
- manipulatorObject.enabled = enabled;
- manipulatorObject.applyLifetimeFilter = applyLifetimeFilter;
- manipulatorObject.lifetimeFilterMinimum = lifetimeFilterMinimum;
- manipulatorObject.lifetimeFilterMaximum = lifetimeFilterMaximum;
- manipulatorObject.applyParticleFilter = applyParticleFilter;
- manipulatorObject.particleFilterMinimum = particleFilterMinimum;
- manipulatorObject.particleFilterMaximum = particleFilterMaximum;
- manipulatorObject.inverseBounds = inverseBounds;
- manipulatorObject.trackParticles = trackParticles;
- manipulatorObject.sendEventEnter = sendEventEnter;
- manipulatorObject.sendEventExit = sendEventExit;
- manipulatorObject.sendEventBirth = sendEventBirth;
- manipulatorObject.sendEventDeath = sendEventDeath;
- manipulatorObject.sendEventCollision = sendEventCollision;
- manipulatorObject.properties = new List<ManipulatorPropertyC>();
- manipulatorObject.axisConstraints = axisConstraints.Clone();
- for (int i = 0; i<properties.Count; i++)
- manipulatorObject.properties.Add(properties[i].Clone());
- return manipulatorObject;
- }
- }
-
-
-
-
- [Serializable]
- public class ManipulatorPropertyC {
-
-
-
- public MANIPULATORPROPERTYTYPEC type;
-
-
-
- public MANIPULATORPROPERTYTRANSITIONC transition;
-
-
-
- public MathManipulatorProperty mathProperty = new MathManipulatorProperty();
-
-
-
- public Vector3 velocity;
-
-
-
- public Vector3 localVelocity;
-
-
-
- public Color color = new Color(1,1,1,1);
-
-
-
- public Gradient lifetimeColor;
-
-
-
- public float size = 1f;
-
-
-
- public List<PlaygroundTransformC> targets = new List<PlaygroundTransformC>();
-
-
-
- public int targetPointer;
-
-
-
- public WorldObject meshTarget = new WorldObject();
-
-
-
- public SkinnedWorldObject skinnedMeshTarget = new SkinnedWorldObject();
-
-
-
- public bool meshTargetIsProcedural = false;
-
-
-
- public Matrix4x4 meshTargetMatrix = new Matrix4x4();
-
-
-
- public ParticleStateC stateTarget = new ParticleStateC();
-
-
-
- public PlaygroundSpline splineTarget;
-
-
-
- public SPLINETARGETMETHOD splineTargetMethod;
- public float splineTimeOffset;
- bool splineTargetIsReady;
-
-
-
- public bool useLocalRotation = false;
-
-
-
- public bool onlyColorInRange = true;
-
-
-
- public bool keepColorAlphas = true;
-
-
-
- public bool onlyPositionInRange = true;
-
-
-
- public bool onlySizeInRange = false;
-
-
-
- public float zeroVelocityStrength = 1f;
-
-
-
- public float strength = 1f;
- public bool unfolded = true;
-
-
-
- public TARGETSORTINGC targetSorting;
-
-
-
- [NonSerialized] public int[] targetSortingList;
-
-
-
- TARGETSORTINGC previousTargetSorting;
-
- public TURBULENCETYPE turbulenceType = TURBULENCETYPE.Simplex;
- public float turbulenceTimeScale = 1f;
- public float turbulenceScale = 1f;
- public bool turbulenceApplyLifetimeStrength;
- public AnimationCurve turbulenceLifetimeStrength;
- public SimplexNoise turbulenceSimplex;
-
-
-
-
-
- public void Update () {
- if (type==MANIPULATORPROPERTYTYPEC.Target) {
- for (int i = 0; i<targets.Count; i++)
- targets[i].Update();
- } else
- if (type==MANIPULATORPROPERTYTYPEC.MeshTarget) {
- if (meshTarget.gameObject!=null) {
- if (meshTarget.cachedId!=meshTarget.gameObject.GetInstanceID())
- meshTarget = PlaygroundParticlesC.NewWorldObject (meshTarget.gameObject.transform);
- if (meshTarget.mesh!=null) {
- meshTargetMatrix.SetTRS(meshTarget.transform.position, meshTarget.transform.rotation, meshTarget.transform.localScale);
- if (meshTargetIsProcedural)
- UpdateMeshTarget();
- }
- if (meshTarget.initialized && (targetSortingList==null || targetSortingList.Length!=meshTarget.vertexPositions.Length || previousTargetSorting!=targetSorting))
- TargetSorting();
- }
- } else
- if (type==MANIPULATORPROPERTYTYPEC.SkinnedMeshTarget) {
- if (skinnedMeshTarget.gameObject!=null) {
- if (skinnedMeshTarget.cachedId!=skinnedMeshTarget.gameObject.GetInstanceID() || !skinnedMeshTarget.initialized) {
- skinnedMeshTarget = PlaygroundParticlesC.NewSkinnedWorldObject (skinnedMeshTarget.gameObject.transform);
- }
- if (skinnedMeshTarget.initialized) {
- if (meshTargetIsProcedural)
- UpdateSkinnedMeshTarget();
- skinnedMeshTarget.BoneUpdate();
- PlaygroundC.RunAsync(()=>{
- skinnedMeshTarget.Update();
- });
- if (targetSortingList==null || targetSortingList.Length!=skinnedMeshTarget.vertexPositions.Length || previousTargetSorting!=targetSorting)
- TargetSorting();
- }
- }
- } else
- if (type==MANIPULATORPROPERTYTYPEC.StateTarget) {
- if (!stateTarget.initialized && (stateTarget.stateMesh!=null || stateTarget.stateTexture!=null) && stateTarget.stateTransform!=null) {
- stateTarget.Initialize();
- } else if (stateTarget.initialized && stateTarget.stateTransform!=null) {
- stateTarget.stateTransformMx.SetTRS(stateTarget.stateTransform.position, stateTarget.stateTransform.rotation, stateTarget.stateTransform.localScale);
- }
- if (stateTarget.initialized && (targetSortingList==null || targetSortingList.Length!=stateTarget.positionLength || previousTargetSorting!=targetSorting))
- TargetSorting();
- } else
- if (type==MANIPULATORPROPERTYTYPEC.SplineTarget) {
- splineTargetIsReady = splineTarget!=null&&splineTarget.IsReady();
- } else
- if (type==MANIPULATORPROPERTYTYPEC.Turbulence) {
- if (turbulenceSimplex==null)
- turbulenceSimplex = new SimplexNoise();
- } else
- if (type==MANIPULATORPROPERTYTYPEC.Math) {
-
- }
- }
-
- public void UpdateMathProperty (Vector3 manipulatorPosition) {
- if (mathProperty==null)
- mathProperty = new MathManipulatorProperty();
- mathProperty.Update (manipulatorPosition);
- }
-
-
-
-
- public void UpdateMeshTarget () {
- meshTarget.Update();
- }
-
-
-
-
- public void UpdateSkinnedMeshTarget () {
- skinnedMeshTarget.Update();
- }
-
-
-
-
-
- public void SetMeshTarget (GameObject gameObject) {
- meshTarget.gameObject = gameObject;
- }
-
-
-
-
-
- public void SetSkinnedMeshTarget (GameObject gameObject) {
- skinnedMeshTarget.gameObject = gameObject;
- }
-
-
-
-
-
- public bool SplineTargetIsReady () {
- return splineTargetIsReady;
- }
-
-
- public void TargetSorting () {
- if (type==MANIPULATORPROPERTYTYPEC.MeshTarget && !meshTarget.initialized || type==MANIPULATORPROPERTYTYPEC.SkinnedMeshTarget && !skinnedMeshTarget.initialized || type==MANIPULATORPROPERTYTYPEC.StateTarget && !stateTarget.initialized) return;
- targetPointer = 0;
- if (type==MANIPULATORPROPERTYTYPEC.MeshTarget)
- targetSortingList = new int[meshTarget.vertexPositions.Length];
- else if (type==MANIPULATORPROPERTYTYPEC.SkinnedMeshTarget)
- targetSortingList = new int[skinnedMeshTarget.vertexPositions.Length];
- else if (type==MANIPULATORPROPERTYTYPEC.StateTarget)
- targetSortingList = new int[stateTarget.positionLength];
- switch (targetSorting) {
- case TARGETSORTINGC.Scrambled:
- for (int i = 0; i<targetSortingList.Length; i++)
- targetSortingList[i]=i;
- PlaygroundC.ShuffleArray(targetSortingList);
- break;
- case TARGETSORTINGC.Linear:
- for (int i = 0; i<targetSortingList.Length; i++)
- targetSortingList[i]=i;
- break;
- case TARGETSORTINGC.Reversed:
- int x = 0;
- for (int i = targetSortingList.Length-1; i>0; i--) {
- targetSortingList[x]=i;
- x++;
- }
- break;
- }
- previousTargetSorting = targetSorting;
- }
-
- public void SetLocalVelocity (Quaternion rotation, Vector3 newVelocity) {
- localVelocity = rotation*newVelocity;
- }
-
- public void SetLocalTargetsPosition (Transform otherTransform) {
- for (int i = 0; i<targets.Count; i++)
- targets[i].SetLocalPosition (otherTransform);
- }
-
-
-
-
-
-
- public bool UpdateTarget (int index) {
- if (targets.Count>0) {
- index=index%targets.Count;
- targets[index].Update();
- }
- return targets[index].available;
- }
-
-
-
-
- public ManipulatorPropertyC Clone () {
- ManipulatorPropertyC manipulatorProperty = new ManipulatorPropertyC();
- manipulatorProperty.type = type;
- manipulatorProperty.transition = transition;
- manipulatorProperty.velocity = velocity;
- manipulatorProperty.color = color;
- manipulatorProperty.lifetimeColor = lifetimeColor;
- manipulatorProperty.size = size;
- manipulatorProperty.useLocalRotation = useLocalRotation;
- manipulatorProperty.onlyColorInRange = onlyColorInRange;
- manipulatorProperty.keepColorAlphas = keepColorAlphas;
- manipulatorProperty.onlyPositionInRange = onlyPositionInRange;
- manipulatorProperty.zeroVelocityStrength = zeroVelocityStrength;
- manipulatorProperty.strength = strength;
- manipulatorProperty.targetPointer = targetPointer;
- manipulatorProperty.targets = new List<PlaygroundTransformC>();
- for (int i = 0; i<targets.Count; i++)
- manipulatorProperty.targets.Add(targets[i].Clone());
- manipulatorProperty.meshTarget = meshTarget.Clone();
- manipulatorProperty.skinnedMeshTarget = skinnedMeshTarget.Clone();
- manipulatorProperty.stateTarget = stateTarget.Clone();
-
- manipulatorProperty.turbulenceType = turbulenceType;
- manipulatorProperty.turbulenceApplyLifetimeStrength = turbulenceApplyLifetimeStrength;
- manipulatorProperty.turbulenceScale = turbulenceScale;
- manipulatorProperty.turbulenceTimeScale = turbulenceTimeScale;
-
- manipulatorProperty.turbulenceLifetimeStrength = new AnimationCurve(turbulenceLifetimeStrength.keys);
-
-
- return manipulatorProperty;
- }
- }
-
-
-
-
- [Serializable]
- public class MathManipulatorProperty {
- public MATHMANIPULATORTYPE type;
- public MATHMANIPULATORPROPERTY property;
- public MATHMANIPULATORCLAMP clamp;
- public float clampCeil = 10f;
- public float clampFloor = 0;
- public float value = 1f;
- public Vector3 value3 = Vector3.up;
- public float rate = 1f;
- public Vector3 rate3 = Vector3.up;
-
- Vector3 value3Position;
-
-
-
-
- public void Update (Vector3 position) {
- value3Position = position+value3;
- }
-
-
-
-
-
-
-
-
-
- public Vector3 Evaluate (Vector3 inValue, float time) {
- Vector3 returnValue;
- if (clamp==MATHMANIPULATORCLAMP.ClampInValue)
- inValue = Clamp (inValue);
- switch (type) {
- case MATHMANIPULATORTYPE.Sin:
- returnValue = new Vector3(
- value3.x!=0? ClampOut(inValue.x+Mathf.Sin (time*rate3.x)*value3.x) : inValue.x,
- value3.y!=0? ClampOut(inValue.y+Mathf.Sin (time*rate3.y)*value3.y) : inValue.y,
- value3.z!=0? ClampOut(inValue.z+Mathf.Sin (time*rate3.z)*value3.z) : inValue.z
- );
- break;
- case MATHMANIPULATORTYPE.Cos:
- returnValue = Clamp(new Vector3(
- value3.x!=0? ClampOut(inValue.x+Mathf.Cos (time*rate3.x)*value3.x) : inValue.x,
- value3.y!=0? ClampOut(inValue.y+Mathf.Cos (time*rate3.y)*value3.y) : inValue.y,
- value3.z!=0? ClampOut(inValue.z+Mathf.Cos (time*rate3.z)*value3.z) : inValue.z
- ));
- break;
- case MATHMANIPULATORTYPE.Lerp:
- returnValue = Clamp(new Vector3(
- value3.x!=0? Mathf.Lerp (inValue.x, ClampOut(value3.x), time*rate3.x) : inValue.x,
- value3.y!=0? Mathf.Lerp (inValue.y, ClampOut(value3.y), time*rate3.y) : inValue.y,
- value3.z!=0? Mathf.Lerp (inValue.z, ClampOut(value3.z), time*rate3.z) : inValue.z
- ));
- break;
- case MATHMANIPULATORTYPE.Add:
- returnValue = inValue+ClampOut((Vector3.Scale (value3, rate3)*time));
- break;
- case MATHMANIPULATORTYPE.Subtract:
- returnValue = inValue-ClampOut((Vector3.Scale (value3, rate3)*time));
- break;
- default:
- returnValue = inValue;
- break;
- }
- return returnValue;
- }
-
-
-
-
-
-
-
-
-
- public Vector3 EvaluatePosition (Vector3 inValue, float time) {
- Vector3 returnValue;
- if (clamp==MATHMANIPULATORCLAMP.ClampInValue)
- inValue = Clamp (inValue);
- switch (type) {
- case MATHMANIPULATORTYPE.Sin:
- returnValue = ClampPosition(new Vector3(
- inValue.x+(Mathf.Sin (time*rate3.x)*value3.x),
- inValue.y+(Mathf.Sin (time*rate3.y)*value3.y),
- inValue.z+(Mathf.Sin (time*rate3.z)*value3.z)
- ));
- break;
- case MATHMANIPULATORTYPE.Cos:
- returnValue = ClampPosition(new Vector3(
- inValue.x+Mathf.Cos (time*rate3.x)*value3.x,
- inValue.y+Mathf.Cos (time*rate3.y)*value3.y,
- inValue.z+Mathf.Cos (time*rate3.z)*value3.z
- ));
- break;
- case MATHMANIPULATORTYPE.Lerp:
- returnValue = ClampPosition(new Vector3(
- Mathf.Lerp (inValue.x, value3Position.x, time*rate3.x),
- Mathf.Lerp (inValue.y, value3Position.y, time*rate3.y),
- Mathf.Lerp (inValue.z, value3Position.z, time*rate3.z)
- ));
- break;
- case MATHMANIPULATORTYPE.Add:
- returnValue = ClampPosition(inValue+(Vector3.Scale (value3, rate3)*time));
- break;
- case MATHMANIPULATORTYPE.Subtract:
- returnValue = ClampPosition(inValue-(Vector3.Scale (value3, rate3)*time));
- break;
- default:
- returnValue = inValue;
- break;
- }
- return returnValue;
- }
-
-
-
-
-
-
-
-
-
- public float Evaluate (float inValue, float time) {
- float returnValue;
- if (clamp==MATHMANIPULATORCLAMP.ClampInValue)
- inValue = Clamp (inValue);
- switch (type) {
- case MATHMANIPULATORTYPE.Sin:
- returnValue = value!=0? ClampOut(Mathf.Sin (time*rate)*value) : inValue;
- break;
- case MATHMANIPULATORTYPE.Cos:
- returnValue = value!=0? ClampOut(Mathf.Cos (time*rate)*value) : inValue;
- break;
- case MATHMANIPULATORTYPE.Lerp:
- returnValue = value!=0? Mathf.Lerp (inValue, ClampOut(value), time*rate) : inValue;
- break;
- case MATHMANIPULATORTYPE.Add:
- returnValue = ClampOut(inValue+(value*rate*time));
- break;
- case MATHMANIPULATORTYPE.Subtract:
- returnValue = ClampOut(inValue-(value*rate*time));
- break;
- default:
- returnValue = inValue;
- break;
- }
- return returnValue;
- }
-
- float Clamp (float val) {
- if (clamp==MATHMANIPULATORCLAMP.None) return val;
- return Mathf.Clamp (val, clampFloor, clampCeil);
- }
-
- Vector3 Clamp (Vector3 val) {
- if (clamp==MATHMANIPULATORCLAMP.None) return val;
- val = new Vector3 (
- Mathf.Clamp (val.x, clampFloor, clampCeil),
- Mathf.Clamp (val.y, clampFloor, clampCeil),
- Mathf.Clamp (val.z, clampFloor, clampCeil)
- );
- return val;
- }
-
- Vector3 ClampPosition (Vector3 val) {
- if (clamp==MATHMANIPULATORCLAMP.None) return val;
- val = new Vector3 (
- Mathf.Clamp (val.x, value3Position.x+clampFloor, value3Position.x+clampCeil),
- Mathf.Clamp (val.y, value3Position.y+clampFloor, value3Position.y+clampCeil),
- Mathf.Clamp (val.z, value3Position.z+clampFloor, value3Position.z+clampCeil)
- );
- return val;
- }
-
- float ClampOut (float val) {
- if (clamp!=MATHMANIPULATORCLAMP.ClampOutValue) return val;
- return Clamp (val);
- }
-
- Vector3 ClampOut (Vector3 val) {
- if (clamp!=MATHMANIPULATORCLAMP.ClampOutValue) return val;
- return Clamp (val);
- }
-
-
-
-
- public MathManipulatorProperty Clone () {
- MathManipulatorProperty clone = new MathManipulatorProperty();
- clone.type = type;
- clone.property = property;
- clone.clamp = clamp;
- clone.clampFloor = clampFloor;
- clone.clampCeil = clampCeil;
- clone.value = value;
- clone.value3 = value3;
- clone.rate = rate;
- clone.rate3 = rate3;
- return clone;
- }
- }
-
-
-
-
- [Serializable]
- public class ManipulatorParticle {
- public int particleSystemId;
- public int particleId;
- public ManipulatorParticle(int setParticleSystemId, int setParticleId) {
- particleSystemId = setParticleSystemId;
- particleId = setParticleId;
- }
- }
-
-
-
-
- [Serializable]
- public class PlaygroundTransformC {
-
-
-
- public Transform transform;
-
-
-
- public int instanceID;
-
-
-
- public bool available;
-
-
-
- public Vector3 position;
-
-
-
- public Vector3 localPosition;
-
-
-
- public Vector3 previousPosition;
-
-
-
- public Vector3 forward;
-
-
-
- public Vector3 up;
-
-
-
- public Vector3 right;
-
-
-
- public Quaternion rotation;
-
-
-
- public Quaternion inverseRotation;
-
-
-
- public Vector3 localScale;
-
-
-
- public Matrix4x4 transformMatrix = new Matrix4x4();
- public bool unfolded;
-
-
-
-
- public bool Update () {
- if (transform!=null) {
- instanceID = transform.GetInstanceID();
- previousPosition = position;
- position = transform.position;
- forward = transform.forward;
- up = transform.up;
- right = transform.right;
- rotation = transform.rotation;
- inverseRotation = rotation;
- inverseRotation.x=-inverseRotation.x;
- inverseRotation.y=-inverseRotation.y;
- inverseRotation.z=-inverseRotation.z;
- localScale = transform.localScale;
- available = true;
- } else {
- available = false;
- }
- return available;
- }
-
-
-
-
- public void UpdateMatrix () {
- if (available)
- transformMatrix.SetTRS(position, rotation, localScale);
- }
-
- public bool IsSameAs (Transform comparer) {
- return (transform==comparer);
- }
-
- public void SetZeroRotation () {
- rotation = Quaternion.identity;
- }
-
-
-
-
-
- public void SetFromTransform (Transform otherTransform) {
- transform = otherTransform;
- Update();
- }
-
-
-
-
-
- public void GetFromTransform (Transform otherTransform) {
- otherTransform.position = position;
- otherTransform.rotation = rotation;
- otherTransform.localScale = localScale;
- }
-
-
-
-
-
- public void SetLocalPosition (Transform otherTransform) {
- if (available)
- localPosition = otherTransform.InverseTransformPoint(transform.position);
- }
-
- public void SetPostitionAsLocal () {
- position = localPosition;
- }
-
-
-
-
-
- public int GetInstanceID () {
- return instanceID;
- }
-
-
-
-
- public PlaygroundTransformC Clone () {
- PlaygroundTransformC manipulatorTransform = new PlaygroundTransformC();
- manipulatorTransform.transform = transform;
- manipulatorTransform.available = available;
- manipulatorTransform.position = position;
- manipulatorTransform.forward = forward;
- manipulatorTransform.up = up;
- manipulatorTransform.right = right;
- manipulatorTransform.rotation = rotation;
- return manipulatorTransform;
- }
- }
-
-
-
-
- [Serializable]
- public class PlaygroundColliderC {
-
-
-
- public bool enabled = true;
-
-
-
- public Transform transform;
-
-
-
- public Plane plane = new Plane();
-
-
-
- public Vector3 offset;
-
-
-
-
- public void UpdatePlane () {
- if (!transform) return;
- plane.SetNormalAndPosition(transform.up, transform.position+offset);
- }
-
-
-
-
- public PlaygroundColliderC Clone () {
- PlaygroundColliderC playgroundCollider = new PlaygroundColliderC();
- playgroundCollider.enabled = enabled;
- playgroundCollider.transform = transform;
- playgroundCollider.plane = new Plane(plane.normal, plane.distance);
- playgroundCollider.offset = offset;
- return playgroundCollider;
- }
- }
-
-
-
-
- [Serializable]
- public class PlaygroundAxisConstraintsC {
-
-
-
- public bool x = false;
-
-
-
- public bool y = false;
-
-
-
- public bool z = false;
-
-
-
-
-
- public bool HasConstraints () {
- return x||y||z;
- }
-
-
-
- public PlaygroundAxisConstraintsC Clone () {
- PlaygroundAxisConstraintsC axisConstraints = new PlaygroundAxisConstraintsC();
- axisConstraints.x = x;
- axisConstraints.y = y;
- axisConstraints.z = z;
- return axisConstraints;
- }
- }
-
-
-
-
- [Serializable]
- public class PlaygroundGradientC {
- public Gradient gradient = new Gradient();
-
-
-
-
-
- public void CopyTo (PlaygroundGradientC copy) {
- copy.gradient.SetKeys (gradient.colorKeys, gradient.alphaKeys);
- }
- }
-
-
-
-
- [Serializable]
- public class PlaygroundEventC {
-
-
-
- public bool enabled = true;
-
-
-
- public bool sendToManager = false;
-
-
-
- [NonSerialized] public bool initializedTarget = false;
-
-
-
- [NonSerialized] public bool initializedEvent = false;
-
-
-
- public PlaygroundParticlesC target;
-
-
-
- public EVENTBROADCASTC broadcastType;
-
-
-
- public EVENTTYPEC eventType;
-
-
-
- public event OnPlaygroundParticle particleEvent;
-
-
-
- public EVENTINHERITANCEC eventInheritancePosition;
-
-
-
- public EVENTINHERITANCEC eventInheritanceVelocity;
-
-
-
- public EVENTINHERITANCEC eventInheritanceColor;
-
-
-
- public Vector3 eventPosition;
-
-
-
- public Vector3 eventVelocity;
-
-
-
- public Color32 eventColor = Color.white;
-
-
-
- public float eventTime = 1f;
-
-
-
- public float collisionThreshold = 10f;
-
-
-
- public float velocityMultiplier = 1f;
-
-
-
- float timer = 0f;
-
-
-
-
- public void Initialize () {
- initializedTarget = (target!=null && target.gameObject.activeSelf && target.gameObject.activeInHierarchy && target.enabled);
- initializedEvent = (particleEvent!=null);
- }
-
-
-
-
-
- public bool UpdateTime () {
- bool readyToSend = false;
- timer+=PlaygroundC.globalDeltaTime;
- if (timer>=eventTime) {
- readyToSend = true;
- timer = 0f;
- }
- return readyToSend;
- }
-
-
-
-
-
- public void SetTimer (float newTime) {
- timer = newTime;
- }
-
-
-
-
-
- public void SendParticleEvent (PlaygroundEventParticle eventParticle) {
- if (initializedEvent)
- particleEvent(eventParticle);
- }
-
-
-
-
- public PlaygroundEventC Clone () {
- PlaygroundEventC playgroundEvent = new PlaygroundEventC();
- playgroundEvent.enabled = enabled;
- playgroundEvent.target = target;
- playgroundEvent.eventType = eventType;
- playgroundEvent.eventInheritancePosition = eventInheritancePosition;
- playgroundEvent.eventInheritanceVelocity = eventInheritanceVelocity;
- playgroundEvent.eventInheritanceColor = eventInheritanceColor;
- playgroundEvent.eventPosition = eventPosition;
- playgroundEvent.eventVelocity = eventVelocity;
- playgroundEvent.eventColor = eventColor;
- playgroundEvent.eventTime = eventTime;
- playgroundEvent.collisionThreshold = collisionThreshold;
- playgroundEvent.velocityMultiplier = velocityMultiplier;
- playgroundEvent.particleEvent = particleEvent;
- playgroundEvent.broadcastType = broadcastType;
- return playgroundEvent;
- }
- }
-
-
-
-
- public enum MANIPULATORTYPEC {
-
-
-
- None,
-
-
-
- Attractor,
-
-
-
- AttractorGravitational,
-
-
-
- Repellent,
-
-
-
- Property,
-
-
-
- Combined,
-
-
-
- Vortex
- }
-
-
-
-
- public enum MANIPULATORPROPERTYTYPEC {
-
-
-
- None,
-
-
-
- Color,
-
-
-
- Velocity,
-
-
-
- AdditiveVelocity,
-
-
-
- Size,
-
-
-
- Target,
-
-
-
- Death,
-
-
-
- Attractor,
-
-
-
- Gravitational,
-
-
-
- Repellent,
-
-
-
- LifetimeColor,
-
-
-
- Vortex,
-
-
-
- MeshTarget,
-
-
-
- SkinnedMeshTarget,
-
-
-
- Turbulence,
-
-
-
- StateTarget,
-
-
-
- SplineTarget,
-
-
-
- Math
- }
-
-
-
-
- public enum MATHMANIPULATORTYPE {
-
-
-
- Sin,
-
-
-
- Cos,
-
-
-
- Lerp,
-
-
-
- Add,
-
-
-
- Subtract
- }
-
-
-
-
- public enum MATHMANIPULATORPROPERTY {
-
-
-
- Size,
-
-
-
- Rotation,
-
-
-
- Velocity,
-
-
-
- Position
- }
-
-
-
-
- public enum MATHMANIPULATORCLAMP {
-
-
-
- None,
-
-
-
- ClampInValue,
-
-
-
- ClampOutValue
- }
-
-
-
-
- public enum MANIPULATORPROPERTYTRANSITIONC {
-
-
-
- None,
-
-
-
- Lerp,
-
-
-
- Linear
- }
-
-
-
-
- public enum MANIPULATORSHAPEC {
-
-
-
- Sphere,
-
-
-
- Box
- }
-
- public enum PLAYGROUNDORIGINC {
- TopLeft, TopCenter, TopRight,
- MiddleLeft, MiddleCenter, MiddleRight,
- BottomLeft, BottomCenter, BottomRight
- }
-
-
-
-
- public enum PIXELMODEC {
-
-
-
- Bilinear,
-
-
-
- Pixel32
- }
-
-
-
-
- public enum COLORSOURCEC {
-
-
-
- Source,
-
-
-
- LifetimeColor,
-
-
-
- LifetimeColors
- }
-
- public enum COLORMETHOD {
- Lifetime,
- ParticleArray
- }
-
-
-
-
- public enum OVERFLOWMODEC {
-
-
-
- SourceTransform,
-
-
-
- World,
-
-
-
- SourcePoint
- }
-
-
-
-
- public enum TRANSITIONTYPEC {
-
-
-
- Linear,
-
-
-
- EaseIn,
-
-
-
- EaseOut,
- }
-
-
-
-
- public enum INDIVIDUALTRANSITIONTYPEC {
-
-
-
- Inherit,
-
-
-
- Linear,
-
-
-
- EaseIn,
-
-
-
- EaseOut,
- }
-
-
-
-
- public enum LERPTYPEC {
- PositionColor,
- Position,
- Color,
- }
-
-
-
-
- public enum SOURCEC {
-
-
-
- State,
-
-
-
- Transform,
-
-
-
- WorldObject,
-
-
-
- SkinnedWorldObject,
-
-
-
- Script,
-
-
-
- Paint,
-
-
-
- Projection,
-
-
-
- Spline
- }
-
-
-
-
- public enum SORTINGC {
-
-
-
- Scrambled,
-
-
-
- ScrambledLinear,
-
-
-
- Burst,
-
-
-
- Linear,
-
-
-
- Reversed,
-
-
-
- NearestNeighbor,
-
-
-
- NearestNeighborReversed,
-
-
-
- Custom
- }
-
-
-
-
- public enum BRUSHDETAILC {
-
-
-
- Perfect,
-
-
-
- High,
-
-
-
- Medium,
-
-
-
- Low
- }
-
-
-
-
- public enum COLLISIONTYPEC {
-
-
-
- Physics3D,
-
-
-
- Physics2D
- }
-
-
-
-
- public enum VELOCITYBENDINGTYPEC {
-
-
-
- SourcePosition,
-
-
-
- ParticleDeltaPosition
- }
-
-
-
-
- public enum TARGETSORTINGC {
- Scrambled,
- Linear,
- Reversed
- }
-
-
-
-
- public enum MASKSORTINGC {
- Linear,
- Reversed,
- Scrambled
- }
-
-
-
-
- public enum NEARESTNEIGHBORORIGINMETHOD {
-
-
-
- SourcePoint,
-
-
-
- Vector3,
-
-
-
- Transform
- }
-
-
-
-
- public enum SPLINETARGETMETHOD {
-
-
-
- SplineTime,
-
-
-
- ParticleTime
- }
-
-
-
-
- public enum MINMAXVECTOR3METHOD {
- Rectangular,
- RectangularLinear,
- Spherical,
- SphericalLinear,
-
-
- }
-
-
-
-
- public enum EVENTTYPEC {
- Birth,
- Death,
- Collision,
- Time
- }
-
-
-
-
- public enum EVENTBROADCASTC {
- Target,
- EventListeners,
- Both
- }
-
-
-
-
- public enum EVENTINHERITANCEC {
- User,
- Particle,
- Source
- }
-
-
-
-
- public enum TURBULENCETYPE {
-
-
-
- None,
-
-
-
- Simplex,
-
-
-
- Perlin
- }
-
-
-
-
- public enum VALUEMETHOD {
- Constant,
- RandomBetweenTwoValues
- }
-
-
-
-
- public enum ONDONE {
-
-
-
- Inactivate,
-
-
-
- Destroy
- }
-
-
-
-
-
-
-
-
- public enum ThreadMethod {
-
-
-
-
- NoThreads,
-
-
-
-
- OnePerSystem,
-
-
-
-
- OneForAll,
-
-
-
-
-
- Automatic
- }
-
-
-
-
-
-
-
-
- public enum ThreadMethodLocal {
-
-
-
- Inherit,
-
-
-
- NoThreads,
-
-
-
- OnePerSystem,
-
-
-
- OneForAll
- }
-
-
-
-
- public enum ThreadMethodComponent {
-
-
-
- InsideParticleCalculation,
-
-
-
- OnePerSystem,
-
-
-
- OneForAll
- }
-
-
-
-
-
-
- public enum TrackingMethod {
-
-
-
- ManipulatorId,
-
-
-
- ParticleId
- }
-
-
-
-
- public static class AnimationCurveExtensions {
-
-
-
-
-
- public static void Reset (this AnimationCurve animationCurve) {
- if (animationCurve==null)
- animationCurve = new AnimationCurve();
- Keyframe[] keys = new Keyframe[2];
- keys[1].time = 1f;
- animationCurve.keys = keys;
- }
-
-
-
-
-
- public static void Reset1 (this AnimationCurve animationCurve) {
- if (animationCurve==null)
- animationCurve = new AnimationCurve();
- Keyframe[] keys = new Keyframe[2];
- keys[1].time = 1f;
- keys[0].value = 1f;
- keys[1].value = 1f;
- animationCurve.keys = keys;
- }
-
- public static void Reset01 (this AnimationCurve animationCurve) {
- if (animationCurve==null)
- animationCurve = new AnimationCurve();
- Keyframe[] keys = new Keyframe[2];
- keys[1].time = 1f;
- keys[0].value = 0;
- keys[1].value = 1f;
- animationCurve.keys = keys;
- }
- }
-
-
-
-
- public delegate void OnPlaygroundParticle(PlaygroundEventParticle particle);
- }
|