예제 #1
0
    private void Awake()
    {
        NEventListener listener = GetComponent <NEventListener>();

        listener.AddClick(OnClick);
        userPackage = FacadeSingleton.Instance.RetrieveData(ConstVal.Package_User) as UserPackage;
    }
예제 #2
0
    //reload prefab of building
    public void ReloadModel()
    {
        GameObject prefab = null;

        if (mState == BuildingState.Locked)
        {
            prefab = Resources.Load <GameObject>("Prefabs/Building/lock");
        }
        else
        {
            NBuildingInfo info = sanctuaryPackage.GetBuildingInfo(buildingID);
            if (info == null)
            {
                return;
            }
            BUILDING configData = sanctuaryPackage.GetBuildingConfigDataByConfigID(info.configID);
            string   prefabName = configData.PrefabName;
            prefabName = prefabName.Substring(0, prefabName.IndexOf("."));
            prefab     = Resources.Load <GameObject>("Prefabs/Building/model/" + prefabName);
        }
        if (prefab == null)
        {
            return;
        }
        if (buildingGo != null)
        {
            buildingGo.SendMessage("ClearHud", SendMessageOptions.DontRequireReceiver);
            DestroyImmediate(buildingGo);
        }

        buildingGo = Instantiate(prefab);
        buildingGo.transform.parent        = transform;
        buildingGo.transform.localPosition = Vector3.zero;
        buildingGo.transform.localRotation = Quaternion.identity;
        hudBinder = buildingGo.AddComponent <HudBinder>();
        Transform pos = buildingGo.transform.Find("pos");

        if (pos != null)
        {
            hudBinder.SetTarget(pos.gameObject);
        }

        NEventListener listener = buildingGo.AddComponent <NEventListener>();

        listener.AddClick(OnClick);
    }