local state=0 --0Short 1Long local color_state=0 --0 White   Others: the state of color. local to_color = Color.__new(1,0,0,1)--Color of preference function onUse(use) --Synchronization-------------------------------- if vci.state.Get("STATE")==nil then--Synchronization of the state vci.state.Set("STATE",state) else state=vci.state.Get("STATE")--Get the state from the sync variable when gripped end if vci.state.Get("STATE")==nil then--Synchronization of the light_state vci.state.Set("COLOR_STATE",color_state) else state=vci.state.Get("STATE")--Get the state from the sync variable when gripped end --State of the light------Executed when the base part is gripped--------------- if use=="light_forstage" then print("base_grab_OK")--------------- if state==0 then vci.assets._ALL_PlayAnimationFromName("light_long",false) state=1 vci.state.Set("STATE",state) elseif state==1 then vci.assets._ALL_PlayAnimationFromName("light_short",false) state=0 vci.state.Set("STATE",state) end end --Executed when the lampshade is gripped------------------------- if use=="light_controller" then color_state=color_state+1 print("light_grab_OK")--------------- if color_state>7 then color_state=0--to the prefered color end vci.state.Set("COLOR_STATE",color_state)--同期 if color_state==0 then to_color = Color.__new(1,1,1,0.2)--The prefered color vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==1 then to_color = Color.__new(1,0,0,0.2)--red vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==2 then to_color = Color.__new(1,0.65,0,0.2)--orange vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==3 then to_color = Color.__new(1,1,0,0.2)--yellow vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==4 then to_color = Color.__new(0,0.5,0,0.2)--green vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==5 then to_color = Color.__new(0,1,1,0.2)--blue vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==6 then to_color = Color.__new(0,0,1,0.2)--indigo vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==7 then to_color = Color.__new(0.5,0,0.5,0.2)--violet vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) else ---- Do nothing end end----------- end