public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale) { GameObject decal = new GameObject(); decal.name = "Decal" + decal.GetInstanceID(); decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale); decal.AddComponent<MeshRenderer>().sharedMaterial = mat; #if UNITY_5 decal.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; #else decal.GetComponent<MeshRenderer>().castShadows = false; #endif qd_Decal decalComponent = decal.AddComponent<qd_Decal>(); decalComponent.SetScale(scale); decalComponent.SetTexture( (Texture2D)mat.mainTexture ); decalComponent.SetUVRect(uvCoords); #if DEBUG decal.AddComponent<qd_DecalDebug>(); #endif return decal; }
/// <summary> ///Returns a SphericalObstacle from the current gameObject /// </summary> /// <param name="gameObject"> /// A game object to create the obstacle from<see cref="GameObject"/> /// </param> /// <returns> /// A SphericalObstacle encompassing the game object<see cref="Obstacle"/> /// </returns> public static Obstacle GetObstacle( GameObject gameObject ) { SphericalObstacle obstacle; int id = gameObject.GetInstanceID(); Component[] colliders; float radius = 0.0f, currentRadius; if(!ObstacleCache.ContainsKey( id )) { var obstacleData = gameObject.GetComponent<SphericalObstacleData>(); // If the object provides his own spherical obstacle information, // use it instead of calculating a sphere that encompasses the // whole collider. if (obstacleData != null) { ObstacleCache[id] = new SphericalObstacle(obstacleData.Radius, gameObject.transform.position + obstacleData.Center); } else { colliders = gameObject.GetComponentsInChildren<Collider>(); if( colliders == null ) { Debug.LogError( "Obstacle '" + gameObject.name + "' has no colliders" ); return null; } foreach( Collider collider in colliders ) { if( collider.isTrigger ) { continue; } // Get the maximum extent to create a sphere that encompasses the whole obstacle float maxExtents = Mathf.Max(Mathf.Max(collider.bounds.extents.x, collider.bounds.extents.y), collider.bounds.extents.z); /* * Calculate the displacement from the object center to the * collider, and add in the maximum extents of the bounds. * Notice that we don't need to multiply by the object's * local scale, since that is already considered in the * bounding rectangle. */ float distanceToCollider = Vector3.Distance(gameObject.transform.position, collider.bounds.center); currentRadius = distanceToCollider + maxExtents; if( currentRadius > radius ) { radius = currentRadius; } } ObstacleCache[id] = new SphericalObstacle( radius, gameObject.transform.position ); } } obstacle = ObstacleCache[ id ] as SphericalObstacle; return obstacle; }
public static PolydrawObject CreateInstance() { GameObject go = new GameObject(); go.name = "Polydraw"+go.GetInstanceID(); go.AddComponent<MeshFilter>(); go.AddComponent<MeshRenderer>(); return go.AddComponent<PolydrawObject>(); }
public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale) { GameObject decal = new GameObject(); decal.name = "Decal" + decal.GetInstanceID(); decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale); decal.AddComponent<MeshRenderer>().sharedMaterial = mat; qd_Decal decalComponent = decal.AddComponent<qd_Decal>(); decalComponent.SetScale(scale); decalComponent.SetTexture( (Texture2D)mat.mainTexture ); decalComponent.SetUVRect(uvCoords); #if DEBUG decal.AddComponent<qd_DecalDebug>(); #endif return decal; }
// 添加单击事件 public void AddClick(GameObject go) { if (go == null) return; string btnKey = go.name + go.GetInstanceID(); buttons.Add(btnKey, go.name); go.GetComponent<Button>().onClick.AddListener( delegate() { luaMgr.CallFunction("DialogClickEvent.OnClick", btnKey); } ); }
string GetID(GameObject gameObject) { var key = gameObject.GetInstanceID(); if (!uniqueGuids.ContainsKey(key)) { uniqueGuids[key] = Guid.NewGuid().ToString(); } return uniqueGuids[key]; }
private static void SetFoldValueForGameObjectInHiearchyRecursive(GameObject gameObject, FoldValue fv) { var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow"); var methodInfo = type.GetMethod("SetExpandedRecursive"); EditorApplication.ExecuteMenuItem("Window/Hierarchy"); EditorWindow window = EditorWindow.focusedWindow; methodInfo.Invoke(window, new object[] { gameObject.GetInstanceID(), fv.BoolValue() }); }
public void RemoveClick(GameObject go) { if (go == null) return; string btnKey = go.name + go.GetInstanceID(); if(buttons.ContainsKey(btnKey)) { buttons.Remove(btnKey); } else { Debug.Log("Empty Operation: RemoveClick target is empty"); return; } go.GetComponent<Button>().onClick.RemoveAllListeners(); }
public void InvokeOnTarget(GameObject target) { UnityAction call; int id = target.GetInstanceID (); //try for runtime added listeners if(m_Calls.TryGetValue(id,out call)){ call.Invoke(); }else{//try persistant(editor) added listeners int listenerNumber = this.GetPersistentEventCount(); if(listenerNumber!=m_PersistentCallsDelegate.Length) m_PersistentCallsDelegate=new PersistantCallDelegate[listenerNumber]; MonoBehaviour listener; for (int i=0; i<listenerNumber; i++) { listener=this.GetPersistentTarget(i) as MonoBehaviour; if(listener.gameObject==target){ PersistantCallDelegate callDelegate=m_PersistentCallsDelegate[i]; if(callDelegate==null){ MethodInfo methodInfo=listener.GetType().GetMethod(this.GetPersistentMethodName(i)); //Call thru reflection is slow //methodInfo.Invoke(listener,new object[]{damage,null}); m_PersistentCallsDelegate[i]=callDelegate=System.Delegate.CreateDelegate(typeof(PersistantCallDelegate),listener,methodInfo) as PersistantCallDelegate; } callDelegate.Invoke(); } } } }
public GameObject Instantiate(GameObject original, Vector3 position, Quaternion rotation) { int instanceID = original.GetInstanceID(); // 缓存池创建时不检查GUID参数,因为外部可能进行改变 ObjectPoolItem item; if (!ObjectPoolItems.TryGetValue(instanceID, out item)) { var newObj = GameObject.Instantiate(original, position, rotation) as GameObject; var parameter = newObj.AddMissingComponent<ObjectPoolParameter>(); parameter.InstanceID = instanceID; newObj.BroadcastMessage("OnSpawned", SendMessageOptions.DontRequireReceiver); return newObj; } var obj = item.GameObjects.Pop(); if (item.GameObjects.Count == 0) ObjectPoolItems.Remove(instanceID); obj.transform.SetParent(null, false); obj.transform.position = position; obj.transform.rotation = rotation; obj.BroadcastMessage("OnSpawned", SendMessageOptions.DontRequireReceiver); return obj; }
private void CameraSetup(int index, string sourceName) { Camera sourceCam = JUtil.GetCameraByName(sourceName); if (sourceCam != null) { var cameraBody = new GameObject(); cameraBody.name = typeof(RasterPropMonitor).Name + index + cameraBody.GetInstanceID(); cameraObject[index] = cameraBody.AddComponent<Camera>(); // Just in case to support JSITransparentPod. cameraObject[index].cullingMask &= ~(1 << 16 | 1 << 20); cameraObject[index].CopyFrom(sourceCam); cameraObject[index].enabled = false; cameraObject[index].targetTexture = screenTexture; cameraObject[index].aspect = cameraAspect; } }
// record listener, if not already recorded private bool recordListener(string eventType, GameObject listener, string function) { if (!checkForListener(eventType, listener)) { ArrayList listenerList = _listeners[eventType] as ArrayList; EventListener callback = new EventListener(); callback.name = listener.GetInstanceID().ToString(); callback.listener = listener; callback.function = function; listenerList.Add(callback); return true; } else { if (allowWarningOutputs) { Debug.LogWarning("Event Manager: Listener: " + listener.name + " is already in list for event: " + eventType); } return false; } }
// check if listener exists private bool checkForListener(string eventType, GameObject listener) { if (!checkForEvent(eventType)) { recordEvent(eventType); } ArrayList listenerList = _listeners[eventType] as ArrayList; foreach (EventListener callback in listenerList) { if (callback.name == listener.GetInstanceID().ToString()) return true; } return false; }
// Remove event listener public bool removeEventListener(string eventType, GameObject listener) { if (!checkForEvent(eventType)) return false; ArrayList listenerList = _listeners[eventType] as ArrayList; foreach (EventListener callback in listenerList) { if (callback.name == listener.GetInstanceID().ToString()) { listenerList.Remove(callback); return true; } } return false; }
public void Start() { if (HighLogic.LoadedSceneIsEditor) return; try { // Parse bloody KSPField colors. if (!string.IsNullOrEmpty(backgroundColor)) backgroundColorValue = ConfigNode.ParseColor32(backgroundColor); if (!string.IsNullOrEmpty(ballColor)) ballColorValue = ConfigNode.ParseColor32(ballColor); if (!string.IsNullOrEmpty(progradeColor)) progradeColorValue = ConfigNode.ParseColor32(progradeColor); if (!string.IsNullOrEmpty(maneuverColor)) maneuverColorValue = ConfigNode.ParseColor32(maneuverColor); if (!string.IsNullOrEmpty(targetColor)) targetColorValue = ConfigNode.ParseColor32(targetColor); if (!string.IsNullOrEmpty(normalColor)) normalColorValue = ConfigNode.ParseColor32(normalColor); if (!string.IsNullOrEmpty(radialColor)) radialColorValue = ConfigNode.ParseColor32(radialColor); if (!string.IsNullOrEmpty(dockingColor)) dockingColorValue = ConfigNode.ParseColor32(dockingColor); Shader unlit = Shader.Find("KSP/Alpha/Unlit Transparent"); overlayMaterial = new Material(unlit); overlayMaterial.mainTexture = GameDatabase.Instance.GetTexture(staticOverlay.EnforceSlashes(), false); if (!string.IsNullOrEmpty(headingBar)) { headingMaterial = new Material(unlit); headingMaterial.mainTexture = GameDatabase.Instance.GetTexture(headingBar.EnforceSlashes(), false); } horizonTex = GameDatabase.Instance.GetTexture(horizonTexture.EnforceSlashes(), false); gizmoTexture = JUtil.GetGizmoTexture(); // Ahaha, that's clever, does it work? stockNavBall = GameObject.Find("NavBall").GetComponent<NavBall>(); // ...well, it does, but the result is bizarre, // apparently, because the stock BALL ITSELF IS MIRRORED. navBall = GameDatabase.Instance.GetModel(navBallModel.EnforceSlashes()); Destroy(navBall.collider); navBall.name = "RPMNB" + navBall.GetInstanceID(); navBall.layer = drawingLayer; navBall.transform.position = Vector3.zero; navBall.transform.rotation = Quaternion.identity; navBall.transform.localRotation = Quaternion.identity; if (ballIsEmissive) { navBall.renderer.material.shader = Shader.Find("KSP/Emissive/Diffuse"); navBall.renderer.material.SetTexture("_MainTex", horizonTex); navBall.renderer.material.SetTextureOffset("_Emissive", navBall.renderer.material.GetTextureOffset("_MainTex")); navBall.renderer.material.SetTexture("_Emissive", horizonTex); navBall.renderer.material.SetColor("_EmissiveColor", ballColorValue); } else { navBall.renderer.material.shader = Shader.Find("KSP/Unlit"); navBall.renderer.material.mainTexture = horizonTex; navBall.renderer.material.color = ballColorValue; } navBall.renderer.material.SetFloat("_Opacity", ballOpacity); markerPrograde = BuildMarker(0, 2, progradeColorValue); markerRetrograde = BuildMarker(1, 2, progradeColorValue); markerManeuver = BuildMarker(2, 0, maneuverColorValue); markerManeuverMinus = BuildMarker(1, 2, maneuverColorValue); markerTarget = BuildMarker(2, 1, targetColorValue); markerTargetMinus = BuildMarker(2, 2, targetColorValue); markerNormal = BuildMarker(0, 0, normalColorValue); markerNormalMinus = BuildMarker(1, 0, normalColorValue); markerRadial = BuildMarker(1, 1, radialColorValue); markerRadialMinus = BuildMarker(0, 1, radialColorValue); markerDockingAlignment = BuildMarker(0, 2, dockingColorValue); // Non-moving parts... cameraBody = new GameObject(); cameraBody.name = "RPMPFD" + cameraBody.GetInstanceID(); cameraBody.layer = drawingLayer; ballCamera = cameraBody.AddComponent<Camera>(); ballCamera.enabled = false; ballCamera.orthographic = true; ballCamera.clearFlags = CameraClearFlags.Nothing; ballCamera.eventMask = 0; ballCamera.farClipPlane = 3f; ballCamera.orthographicSize = cameraSpan; ballCamera.cullingMask = 1 << drawingLayer; ballCamera.clearFlags = CameraClearFlags.Depth; // -2,0,0 seems to get the orientation exactly as the ship. // But logically, forward is Z+, right? // Which means that ballCamera.transform.position = new Vector3(0, 0, 2); ballCamera.transform.LookAt(Vector3.zero, Vector3.up); ballCamera.transform.position = new Vector3(cameraShift.x, cameraShift.y, 2); overlay = CreateSimplePlane("RPMPFDOverlay" + internalProp.propID, 1f, drawingLayer); overlay.layer = drawingLayer; overlay.transform.position = new Vector3(0, 0, 1.5f); overlay.renderer.material = overlayMaterial; overlay.transform.parent = cameraBody.transform; FaceCamera(overlay); if (headingMaterial != null) { heading = CreateSimplePlane("RPMPFDHeading" + internalProp.propID, 1f, drawingLayer); heading.layer = drawingLayer; heading.transform.position = new Vector3(headingBarPosition.x, headingBarPosition.y, headingAboveOverlay ? 1.55f : 1.45f); heading.transform.parent = cameraBody.transform; heading.transform.localScale = new Vector3(headingBarPosition.z, 0, headingBarPosition.w); heading.renderer.material = headingMaterial; heading.renderer.material.SetTextureScale("_MainTex", new Vector2(headingSpan, 1f)); FaceCamera(heading); } ShowHide(false, navBall, cameraBody, overlay, heading); startupComplete = true; } catch { JUtil.AnnoyUser(this); throw; } }
public float GetMinVolume(GameObject go, InAudioNode node) { ObjectAudioList infoList; int instanceID = go.GetInstanceID(); float minVolume = -1; //volume should be (0-1) if (GOAudioNodes.TryGetValue(instanceID, out infoList)) { var list = infoList.InfoList; int count = list.Count; minVolume = 10000f; //volume should be (0-1) for (int i = 0; i < count; i++) { var info = list[i]; float volume = info.Player.Volume; if (volume < minVolume) { minVolume = volume; } } } else { Debug.LogWarning("InAudio: Node not found"); } return minVolume; }
public AddCurvesPopupGameObjectNode(GameObject gameObject, TreeViewItem parent, string displayName) : base(gameObject.GetInstanceID(), (parent == null) ? -1 : (parent.depth + 1), parent, displayName) { }
void Obj2Json(GameObject _obj, MyJson.JsonNode_Object _json) { _json["name"] = new MyJson.JsonNode_ValueString(_obj.name); _json["id"] = new MyJson.JsonNode_ValueNumber(_obj.GetInstanceID()); //遍历填充组件 MyJson.JsonNode_Array comps = new MyJson.JsonNode_Array(); _json["components"] = comps; foreach (var c in _obj.GetComponents<Component>()) { if (c == null) { Debug.LogWarning("got a commponet null."); continue; } string type = c.GetType().Name.ToLower(); var _cjson = new MyJson.JsonNode_Object(); _cjson["type"] = new MyJson.JsonNode_ValueString(type); if (componentParsers.ContainsKey(type) == false) { Debug.LogWarning("can't find comparser:" + type); continue; } componentParsers[type].WriteToJson(resmgr, _obj, c, _cjson); comps.Add(_cjson); } //遍历填充树 if (_obj.transform.childCount > 0) { MyJson.JsonNode_Array children = new MyJson.JsonNode_Array(); _json["children"] = children; for (int i = 0; i < _obj.transform.childCount; i++) { var subobj = _obj.transform.GetChild(i).gameObject; MyJson.JsonNode_Object _subjson = new MyJson.JsonNode_Object(); Obj2Json(subobj, _subjson); children.Add(_subjson); } } }
void MarkForPickup(GameObject headObject, Joint2D[] joints, GameObject[] playerParts) { Hashtable table = new Hashtable (); table.Add (headObject.GetInstanceID (), headObject); if (joints != null) { foreach (Joint2D joint in joints) { if (joint != null && joint.connectedBody != null && joint.connectedBody.gameObject != null) { GameObject obj = joint.connectedBody.gameObject; if (!table.ContainsKey (obj.GetInstanceID ())) { table.Add (obj.GetInstanceID (), obj); ProcessConnectedObjects (obj, table); } } else { DestroyImmediate (joint); } } } if (table.Count < playerParts.Length + 1) { foreach (GameObject part in playerParts) { if (part.tag.Equals (Constants.TAG_CURRENT_PLAYER)) continue; if (!table.ContainsKey (part.GetInstanceID ())) { MarkForPickup (part); } } } }
public InPlayer[] GetPlayers(GameObject go) { ObjectAudioList infoList; GOAudioNodes.TryGetValue(go.GetInstanceID(), out infoList); if (infoList != null) { InPlayer[] players = new InPlayer[infoList.InfoList.Count]; var list = infoList.InfoList; for (int i = 0; i < list.Count; i++) { players[i] = infoList.InfoList[i].Player; } return players; } return null; }
public void SetVolumeForGameObject(GameObject controllingObject, float newVolume) { ObjectAudioList outInfoList; GOAudioNodes.TryGetValue(controllingObject.GetInstanceID(), out outInfoList); if (outInfoList != null) { List<RuntimeInfo> infoList = outInfoList.InfoList; int count = infoList.Count; for (int i = 0; i < count; ++i) { var player = infoList[i].Player; player.Volume = newVolume; } } }
public void StopAll(GameObject controllingObject, float fadeOutTime, LeanTweenType type) { ObjectAudioList infoList; GOAudioNodes.TryGetValue(controllingObject.GetInstanceID(), out infoList); if (infoList != null) { var list = infoList.InfoList; for (int i = 0; i < list.Count; ++i) { if (fadeOutTime > 0) list[i].Player.Stop(fadeOutTime, type); else list[i].Player.Stop(); } } }
public void GetPlayers(GameObject go, IList<InPlayer> copyTo) { ObjectAudioList infoList; GOAudioNodes.TryGetValue(go.GetInstanceID(), out infoList); if (infoList != null) { var list = infoList.InfoList; for (int i = 0; i < list.Count && i < copyTo.Count; i++) { copyTo[i] = infoList.InfoList[i].Player; } } }
}//Update() // /// <summary> // ///Process inputs and update state of ui element. // /// </summary> // public void UpdateOld() // { // //Log.Debug("UI Update"); // // // if(modalWindow != null) // { // if(!modalWindow.active) // { // //modal not active anymore, remove it // modalWindow = null; // } // } // GameObject obj = GetObjectUnderCursor(); // if(obj != null) // { // //check if we are in modal mode // if(modalWindow != null) // { // //check if obj is in the modals list // if(!modals.ContainsKey(obj.GetInstanceID())) // { // if(lastButton != null) // { // lastButton.Release(); // lastButton = null; // } // //not in the list // return; // } // } // //check if this is a button. // // Log.Info("HIT something:"+obj.name+" images:"+images.Count); // UIButton button = null; // if(images.ContainsKey(obj.GetInstanceID())) // { // try // { // UIObject b = (UIObject)images[obj.GetInstanceID()]; // UIType t = b.GetType(); // // if(t == UIType.Button // // || t.GetType().IsSubclassOf(typeof(UIButton))) // if(t == UIType.Button // || t == UIType.ToggleButton // || t == UIType.Slider // || t == UIType.Checkbox) // { // button = (UIButton)b; // } // } // catch(System.Exception e) // { // Log.Debug("Could not find ui key:"+obj.name); // Log.Debug("error :"+e.ToString()); // } // } // // if(button!=null) // // Log.Debug("---------------- Button:"+button.Name); // // else // // Log.Debug("---------------- Button NULL"); // if(button != null && lastButton != null // && button != lastButton ) // { // //Log.Debug("Release!!"); // lastButton.OverExit(); // lastButton.Release(); // lastButton = null; // return; // } // if(button == null && lastButton != null ) // { // lastButton.OverExit(); // lastButton.Release(); // lastButton = null; // return; // } // if(button != null // && button.State != UIButtonState.OVER // && button.State != UIButtonState.DISABLED // && button.State != UIButtonState.ACTIVE_DISABLED // && GameManager.Instance.hidTouch // ) // { // if(lastButton != null) // { // lastButton.Release(); // lastButton = button; // lastButton.Push(); // } // activeButton = button; // } // else if(button != null && button.State != UIButtonState.DISABLED && button.State != UIButtonState.ACTIVE_DISABLED) // { // //Log.Debug("button:"+button.Name); // if(Input.GetMouseButtonDown((int)MouseButton.Left)) // { // //Log.Debug("button Push1:"+button.Name); // if(lastButton != null) // { // lastButton.Release(); // } // lastButton = button; // button.Push(); // activeButton = button; // } // else if(Input.GetMouseButton((int)MouseButton.Left)) // { // //Log.Debug("button push:"+button.Name); // //lastButton = button; // if(activeButton == button) // { // button.Push(); // lastButton = button; // } // else if(lastButton != null) // { // lastButton.Release(); // } // } // else if (Input.GetMouseButtonUp((int)MouseButton.Left)) // { // //Log.Debug("button Up:"+button.Name+" ab:"+lastButton.Name+" s:"+button.State); // if(activeButton == button) // { // button.Click(); // button.Release(); // } // if(lastButton != null) // lastButton.Release(); // lastButton = null; // activeButton = null; // } // else // { // if(lastButton != null && button != lastButton) // { // lastButton.OverExit(); // lastButton.Release(); // } // else if(activeButton == null) // { // lastButton = button; // button.Over(); // } // } // } // }//tophit // else if(lastButton != null) // { // lastButton.OverExit(); // //Log.Debug("***********************"); // lastButton.Release(); // lastButton = null; // //WebPlayerDebugManager.addOutput("------------- not tophit, activeButton="+activeButton+", lastButton="+lastButton,1); // } // }//Update() /// <summary> /// Check if the tooltip can be visible at the moment /// or should be hidden /// </summary> public bool CheckTooltipVisibility(GameObject obj) { if (modalWindow != null && modalWindow.active == true && !modals.ContainsKey(obj.GetInstanceID())) { return false; } return true; }
public void Start() { if (HighLogic.LoadedSceneIsEditor) { return; } try { backgroundColorValue = ConfigNode.ParseColor32(backgroundColor); cameraBody = new GameObject(); cameraBody.name = "RPMPFD" + cameraBody.GetInstanceID(); cameraBody.layer = drawingLayer; hudCamera = cameraBody.AddComponent<Camera>(); hudCamera.enabled = false; hudCamera.orthographic = true; hudCamera.eventMask = 0; hudCamera.farClipPlane = 3f; hudCamera.orthographicSize = 1.0f; hudCamera.cullingMask = 1 << drawingLayer; // does this actually work? hudCamera.backgroundColor = backgroundColorValue; hudCamera.clearFlags = CameraClearFlags.Depth | CameraClearFlags.Color; hudCamera.transparencySortMode = TransparencySortMode.Orthographic; hudCamera.transform.position = Vector3.zero; hudCamera.transform.LookAt(new Vector3(0.0f, 0.0f, 1.5f), Vector3.up); if (!string.IsNullOrEmpty(progradeColor)) { progradeColorValue = ConfigNode.ParseColor32(progradeColor); } persistence = new PersistenceAccessor(internalProp); } catch (Exception e) { JUtil.LogErrorMessage(this, "Start() failed with an exception: {0}", e); JUtil.AnnoyUser(this); throw; } startupComplete = true; }
public void Break(GameObject controllingObject, InAudioNode toBreak) { ObjectAudioList infoList; GOAudioNodes.TryGetValue(controllingObject.GetInstanceID(), out infoList); if (infoList != null) { var list = infoList.InfoList; for (int i = 0; i < list.Count; ++i) { if (list[i].Node == toBreak) { list[i].Player.Break(); } } } }
///<summary> /// Internal helper to get a uiButton from an object ///</summary> private UIButton GetUIButtonFromObject(GameObject obj) { UIButton button = null; if(images.ContainsKey(obj.GetInstanceID())) { try { UIObject b = (UIObject)images[obj.GetInstanceID()]; UIType t = b.GetType(); // if(t == UIType.Button // || t.GetType().IsSubclassOf(typeof(UIButton))) if(t == UIType.Button || t == UIType.ToggleButton || t == UIType.Slider || t == UIType.Checkbox) { button = (UIButton)b; } } catch(System.Exception e) { Log.Debug("Could not find ui key:"+obj.name); Log.Debug("error :"+e.ToString()); button = null; } } return button; }
public void StopByNode(GameObject controllingObject, InAudioNode nodeToStop, float fadeOutTime = 0.0f, LeanTweenType tweenType = LeanTweenType.easeOutCubic) { ObjectAudioList infoList; GOAudioNodes.TryGetValue(controllingObject.GetInstanceID(), out infoList); if (infoList != null) { var list = infoList.InfoList; for (int i = 0; i < list.Count; ++i) { if (list[i].Node == nodeToStop) { list[i].Player.Stop(fadeOutTime, tweenType); } } } }
}//LoadSprite() /// <summary> /// Adds a UI button. /// </summary> /// <param name="obj">Parent game object.</param> /// <param name="fileName">Resource file name with path, relative to Rersources folder.</param> public UIObject Add(UIType type, GameObject obj, string fileName, Sprite spr = null) { Log.Info("Add: <color=yellow>"+obj.name+" - id:"+obj.GetComponent<GUIText>()+"</color> type:"+type); //// Log.GameTimes("_______________-_-_-_-_-_ <color=yellow>"+fileName+" _____ obj: "+obj+"</color>, type: "+type); if(images.ContainsKey(obj.GetInstanceID())) { //give warning, then return existing one (ignore new registration) Log.Debug("This button already registered, ignoring new registration. <color=cyan>" + obj.name+"</color> "); return images[obj.GetInstanceID()]; } Sprite[] sprList = new Sprite[1]; if(fileName.Length == 0) { if(spr == null) { Log.Debug("This button <color=yellow>"+obj.name+"</color> has no image."); } else { Log.Debug("Sprite >>>>>>>>>>>>>>>>> "+spr.name); sprList[0] = spr; } } else { sprList = LoadSprite(fileName); } UIObject image = null; switch(type) { case UIType.Image: Log.Debug("Add UIImage"); image = new UIImage(obj, sprList); break; case UIType.Button: Log.Debug("Add UIButton"); image = new UIButton(obj, sprList); break; case UIType.ToggleButton: Log.Debug("Add UIToggleButton"); image = new UIToggleButton(obj, sprList); break; case UIType.Slider: Log.Debug("Add UISlider"); image = new UISlider(obj, sprList); break; case UIType.Character: Log.Debug("Add UICharacter"); image = new UICharacter(obj, sprList); break; case UIType.ChartPie: Log.Debug("Add UIChartPie"); image = new UIChartPie(obj); break; case UIType.ChartLine: Log.Debug("Add UIChartLine"); image = new UIChartLine(obj); break; case UIType.Checkbox: Log.Debug("Add Checkbox"); image = new UICheckbox(obj, sprList); break; default: Log.Exception("Invalid UIType to add:" + type); break; } //TODO remove this images.Add(obj.GetInstanceID(), image); // //images.Add(""+lastId++, image); //Log.Info("Button added:"+obj.name+" image:"+image.Name); return image; }//Add()
private ObjectAudioList GetValue(Dictionary<int, ObjectAudioList> dictionary, GameObject go) { ObjectAudioList infoList; int instanceID = go.GetInstanceID(); if (!dictionary.TryGetValue(instanceID, out infoList)) { infoList = AudioListPool.GetObject(); dictionary.Add(instanceID, infoList); } return infoList; }