コード例 #1
0
    public void ResetProp()
    {
        cachedAnchor = null;
        cachedFrame  = 1.0f;

        propId = -1;
    }
コード例 #2
0
    public bool UpdateProp(int scriptId)
    {
        bool ret = false;

        if (propId != -1)
        {
            if (gameObject.activeInHierarchy)
            {
                if (frame != cachedFrame)
                {
                    Internal.UpdateProp(scriptId, propId, frame);
                    cachedFrame = frame;
                    ret         = true;
                }

                //  Prop is only visible if parented to a visible anchor.
                HarmonyAnchor anchor = GetComponentInParent <HarmonyAnchor>();
                if (anchor != cachedAnchor)
                {
                    if (anchor != null)
                    {
                        //Message.Log( "Anchoring prop " + playName + " in script " + scriptId );
                        Internal.AnchorProp(scriptId, propId, anchor.playName, anchor.nodeName);
                    }
                    else
                    {
                        //Message.Log( "Unanchoring prop " + playName + " in script " + scriptId );
                        Internal.UnanchorProp(scriptId, propId);
                    }

                    cachedAnchor = anchor;
                    ret          = true;
                }
            }
            else
            {
                //  Current game object is deactivated.  Disable prop rendering.
                if (cachedAnchor != null)
                {
                    //Message.Log( "Unanchoring prop " + playName + " in script " + scriptId );
                    Internal.UnanchorProp(scriptId, propId);
                    cachedAnchor = null;
                    ret          = true;
                }
            }
        }

        return(ret);
    }
コード例 #3
0
ファイル: DemoCallback.cs プロジェクト: die-mt/Test-It
    void CallbackMethod2(GameObject sender)
    {
        HarmonyAnchor anchor = sender.GetComponentInChildren <HarmonyAnchor>();

        if (anchor != null)
        {
            //  Create a projectile at anchor location and following same direction.
            GameObject projectile = GameObject.CreatePrimitive(PrimitiveType.Cube);
            projectile.AddComponent <Rigidbody>();

            projectile.transform.localPosition = anchor.gameObject.transform.TransformPoint(0, 0, 0);

            Vector3 direction = anchor.gameObject.transform.localToWorldMatrix.MultiplyVector(Vector3.right).normalized;
            projectile.GetComponent <Rigidbody>().AddForce(direction * 500);

            //  Destroy projectile after 2 seconds.
            Destroy(projectile, 2);
        }
    }
コード例 #4
0
  public bool UpdateProp( int scriptId )
  {
    bool ret = false;

    if ( propId != -1 )
    {
      if ( gameObject.activeInHierarchy )
      {
        if ( frame != cachedFrame )
        {
          Internal.UpdateProp( scriptId, propId, frame );
          cachedFrame = frame;
          ret = true;
        }

        //  Prop is only visible if parented to a visible anchor.
        HarmonyAnchor anchor = GetComponentInParent<HarmonyAnchor>();
        if (anchor != cachedAnchor)
        {
          if (anchor != null)
          {
            //Message.Log( "Anchoring prop " + playName + " in script " + scriptId );
            Internal.AnchorProp( scriptId, propId, anchor.playName, anchor.nodeName );
          }
          else
          {
            //Message.Log( "Unanchoring prop " + playName + " in script " + scriptId );
            Internal.UnanchorProp( scriptId, propId );
          }

          cachedAnchor = anchor;
          ret = true;
        }
      }
      else
      {
        //  Current game object is deactivated.  Disable prop rendering.
        if (cachedAnchor != null)
        {
          //Message.Log( "Unanchoring prop " + playName + " in script " + scriptId );
          Internal.UnanchorProp( scriptId, propId );
          cachedAnchor = null;
          ret = true;
        }
      }
    }

    return ret;
  }
コード例 #5
0
  public void ResetProp()
  {
    cachedAnchor = null;
    cachedFrame = 1.0f;

    propId = -1;
  }
コード例 #6
0
    static void RenderAnchorControls(Transform objectTransform, GizmoType gizmoType, bool selected)
    {
        GameObject    gameObject    = objectTransform.gameObject;
        HarmonyAnchor harmonyAnchor = gameObject.GetComponent <HarmonyAnchor>();

        if (harmonyAnchor == null)
        {
            return;
        }

        HarmonyRenderer harmonyRenderer = harmonyAnchor.GetComponentInParent <HarmonyRenderer>();

        if (harmonyRenderer == null)
        {
            return;
        }

        string clipName = harmonyRenderer.currentClipName;

        if (string.IsNullOrEmpty(clipName))
        {
            return;
        }

        string projectFolder = harmonyRenderer.currentProjectFolder;

        if (string.IsNullOrEmpty(projectFolder))
        {
            return;
        }

        float[] position = new float[3];
        float[] rotation = new float[3];
        float[] scale    = new float[3];

        if (Internal.CalculateLocatorTransform(projectFolder, clipName, harmonyRenderer.currentFrame, harmonyAnchor.nodeName, position, rotation, scale))
        {
            Vector3    localPosition   = new Vector3(position[0], position[1], position[2]);
            Quaternion localQuaternion = Quaternion.Euler(rotation[0], rotation[1], rotation[2]);
            Vector3    localScale      = new Vector3(scale[0], scale[1], scale[2]);

            Matrix4x4 localMatrix = Matrix4x4.TRS(localPosition, localQuaternion, localScale);

            Vector3 globalPosition       = localMatrix.MultiplyPoint(Vector3.zero);
            Vector3 globalRightDirection = localMatrix.MultiplyVector(Vector3.right);
            Vector3 globalUpDirection    = localMatrix.MultiplyVector(Vector3.up);

            if (gameObject.transform.parent != null)
            {
                globalPosition       = gameObject.transform.parent.localToWorldMatrix.MultiplyPoint(globalPosition);
                globalRightDirection = gameObject.transform.parent.localToWorldMatrix.MultiplyVector(globalRightDirection);
                globalUpDirection    = gameObject.transform.parent.localToWorldMatrix.MultiplyVector(globalUpDirection);
            }

            globalRightDirection.Normalize();
            globalUpDirection.Normalize();

            Quaternion axisQuaternion        = Quaternion.FromToRotation(Vector3.forward, Vector3.right);
            Quaternion globalRightQuaternion = Quaternion.FromToRotation(new Vector3(1, 0, 0), globalRightDirection);

            float arrowLength  = HandleUtility.GetHandleSize(globalPosition) * 0.5f;
            float axisLength   = arrowLength * 0.6f;
            float circleRadius = arrowLength * 0.5f;

            Handles.color = selected ? Color.cyan : Color.red;

            Handles.DrawWireDisc(globalPosition,
                                 Vector3.forward,
                                 circleRadius);

            Handles.DrawLine(globalPosition - globalRightDirection * axisLength,
                             globalPosition);

            Handles.DrawLine(globalPosition - globalUpDirection * axisLength,
                             globalPosition + globalUpDirection * axisLength);

            Handles.ArrowCap(0,
                             globalPosition,
                             globalRightQuaternion * axisQuaternion,
                             arrowLength);
        }
    }
コード例 #7
0
ファイル: GenerateHarmonyMeta.cs プロジェクト: die-mt/Test-It
    public static void CreateOrUpdateAnchorsFromMetadata(GameObject rootObject)
    {
        HarmonyRenderer renderer = rootObject.GetComponent <HarmonyRenderer>();

        if (renderer == null)
        {
            return;
        }

        string projectFolder = renderer.projectFolder;

        if (!new DirectoryInfo(projectFolder).Exists)
        {
            projectFolder = Application.streamingAssetsPath + "/" + projectFolder;
        }

        //  Load anchors metadata from XML
        XML_Types.XML_AnchorMeta[] xmlAnchors = XML_StageLoader.loadAnchorMeta(projectFolder).ToArray();
        if (xmlAnchors.Length > 0)
        {
            string     anchorObjectName      = "Anchors";
            GameObject anchorContainerObject = null;

            Transform[] childTransforms = rootObject.GetComponentsInChildren <Transform>(true /*includeInactive*/);
            foreach (Transform childTransform in childTransforms)
            {
                GameObject childObject = childTransform.gameObject;

                //  Direct child to root object
                if (childObject.transform.parent == rootObject.transform)
                {
                    //  Object matching preset Anchors game object name.
                    if (childObject.name == anchorObjectName)
                    {
                        anchorContainerObject = childObject;
                        break;
                    }
                }
            }

            HarmonyAnchor[] anchorComponents = rootObject.GetComponentsInChildren <HarmonyAnchor>(true /*includeInactive*/);

            foreach (XML_Types.XML_AnchorMeta xmlAnchor in xmlAnchors)
            {
                if (!Array.Exists(anchorComponents, anchor => (anchor.playName == xmlAnchor._playName) && (anchor.nodeName == xmlAnchor._nodeName)))
                {
                    if (anchorContainerObject == null)
                    {
                        //  Create container game object from anchors child to renderer object.
                        anchorContainerObject = new GameObject(anchorObjectName);
                        anchorContainerObject.transform.parent = rootObject.transform;
                    }

                    GameObject anchorObject = new GameObject(xmlAnchor._nodeName);
                    anchorObject.transform.parent = anchorContainerObject.transform;

                    HarmonyAnchor anchorComponent = anchorObject.AddComponent <HarmonyAnchor>();

                    anchorComponent.playName = xmlAnchor._playName;
                    anchorComponent.nodeName = xmlAnchor._nodeName;
                }
            }
        }
    }