zoukankan      html  css  js  c++  java
  • [Unity UGUI]卡卡西大法

    我一直以为我发过了,结果收到评论才发现是自己老年痴呆了 ;>

    =================================================================

    做这个就是仿NGUI的UIGridManager

    先上脚本

     1 using System.Collections;
     2 using System.Collections.Generic;
     3 using UnityEngine;
     4 
     5 public class CopyObjs : MonoBehaviour
     6 {
     7     public GameObject tempObj;
     8 
     9     public List<GameObject> copyObjList = new List<GameObject>();
    10 
    11     //[HideInInspector]
    12     [SerializeField]
    13     private int mCount;
    14 
    15     public int MaxCount
    16     {
    17         get { return mCount; }
    18         set
    19         {
    20             if (mCount == value) return;
    21             mCount = value;
    22             copyObjList.RemoveAll(obj=>obj == null);
    23             tempObj.SetActive(false);
    24 
    25             for (int i = mCount - copyObjList.Count; i > 0; i--)
    26             {
    27                 copyObjList.Add(GameObject.Instantiate(tempObj,transform));
    28             }
    29 
    30             for (int i = 0; i < copyObjList.Count; i++)
    31             {
    32                 if (Application.isPlaying || i < mCount)
    33                 {
    34                     copyObjList[i].SetActive(i < mCount);
    35                 }
    36                 else
    37                 {
    38                     DestroyImmediate(copyObjList[i]);
    39                 }
    40             }
    41 
    42             copyObjList.RemoveAll(obj => obj == null);
    43 
    44         }
    45     }
    46 }
    View Code

    搭配这个带土使用更香哦

     1 using System.Collections;
     2 using System.Collections.Generic;
     3 using UnityEditor;
     4 using UnityEngine;
     5 
     6 [CanEditMultipleObjects]
     7 [CustomEditor(typeof(CopyObjs),true)]
     8 public class CopyObjsEditor : Editor
     9 {
    10     CopyObjs mUICopy;
    11     private void OnEnable()
    12     {
    13         mUICopy = target as CopyObjs;
    14     }
    15 
    16     public override void OnInspectorGUI()
    17     {
    18         EditorGUILayout.LabelField("克隆的最大数量");
    19         mUICopy.MaxCount = EditorGUILayout.IntField("MaxCount",mUICopy.MaxCount);
    20         base.DrawDefaultInspector();
    21     }
    22 }
    View Code

    =================================================================

    好了大结局。。。。啊哈哈

  • 相关阅读:
    vCenter6.7的简单安装与使用
    大家来找茬
    Android APP分享功能实现
    为免费app嵌入Admob广告
    Google Admob广告Android全攻略1
    开始Admob广告盈利模式详细教程
    android软件中加入广告实现方法
    onWindowFocusChanged重要作用 and Activity生命周期
    WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式
    android之intent显式,显式学习
  • 原文地址:https://www.cnblogs.com/lovewaits/p/13060503.html
Copyright © 2011-2022 走看看