enum property + other script access

使用enum property

BOM2 项目中需要有一个单独的script控制mode的切换,其他scipt根据这个mode切换到哪一个enum来决定该mode下的一些功能的开启。一开 始我用的是inspector的方法,在enum的script里控制enum选择的值,然后在需要做判断的script里创建一个public变量来接 受enum值的变化。后来我改为完全用类的enum方法实现。
 
//ModeSelector.cs



using UnityEngine;

using System.Collections;



    public enum ModeEnum

    {

        AssemblyView,

        TearView,

        ProfileView,

        TiffView

    }



    public class ModeSelector : MonoBehaviour

    {

        private static int myVar;

        public static ModeEnum ModeEnumProperty 

        {

            get { return (ModeEnum)myVar; }

            set { myVar = (int)value; }

        }

        // Use this for initialization

        void Start()

        {

            ModeEnumProperty = ModeEnum.AssemblyView;

        }



        // Update is called once per frame

        void Update()

        {



        }



        void OnGUI()

        {

            if (GUI.Button(new Rect(Screen.width / 2 - 150, 50, 100, 20), "Tear Apart"))

            {

                ModeEnumProperty = ModeEnum.TearView;

            }

            if (GUI.Button(new Rect(Screen.width / 2 + 50, 50, 100, 20), "3D Viewer"))

            {

                ModeEnumProperty = ModeEnum.AssemblyView;

            }

        }

    }
//NavigationControl.cs



OnGUI()

{

    ...

    if(ModeSelector.ModeEnumProperty == ModeEnum.AssemblyView)

    {

        

        //something to do

        

    }

    ...

}

 

你可能感兴趣的:(property)