public void Init(int vcnt, Material customMaterial = null) { GameObject go = new GameObject("__particle_marker"); //go.hideFlags = HideFlags.HideAndDontSave; m_PS = go.AddComponent <ParticleSystem>(); m_PS.simulationSpace = ParticleSystemSimulationSpace.World; m_PS.startLifetime = float.MaxValue * 0.1f; m_PS.maxParticles = 1000000; m_Renderer = go.GetComponent <Renderer>(); Dbg.Assert(m_Renderer != null, "ParticleMarker.Init: failed to get renderer"); if (customMaterial != null) { m_Renderer.sharedMaterial = customMaterial; } m_Particles = new ParticleSystem.Particle[vcnt]; ParticleSystemRenderer psr = m_PS.GetComponent <Renderer>() as ParticleSystemRenderer; psr.maxParticleSize = MAX_PARTICLE_SCREEN_SIZE; m_PS.enableEmission = false; m_PS.Emit(vcnt); m_PS.GetParticles(m_Particles); m_PS.SetParticles(m_Particles, 0); m_PS.Simulate(0.1f); //Simulate will pause the PS, required }
public void Init(MeshSelection s, EditableMesh m) { m_Selection = s; m_EditMesh = m; // connect events m_Selection.evtSelectionChanged += this.OnSelectionChanged; MeshUndoer.AddDeleMeshModified(this.OnMeshModified); m_VertMarker = new VertMarker(); Material vertBillboardMat = AssetDatabase.LoadAssetAtPath(VertBillboardMatPath, typeof(Material)) as Material; Dbg.Assert(vertBillboardMat != null, "MeshMaker.Init: failed to load vertBillboard Material at {0}", VertBillboardMatPath); m_VertMarker.Init(vertBillboardMat, 0); m_EdgeMarker = new EdgeMarker(); Material edgeMat = AssetDatabase.LoadAssetAtPath(EdgeMatPath, typeof(Material)) as Material; Dbg.Assert(edgeMat != null, "MeshMaker.Init: failed to load edge Material at {0}", EdgeMatPath); m_EdgeMarker.Init(edgeMat); _PrepareEdgeIndices(); m_TriMarker = new TriMarker(); m_TriMarker.Init(); EUtil.SetEnableWireframe(m.renderer, false); //EditorUtility.SetSelectedWireframeHidden(m.renderer, true); //hide the wireframe }
/// <summary> /// return null for SceneRoot or failure /// return CCRoot if empty /// return the corresponding transform for valid transformPath /// </summary> public Transform GetTransform(Transform ccroot) { if (m_trPath == SceneRoot) { return(null); } else if (m_trPath == CCRoot) { return(ccroot); } else if (m_trPath.StartsWith(SceneRoot)) { GameObject go = GameObject.Find(m_trPath); if (go == null) { Dbg.LogWarn("CCTrPath: cannot find GameObject at path: {0}", m_trPath); return(null); } else { return(go.transform); } } else { Transform tr = ccroot.Find(m_trPath); Dbg.Assert(tr != null, "CCTrPath.GetTransform: failed to get transform for transformPath: {0}", m_trPath); return(tr); } }
private void _GenMatchMap() { SkinnedMeshRenderer smr = SMREditor.GetSMR(); Dbg.Assert(smr != null, "MirrorCtrl.__GenMatchMap: failed to get SMR"); Transform[] bones = smr.bones; // build trPath map Dictionary <string, bool> trPathMap = new Dictionary <string, bool>(); for (int idx = 0; idx < bones.Length; ++idx) { Transform thisBone = bones[idx]; string thisPath = AnimationUtility.CalculateTransformPath(thisBone, m_AnimRoot); trPathMap[thisPath] = true; } // gen match map for (int idx = 0; idx < bones.Length; ++idx) { Transform thisBone = bones[idx]; string thisPath = AnimationUtility.CalculateTransformPath(thisBone, m_AnimRoot); int matchREIdx = IsMatchRE(thisPath); if (matchREIdx >= 0) { string thatPath = GetMatchPath(thisPath, matchREIdx); bool bFound = trPathMap.ContainsKey(thatPath); m_MatchMap[thisPath] = new MatchBone(thatPath, bFound); } } }
public void SetLimit(float v, ELimit eLimit, int jointIdx) { Dbg.Assert(jointIdx < this.Count, "IKRTSolver.SetLimit: jointIdx beyond range: {0}", jointIdx); float fv = Misc.NormalizeAngle(v); Limit l = m_Limits[jointIdx]; switch (eLimit) { case ELimit.XFrom: l.X.first = fv; break; case ELimit.XTo: l.X.second = fv; break; case ELimit.YFrom: l.Y.first = fv; break; case ELimit.YTo: l.Y.second = fv; break; case ELimit.ZFrom: l.Z.first = fv; break; case ELimit.ZTo: l.Z.second = fv; break; default: Dbg.LogErr("IKSovler.SetLimit: unexpected value: {0}", eLimit); break; } }
public _AnimCurve(AnimationCurve[] curves, KFType tp, EditorCurveBinding[] bindings, AnimationClip clip) { Dbg.Assert(curves.Length > 0, "_AnimCurve.ctor: curves[] has zero element"); m_Curves = curves; m_Clip = clip; m_KfType = tp; m_KeyCnt = m_Curves[0].length; //Dbg.Log("{0}:{1} keyCnt:{2}", binding.path, binding.propertyName, m_KeyCnt); m_Bindings = bindings; // check key count for (int i = 0; i < m_Curves.Length; ++i) { if (m_Curves[i].length != m_KeyCnt) { Dbg.LogWarn("_AnimCurve.ctor: the key count not match other curves: {0} != {1}, {2}:{3}", m_Curves[i], m_KeyCnt, m_Bindings[0].path, m_Bindings[0].propertyName); } } // assign keys m_Kf4Curves = new Keyframe[m_Curves.Length][]; for (int i = 0; i < m_Curves.Length; ++i) { m_Kf4Curves[i] = m_Curves[i].keys; } Dbg.Assert(m_KeyCnt >= 2, "_AnimCurve.ctor: curve has less than 2 keys: {0}", m_Curves[0]); // init _KeyFrame array _InitKeyframes(); }
private void _ModifyCurveBinding(EditorCurveBinding oneBinding, string newPath, string newProp, Type newType) { //object animWndCurve = oneInfo.m_AnimationWindowCurve; if (oneBinding.isPPtrCurve) { EditorCurveBinding newBinding = EditorCurveBinding.PPtrCurve(newPath, newType, newProp); //var array = (ObjectReferenceKeyframe[])RCall.CallMtd("UnityEditorInternal.AnimationWindowCurve", "ToObjectCurve", animWndCurve); ObjectReferenceKeyframe[] array = AnimationUtility.GetObjectReferenceCurve(m_CurClip, oneBinding); AnimationUtility.SetObjectReferenceCurve(m_CurClip, newBinding, array); //add new AnimationUtility.SetObjectReferenceCurve(m_CurClip, oneBinding, null); //remove old } else { EditorCurveBinding newBinding = EditorCurveBinding.FloatCurve(newPath, newType, newProp); //AnimationCurve curve = (AnimationCurve)RCall.CallMtd("UnityEditorInternal.AnimationWindowCurve", "ToAnimationCurve", animWndCurve); AnimationCurve curve = AnimationUtility.GetEditorCurve(m_CurClip, oneBinding); Dbg.Assert(curve != null, "AnimCurvePropEditor._ModifyCurveBinding: failed to get editorCurve"); AnimationUtility.SetEditorCurve(m_CurClip, newBinding, curve); //add new AnimationUtility.SetEditorCurve(m_CurClip, oneBinding, null); //remove old } }
private void _StartEdit() { var curGO = Selection.activeGameObject; Dbg.Assert(curGO != null, "MeshPivotFixerEditorWindow._StartEdit: no selection GameObject"); m_InEditMF = curGO.GetComponent <MeshFilter>(); Dbg.Assert(m_InEditMF != null, "MeshPivotFixerEditorWindow._StartEdit: MeshFilter is not found"); m_PivotPos = Vector3.zero; m_PivotRot = Quaternion.identity; _SwitchEditMode(EditMode.Fixer); // subscribe onSceneGUI { SceneView.onSceneGUIDelegate += this.OnSceneGUI; } //// hide wireframe //{ // Renderer ren = m_InEditMF.renderer; // Dbg.Assert(ren != null, "MeshPivotFixerEditorWindow._StartEdit: there is not renderer on specified GameObject"); // EditorUtility.SetSelectedWireframeHidden(ren, true); //} // subscribe onUpdate EditorApplication.update += this.OnUpdate; }
private void _CalcTrPath() { #if UNITY_EDITOR Dbg.Assert(RebindOption.editTimeRoot != null, "RebindTr.CalcTrPath: m_editTimeRoot is null!"); m_trPath = AMUtil.CalculateTransformPath(m_editTimeTr, RebindOption.editTimeRoot); #endif }
private void _CalcTrPath() { #if UNITY_EDITOR Dbg.Assert(RebindOption.editTimeRoot != null, "RebindCp.CalcTrPath: ms_editTimeRoot is null!"); m_trPath = AMUtil.CalculateTransformPath(m_editTimeCp.SafeGetComponent <Transform>(), RebindOption.editTimeRoot); #endif }
public void SetBones(Transform endJoint, int len) { //Dbg.Assert(len > 0, "CCDSolver.SetBones: the link length must be larger than 0"); _ClearBones(); m_joints.Resize(len + 1); //+1 for the endJoint // the endJoint is the joint user moves, the link's last joint is its parent Transform joint = endJoint; // add the endJoint JointData endInfo = new JointData(); endInfo.joint = endJoint; m_joints[len] = (endInfo); // add joint from the end to the head for (int idx = len - 1; idx >= 0; --idx) { Transform parentJoint = joint.parent; Dbg.Assert(parentJoint != null, "CCDSolver.SetBones: the link length is too big, there is already no parent joint for: {0}", joint); JointData info = new JointData(); info.joint = parentJoint; parentJoint.GetComponents <IKConstraintMB>(info.constraints); m_joints[idx] = info; joint = parentJoint; } Array.Resize(ref m_jointArr, len + 1); for (int i = 0; i < m_jointArr.Length; ++i) { m_jointArr[i] = m_joints[i].joint; } // notify init constraints for (int idx = len - 1; idx >= 0; --idx) { var info = m_joints[idx]; foreach (var mb in info.constraints) { mb.Init(this, idx); } } //calc total bone length & highDistThres float totalLen = 0; for (int i = 0; i < len; ++i) { var j0 = m_jointArr[i]; var j1 = m_jointArr[i + 1]; totalLen += (j0.position - j1.position).magnitude; } m_totalBoneLength = totalLen; m_highDistThres = m_totalBoneLength * m_highDistThresRatio; }
private void _AddToVGroup(int idx, VGroup grp) { Dbg.Assert(!m_VGCont.ContainsKey(idx), "OverlapChecker._AddToGroup: vert already in VGCont: {0}", idx); Dbg.Assert(!grp.Contains(idx), "OverlapChecker._AddToGroup: vert already in group: {0}", idx); m_VGCont.Add(idx, grp); grp.Add(idx); }
////////////////////////////////////////////////////////////////////////// // "public methods" ////////////////////////////////////////////////////////////////////////// /// <summary> /// added a pool to the management of PoolMgr /// check if already a pool with same name exists /// </summary> public void Add(IPool pool) { string poolName = pool.Name; Dbg.Assert(!m_poolCont.ContainsKey(poolName), "PoolMgr.Add: poolName {0} already registered", poolName); m_poolCont.Add(poolName, pool); }
} //get all joints, including the end-effector /// <summary> /// [0] is the root, [last] is the endJoint /// NOTE: the transforms in the list could be NON-continuous /// </summary> public void SetBones(List <Transform> _joints) { Dbg.Assert(_joints.Count > /*1*/ 0, "CCDSolver.SetBones: the joints list length must be larger than 0"); _ClearBones(); m_joints.Resize(_joints.Count); // the endJoint is the joint user moves int len = _joints.Count - 1; //len is the bone count, not joint count Transform endJoint = _joints.Last(); // add the endJoint JointData endInfo = new JointData(); endInfo.joint = endJoint; m_joints[len] = (endInfo); // add joint from the end to the head for (int idx = len - 1; idx >= 0; --idx) { Transform j = _joints[idx]; JointData info = new JointData(); info.joint = j; j.GetComponents <IKConstraintMB>(info.constraints); m_joints[idx] = info; } Array.Resize(ref m_jointArr, len + 1); for (int i = 0; i < m_jointArr.Length; ++i) { m_jointArr[i] = m_joints[i].joint; } // notify init constraints for (int idx = len - 1; idx >= 0; --idx) { var info = m_joints[idx]; foreach (var mb in info.constraints) { mb.Init(this, idx); } } //calc total bone length & highDistThres float totalLen = 0; for (int i = 0; i < len; ++i) { var j0 = m_jointArr[i]; var j1 = m_jointArr[i + 1]; totalLen += (j0.position - j1.position).magnitude; } m_totalBoneLength = totalLen; m_highDistThres = m_totalBoneLength * m_highDistThresRatio; }
public static Shader GetRenderDepthShader() { if (m_RenderDepthShader == null) { m_RenderDepthShader = Shader.Find(RenderDepthShaderName); Dbg.Assert(m_RenderDepthShader != null, "GfxUtil.GetRenderDepthShader: failed to get: {0}", RenderDepthShaderName); } return(m_RenderDepthShader); }
// unity event handlers void Start() { Dbg.Assert(m_EnemyDescLst.Count > 0, "CCDemo3_EnemyCtrl.Start: enemy prefabs not set"); m_ActiveEnemies = new List <Transform>(); m_MainCtrl = GetComponent <CCDemo3_MainCtrl>(); Dbg.Assert(m_MainCtrl != null, "CCDemo3_EnemyCtrl.Start: failed to get mainctrl"); }
public List <GraphNode <V> > GetAdjList_Internal(V data) { GraphNode <V> lnode = GetNode(data); Dbg.Assert(lnode != null, "Graph.GetAdjList_Internal: cannot get node"); List <GraphNode <V> > llst = m_node2neighbors.TryGet(lnode); return(llst); }
public T Spawn <T>(string poolname) where T : class { IPool pool = null; bool bFound = m_poolCont.TryGetValue(poolname, out pool); Dbg.Assert(bFound, "PoolMgr.Spawn: failed to find pool: {0}", poolname); return(pool.Spawn() as T); }
/// <summary> /// remove a pool, all inactive objects are destroyed, /// </summary> public void Remove(string name) { Dbg.Assert(m_poolCont.ContainsKey(name), "PoolMgr.Remove: poolName {0} not regiestered", name); IPool pool = m_poolCont[name]; m_poolCont.Remove(name); pool.OnDestroy(); //destroy not-in-use object }
/// <summary> /// remove a pool, all inactive objects are destroyed, /// </summary> public void RemoveTypePool(RuntimeTypeHandle tp) { Dbg.Assert(m_TypePoolCont.ContainsKey(tp), "PoolMgr.RemoveTypePool: type {0} not regiestered", tp); IPool pool = m_TypePoolCont[tp]; m_TypePoolCont.Remove(tp); pool.OnDestroy(); //destroy not-in-use object }
/// <summary> /// find the specified pool, and spawn a object; /// assert when not found the pool /// </summary> public object Spawn(string poolname) { IPool pool = null; bool bFound = m_poolCont.TryGetValue(poolname, out pool); Dbg.Assert(bFound, "PoolMgr.Spawn: failed to find pool: {0}", poolname); return(pool.Spawn()); }
/// <summary> /// set a new EndEffector /// </summary> public void SetEndEffector(Transform tr) { var mb = tr.GetComponent <CCDSolverMB>(); Dbg.Assert(mb != null, "MarkerCtrl.SetEndEffector: failed to get CCDSolverMB: {0}", tr.name); m_IK_0 = mb.GetSolver(); m_IK_0.SetBones(tr, 2); m_Collider.position = m_IK_0.GetJoints()[0].position; m_Marker.position = m_Collider.position; }
/// <summary> /// check if the two NORMALIZED directions are near /// </summary> public static bool DirNear(Vector3 lhs, Vector3 rhs) { Dbg.Assert(lhs != Vector3.zero && rhs != Vector3.zero, "IKSolverUtil.DirNear: zero vector"); //float c = Vector3.Dot(lhs, rhs); //return Mathf.Approximately(c, 1.0f); Vector3 c = Vector3.Cross(lhs, rhs).normalized; return(c == Vector3.zero); }
void OnEnable() { EUtil.LoadAsset(ref ms_inspectTex, ASSET_InspectIcon); m_spPlayOnStart = serializedObject.FindProperty(SP_PlayOnStart); m_spTakes = serializedObject.FindProperty(SP_Takes); Dbg.Assert(m_spPlayOnStart != null, "AnimatorDataEditor.OnEnable: failed to find property: {0}", SP_PlayOnStart); Dbg.Assert(m_spTakes != null, "AnimatorDataEditor.OnEnable: failed to find property: {0}", SP_Takes); }
// unity event handlers void Start() { m_MainCtrl = GameObject.Find("GlobalScript").GetComponent <CCDemo3_MainCtrl>(); m_RefTr = transform.Find("Hips/Spine/Spine1/Spine2/Neck/Neck1"); m_Prop = GetComponent <CCDemo3_EnemyProp>(); Dbg.Assert(m_MainCtrl != null, "CCDemo3_EnemyMarker.Start: failed to get mainctrl"); Dbg.Assert(m_RefTr != null, "CCDemo3_EnemyMarker.Start: failed to get spine transform"); Dbg.Assert(m_Prop != null, "CCDemo3_EnemyMarker.Start: failed to get prop"); }
// unity event handlers void Start() { Dbg.Assert(m_ForwardHint != null, "CCDemo1_MainCtrl.Start: ForwardHint not set"); Dbg.Assert(m_AtkHint != null, "CCDemo1_MainCtrl.Start: AtkHint not set"); Dbg.Assert(m_Animator != null, "CCDemo1_MainCtrl.Start: not set Animator"); Dbg.Assert(m_PrefabAction != null, "CCDemo1_MainCtrl.Start: prefab action not set"); Dbg.Assert(m_Enemies.Length > 0, "CCDemo1.MainCtrl.Start: not set enemies"); m_Player = m_Animator.transform; m_Enemy = m_Enemies[0]; }
// unity event handlers void OnEnable() { EUtil.LoadAsset(ref ms_icon, ASSET_ICON); m_spName = serializedObject.FindProperty("_name"); m_spNumFrames = serializedObject.FindProperty("numFrames"); m_spFps = serializedObject.FindProperty("frameRate"); Dbg.Assert(m_spName != null, "AMTakeEditor.OnEnable: failed to find property: _name"); Dbg.Assert(m_spNumFrames != null, "AMTakeEditor.OnEnable: failed to find property: numFrames"); Dbg.Assert(m_spFps != null, "AMTakeEditor.OnEnable: failed to find property: frameRate"); }
public void GetAdjList(V data, List <V> outLst) { GraphNode <V> lnode = GetNode(data); Dbg.Assert(lnode != null, "Graph.GetAdjList: cannot get node"); List <GraphNode <V> > llst = m_node2neighbors.TryGet(lnode); for (var i = llst.GetEnumerator(); i.MoveNext();) { outLst.Add(i.Current.data); } }
/// <summary> /// save the data to the specified file /// </summary> public void Save() { Dbg.Assert(m_FileName != null, "PoseSet.Save: m_FileName is null"); string pathFile = m_FileName; string str = Json.ToStr(this); Directory.CreateDirectory(Path.GetDirectoryName(pathFile)); File.WriteAllText(pathFile, str, Encoding.UTF8); Dbg.Log("PoseSet.Save: Save poses to file: {0}", m_FileName); }
public static Delegate CreateDelegate(string className, string mtdName, Type deleType, object inst) { string combineName = className + "|" + mtdName; Delegate dele = null; if (ms_deleDict.TryGetValue(combineName, out dele)) { MethodInfo mi = dele.Method; if (inst != null) { dele = Delegate.CreateDelegate(deleType, inst, mi); } else { dele = Delegate.CreateDelegate(deleType, mi); } } else { Type t = GetTypeFromString(className); if (null == t) { Dbg.LogErr("RCall.CreateDelegate: failed to find className: {0}", className); } if (inst != null) { MethodInfo mi = t.GetMethod(mtdName, InstFlags); if (null == mi) { Dbg.LogErr("RCall.CreateDelegate: failed to GetMethod \"{0}\" for class \"{1}\"", mtdName, className); return(null); } dele = Delegate.CreateDelegate(deleType, inst, mi); } else { MethodInfo mi = t.GetMethod(mtdName, StaticFlags); if (null == mi) { Dbg.LogErr("RCall.CreateDelegate: failed to GetMethod \"{0}\" for class \"{1}\"", mtdName, className); return(null); } dele = Delegate.CreateDelegate(deleType, mi); } Dbg.Assert(dele != null, "RCall.CreateDelegate: failed to create delegate"); ms_deleDict[combineName] = dele; } return(dele); }