自写底层。粗糙版-只有场景加载

闲着蛋疼,写了套底层。就写了场景底层。很粗略的

首先场景加载脚本

using UnityEngine;
using System.Collections;

public class XScene : MonoBehaviour
{
    private string mScenePath = "";
    private GameObject mParent;
    private GameObject mUI;
	void Start ()
    {
        OnStart();
        StartCoroutine(LoadScenePath());
	}

	void Update ()
    {
        OnUpdata();
	}

    ///  接管上层用户点击事件 
    protected virtual void OnClickUIButton(GameObject click) { }
    protected virtual void OnStart() { }
    protected virtual void OnUpdata() { }



    public void SetScenePath(string path)
    {
        mScenePath = "Assets/UI/" + path + ".prefab";
    }
    public void ClickUIButton(GameObject click)
    {
        OnClickUIButton(click);
    }
    /// 
    /// 异步加载场景
    /// 
    /// 
    public IEnumerator LoadScenePath()
    {
        yield return 1;
        //if (mScenePath.Equals("") != true)
        {
            mParent = GameObject.Find("UIPrefab");

            GameObject prefab = Resources.LoadAssetAtPath(mScenePath,typeof(GameObject)) as GameObject;
            mUI = GameObject.Instantiate(prefab) as GameObject;
            Debug.Log(mUI.name + "----" + prefab.name);
            mUI.name = "UI";
            mUI.transform.parent = this.transform;
            mUI.transform.localPosition = Vector3.zero;
            mUI.transform.localEulerAngles = Vector3.zero;
            mUI.transform.localScale = Vector3.one;

            BoxCollider[] triggers = mUI.GetComponentsInChildren(true);
            BoxCollider trigge;
            for (int i = 0, max = triggers.Length; i < max; i++)
            {
                trigge = triggers[i];
                UIEventListener listener = UIEventListener.Get(trigge.gameObject);
                listener.onClick = ClickUIButton;
            }
        }
    }
}

然后总管理脚本

using UnityEngine;
using System.Collections;
using System;

public class Manages : MonoBehaviour
{

	void Start ()
    {
        XScene scene = ShowScene(typeof(PlaneGamePlay));
	}
    public XScene ShowScene(Type type)
    {
        XScene scene = null;
        GameObject obj = new GameObject(type.Name);
        obj.transform.parent = this.transform;
        obj.transform.localPosition = Vector3.zero;
        obj.transform.localEulerAngles = Vector3.zero;
        obj.transform.localScale = Vector3.one;
        scene = obj.AddComponent(type) as XScene;
        return scene;
    }
}

然后scene上层用户脚本模版

using UnityEngine;
using System.Collections;

public class PlaneGamePlay : XScene
{
    protected override void OnStart()
    {
        base.SetScenePath("UIPanelGamePlay");
        base.OnStart();
    }
    protected override void OnUpdata()
    {
        base.OnUpdata();
    }
    protected override void OnClickUIButton(GameObject click)
    {
        base.OnClickUIButton(click);
    }
}

 

本文链接:

https://www.bobsong.net/147.html
1 + 5 =
快来做第一个评论的人吧~