protected virtual GListItem TryCreateItem() { if (CellTemplate == null) { return(null); } GListItem rv = null; rv = _CellPool.TakeOut(); if (rv == null) { GameObject item = CUnityUtil.Instantiate(CellTemplate.gameObject) as GameObject; GListItem itemCon = GListItem.Get(item); itemCon.RectTrans.SetParent(_Content, false); rv = itemCon; if (HasChildButton && this.ClickItemButtonCallBack != null) { itemCon.OnItemClickButton = this.OnClickItemButton; } } GNewUITools.SetVisible(rv.RectTrans, true); return(rv); }
static int Instantiate(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 1) { Object arg0 = (Object)LuaScriptMgr.GetUnityObject(L, 1, typeof(Object)); Object o = CUnityUtil.Instantiate(arg0); LuaScriptMgr.Push(L, o); return(1); } else if (count == 3) { Object arg0 = (Object)LuaScriptMgr.GetUnityObject(L, 1, typeof(Object)); Vector3 arg1 = LuaScriptMgr.GetVector3(L, 2); Quaternion arg2 = LuaScriptMgr.GetQuaternion(L, 3); Object o = CUnityUtil.Instantiate(arg0, arg1, arg2); LuaScriptMgr.Push(L, o); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: Object.Instantiate"); } return(0); }
void OnPBLoaded(GameObject pb_cache, ref Transform _ground, GROUND_TYPE ground_type) { if (pb_cache != null) { //if (pb_cache == null) //{ // GameObject g_pb_new = obj as GameObject; // pb_cache = g_pb_new; //} if (_ground == null) { if (_GroundT != null && pb_cache != null) { GameObject g_g = CUnityUtil.Instantiate(pb_cache) as GameObject; if (g_g != null) { _ground = g_g.transform; _ground.SetParent(_GroundT, false); g_g.name = ground_type.ToString(); //g_g.SetActive(GroundType == ground_type); } } } } }
public void Show(TweenCallback cb) { if (_MaskGameObject == null) { Action <UnityEngine.Object> callback = (asset) => { _MaskGameObject = CUnityUtil.Instantiate(asset) as GameObject; if (_MaskGameObject == null) { return; } _MaskGameObject.transform.localScale = Vector3.one; _ImageComp = _MaskGameObject.transform.Find("Canvas/Image").GetComponent <Image>(); _TextComp = _MaskGameObject.transform.Find("Canvas/Text").GetComponent <Text>(); if (_ImageComp != null) { _ImageBenginAlpha = _ImageComp.color.a; var tweener = _ImageComp.DOFade(1, 0.5F); if (cb != null && tweener != null) { tweener.OnComplete <Tweener>(cb); } } if (_TextComp != null) { _TextBenginAlpha = _TextComp.color.a; _TextComp.DOFade(1, 0.5F); } }; CAssetBundleManager.AsyncLoadResource(CgMaskPath, callback, false); } else { _MaskGameObject.SetActive(true); _MaskGameObject.transform.localScale = Vector3.one; if (_ImageComp != null) { var c = _ImageComp.color; c.a = _ImageBenginAlpha; _ImageComp.color = c; var tweener = _ImageComp.DOFade(1, 0.5F); if (cb != null) { tweener.OnComplete <Tweener>(cb); } } if (_TextComp != null) { var c = _TextComp.color; c.a = _TextBenginAlpha; _TextComp.color = c; _TextComp.DOFade(1, 0.5F); } } }
protected GListItem TryCreateItem() { GListItem rv = null; #if IN_GAME rv = _Pool.TakeOut(); #endif if (rv == null) { RectTransform item = CUnityUtil.Instantiate(_CellRect) as RectTransform; item.SetParent(Trans, false); GListItem item_com = item.GetComponent <GListItem>(); if (item_com == null) { item_com = item.gameObject.AddComponent <GListItem>(); } //register events if (this.InitItemCallBack != null) { item_com.OnItemInit = this.OnShowItem; } if (this.ClickItemCallBack != null) { item_com.OnItemClick = this.OnClickItem; } //if (this.PressItemCallBack != null) //{ // item_com.OnItemPointerDown = this.OnPressItem; //} //if (this.ReleaseItemCallBack != null) //{ // item_com.OnItemPointerUp = this.OnReleaseItem; //} if (this.LongPressCallBack != null) { item_com.OnItemLongPress = this.OnLongPressItem; } if (HasChildButton && this.ClickItemButtonCallBack != null) { item_com.OnItemClickButton = this.OnClickItemButton; } rv = item_com; } GNewUITools.SetVisible(rv.RectTrans, true); return(rv); }
protected override void OnSafeInit() { base.OnSafeInit(); ScrollRect scrollRect = GetComponent <ScrollRect>(); for (int i = 0; i < 8; i++) { RectTransform item = CUnityUtil.Instantiate(CellTemplate) as RectTransform; item.SetParent(scrollRect.content, false); } }
public static GameObject Clone(this GameObject prefab) { if (null == prefab) { return(null); } var cloned = CUnityUtil.Instantiate(prefab) as GameObject; var prefabTransform = prefab.transform; cloned.transform.parent = prefabTransform.parent; // in NGUI, the localScale will be adjusted automatically according to the scale of camera. so restore it. cloned.transform.localScale = prefabTransform.localScale; return(cloned); }
public Object Get() { Object element = null; if (_Stack.Count == 0) { element = CUnityUtil.Instantiate(_Prefab); } else { element = _Stack.Pop(); } return(element); }
private void PlayCommonCG() { Action <UnityEngine.Object> callback = (asset) => { // 异步加载中 可能存在其他操作(比如cg结束 切换成功) if (asset == null || _CgXmlConfig.Path == null || !_CgXmlConfig.Path.Contains(asset.name)) { return; } var cg = CUnityUtil.Instantiate(asset) as GameObject; if (cg == null) { return; } var cgg = cg.GetComponent <CGGlobal>(); if (cgg == null) { Destroy(cg); return; } _CurCGGlobal = cgg; _CurCutscene = cg.GetComponentInChildren <Cutscene>(); _CurCutscene.CutsceneStarted += OnCutsceneStarted; _CurCutscene.CutsceneFinished += OnCutsceneFinished; if (_CgXmlConfig.StartCallback != null) { _CgXmlConfig.StartCallback(); _CgXmlConfig.StartCallback = null; } if (_CgXmlConfig.IsMaskShown) { _CGMask.Hide(); } if (_CurCutscene != null) { _CurCutscene.Optimize(); _CurCutscene.Play(); } }; CAssetBundleManager.AsyncLoadResource(_CgXmlConfig.Path, callback, false); }
private void CreateDefault() { var parentTrans = GetTransformParent(); if (parentTrans == null) { return; } var prefab = CAssetBundleManager.SyncLoadAssetFromBundle <GameObject>(path); if (prefab == null) { return; } var go = CUnityUtil.Instantiate(prefab) as GameObject; if (go != null) { go.name = EntityId; var goT = go.transform; if (clientPath != string.Empty) { GameObject goParent = GameObject.Find(clientPath); if (goParent) { goT.parent = goParent.transform; } goT.localPosition = position; goT.localRotation = Quaternion.Euler(rotation); } else { goT.parent = parentTrans; goT.position = position; goT.rotation = Quaternion.Euler(rotation); } Util.SetLayerRecursively(go, LAYER_CG); SetTransform(goT); if (type == EntityType.Sfx) { go.SetActive(false); } } }
protected GDragablePageItem CreateItem() { GDragablePageItem page_item = null; page_item = _Pool.TakeOut(); if (page_item == null) { RectTransform item = CUnityUtil.Instantiate(_CellItem) as RectTransform; item.SetParent(Trans, false); Vector2 new_pos = GNewUITools.GetAlignedPivot(NewAlign.Left); if (IsVertical) { new_pos = GNewUITools.GetAlignedPivot(NewAlign.Top); } item.pivot = new_pos; item.anchorMax = new_pos; item.anchorMin = new_pos; GDragablePageItem item_com = item.GetComponent <GDragablePageItem>(); if (item_com == null) { item_com = item.gameObject.AddComponent <GDragablePageItem>(); } if (this._PageItemInitCallBack != null) { item_com.OnItemInit = OnInitPageItem; } if (this._ClickPageItemCallBack != null) { item_com.OnItemClick = OnClickPageItem; } if (_HasChildButton && this._ClickPageItemButtonCallBack != null) { item_com.OnItemClickButton = this.OnClickPageItemButton; } page_item = item_com; } GNewUITools.SetVisible(page_item.RectTrans, true); return(page_item); }
private void OnPrefabLoaded(UnityEngine.Object obj_pf) { if (obj_pf == null) { Debug.LogWarning("Resource not found: " + this.FxPath); return; } _IsLoading = false; PoolPrefabe(FxPath, obj_pf); //1.Am I Destroyed? if (_CachedTrans == null || gameObject == null || Target == null) { return; } //2.Inst _FxObject = CUnityUtil.Instantiate(obj_pf) as GameObject; Transform t_fx = _FxObject.transform; t_fx.SetParent(_CachedTrans, false); //3.Adjust Layer if (_FxObject.layer != Target.layer) { Util.SetLayerRecursively(_FxObject, Target.layer); } //4.Adjust sorting mode _IsUSortDirty = true; if (gameObject.activeInHierarchy) { AjustSorting(); } //else if(_IsStarted) //{ // Debug.LogError("Playing fx on Inactive Node " + GNewUITools.PrintScenePath(_CachedTrans)); //} //5 //6 StartPlay(); }
private void PlayVideoCG() { if (_CommonVideoFrame == null) { if (_IsCommonVideoFrameLoading) { return; } Action <UnityEngine.Object> callback = (asset) => { var cg = CUnityUtil.Instantiate(asset) as GameObject; if (cg == null) { return; } _CommonVideoFrame = cg; _VideoRawImage = cg.transform.Find("UICanvas/UI_Video/Img_Video").GetComponent <RawImage>(); _DialogueRoot = cg.transform.Find("UICanvas/UIBasic/Down").gameObject; _DialogueNameText = _DialogueRoot.transform.Find("Name").GetComponent <Text>(); _DialogueContentText = _DialogueRoot.transform.Find("Content").GetComponent <Text>(); _IsCommonVideoFrameLoading = false; // 异步加载中 可能存在其他操作(比如cg结束 切换成功) if (asset == null || _CgXmlConfig.Path == null || !_CgXmlConfig.IsVideo) { return; } PlayVideoImp(); }; _IsCommonVideoFrameLoading = true; CAssetBundleManager.AsyncLoadResource(VIDEO_CG_COMMON_UI_PATH, callback, false); } else { PlayVideoImp(); } }
protected override GListItem TryCreateItem() { if (CellTemplate == null) { return(null); } GListItem rv = null; rv = _CellPool.TakeOut(); if (rv == null) { GameObject item = CUnityUtil.Instantiate(CellTemplate.gameObject) as GameObject; GListItem itemCon = GListItem.Get(item); rv = itemCon; if (HasChildButton && ClickItemButtonCallBack != null) { rv.OnItemClickButton = OnClickItemButton; } //register events if (InitItemCallBack != null) { rv.OnItemInit = OnShowItem; } if (ClickItemCallBack != null) { rv.OnItemClick = OnClickItem; } } rv.RectTrans.SetParent(_Content, false); GNewUITools.SetVisible(rv.RectTrans, true); return(rv); }
private void CreateHostPlayer() { Transform parent = GetTransformParent(); if (!parent) { return; } var hostPlayer = CUnityUtil.Instantiate(Main.HostPalyer.gameObject) as GameObject; if (hostPlayer != null) { var ob = hostPlayer.GetComponent <EntityComponent.ObjectBehaviour>(); ob.enabled = false; hostPlayer.name = EntityId; var hostPlayerT = hostPlayer.transform; hostPlayerT.parent = parent; hostPlayerT.position = position; hostPlayerT.rotation = Quaternion.Euler(rotation); Util.SetLayerRecursively(hostPlayer, LAYER_CG); SetTransform(hostPlayerT); } }
void CreateCam() { GameObject cam_obj = null; RenderTexture rt = null; if (_CameraPool != null) { cam_obj = _CameraPool.Get() as GameObject; if (cam_obj == null) { cam_obj = CUnityUtil.Instantiate(imageModelCameraSrc) as GameObject; rt = CUnityUtil.Instantiate(renderTextureSrc) as RenderTexture; } if (cam_obj != null) { //_RenderTexture = CreateRT(); //GameObject cam_obj = CreateCam(); cam_obj.SetActive(true); _IMRootT = cam_obj.transform; _IMRootT.localRotation = Quaternion.identity; //in case of |-><-|, looking at eact other _IMRootT.localPosition = Vector3.right * (2000 + _ID * VIEW_DIST * 2); _StageT = _IMRootT.Find("Stage"); if (_StageT == null) { return; } _PlatformT = _StageT.Find("Platform"); if (_PlatformT == null) { return; } _PlatformT.localRotation = Quaternion.identity; //shadow _GroundT = _StageT.Find("Ground"); if (_GroundT == null) { return; } _UICameraT = _IMRootT.Find("UICamera"); if (_UICameraT == null) { return; } _UICamera = _UICameraT.GetComponent <Camera>(); if (_UICamera == null) { return; } _UICamera.orthographic = true; _UICamera.orthographicSize = DEFAULT_CAM_SIZE; _UICamera.farClipPlane = VIEW_DIST; _UICamera.clearFlags = CameraClearFlags.Skybox; if (rt != null) { _UICamera.targetTexture = rt; } _UICamera.enabled = this.enabled; texture = _UICamera.targetTexture; //ground effect InitGroundEffect(); _CameraDist = STAGE_DIST; UpdateCameraRot(Vector3.zero); UpdateCameraPos(); //post effects SetupPP(); UpdatePP(); } } }
public override void SetActive(bool active) { if (arcs == null || arcs.Length == 0) { Common.HobaDebuger.LogErrorFormat("arcs of ArcReactor_Arc {0} is null", gameObject.name); enabled = false; return; } if (active) { for (int i = 0; i < arcs.Length; i++) { var sizeOptions = arcs[i].sizeOptions; if (sizeOptions != null && sizeOptions.startWidthCurve.keys.Length == 0 && (sizeOptions.onlyStartWidth || sizeOptions.endWidthCurve.keys.Length == 0)) { sizeOptions.startWidthCurve.AddKey(0, 0.5f); if (!sizeOptions.onlyStartWidth) { sizeOptions.endWidthCurve.AddKey(0, 0.5f); } } var oscillations = arcs[i].oscillations; if (oscillations != null) { for (int q = 0; q < oscillations.Length; q++) { if (Util.IsZero(oscillations[q].wavelength)) { enabled = false; return; } } } arcs[i].fadeOutTime = EFFECT_FADEOUT_TIME; arcs[i].StartFadeOutTime = 0; } _ElapsedTime = 0; #region 初始化 if (!_IsValid) { _EmitterSystems = new ParticleSystem[arcs.Length][]; _LineRenderers = new LineRenderer[arcs.Length]; //Service array initialization, actual data creation happens at Initialize() for (int n = 0; n < arcs.Length; n++) { _EmitterSystems[n] = new ParticleSystem[arcs[n].emissionOptions.Length]; var emissionOptions = arcs[n].emissionOptions; for (int q = 0; q < emissionOptions.Length; q++) { var ps = _EmitterSystems[n][q]; if (ps == null && emissionOptions[q].shurikenPrefab != null) { var partGameObject = (GameObject)CUnityUtil.Instantiate(emissionOptions[q].shurikenPrefab); ps = partGameObject.GetComponent <ParticleSystem>(); var em = ps.emission; em.enabled = false; partGameObject.transform.parent = transform; partGameObject.transform.localPosition = Vector3.zero; partGameObject.transform.localRotation = Quaternion.identity; _EmitterSystems[n][q] = ps; } } var rayLineRenderer = new GameObject("ArcLineRenderer"); rayLineRenderer.transform.parent = transform; _LineRenderers[n] = rayLineRenderer.AddComponent <LineRenderer>(); _LineRenderers[n].material = arcs[n].material; _LineRenderers[n].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; _LineRenderers[n].receiveShadows = false; _LineRenderers[n].material.SetFloat(ShaderIDs.ARCAlphaFadeOut, 1.0f); } _SegmentNums = new int[arcs.Length]; _VertexCounts = new int[arcs.Length]; _Vertices = new Vector3[arcs.Length][]; _IsValid = true; } #endregion } if (_IsValid) { foreach (var ess in _EmitterSystems) { if (ess != null) { foreach (var ps in ess) { if (ps == null) { continue; } var em = ps.emission; em.enabled = active; } } } foreach (var lr in _LineRenderers) { if (lr == null) { continue; } lr.enabled = active; } base.SetActive(active); } }