From b24ab3957647190eb5bc43ca19911587801838f3 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Fri, 9 May 2025 17:09:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=8F=8D=E9=A6=88=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Controller/Body3DController.cs | 9 ++++- Assets/Scripts/Item/Body3DObjItem.cs | 19 ---------- Assets/Scripts/Item/LineModeItem.cs | 38 +++++++++++++++++++ Assets/Scripts/Item/LineModeItem.cs.meta | 11 ++++++ Assets/Scripts/Xml/XmlParser.cs | 9 +++++ Data/Xml/3DJiePao.xml | 2 +- 6 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 Assets/Scripts/Item/LineModeItem.cs create mode 100644 Assets/Scripts/Item/LineModeItem.cs.meta diff --git a/Assets/Scripts/Controller/Body3DController.cs b/Assets/Scripts/Controller/Body3DController.cs index 3f6ffe6b..4e45c22f 100644 --- a/Assets/Scripts/Controller/Body3DController.cs +++ b/Assets/Scripts/Controller/Body3DController.cs @@ -213,14 +213,21 @@ public class Body3DController : MonoSingleton { Parser(item.Value); } + + if (body.isLineModeItem) + { + GameObject obj = Utility.FindObj(body.Path); + obj.GetOrAddComponent().Init(body); + } } else { GameObject obj = Utility.FindObj(body.Path); - + //if (obj != null) { Debug.Log("????" + body.Path + "????"); }; var bodyObjItem = obj.GetOrAddComponent(); bodyObjItem.Init(body); + var lineModeItem = obj.GetOrAddComponent().Init(body); objs.Add(obj, bodyObjItem); } } diff --git a/Assets/Scripts/Item/Body3DObjItem.cs b/Assets/Scripts/Item/Body3DObjItem.cs index dbd9df84..5b5453b4 100644 --- a/Assets/Scripts/Item/Body3DObjItem.cs +++ b/Assets/Scripts/Item/Body3DObjItem.cs @@ -19,7 +19,6 @@ public class Body3DObjItem : MonoBehaviour private float lastClickTime; // ˫ʱֵ private const float doubleClickTimeThreshold = 0.3f; - Shader shader; private void Awake() { @@ -74,29 +73,11 @@ public class Body3DObjItem : MonoBehaviour } } #endif - private void OnChangeMatEvent(OnChangeMat t) - { - if (t.shader != null) - { - GetComponent().material.shader = t.shader; - if (body.lineModeWidth != 0) - { - GetComponent().material.SetFloat("_OutlineWidth", body.lineModeWidth); - } - } - else - { - GetComponent().material.shader = this.shader; - } - - } public void Init(Body3D.Body body) { this.body = body; - shader = GetComponent()?.material.shader; - TypeEventSystem.Global.Register(OnChangeMatEvent).UnRegisterWhenGameObjectDestroyed(this); if (body.subBody == null || body.subBody.Count == 0) { if (body.toggle != null) diff --git a/Assets/Scripts/Item/LineModeItem.cs b/Assets/Scripts/Item/LineModeItem.cs new file mode 100644 index 00000000..ba8377ff --- /dev/null +++ b/Assets/Scripts/Item/LineModeItem.cs @@ -0,0 +1,38 @@ +using QFramework; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using XMLTool; + +public class LineModeItem : MonoBehaviour +{ + Shader shader; + public Body3D.Body body; + public LineModeItem Init(Body3D.Body body) + { + this.body = body; + shader = GetComponent()?.material.shader; + TypeEventSystem.Global.Register(OnChangeMatEvent).UnRegisterWhenGameObjectDestroyed(this); + return this; + } + + + private void OnChangeMatEvent(OnChangeMat t) + { + if (t.shader != null) + { + GetComponent().material.shader = t.shader; + if (body.lineModeWidth != 0) + { + GetComponent().material.SetFloat("_OutlineWidth", body.lineModeWidth); + } + } + else + { + + GetComponent().material.shader = this.shader; + } + + } + +} diff --git a/Assets/Scripts/Item/LineModeItem.cs.meta b/Assets/Scripts/Item/LineModeItem.cs.meta new file mode 100644 index 00000000..223e80d0 --- /dev/null +++ b/Assets/Scripts/Item/LineModeItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c29f8a68d4de741499c43ccf8a9d6bf0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 884dd17a..071d1403 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -187,6 +187,7 @@ namespace XMLTool public Body parent; public float lineModeWidth = 0; + public bool isLineModeItem = false; //public Dictionary bodyList { get; set; } = new Dictionary(); } @@ -447,6 +448,14 @@ namespace XMLTool { float.TryParse(lineModeWidth.Value, out body.lineModeWidth); } + + + var isLineModeItem = bodyElement.Attribute("isLineModeItem"); + if (isLineModeItem != null) + { + bool.TryParse(isLineModeItem.Value, out body.isLineModeItem); + } + return body; } diff --git a/Data/Xml/3DJiePao.xml b/Data/Xml/3DJiePao.xml index 3fda8c5a..fc5dfd38 100644 --- a/Data/Xml/3DJiePao.xml +++ b/Data/Xml/3DJiePao.xml @@ -11432,7 +11432,7 @@ - +