源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

211 wiersze
7.0 KiB

--ui挂接模型处理, 单一模型展示,比如只显示武器,不显示人物模型
UIPartModelClass = UIPartModelClass or BaseClass()
local UIPartModelClass = UIPartModelClass
--当前正在使用的rendertexture列表
function UIPartModelClass:__init(go, parent, res_id, texture_id, modelPartPos,type,raycastParent,texture_size,model_scale)
self.gameObject = go
self.parent = parent
self.particle_list = {}
self.pos_x = 0
self.curr_index = UIModelClassByRT.GetRenderTextureIndex()
self.gameObject.transform.position = Vector3(self.curr_index * 100,0,0)
self.raycastParent = raycastParent
self:SetData(parent, res_id, texture_id, modelPartPos, type,texture_size,model_scale)
self:AddEvents()
end
function UIPartModelClass:__delete()
UIModelClassByRT.using_render_texture_list[self.curr_index] = nil
if self.clothe then
self.clothe:DeleteMe()
self.clothe = nil
end
destroy(self.gameObject)
if self.raycastGo then
destroy(self.raycastGo)
end
if self.rt then
self.rt:Release()
destroy(self.rt)
self.rt = nil
end
end
--UIPartModelConfig 模型位置,大小等的配置,由策划自己去调整
function UIPartModelClass:SetData(parent, res_id, texture_id, modelPartPos, role_type, texture_size,model_scale)
local cfg = UIPartModelConfig[res_id]
local size = nil
local rotate = nil
local can_rotate = nil
local position = nil
local scale = nil
if cfg then
size = cfg.size
rotate = cfg.rotate
can_rotate = cfg.can_rotate
position = cfg.position
scale = cfg.scale
end
self.res_id = res_id
self.texture_id = texture_id
self.type = role_type or nil
self.size = texture_size or size or Vector2(600,360)
self.rotate = 0
self.can_rotate = can_rotate == nil or can_rotate == true
self.scale = model_scale or scale
self.position = position
self.camera = self.gameObject.transform:Find("Camera"):GetComponent("Camera")
local role_con = self.gameObject.transform:Find("role")
role_con.localPosition = Vector3(0, 0, 500)
local anName = ModelPartName[role_type] .. res_id
local resName = ModelPartName[role_type] .. res_id
if modelPartPos == FashionPartPos.Weapon then
anName = "model_wepon_" .. res_id
resName = ModelPartName[role_type] .. res_id
else
end
local function loadRoleCallback(objs)
if self._use_delete_method then
return
end
if not objs or not objs[0] then
return
end
if self.role then
destroy(self.role)
end
self.role = newObject(objs[0])
local custom_speed = Config.ConfigModelSpeed.ModelActionSpeed[tonumber(res_id)]
if custom_speed then
local animator = self.role:GetComponent("Animator")
if animator then
animator.speed = custom_speed
end
end
self.role:GetComponent("Animator").cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
self.role.transform:SetParent(role_con)
self.role.transform.localRotation = Quaternion.identity
if position then
-- self.role.transform.localPosition = position
SetLocalPosition(self.role.transform, position.x, position.y, position.z)
else
SetLocalPosition(self.role.transform, 0)
-- self.role.transform.localPosition = Vector3(0,0,0)
end
if self.scale then
self.role.transform.localScale = Vector3(self.scale,self.scale,self.scale)
else
self.role.transform.localScale = Vector3(100,100,100)
end
local rotate_type = type(rotate)
if rotate_type == "number" then
self.role.transform:Rotate(Vector3(0, 180 + (rotate), 0))
self.rotate = rotate
elseif rotate_type == "table" then
self.role.transform:Rotate(rotate)
self.rotate = rotate.y
else
self.role.transform:Rotate(Vector3(0, 180, 0))
self.rotate = 0
end
-- self.role.transform:Rotate(Vector3(0, 180 + (self.rotate), 0))
local animator = self.role:GetComponent("Animator")
if animator then
animator:CrossFade( "idle2",0, 0.0 )
end
if texture_id then
self:CreateClothTexture(res_id, texture_id)
end
end
local renderSize = {x = 1500, y = 900}
self.rt = UnityEngine.RenderTexture.New(renderSize.x, renderSize.y, 24)
self.camera.targetTexture = self.rt
parent:GetComponent("RawImage").texture = self.rt
--size = size or Vector2(600,360)
parent.sizeDelta = Vector2(self.size.x, self.size.y)
LuaResManager:getInstance():loadPrefab(self,anName,resName, loadRoleCallback, true)
end
--贴图
function UIPartModelClass:CreateClothTexture(fashion_model_id, texture_id)
self.fashion_model_id = fashion_model_id
self.texture_id = texture_id
if fashion_model_id and texture_id and tonumber(texture_id) ~= 0 and self.gameObject then --使用贴图
if self.clothe then
self.clothe:DeleteMe()
self.clothe = nil
end
local texture_res = fashion_model_id .. "_" .. texture_id
self.skin_mesh_renderer = self.gameObject:GetComponentInChildren(typeof(UnityEngine.SkinnedMeshRenderer))
if self.skin_mesh_renderer and self.skin_mesh_renderer.material and texture_res then
self.clothe = Clothe.New(self.skin_mesh_renderer.material,texture_res)
end
end
end
function UIPartModelClass:AddEvents()
if self.can_rotate then
local function touch_begin(target,pos_x, pos_y)
self.pos_x = pos_x
end
local function draging(target,pos_x, pos_y)
self:OnDragging(pos_x, pos_y)
end
local function touch_end(target,pos_x, pos_y)
end
local rtGo = self.parent.gameObject
-- AddDownEvent(self.parent.gameObject, touch_begin)
if self.raycastParent then
self.parent:GetComponent("RawImage").raycastTarget = false
self.raycastGo = GameObject.New("raycast_"..self.parent.gameObject.name)
self.raycastGo.transform:SetParent(self.raycastParent.transform)
local eImage = self.raycastGo:AddComponent(typeof(LuaFramework.EmptyRaycast))
self.raycastGo.transform.position = self.parent.position
self.raycastGo.transform.sizeDelta = Vector2(self.size.x, self.size.y)
self.raycastGo.transform.localScale = Vector3.one
eImage.raycastTarget = true
if type(self.raycastParent) ~= "userdata" and self.raycastParent.use_background then
self.raycastGo.transform:SetSiblingIndex(1)
else
self.raycastGo.transform:SetSiblingIndex(0)
end
rtGo = self.raycastGo
else
self.parent:GetComponent("RawImage").raycastTarget = true
end
AddDragBeginEvent(rtGo, touch_begin)
AddDragEvent(rtGo, draging)
AddDragEndEvent(rtGo, touch_end)
-- AddUpEvent(self.parent.gameObject, touch_end)
else
self.parent:GetComponent("RawImage").raycastTarget = false
end
end
function UIPartModelClass:OnDragging(pos_x, pos_y)
if pos_x and self.pos_x then
local delta_x = pos_x - self.pos_x
if self.role then
if delta_x > 0 then
self.rotate = self.rotate - 10
-- self.role.transform:Rotate(Vector3(0, -10, 0))
self.role.transform:Rotate(Vector3.up, -10, UnityEngine.Space.World)
else
self.rotate = self.rotate + 10
-- self.role.transform:Rotate(Vector3(0, 10, 0))
self.role.transform:Rotate(Vector3.up, 10, UnityEngine.Space.World)
end
self.pos_x = pos_x
end
else
print("---UIPartModelClass--OnDragging-pos_x-:", pos_x)
print("---UIPartModelClass--OnDragging-pos_y-:", pos_y)
end
end