private void OnCheckAtlas() { _selectHit = null; _selectSpriteName = ""; HitManager.Clear(); List <Object> prefabList = GetPrefabs(); foreach (Object obj in prefabList) { GameObject go = obj as GameObject; List <UISprite> sprites = PrefabSpriteManager.GetAllSprite(go); foreach (UISprite sprite in sprites) { if (sprite.atlas != _targetAtlas) { continue; } foreach (UISpriteData data in _targetAtlas.spriteList) { HitManager managr = HitManager.GetManager(data.name); if (sprite.spriteName != data.name) { continue; } string path = GameObjectExt.GetHierarchyWithRoot(sprite.transform, go.transform); managr.SetEditPrefab(go); managr.AddHit(path); } } } }
public float FindClosestRopePosition(Vector3 pos_ws) { float closestDistance = 99999.0f; float bestPosition = -1.0f; for (int i = 0; i < m_Links.Count; i++) { var link = m_Links[i]; Vector3 linkStart = link.transform.TransformPoint(Vector3.up); Vector3 linkEnd = link.transform.TransformPoint(Vector3.down); Vector3 closestPointToPos = GameObjectExt.NearestPointOnFiniteLine(linkStart, linkEnd, pos_ws); float dist = (closestPointToPos - pos_ws).magnitude; if (dist < closestDistance) { closestDistance = dist; // Find placement along link float t = Vector3.Dot(link.transform.TransformDirection(Vector3.down), closestPointToPos - linkStart) / (linkEnd - linkStart).magnitude; bestPosition = i + Mathf.Clamp(t, 0.0f, 0.99f); } } return(bestPosition); }
/// <summary> /// 添加组件 /// </summary> /// <param name="type"></param> public void AddComponent(Type type) { if (GameObjectExt != null) { GameObjectExt.AddComponent(type); } }
public UIComponentInfo(GameObject go, Transform prefabRoot) { this.comType = "GameObject"; this.memberName = go.name; this.path = GameObjectExt.GetHierarchyWithRoot(go.transform, prefabRoot); uid = MD5Hashing.HashString(string.Format("{0}:{1}|{2}", prefabRoot.name, this.memberName, this.path)); }
// Use this for initialization void Start() { //NetMgr.GetInstance ().connect ("113.105.250.96", 12000); gameObject.AddComponent <GlobalTimer>(); GameObjectExt.Instantiate(Resources.Load <UnityEngine.Object>("UILoading")); ShowLoadingBar(); }
public UIComponentInfo(Component component, Transform prefabRoot) { // this.com = component; this.comType = component.GetType().Name; this.memberName = string.Format("{0}_{1}", component.name, comType); this.path = GameObjectExt.GetHierarchyWithRoot(component.transform, prefabRoot); uid = MD5Hashing.HashString(string.Format("{0}:{1}|{2}", prefabRoot.name, this.memberName, this.path)); }
// Use this for initialization void Start() { Instance = this; NetMgr.Instance.connect("192.168.0.100", 8888); gameObject.AddComponent <GlobalTimer>(); GameObjectExt.Instantiate(Resources.Load <UnityEngine.Object>("UILoading")); ShowLoadingBar(); }
public void ChangeTargetPOI(Vertex nextTargetPOI) { if (targetPOI) { Destroy(targetPOI.gameObject.GetComponent <LineRenderer>()); } targetPOI = nextTargetPOI; path = graph.GetPathToNextPointOfInterest(pOI, targetPOI, this); GameObjectExt.DrawCircle(targetPOI.gameObject, 1, 0.1f); }
public static GameObject InstantGameObject(Object original, GameObject parent) { var obj = GameObjectExt.Instantiate(original) as GameObject; if (obj) { obj.transform.parent = parent.transform.parent; } return(obj); }
public static GameObject GetGameObject(string relativePath, bool depends = false) { Resource res; UnityEngine.Object original; res = ResourceMgr.Instance.GetResource(relativePath); original = res.MainAsset; res.Destory(false, true); return(GameObjectExt.Instantiate(original) as GameObject); }
/// 获得一个组件,如果该组件不存在,则添加一个到对象上 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T GetOrAddComponent <T>() where T : Component { string key = typeof(T).Name; Component exists = mComponents.get(key); if (exists == null) { exists = GameObjectExt.getOrAddComponent <T>(); mComponents.add(key, exists); } return((T)exists); }
public void UpdateEffects() { var reouts = new List <RenderEffectsOut>(); foreach (var ire in m_RenderEffects) { var reo = new RenderEffectsOut(); ire.GetRenderEffects(ref reo); reouts.Add(reo); } var finalReout = new RenderEffectsOut(); finalReout.m_Color = Color.white; finalReout.m_Visible = true; foreach (var renderer in GameObjectExt.GetComponentsInSelfOrChildren <Renderer>(gameObject)) { finalReout.m_Renderers.Add(renderer); } reouts.Sort((x, y) => x.m_Priority.CompareTo(y.m_Priority)); foreach (var reo in reouts) { if (reo.m_Color.HasValue) { finalReout.m_Color = reo.m_Color; } if (reo.m_Visible.HasValue) { finalReout.m_Visible = reo.m_Visible; } foreach (var renderer in reo.m_Renderers) { finalReout.m_Renderers.Add(renderer); } } { foreach (var renderer in finalReout.m_Renderers) { Material mat = renderer.material; Color finalColor = finalReout.m_Color.Value; //bool renderEnabled = finalReout.m_Visible.Value; mat.SetColor("_Color", finalColor); //renderer.enabled = renderEnabled; } } }
public void OnTick(float dt) { if (_isLoadingComplete) { _isLoadingComplete = false; isLoading = false; TickMgr.Instance.RemoveTick(this); Resource resPrefab = ResourceMgr.Instance.GetResource(URLConst.GetScenePrefab(m_sceneId)); m_kScenePrefab = GameObjectExt.Instantiate(resPrefab.MainAsset, true) as GameObject; GameObject.DontDestroyOnLoad(m_kScenePrefab); resPrefab.Destory(false, true); DownLoadCompleteAll(); } }
public static void SharedFixedUpdate(StateArgs args) { var pargs = args as PlanetsStateArgs; if (pargs.m_RawControl_controller.y > 0.8f) { // Check if there is a link to climb on. var rl = GameObjectExt.GetNearestObject <RopeLink>(args.m_Character.transform.position, 1.0f, GameObjectExt.GetLayerMask("Rope")); if (rl != null) { pargs.m_PlanetsCharacter.m_ClimbState.m_Rope = rl.m_Rope; pargs.m_PlanetsCharacter.m_ClimbState.m_RopePosition = rl.m_Rope.FindClosestRopePosition(args.m_Character.transform.position); pargs.ChangeState(pargs.m_PlanetsCharacter.m_ClimbState); } } }
private void SetBullet(IzCommonEffect effect) { if (effect.m_kGO == null || effect.m_kTRS == null) { return; } if (_gameObject != null) { GameObjectExt.Destroy(_gameObject); } _effect = effect; _gameObject = _effect.m_kGO; _gameObject.name = "defaultBullet"; _transform = _effect.m_kTRS; _transform.localPosition = _pos; //_transform.forward = _dir; //_gameObject.SetActive(false); }
public void ReplaceModel(Transform trans) { if (m_Transform == null && m_DefaultTransform != null) { trans.parent = m_DefaultTransform.parent; trans.gameObject.ResetAll(); trans.position = m_DefaultTransform.position; trans.rotation = m_DefaultTransform.rotation; trans.localScale = m_DefaultTransform.localScale; trans.name = m_DefaultTransform.name; GameObjectExt.Destroy(m_DefaultTransform.gameObject); m_Transform = trans; m_DefaultTransform = null; } else { throw new ArgumentException(string.Format("m_Transform={0},m_DefaultTransform={1}", m_Transform, m_DefaultTransform)); } }
public void Load(SceneVo Vo, Action <GameObject> callBack = null, string[] preloadAssets = null) { if (isLoading) { return; } UILoading.ShowLoading(string.Concat("正在进入", Vo.id, "场景..."), "正在预加载", 0); this.callBack = callBack; this.m_sceneId = Vo.id; SceneMgr.Instance.SceneVo = Vo; isLoading = true; _isLoadingComplete = false; GameObjectExt.Destroy(m_kScenePrefab); // Loadinge string[] sceneURLs; int len = 1; if (preloadAssets == null) { sceneURLs = new string[len]; } else { sceneURLs = new string[len + preloadAssets.Length]; for (int i = 0; i < preloadAssets.Length; i++) { sceneURLs[len + i] = preloadAssets[i]; } } sceneURLs[0] = URLConst.GetScenePrefab(Vo.id); ResourceMgr.Instance.DownLoadBundles( sceneURLs, DownLoadComplete, ResourceMgr.UI_PRIORITY, delegate(Resource res, int listCount, int index) { totalNum++; }); }
void Update() { var worldState = WorldState.Instance; if (worldState == null) { return; } var cam = Camera.main; transform.localScale = new Vector3(5.0f, 5.0f, 1.0f); float intensity = worldState.SunlightIntensity; foreach (var renderer in GameObjectExt.GetComponentsInSelfOrChildren <Renderer>(gameObject)) { Material mat = renderer.material; mat.SetColor("_EmissionColor", new Color(intensity, intensity, intensity, 1.0f)); } }
public override void UpdateSelected(UseContext args) { base.UpdateSelected(args); var clampedPos = ClampedPos(args); // For blueprint, we can only place nearby us. m_Ghost.transform.position = clampedPos; int consideredGround = (GameObjectExt.GetLayerMask("Ground")) | (GameObjectExt.GetLayerMask("StructurePlatform")); // Should be clear to the target as well var origin = args.m_OriginPos; var delta = args.m_TargetPos - args.m_OriginPos; RaycastHit hitInfo; m_ValidPlacement = m_GhostTT.CollidingObjects.ToList().Count == 0; if (Physics.Raycast(origin, delta.normalized, out hitInfo, delta.magnitude, consideredGround)) { // m_ValidPlacement = false; } }
void ConnectToRope(UseContext args) { var ropeLinkPos = TractorRopeLink.gameObject.transform.position; foreach (Rigidbody body in GameObjectExt.GetNearbyObjects <Rigidbody>(ropeLinkPos, 0.7f, GameObjectExt.GetLayerMask("Objects") | GameObjectExt.GetLayerMask("StructurePlatform") | GameObjectExt.GetLayerMask("Structure") )) { var go = body.gameObject; float ps = 322.0f; float mf = 322.0f; ps = mf = 1000.0f; float pd = 111.0f; var hj = CreateJoint(body, m_Tractor.GetComponent <Rigidbody>(), ps, mf, pd); // ore always connects in the center if (go.name.ToLower().Contains("ore")) { hj.autoConfigureConnectedAnchor = false; hj.connectedAnchor = Vector3.zero; hj.targetPosition = Vector3.zero; } else { hj.autoConfigureConnectedAnchor = false; hj.anchor = go.transform.InverseTransformPoint(args.m_TargetPos); hj.targetPosition = Vector3.zero; } if (TractorRopeLink.ConnectJoint(hj)) { return; } } // Couldn't connect, see if we assume it was a refund TractorRopeLink.m_Rope.CheckRefund(TractorRopeLink); }
public static GameObject GetGameObject(string relativePath, bool depends = false) { Material kMaterial = null; Resource res; UnityEngine.Object original; res = ResourceManager.Instance.GetResource(relativePath); original = res.MainAsset; res.Destory(false, true); if (hasReleaseSharedAlpha == false) { res = ResourceManager.Instance.GetResource(URLConst.SHARED_ALPHA_PATH); res.Release(true); res = ResourceManager.Instance.GetResource(URLConst.SHARED_ETC_PATH); kMaterial = res.MainAsset as Material; if (kMaterial != null) { SharedManager.Instance.material = kMaterial; } hasReleaseSharedAlpha = true; } return(GameObjectExt.Instantiate(original) as GameObject); }
int GetGroundMask() { return((GameObjectExt.GetLayerMask("Ground")) | (GameObjectExt.GetLayerMask("StructurePlatform"))); }
/* * private static string _cachePath; * public static string CachePath * { * get * { * if (_cachePath != null) * return _cachePath; * * string path = Application.dataPath; * _cachePath = path.Substring(0, path.LastIndexOf("/")) + "/PrefabSpriteInfo.txt"; * return _cachePath; * } * * } */ public static bool CheckUpdate(string root) { bool bChange = false; string[] strs = Directory.GetFiles(root, "*.prefab", SearchOption.AllDirectories); _prefabDct.Clear(); foreach (string name in strs) { string filename = name.Replace("\\", "/"); PrefabData prefabData; if (_prefabDct.ContainsKey(filename)) { prefabData = _prefabDct[filename]; } else { prefabData = new PrefabData(filename); _prefabDct.Add(filename, prefabData); } FileInfo file = new FileInfo(filename); System.TimeSpan ts = file.LastWriteTime - new System.DateTime(1970, 1, 1, 0, 0, 0, 0); string lastTime = System.Convert.ToInt64(ts.TotalSeconds).ToString(); //图集增加和删除可能会导致prefab.UISprite 的atlas属性变化 //所以这里每次都刷新了 //时间戳一样,忽略检测 //if (prefabData.lastTime == lastTime) // continue; prefabData.lastTime = lastTime; prefabData.ClearItem(); GameObject go = AssetDatabase.LoadMainAssetAtPath(filename) as GameObject; if (go == null) { continue; } var spriteList = GetAllSprite(go); foreach (UISprite sprite in spriteList) { SpriteData data = new SpriteData(); data.uiPath = filename; data.spriteName = sprite.spriteName; data.prefabName = go.name; if (sprite.atlas != null) { data.atlasName = sprite.atlas.name; data.atlasPath = AssetDatabase.GetAssetPath(sprite.atlas); data.atlasPath = data.atlasPath.Replace("\\", "/"); } data.spriteUIPath = GameObjectExt.GetHierarchyWithRoot(sprite.transform, go.transform); prefabData.AddItem(data); } bChange = true; } return(bChange); }
public static GameObject InstantGameObject(Object original, bool record = false) { return(GameObjectExt.Instantiate(original, record) as GameObject); }
public void GetModel(string strURL, Action <GameObject, object> fnLoaded, object kArg = null, ushort priority = 100, bool isPreload = false) { GameObject kNewGO = null; GameObject kRawGO; List <GameObject> listGO; List <MODEL_LOAD_INFO> listMR; Action <string, GameObject, Action <GameObject, object>, object> callBack = (string strUrl, GameObject kgo, Action <GameObject, object> loadCall, object arg) => { if (kgo != null) { //kgo.ResetLocalPosition(); m_mapModelUsing.Add <string, GameObject>(strUrl, kgo); GameObject.DontDestroyOnLoad(kgo); loadCall(kgo, arg); } }; //从缓存池中取 if (isPreload == false) { if (m_mapModel.ContainsKey(strURL)) { listGO = m_mapModel[strURL]; if (listGO.Count > 0) { callBack(strURL, listGO[0], fnLoaded, kArg); listGO.RemoveAt(0); return; } } } //从内存中创建新的一个 if (m_mapRawModel.ContainsKey(strURL)) { kRawGO = m_mapRawModel[strURL]; if (isPreload == false) { kNewGO = GameObjectExt.Instantiate(kRawGO, true) as GameObject; } callBack(strURL, kNewGO, fnLoaded, kArg); return; } //如果当前资源正在加载,返回 MODEL_LOAD_INFO kMLI; if (m_mapRawModelLoading.ContainsKey(strURL)) { listMR = m_mapRawModelLoading[strURL]; kMLI.fnLoaded = fnLoaded; kMLI.kArg = kArg; kMLI.isPreload = isPreload; listMR.Add(kMLI); return; } //从文件中加载对象 Action <object> fnLoadFinish = delegate(object kData) { listMR = m_mapRawModelLoading[strURL]; m_mapRawModelLoading.Remove(strURL); if (m_stopLoading.Contains(strURL)) { m_stopLoading.Remove(strURL); listMR.Clear(); listMR = null; return; } Resource kRes = ResourceMgr.Instance.GetResource(strURL); kRawGO = kRes.MainAsset as GameObject; if (kRawGO == null) { Debug.LogError("AssetBundle' mainAsset is null, url: " + strURL); return; } m_mapRawModel[strURL] = kRawGO; for (int i = 0; i < listMR.Count; i++) { if (listMR[i].fnLoaded != null) { if (listMR[i].isPreload == false) { kNewGO = GameObjectExt.Instantiate(kRawGO, true) as GameObject; } callBack(strURL, kNewGO, listMR[i].fnLoaded, listMR[i].kArg); } } kRes.Destory(false, true); kRes = null; listMR.Clear(); listMR = null; }; if (!m_mapRawModelLoading.ContainsKey(strURL)) { listMR = new List <MODEL_LOAD_INFO>(); m_mapRawModelLoading[strURL] = listMR; } else { listMR = m_mapRawModelLoading[strURL]; } kMLI.fnLoaded = fnLoaded; kMLI.kArg = kArg; kMLI.isPreload = isPreload; listMR.Add(kMLI); ResourceMgr.Instance.DownLoadBundle(strURL, fnLoadFinish, priority); }
bool InternalBeginUse(UseContext args) { m_UsingStrongBeam = args.m_ButtonPressed != 0; m_Tractor = null; var target = args.m_TargetPos; if ((target - args.m_OriginPos).magnitude > MaxUseDistance) { args.m_ShowStatusMessage = "Target position too far away to tractor"; return(false); } var ropes = GameObjectExt.GetNearbyObjects <Rigidbody>(target, 1.0f, GameObjectExt.GetLayerMask("Rope")); ropes.Sort((a, b) => { return(a.transform.position.DistanceTo(target).CompareTo(b.transform.position.DistanceTo(target))); } ); var bodies = GameObjectExt.GetNearbyObjects <Rigidbody>(target, 1.0f, GameObjectExt.GetLayerMask("Objects") | GameObjectExt.GetLayerMask("Rope") | GameObjectExt.GetLayerMask("Trees") ); bodies.Sort((a, b) => { return(a.transform.position.DistanceTo(target).CompareTo(b.transform.position.DistanceTo(target))); } ); foreach (var rope in ropes) { bodies.Insert(0, rope); } foreach (Rigidbody body in bodies) { var link = body.gameObject.GetComponent <RopeLink>(); if (link != null && !link.CanTractor) { continue; } // whelp we're not moving this thing if (body.isKinematic) { continue; } m_Tractor = body.gameObject; m_TractorLocalOffset = body.gameObject.transform.InverseTransformPoint(args.m_TargetPos); if (TractorRopeLink != null) { TractorRopeLink.ConnectJoint(null); } return(true); } args.m_ShowStatusMessage = "Tractor must be used on loose object"; return(false); }