Exemple #1
0
 public static void SetUsableCollider(ref UseableCollider useableCollider, Transform root,
                                      ObjInfo info, int useTag, bool defaultEnable, bool create = false)
 {
     if (useableCollider == null)
     {
         Transform colliderTrans = null;
         if (!create)
         {
             colliderTrans = root.Find("useable");
         }
         if (null == colliderTrans)
         {
             GameObject go = new GameObject("useable");
             colliderTrans = go.transform;
             colliderTrans.SetParentIndentical(root);
         }
         useableCollider = colliderTrans.GetComponent <UseableCollider>();
         if (useableCollider == null)
         {
             useableCollider = colliderTrans.gameObject.AddComponent <UseableCollider>();
         }
     }
     useableCollider.collider = useableCollider.gameObject.GetComponent <SphereCollider>();
     if (useableCollider.collider == null)
     {
         useableCollider.collider = useableCollider.gameObject.AddComponent <SphereCollider>();
     }
     useableCollider.gameObject.SetActive(defaultEnable);
     useableCollider.useable          = defaultEnable;
     useableCollider.gameObject.layer = Const.LAYER_USABLE;
     useableCollider.info             = info;
     useableCollider.useTag           = useTag;
 }
Exemple #2
0
        private void DrawUsableColliderInfo()
        {
            ShowUtil.DrawTitle("使用的碰撞信息", Color.magenta);
            ShowUtil.DrawLine();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("添加", GUILayout.Width(120f)))
            {
                UseableCollider        collider     = EditorUtils.AddUsableCollider(furniture.transform, furnitureInfo, 3, true);
                List <UseableCollider> newColliders = new List <UseableCollider>(furnitureInfo.usableColliders);
                newColliders.Add(collider);
                furnitureInfo.usableColliders = newColliders.ToArray();
            }
            GUILayout.EndHorizontal();

            if (furnitureInfo.usableColliders == null || furnitureInfo.usableColliders.Length == 0)
            {
                EditorUtils.DrawNoCollider();
                return;
            }
            for (int i = 0; i < furnitureInfo.usableColliders.Length; ++i)
            {
                ShowUtil.DrawLine();
                EditorUtils.DrawUsableColliderInfo(ref furnitureInfo.usableColliders[i]);
            }
        }
Exemple #3
0
        //设置使用碰撞体
        public static UseableCollider AddUsableCollider(Transform root,
                                                        ObjInfo info, int useTag, bool defaultEnable)
        {
            UseableCollider useableCollider = null;

            SetUsableCollider(ref useableCollider, root, info, useTag, defaultEnable, true);
            return(useableCollider);
        }
Exemple #4
0
 private void OneExit(UseableCollider useCollider)
 {
     if (visibles.Contains(useCollider))
     {
         useCollider.onRelease =
             (Action <UseableCollider>)Delegate.Remove(useCollider.onRelease, CachedOnRemove);
         visibles.Remove(useCollider);
     }
 }
Exemple #5
0
 private void OneEnter(UseableCollider useCollider)
 {
     if (visibles.Contains(useCollider))
     {
         return;
     }
     useCollider.onRelease = (Action <UseableCollider>)Delegate.Combine(useCollider.onRelease, CachedOnRemove);
     visibles.Add(useCollider);
 }
Exemple #6
0
 public void EnableCheck(bool bEnable)
 {
     isEnabled = bEnable;
     triggerCollider.enabled = bEnable;
     if (!bEnable)
     {
         this.ReleaseAll();
     }
     currentTarget = null;
 }
Exemple #7
0
 public static void DrawUsableColliderInfo(ref UseableCollider useableCollider)
 {
     EditorGUI.indentLevel += 2;
     EditorGUILayout.ObjectField("碰撞体",
                                 useableCollider,
                                 typeof(ObjCollider), true);
     useableCollider.gameObject.layer = EditorGUILayout.LayerField("碰撞体层级", useableCollider.gameObject.layer, GUILayout.ExpandWidth(true));
     EditorGUILayout.ObjectField("信息体", useableCollider.info, typeof(ObjInfo), true);
     EditorGUILayout.ObjectField("Collider", useableCollider.collider, typeof(CapsuleCollider), true);
     EditorGUILayout.FloatField("使用半径", useableCollider.radius);
     useableCollider.useTag = EditorGUILayout.IntField("使用标记", useableCollider.useTag);
     useableCollider.gameObject.SetActive(
         EditorGUILayout.Toggle("默认开启", useableCollider.gameObject.activeSelf));
     useableCollider.useable = EditorGUILayout.Toggle("当前可用", useableCollider.useable);
     EditorGUI.indentLevel  -= 2;
 }
Exemple #8
0
        private void SetTarget(UseableCollider target)
        {
            if (target == currentTarget)
            {
                return;
            }
            currentTarget = target;
            if (null != onTargetSet)
            {
                int id     = -1;
                int useTag = -1;
                if (null != target)
                {
                    id     = target.GetId();
                    useTag = target.useTag;
                }

                onTargetSet(id, useTag);
            }
        }
Exemple #9
0
 private void Update()
 {
     if (enabled)
     {
         UseableCollider target  = null;
         float           dist    = float.MaxValue;
         Vector3         selfPos = Trans.position;
         foreach (var visibleOne in visibles)
         {
             if (visibleOne.IsValid() && visibleOne.useable)
             {
                 Vector3 delta     = visibleOne.Trans.position - selfPos;
                 float   deltaDist = Mathf.Max(0f, delta.magnitude - visibleOne.radius);
                 if (deltaDist < dist)
                 {
                     dist   = deltaDist;
                     target = visibleOne;
                 }
             }
         }
         SetTarget(target);
     }
 }
Exemple #10
0
 private void RemoveOne(UseableCollider useCollider)
 {
     visibles.Remove(useCollider);
 }